def ECRadRunner(cls, input_queue, output_queue): ECRad_inferface = ECRadF2PYInterface() while True: args = input_queue.get() try: command = args[0] if(command == "close"): break Results = args[1] if(Results.Config["Execution"]["batch"]): scratch_dir = Results.Config["Execution"]["scratch_dir"] Results.Scenario.to_netcdf(filename=os.path.join(scratch_dir, "Scenario.nc")) Results.Config.to_netcdf(filename=os.path.join(scratch_dir, "Config.nc")) run_ECRad = SetupECRadBatch(Results.Config, Results.Scenario, Results.Scenario["time"][args[2]]) ECRad_batch = Popen(run_ECRad) ECRad_batch.wait() try: filename, ed = Results.get_default_filename_and_edition(True) NewResults = ECRadResults(False) NewResults.from_netcdf(filename) NewResults.to_netcdf() output_queue.put([True, NewResults]) except: print("Failed to run remotely. Please check .o and .e files at") print(scratch_dir) output_queue.put([False, Results]) else: Results = ECRad_inferface.process_single_timepoint(Results, args[2]) output_queue.put([True, Results]) except Exception as e: print(e) output_queue.put([False, Results])
class ECRadDriver(): ''' Driver for ECRad. Passes information to ECRad, runs ECRad and extracts results ''' def __init__(self, Result=None, Scenario_file=None, Config_file=None): ''' Constructor ''' if (Result is None): if (Scenario_file is None or Config_file is None): raise ValueError( "Either result or a Scenario and Config file must be present" ) else: self.Result = ECRadResults() self.Result.Scenario = ECRadScenario(noLoad=True) self.Result.Scenario.load(Scenario_file) self.Result.Config = ECRadConfig(noLoad=True) self.Result.Config.load(Config_file) else: self.Result = Result self.ECRad_F2PY_interface = ECRadF2PYInterface() def run(self, id=None): itime = 0 self.Result.set_dimensions() while itime < self.Result.Scenario["dimensions"]["N_time"]: try: self.process_time_point(itime) itime += 1 except Exception as e: print("Error when processing t = {0:1.4f}".format( self.Result.Scenario["time"][itime])) print("Removing this time point and continuing") raise (e) self.Result.Scenario.drop_time_point(itime) self.Result.set_dimensions() self.Result.tidy_up(autosave=False) self.Result.to_netcdf(scratch=True, ed=id) def process_time_point(self, itime): self.Result = self.ECRad_F2PY_interface.process_single_timepoint( self.Result, itime)