Commit 7efad832 authored by karolina's avatar karolina
Browse files

removed need for dacycle from ct/obs, obspack, obspack_geocarbon

parent 4d0a98b3
......@@ -26,15 +26,15 @@ from da.baseclasses.obs import Observation
class CtObservations(Observation):
""" an object that holds data + methods and attributes needed to manipulate mixing ratio values """
def Initialize(self):
self.startdate = self.DaCycle['time.sample.start']
self.enddate = self.DaCycle['time.sample.end']
def Initialize(self, start, end, params):
self.startdate = start
self.enddate = end
sfname = self.DaCycle.DaSystem['obs.input.fname']
sfname = params['obs.input.fname']
if sfname.endswith('.nc'):
filename = os.path.join(self.DaCycle.DaSystem['obs.input.dir'], sfname)
filename = os.path.join(params['obs.input.dir'], sfname)
else:
filename = os.path.join(self.DaCycle.DaSystem['obs.input.dir'], sfname + '.' + self.startdate.strftime('%Y%m%d') + '.nc')
filename = os.path.join(params['obs.input.dir'], sfname + '.' + self.startdate.strftime('%Y%m%d') + '.nc')
if not os.path.exists(filename):
msg = 'Could not find the required observation input file (%s) ' % filename
......@@ -136,14 +136,14 @@ class CtObservations(Observation):
logging.debug("Added %d simulated values to the Data list" % (len(ids) - len(missing_samples)))
def write_sample_info(self):
def write_sample_info(self, dirinput, timestamp):
"""
Write the information needed by the observation operator to a file. Return the filename that was written for later use
"""
import da.tools.io4 as io
obsinputfile = os.path.join(self.DaCycle['dir.input'], 'observations_%s.nc' % self.DaCycle['time.sample.stamp'])
obsinputfile = os.path.join(dirinput, 'observations_%s.nc' % timestamp)
f = io.CT_CDF(obsinputfile, method='create')
logging.debug('Creating new observations file for ObservationOperator (%s)' % obsinputfile)
......@@ -241,7 +241,7 @@ class CtObservations(Observation):
return obsinputfile
def add_model_data_mismatch(self):
def add_model_data_mismatch(self, filename):
"""
Get the model-data mismatch values for this cycle.
......@@ -253,7 +253,7 @@ class CtObservations(Observation):
"""
import da.tools.rc as rc
filename = self.DaCycle.DaSystem['obs.sites.rc']
if not os.path.exists(filename):
msg = 'Could not find the required sites.rc input file (%s)' % filename
......@@ -314,14 +314,14 @@ class CtObservations(Observation):
self.SiteInfo = SiteInfo
def write_obs_to_file(self,filenam="oldstyle"):
def write_obs_to_file(self, outdir, timestamp, filenam="oldstyle"):
"""
Write selected information contained in the Observation object to a file.
"""
import da.tools.io4 as io
outfile = os.path.join(self.DaCycle['dir.output'], 'sampleinfo_%s__%s.nc' % (self.DaCycle['time.sample.stamp'], filenam))
outfile = os.path.join(outdir, 'sampleinfo_%s__%s.nc' % (timestamp, filenam))
f = io.CT_CDF(outfile, method='create')
logging.debug('Creating new Sample output file for postprocessing (%s)' % outfile)
......
......@@ -25,13 +25,13 @@ from da.baseclasses.obs import Observation
class ObsPackObservations(Observation):
""" an object that holds data + methods and attributes needed to manipulate mixing ratio values """
def Initialize(self):
def Initialize(self, start, end, params):
self.startdate = self.DaCycle['time.sample.start']
self.enddate = self.DaCycle['time.sample.end']
self.startdate = start
self.enddate = end
op_id = self.DaCycle.DaSystem['obspack.input.id']
op_dir = self.DaCycle.DaSystem['obspack.input.dir']
op_id = params['obspack.input.id']
op_dir = params['obspack.input.dir']
if not os.path.exists(op_dir):
msg = 'Could not find the required ObsPack distribution (%s) ' % op_dir
......@@ -147,14 +147,14 @@ class ObsPackObservations(Observation):
logging.debug("Added %d simulated values to the Data list" % (len(ids) - len(missing_samples)))
def write_sample_info(self):
def write_sample_info(self, dirinput, timestamp):
"""
Write the information needed by the observation operator to a file. Return the filename that was written for later use
"""
import da.tools.io4 as io
obsinputfile = os.path.join(self.DaCycle['dir.input'], 'observations_%s.nc' % self.DaCycle['time.sample.stamp'])
obsinputfile = os.path.join(dirinput, 'observations_%s.nc' % timestamp)
f = io.CT_CDF(obsinputfile, method='create')
logging.debug('Creating new observations file for ObservationOperator (%s)' % obsinputfile)
......@@ -253,7 +253,7 @@ class ObsPackObservations(Observation):
return obsinputfile
def add_model_data_mismatch(self):
def add_model_data_mismatch(self, filename):
"""
Get the model-data mismatch values for this cycle.
......@@ -266,7 +266,6 @@ class ObsPackObservations(Observation):
import da.tools.rc as rc
from da.tools.general import NameConvert
filename = self.DaCycle.DaSystem['obs.sites.rc']
if not os.path.exists(filename):
msg = 'Could not find the required sites.rc input file (%s) ' % filename
......@@ -340,14 +339,14 @@ class ObsPackObservations(Observation):
self.SiteInfo = SiteInfo
def write_obs_to_file(self):
def write_obs_to_file(self, outdir, timestamp):
"""
Write selected information contained in the Observation object to a file.
"""
import da.tools.io4 as io
outfile = os.path.join(self.DaCycle['dir.output'], 'sampleinfo_%s.nc' % self.DaCycle['time.sample.stamp'])
outfile = os.path.join(outdir, 'sampleinfo_%s.nc' % timestamp)
f = io.CT_CDF(outfile, method='create')
logging.debug('Creating new Sample output file for postprocessing (%s)' % outfile)
......
......@@ -24,13 +24,13 @@ from da.baseclasses.obs import Observation
class ObsPackObservations(Observation):
""" an object that holds data + methods and attributes needed to manipulate mixing ratio values """
def Initialize(self):
def Initialize(self, start, end, params):
self.startdate = self.DaCycle['time.sample.start']
self.enddate = self.DaCycle['time.sample.end']
self.startdate = start
self.enddate = end
op_id = self.DaCycle.DaSystem['obspack.input.id']
op_dir = self.DaCycle.DaSystem['obspack.input.dir']
op_id = params['obspack.input.id']
op_dir = params['obspack.input.dir']
if not os.path.exists(op_dir):
msg = 'Could not find the required ObsPack distribution (%s) ' % op_dir
......@@ -67,7 +67,7 @@ class ObsPackObservations(Observation):
items = line.split()
#ncfile, lab , start_date, stop_date, data_comparison = items[0:5]
ncfile, lab , start_date, stop_date, data_comparison= line[:105].split()
ncfile, lab, start_date, stop_date, data_comparison= line[:105].split()
ncfilelist += [ncfile]
......@@ -144,14 +144,14 @@ class ObsPackObservations(Observation):
logging.debug("Added %d simulated values to the Data list" % (len(ids) - len(missing_samples)))
def write_sample_info(self):
def write_sample_info(self, dirinput, timestamp):
"""
Write the information needed by the observation operator to a file. Return the filename that was written for later use
"""
import da.tools.io4 as io
obsinputfile = os.path.join(self.DaCycle['dir.input'], 'observations_%s.nc' % self.DaCycle['time.sample.stamp'])
obsinputfile = os.path.join(dirinput, 'observations_%s.nc' % timestamp)
f = io.CT_CDF(obsinputfile, method='create')
logging.debug('Creating new observations file for ObservationOperator (%s)' % obsinputfile)
......@@ -253,7 +253,7 @@ class ObsPackObservations(Observation):
return obsinputfile
def add_model_data_mismatch(self):
def add_model_data_mismatch(self, filename):
"""
Get the model-data mismatch values for this cycle.
......@@ -265,7 +265,7 @@ class ObsPackObservations(Observation):
"""
import da.tools.rc as rc
filename = self.DaCycle.DaSystem['obs.sites.rc']
if not os.path.exists(filename):
msg = 'Could not find the required sites.rc input file (%s) ' % filename
......@@ -350,14 +350,14 @@ class ObsPackObservations(Observation):
logging.debug("Added Model Data Mismatch to all samples ")
def write_obs_to_file(self,filenam="oldstyle"):
def write_obs_to_file(self, outdir, timestamp, filenam="oldstyle"):
"""
Write selected information contained in the Observation object to a file.
"""
import da.tools.io4 as io
outfile = os.path.join(self.DaCycle['dir.output'], 'sampleinfo_%s__%s.nc' % (self.DaCycle['time.sample.stamp'], filenam))
outfile = os.path.join(outdir, 'sampleinfo_%s__%s.nc' % (timestamp, filenam))
f = io.CT_CDF(outfile, method='create')
logging.debug('Creating new Sample output file for postprocessing (%s)' % outfile)
......
......@@ -78,7 +78,7 @@ def prepare_state(DaCycle, StateVector, newrc):
date = DaCycle['time.start'] + datetime.timedelta(days=(n + 0.5) * int(DaCycle['time.cycle']))
#LU ta data jest tutaj potrzebna tylko do znalezienia odpowiedniego pliku z kowariancja.
svparams = {k: newrc[k] for k in ('ocn.covariance', 'bio.covariance')}
cov = StateVector.get_covariance(date, svparams)
cov = StateVector.get_covariance(date, svparams) #LU to mozna zrobic w srodku, bo przeciez nie potrzebna mu ta kowariancja a z drugiej strony zawsze potrzebuje kowariancji zeby stworzyc nowa ensemble
StateVector.make_new_ensemble(n + 1, cov)
else:
......@@ -188,15 +188,16 @@ def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, newrc,
#LU Samples.Initialize(newrc, startdate, enddate)
Samples.Initialize() #LU to daje przede wszystkim zresetowanie data list. czyli to znaczy ze data list jest za kazdym razem nowa przy odpalaniu nowego stepu. czyli jeszcze innymi slowy, nowy obiekt observations, no moze ma te same params...
obsparams = {k: newrc[k] for k in ('obs.input.fname', 'obs.input.dir', 'obspack.input.dir', 'obspack.input.id')}
Samples.Initialize(startdate, enddate, obsparams) #LU to daje przede wszystkim zresetowanie data list. czyli to znaczy ze data list jest za kazdym razem nowa przy odpalaniu nowego stepu. czyli jeszcze innymi slowy, nowy obiekt observations, no moze ma te same params...
#LU nie potrzebuje nic z dat
Samples.add_observations() #LU wydaje mi sie ze tutaj za kazdym stepem wczytywany jest cale observations --> nie, jest subselect po self.startdate i self.enddate (ustawione wczesniej w initialize)
# Add model-data mismatch to all samples, this *might* use output from the ensemble in the future??
Samples.add_model_data_mismatch()
filename = Samples.write_sample_info() #LU observations.nc
Samples.add_model_data_mismatch(DaCycle.DaSystem['obs.sites.rc'])
filename = Samples.write_sample_info(DaCycle['dir.input'], DaCycle['time.sample.stamp']) #LU observations.nc
# Write filename to DaCycle, and to output collection list
......@@ -224,7 +225,7 @@ def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, newrc,
# Now write a small file that holds for each observation a number of values that we need in postprocessing
filename = Samples.write_sample_info() #LU NIEPOTRZEBNE
#filename = Samples.write_sample_info() #LU NIEPOTRZEBNE
# Now add the observations that need to be assimilated to the StateVector.
# Note that obs will only be added to the statevector if either this is the first step (restart=False), or lag==nlag
......@@ -243,7 +244,7 @@ def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, newrc,
StateVector.ObsToAssimmilate += (None,)
#LU tego nie ma w oryginalnym kodzie
if isadvance:
Samples.write_obs_to_file("newstyle")
Samples.write_obs_to_file(DaCycle['dir.output'], DaCycle['time.sample.stamp'], "newstyle")
def invert(DaCycle, StateVector, Optimizer):
......@@ -290,7 +291,7 @@ def advance(DaCycle, Samples, StateVector, ObservationOperator, newrc):
#LU skoro w srodku sample step jest inicjalizowanie samples przez przypisanie datalist=[], to czy ten obiekt samples ma jkaies podobiekty ktore kaza mu byc przekazywanym?
# Write info from optimized flux cycle to a file
Samples.write_obs_to_file()
Samples.write_obs_to_file(DaCycle['dir.output'], DaCycle['time.sample.stamp'])
def save_and_submit(DaCycle, StateVector):
......
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