def run_model(self, print_output=True): """Runs the LUMPREM on model. """ model_name = self.lumprem_model_name path = self.workspace run.run_process( 'lumprem', commands=['lr_' + model_name + '.in', 'lr_' + model_name + '.out'], path=path, print_output=print_output)
def run_simulation(self): """Runs LUMPREM on models created using LUMPREP in the Simulation object. """ for model in self.model_list: model_name = model.lumprem_model_name run.run_process('lumprem', commands=[ 'lr_' + model_name + '.in', 'lr_' + model_name + '.out' ], path=self.workspace)
def write_ts(self): """Writes the MODFLOW6 timeseries file. Parameters ---------- """ #number of columns to include in the ts file count = len(self.lumprem_output_cols) ts_file = os.path.join(self.workspace, self.ts_file + '.in') with open(ts_file, 'w') as f: for i in range(len(self.lr_models)): sel_tsnames = self.ts_names[i::len(self.lr_models)] model = self.lr_models[i] model_name = model.lumprem_model_name f.write('READ_LUMPREM_OUTPUT_FILE lr_' + model_name + '.out ' + str(count) + '\n') f.write( '# my_name LUMPREM_name divide_by_delta_t?\n\n') for col in range(count): f.write("\t{0}\t\t{1}\t\t{2}".format( sel_tsnames[col], self.lumprem_output_cols[col], self.div_delta[col] + '\n')) f.write('\n\n') f.write('WRITE_MF6_TIME_SERIES_FILE ' + self.ts_file + ' ' + str(count * len(self.lr_models)) + ' ' + str(self.timeoffset) + '\n') f.write("#\t{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}".format( 'ts_name', 'scale', 'offset', 'mf6method', 'time_offset_method\n\n')) for i in range(len(self.lr_models)): sel_tsnames = self.ts_names[i::len(self.lr_models)] model = self.lr_models[i] model_name = model.lumprem_model_name for col in range(count): f.write("\t{0}\t\t{1}\t\t{2}\t\t{3}\t{4}\t{5}".format( sel_tsnames[col], self.scales[col], self.offsets[col], self.methods[col], self.time_offset_method[col], '#' + model_name + '\n')) f.close() print('MF6 timeseries file ' + ts_file + ' written to:\n' + ts_file) #write ts file filename = self.ts_file path = self.workspace run.run_process('lr2series', commands=[filename + '.in'], path=path)
def run_model(self, print_output=True, version=1): """Runs the LUMPREM on model. Parameters ---------- print_output : boolean, optional optionaly print LUMPREM output to screen version : int, optional determines whether LUMPREM or LUMPREM2 is called. Note that if LUMPREM2 parameters are used in the input files an error will be returned """ model_name = self.lumprem_model_name path = self.workspace if version==1: exe = 'lumprem' if version==2: exe = 'lumprem2' run.run_process(exe, commands=['lr_'+model_name+'.in','lr_'+model_name+'.out','lr_'+model_name+'.csv'],path=path, print_output=print_output)
def write_simulation(self, infile='lumprep.in'): """Writes the LUMPREP input file from the Simulation object. Parameters ---------- infile : str filename for the LUMPREP input file (default 'lumprep.in') """ infile = os.path.join(self.workspace, infile) if not os.path.exists(self.workspace): os.makedirs(self.workspace) unique_keys = ['start_date', 'end_date', 'nday_out', 'steps_per_day'] selfdict = self.__dict__ with open(infile, 'w') as f: f.write('# File created using lumpyrem. \n\n') for key in unique_keys: f.write("{0:} {1:}\n".format(key.upper(), selfdict[key])) f.write('\n') f.close() #write models to lumprep input file count = 0 for model in self.model_list: model_dict = model.__dict__ count = count + 1 with open(infile, 'a') as f: f.write('# Lumprem dataset number ' + str(count) + '\n') f.write("{0: <32} {1:}{2:}".format( 'SILOFILE', self.silofile[0], '\t' + str(self.silofile[1]) + '\n')) #f.write("{0: <32} {1:}{2:}".format('RAINFILE', os.path.join(self.workspace,'rain.dat'),'\n')) #f.write("{0: <32} {1:}{2:}".format('EPOTFILE', os.path.join(self.workspace,'epot.dat'),'\n')) for key in model_dict: if type(model_dict[key]) == tuple: input1 = model_dict[key][0] input2 = model_dict[key][1] else: input1 = model_dict[key] input2 = '' if input1 == None: continue if key in ['workspace', 'elevmin', 'elevmax']: #, 'rainfile','epotfile']: continue f.write("{0: <32}{1:}{2:}".format( key.upper(), str(input1), '\t' + str(input2) + '\n')) f.write('\n') with open(infile, 'a') as f: f.write("{0: <32} {1:}{2:}".format('BATCH_FILE_NAME', self.batch_file, '\n')) f.write("{0: <32} {1:}{2:}".format('PEST_CONTROL_FILE', self.pest_control_file, '\n')) f.write('\n') f.close() lumprepin = os.path.basename(infile) run.run_process('lumprep', commands=[lumprepin], path=self.workspace)