From bc392c94ce4cffa6dda3d63225aa1cdd570aa9dc Mon Sep 17 00:00:00 2001 From: karolina <amvdw95@gmail.com> Date: Thu, 6 Jun 2013 15:43:45 +0000 Subject: [PATCH] removed checking for rc filetype, as it is always pycasso --- gridded/da/tm5/observationoperator.py | 105 +++++++++----------------- 1 file changed, 34 insertions(+), 71 deletions(-) diff --git a/gridded/da/tm5/observationoperator.py b/gridded/da/tm5/observationoperator.py index 994164a..5d62cdb 100755 --- a/gridded/da/tm5/observationoperator.py +++ b/gridded/da/tm5/observationoperator.py @@ -63,26 +63,18 @@ class TM5ObservationOperator(ObservationOperator): """ - def __init__(self, RcFileName, DaCycle=None): + def __init__(self, filename): """ The instance of an TMObservationOperator is application dependent """ self.Identifier = identifier # the identifier gives the model name self.Version = version # the model version used self.RestartFileList = [] self.OutputFileList = [] - self.RcFileType = 'None' + self.outputdir = None # Needed for opening the samples.nc files created - self.load_rc(RcFileName) # load the specified rc-file + self.load_rc(filename) # load the specified rc-file self.validate_rc() # validate the contents - # The following code allows the object to be initialized with a DaCycle object already present. Otherwise, it can - # be added at a later moment. - - if DaCycle != None: - self.DaCycle = DaCycle - else: - self.DaCycle = {} - logging.info('Observation Operator initialized: %s (%s)' % (self.Identifier, self.Version)) def initialize(self, DaCycle): @@ -101,7 +93,7 @@ class TM5ObservationOperator(ObservationOperator): # Create the TM5 run directory to hold a copy of the modified rc-file - tm5compiledir = self.tm_settings[self.rundirkey] + tm5compiledir = self.tm_settings['my.run.dir'] create_dirs(tm5compiledir) rcfilename = os.path.join(tm5compiledir, 'tm5_setup_init.rc') @@ -125,7 +117,7 @@ class TM5ObservationOperator(ObservationOperator): logging.debug('Reloading the da.obsoperator.rc file for this DaCycle') - self.load_rc(self.DaCycle['da.obsoperator.rc']) #LU czy tutaj jest to kiedykolwiek zapisywane? chyba tak, jak zapisujemy daCycle... + self.load_rc(self.DaCycle['da.obsoperator.rc']) logging.debug('Note that the obsoperator is not recompiled if this is a recovery from a crash!!!') @@ -178,8 +170,8 @@ class TM5ObservationOperator(ObservationOperator): NewItems = { 'submit.options': DaPlatForm.give_blocking_flag(), - self.timestartkey: self.DaCycle['time.sample.start'], - self.timefinalkey: self.DaCycle['time.sample.end'], + 'timerange.start': self.DaCycle['time.sample.start'], + 'timerange.end': self.DaCycle['time.sample.end'], 'jobstep.timerange.start': self.DaCycle['time.sample.start'], 'jobstep.timerange.end': self.DaCycle['time.sample.end'], 'jobstep.length': 'inf', @@ -190,10 +182,10 @@ class TM5ObservationOperator(ObservationOperator): } if self.DaCycle['time.restart']: # If this is a restart from a previous cycle, the TM5 model should do a restart - NewItems[self.istartkey] = self.restartvalue + NewItems['istart'] = self.restartvalue logging.debug('Resetting TM5 to perform restart') else: - NewItems[self.istartkey] = self.coldstartvalue # if not, start TM5 'cold' + NewItems['istart'] = self.coldstartvalue # if not, start TM5 'cold' logging.debug('Resetting TM5 to perform cold start') #LU to ponizej: po prostu jesli to jest inny lag niz pierwszy #LU czyli: restart wtedy kiedy albo time.restart = true czyli w kazdym nastepnym cyklu, albo kiedy jest to nie pierwszy step w sample step. tylko wtedy to skad robimy restart sie rozni...czy nie , bo robimy po advance? @@ -201,7 +193,7 @@ class TM5ObservationOperator(ObservationOperator): #LU ale: nowy RC zapisywany jst przy koncu cyklu. czyli time. sample.window bedzie zawsze 0. if self.DaCycle['time.sample.window'] != 0: # If this is a restart from a previous time step within the filter lag, the TM5 model should do a restart - NewItems[self.istartkey] = self.restartvalue + NewItems['istart'] = self.restartvalue logging.debug('Resetting TM5 to perform restart') # If neither one is true, simply take the istart value from the tm5.rc file that was read @@ -209,20 +201,16 @@ class TM5ObservationOperator(ObservationOperator): self.modify_rc(NewItems) self.write_rc(self.RcFileName) - def load_rc(self, RcFileName):#LU tutaj bylo wczesniej rcfIletype. to znaczy ze pewnie zawsze bylo pycasso. bo wpp byloby blad. + def load_rc(self, name):#LU tutaj bylo wczesniej rcfIletype. to znaczy ze pewnie zawsze bylo pycasso. bo wpp byloby blad. """ This method loads a TM5 rc-file with settings for this simulation """ import da.tools.rcn as rc - self.rcfile = rc.RcFile(RcFileName) + self.rcfile = rc.RcFile(name) self.tm_settings = self.rcfile.values - self.RcFileName = RcFileName - self.Tm5RcLoaded = True #LU to wyglada na zupelnie niepotrzebne - if 'my.source.dirs' in self.tm_settings.keys(): - self.RcFileType = 'pycasso' - else: - self.RcFileType = 'pre-pycasso' + self.RcFileName = name + logging.debug('TM5 rc-file loaded successfully') def validate_rc(self): @@ -230,40 +218,18 @@ class TM5ObservationOperator(ObservationOperator): Validate the contents of the tm_settings dictionary and add extra values. The required items for the TM5 rc-file are specified in the tm5_tools module, as dictionary variable "needed_rc_items". """ - - - if self.RcFileType == 'pycasso': - self.projectkey = 'my.project.dir' - self.rundirkey = 'my.run.dir' - self.outputdirkey = 'output.dir' - self.savedirkey = 'restart.write.dir' - self.timestartkey = 'timerange.start' - self.timefinalkey = 'timerange.end' - self.timelengthkey = 'jobstep.length' - self.istartkey = 'istart' - self.restartvalue = 33 - self.coldstartvalue = 9 - else: - self.projectkey = 'runid' - self.rundirkey = 'rundir' - self.outputdirkey = 'outputdir' - self.savedirkey = 'savedir' - self.timestartkey = 'time.start' - self.timefinalkey = 'time.final' - self.timelengthkey = 'time.break.nday' - self.istartkey = 'istart' - self.restartvalue = 3 - self.coldstartvalue = 9 + self.restartvalue = 33 + self.coldstartvalue = 9 needed_rc_items = [ - self.projectkey, - self.rundirkey, - self.outputdirkey, - self.savedirkey, - self.timestartkey, - self.timefinalkey, - self.timelengthkey, - self.istartkey + 'my.project.dir', + 'my.run.dir', + 'output.dir', + 'restart.write.dir', + 'timerange.start', + 'timerange.end', + 'jobstep.length', + 'istart' ] for k, v in self.tm_settings.iteritems(): @@ -280,7 +246,6 @@ class TM5ObservationOperator(ObservationOperator): self.tm_settings[k] = to_datetime(v) for key in needed_rc_items: - if not self.tm_settings.has_key(key): msg = 'Missing a required value in rc-file : %s' % key logging.error(msg) @@ -357,12 +322,10 @@ class TM5ObservationOperator(ObservationOperator): # Next, make sure there is an actual model version compiled and ready to execute - targetdir = os.path.join(self.tm_settings[self.rundirkey]) + targetdir = os.path.join(self.tm_settings['my.run.dir']) - if self.RcFileType == 'pycasso': - self.Tm5Executable = os.path.join(targetdir, self.tm_settings['my.basename'] + '.x') - else: - self.Tm5Executable = os.path.join(targetdir, 'tm5.x') + + self.Tm5Executable = os.path.join(targetdir, self.tm_settings['my.basename'] + '.x') if not os.path.exists(self.Tm5Executable): logging.error("Required TM5 executable was not found %s" % self.Tm5Executable) @@ -386,8 +349,8 @@ class TM5ObservationOperator(ObservationOperator): # First get the restart data for TM5 from the current restart dir of the filter sourcedir = self.DaCycle['dir.restart'] - targetdir = self.tm_settings[self.savedirkey] - self.outputdir = self.tm_settings[self.outputdirkey] #IV test + targetdir = self.tm_settings['restart.write.dir'] + self.outputdir = self.tm_settings['output.dir'] #IV test for f in os.listdir(sourcedir): fpath = os.path.join(sourcedir, f) @@ -458,7 +421,7 @@ class TM5ObservationOperator(ObservationOperator): """ Method handles the case where a shell runs an MPI process that forks into N TM5 model instances """ DaPlatForm = self.DaCycle.DaPlatForm - targetdir = os.path.join(self.tm_settings[self.rundirkey]) + targetdir = os.path.join(self.tm_settings['my.run.dir']) if not os.path.exists(os.path.join(mpi_shell_location, mpi_shell_filename)): logging.error("Cannot find the mpi_shell wrapper needed for completion (%s) in (%s)" % (mpi_shell_filename, mpi_shell_location)) @@ -513,7 +476,7 @@ class TM5ObservationOperator(ObservationOperator): """ Method handles the case where one TM5 model instance with N tracers does the sampling of all ensemble members""" - tm5submitdir = os.path.join(self.tm_settings[self.rundirkey]) + tm5submitdir = os.path.join(self.tm_settings['my.run.dir']) logging.info('tm5submitdir', tm5submitdir) # Go to executable directory and start the subprocess, using a new logfile @@ -558,8 +521,8 @@ class TM5ObservationOperator(ObservationOperator): Note 2: also adding the weekly mean flux output to the OutputFileList for later collection """ - sourcedir = os.path.join(self.tm_settings[self.savedirkey]) - filterlist = ['%s' % self.tm_settings[self.timefinalkey].strftime('%Y%m%d')] + sourcedir = os.path.join(self.tm_settings['restart.write.dir']) + filterlist = ['%s' % self.tm_settings['timerange.end'].strftime('%Y%m%d')] logging.debug("Creating a new list of TM5 restart data") logging.debug(" from directory: %s " % sourcedir) @@ -591,7 +554,7 @@ class TM5ObservationOperator(ObservationOperator): self.RestartFileList.append(fil) logging.debug(" [added to restart list] .... %s " % fil) - sourcedir = os.path.join(self.tm_settings[self.outputdirkey]) + sourcedir = os.path.join(self.tm_settings['output.dir']) sd_ed = self.DaCycle['time.sample.stamp'] filterlist = ['flask_output.%s' % sd_ed, 'flux1x1_%s' % sd_ed] -- GitLab