Page MenuHomec4science

potential_shortening.py
No OneTemporary

File Metadata

Created
Wed, Nov 20, 13:29

potential_shortening.py

import numpy as np
from collections import defaultdict
class Consts:
def __init__(self, fname):
self.nlayer, self.nsp, self.nhl0, self.nhl1, self.lines = self.read(fname)
def read(self, fname):
with open(fname) as fh:
line = fh.__next__()
line_read = tuple((int(item) for item in line.split()))
nlayer, nsp, nhl0, nhl1 = line_read
lines = []
for i in range(nhl0):
lines.append(fh.__next__())
return *line_read, lines
def reformulate(self, outfname, nhl0_div, nhl1_div):
with open(outfname) as fh:
print(
"\t{}\t{}\t{}\t{}".format(
self.nlayer, self.nsp,
self.nhl0/nhl0_div, self.nhl1/nhl1_div),
file=fh)
for i in range(self.nhl0/nhl0_div):
print(self.lines[i*nhl0_div], file=fh)
class Params:
def __init__(self, fname):
self.nb_comb, self.r1, self.r2, self.lines = self.read(fname)
def read(self, fname):
with open(fname) as fh:
line = fh.__next__()
line_read = tuple((int(item) for item in line.split()))
n_comb, r1, r2 = line_read
lines = [line for line in fh]
return n_comb, r1, r2, lines
def reformulate(self, outfname, nhl0_div, nhl1_div):
with open(outfname) as fh:
print(
"\t{}\t{}\t{}".format(
self.nb_comb/nhl0_div/nhl1_div,
self.r1, self.r2), file=fh)
n0 = self.nhl0/nhl0_div
n1 = self.nhl1/nhl1_div
for i0 in range(n0):
for i1 in range(n1):
print(self.lines[i0*nhl0_div*self.nhl1 + i1*nhl1_div],
file= fh)
def main():
cfname = 'in.const.NN'
pfname = 'in.params.NN'
suffix = '_short'
ocfname = cfname + suffix
opfname = cpname + suffix
div0 = 5
div1 = 10
Const(cfname).reformulate(ocfname, div0, div1)
Params(cpname).reformulate(opfname, div0, div1)
if __name__ == "__main__":
main()

Event Timeline