Commit 440a0da9 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

slight changes to how start/end time are advanced, no consequences, just more clear...

parent 263573c0
......@@ -87,6 +87,8 @@ def AdvanceTime(time_in,interval):
time_out = datetime.datetime(time_in.year+1,1,1,time_in.hour,0,0) # end of year provision
elif interval == 'week':
time_out = time_in + datetime.timedelta(days=7)
elif isinstance(interval,datetime.timedelta):
time_out = time_in + interval
else: # assume that the interval specified is the number of days to run forward before resubmitting
time_out = time_in + datetime.timedelta(days=float(interval))
......
......@@ -149,9 +149,9 @@ class CycleControl(dict):
from da.tools.general import ToDatetime
for k,v in self.iteritems():
if v in ['True','true', '1', 't','T', 'y', 'yes']:
if v in ['True','true', 't','T', 'y', 'yes']:
self[k] = True
if v in ['False','false', '0', 'f','F', 'n', 'no']:
if v in ['False','false', 'f','F', 'n', 'no']:
self[k] = False
if 'date' in k : self[k] = ToDatetime(v)
if 'time.start' in k :
......@@ -199,6 +199,8 @@ class CycleControl(dict):
else:
enddate = AdvanceTime(startdate,cyclelength)
dt = enddate-startdate
#
if enddate > finaldate: # do not run beyon finaldate
enddate = finaldate
......@@ -206,7 +208,7 @@ class CycleControl(dict):
self['time.start'] = startdate
self['time.end'] = enddate
self['time.finish'] = finaldate
self['cyclelength'] = cyclelength
self['cyclelength'] = dt
msg = "===============================================================" ; logging.info(msg)
msg = "DA Cycle start date is %s" % startdate.strftime('%Y-%m-%d %H:%M') ; logging.info(msg)
......@@ -218,6 +220,63 @@ class CycleControl(dict):
return None
def SetSampleTimes(self,lag):
"""
Set the times over which a sampling interval will loop, depending on
the lag. Note that lag falls in the interval [0,nlag-1]
"""
import copy
# Start from cycle times
self['time.sample.start'] = copy.deepcopy(self['time.start'])
self['time.sample.end'] = copy.deepcopy(self['time.end'])
# Now advance depending on lag
for l in range(lag):
dummy = self.AdvanceSampleTimes()
return None
def AdvanceSampleTimes(self):
"""
Advance sampling start and end time by one cycle interval
"""
from da.tools.general import AdvanceTime
startdate = self['time.sample.start']
enddate = self['time.sample.end']
cyclelength = self['cyclelength']
startdate = AdvanceTime(startdate,cyclelength.days)
enddate = AdvanceTime(enddate,cyclelength.days)
self['time.sample.start'] = startdate
self['time.sample.end'] = enddate
return None
def AdvanceCycleTimes(self):
"""
Advance cycle start and end time by one cycle interval
"""
from da.tools.general import AdvanceTime
startdate = self['time.start']
enddate = self['time.end']
cyclelength = self['cyclelength']
startdate = AdvanceTime(startdate,cyclelength.days)
enddate = AdvanceTime(enddate,cyclelength.days)
filtertime = startdate.strftime('%Y%m%d')
self['dir.output'] = os.path.join(self['dir.da_run'],'output',filtertime)
self['time.start'] = startdate
self['time.end'] = enddate
return None
def RandomSeed(self,action='read'):
"""
Get the randomseed and save it, or read the random seed and set it. The seed is currently stored
......@@ -425,9 +484,9 @@ class CycleControl(dict):
# Re-create the output dir for this time step, if needed
filtertime = self['time.start'].strftime('%Y%m%d')
filtertime = self['time.start'].strftime('%Y%m%d')
self['dir.output'] = os.path.join(self['dir.da_run'],'output',filtertime)
CreateDirs(os.path.join(self['dir.output']))
dummy = CreateDirs(os.path.join(self['dir.output']))
return None
......@@ -591,28 +650,27 @@ class CycleControl(dict):
The resulting rc-file is written to the ``dir.exec`` so that it can be used when resubmitting the next cycle
"""
from da.tools.general import AdvanceTime
import da.tools.rc as rc
import copy
# These first two lines advance the filter time for the next cycle
# We make a copy of the current DaCycle object, and modify the start + end dates and restart value
self['time.start'] = self['time.end']
self['time.end'] = AdvanceTime(self['time.end'],self['cyclelength'])
newDaCycle = copy.deepcopy(self)
dummy = newDaCycle.AdvanceCycleTimes()
newDaCycle['time.restart'] = True
# The rest is info needed for a system restart
# Create the name of the rc-file that will hold this new input, and write it
self['time.restart'] = True
#self['time.start'] = self['time.start'].strftime('%Y-%m-%d %H:%M:%S')
#self['time.finish'] = self['time.finish'].strftime('%Y-%m-%d %H:%M:%S')
fname = os.path.join(self['dir.exec'],'da_runtime.rc') # current exec dir holds next rc file
dummy = rc.write(fname,newDaCycle)
msg = 'Wrote new da_runtime.rc (%s) to exec dir'%fname ; logging.debug(msg)
fname = os.path.join(self['dir.exec'],'da_runtime.rc')
self['da.restart.fname'] = fname
dummy = rc.write(fname,self)
# The rest is info needed for a system restart, so it modifies the current DaCycle object (self)
dummy = self.RestartFileList.extend([fname])
self['da.restart.fname'] = fname # needed for next job template
dummy = self.RestartFileList.extend([fname]) # current restart list holds next rc file name
msg = 'Added da_runtime.rc to the RestartFileList for later collection' ; logging.debug(msg)
msg = 'Wrote new da_runtime.rc (%s) to exec dir'%fname ; logging.debug(msg)
def WriteRC(self,fname):
......@@ -643,7 +701,7 @@ class CycleControl(dict):
if self['time.start'] < self['time.finish']:
# file ID and names
jobid = self['time.start'].strftime('%Y%m%d')
jobid = self['time.end'].strftime('%Y%m%d')
targetdir = os.path.join(self['dir.exec'])
jobfile = os.path.join(targetdir,'jb.%s.jb'%jobid)
logfile = jobfile.replace('.jb','.log')
......
......@@ -56,12 +56,7 @@ def EnsembleSmootherPipeline(DaCycle,PlatForm, DaSystem, Samples,StateVector,Obs
dummy = SaveAndSubmit(DaCycle, StateVector)
msg = "Cycle finished...exiting" ; logging.info(msg)
dummy = DaCycle.CleanUpCycle()
sys.exit(0)
msg = "Cycle finished...exiting pipeline" ; logging.info(msg)
####################################################################################################
......@@ -152,27 +147,20 @@ def SampleState(DaCycle,Samples,StateVector, ObservationOperator):
def SampleOneCycle(DaCycle,Samples,StateVector, ObservationOperator,lag):
""" Perform all actions needed to sample one cycle """
from da.tools.general import AdvanceTime
import copy
# First set up the information for time start and time end of this sample
cyclelen = DaCycle['cyclelength']
if lag == 0:
startdate = DaCycle['time.start']
dummy = ObservationOperator.GetInitialData()
else:
startdate = DaCycle['time.sample.start']
enddate = AdvanceTime(startdate,cyclelen)
dummy = DaCycle.SetSampleTimes(lag)
DaCycle['time.sample.start'] = startdate
DaCycle['time.sample.end'] = enddate
DaCycle['time.sample.window'] = lag
DaCycle['time.sample.stamp'] = "%s_%s"%(startdate.strftime("%Y%m%d%H"),enddate.strftime("%Y%m%d%H"),)
startdate = DaCycle['time.sample.start']
enddate = DaCycle['time.sample.end']
DaCycle['time.sample.window'] = lag
DaCycle['time.sample.stamp'] = "%s_%s"%(startdate.strftime("%Y%m%d%H"),enddate.strftime("%Y%m%d%H"),)
msg = "New simulation interval set : " ; logging.info(msg)
msg = " start date : %s " % startdate.strftime('%F %H:%M') ; logging.info(msg)
......@@ -247,11 +235,6 @@ def SampleOneCycle(DaCycle,Samples,StateVector, ObservationOperator,lag):
msg = "StateVector now carries %d samples"%StateVector.nobs ; logging.debug(msg)
# Advance the sample time
startdate = AdvanceTime( startdate, cyclelen)
DaCycle['time.sample.start'] = startdate
return None
def Invert(DaCycle, StateVector, Optimizer ):
......@@ -337,7 +320,7 @@ def RunForecastModel(DaCycle,ObsOperator):
status = ObsOperator.ValidateInput()
status = ObsOperator.Run()
#status = ObsOperator.Run()
dummy = ObsOperator.SaveData()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment