Commit d30e2d5e authored by karolina's avatar karolina
Browse files

removed StateVector.isOptimized and replaced with an "optimized" parameter in...

removed StateVector.isOptimized and replaced with an "optimized" parameter in StateVector.write_to_file call

in obs and obspack_geocarbon adding some parameters to function calls
parent 51a698e1
......@@ -148,7 +148,6 @@ class Optimizer(object):
for m, mem in enumerate(members):
members[m].ParameterValues[:] = self.X_prime[n * self.nparams:(n + 1) * self.nparams, m] + self.x[n * self.nparams:(n + 1) * self.nparams]
StateVector.isOptimized = True
logging.debug('Returning optimized data to the StateVector, setting "StateVector.isOptimized = True" ')
def write_diagnostics(self, DaCycle, StateVector, type='prior'):
......
......@@ -143,7 +143,6 @@ class StateVector(object):
self.nparams = int(self.DaCycle.DaSystem['nparameters'])
self.nobs = 0
self.isOptimized = False
self.ObsToAssimmilate = () # empty containter to hold observations to assimilate later on
# These list objects hold the data for each time step of lag in the system. Note that the ensembles for each time step consist
......@@ -308,7 +307,7 @@ class StateVector(object):
logging.info('The state vector has been propagated by one cycle')
def write_to_file(self, filename):
def write_to_file(self, filename, optimized):
"""
:param filename: the full filename for the output NetCDF file
:rtype: None
......@@ -326,7 +325,7 @@ class StateVector(object):
#import da.tools.io4 as io
#import da.tools.io as io
if not self.isOptimized:
if not optimized:
f = io.CT_CDF(filename, method='create')
logging.debug('Creating new StateVector output file (%s)' % filename)
qual = 'prior'
......
......@@ -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,7 +314,7 @@ class CtObservations(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.
......@@ -322,7 +322,8 @@ class CtObservations(Observation):
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)
......
......@@ -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
......@@ -360,7 +360,7 @@ class ObsPackObservations(Observation):
logging.debug("Added Model Data Mismatch to all samples ")
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.
......@@ -368,6 +368,8 @@ class ObsPackObservations(Observation):
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)
......
......@@ -56,12 +56,12 @@ def forward_pipeline(DaCycle, PlatForm, DaSystem, Samples, StateVector, ObsOpera
else:
prepare_state(DaCycle, StateVector)
StateVector.isOptimized = False
# Write as prior fluxes to output dir
savefilename = os.path.join(DaCycle['dir.output'], 'savestate.nc') #LU to jest state vector po zoptymalizowaniu.
StateVector.write_to_file(savefilename)
StateVector.write_to_file(savefilename, False)
# Now read optimized fluxes to propagate
......@@ -70,7 +70,6 @@ def forward_pipeline(DaCycle, PlatForm, DaSystem, Samples, StateVector, ObsOpera
else:
StateVector.read_from_file(savefilename, 'prior')
StateVector.isOptimized = True
# Run forward with these parameters
......@@ -131,7 +130,7 @@ def prepare_state(DaCycle, StateVector):
# Finally, also write the StateVector to a file so that we can always access the a-priori information
filename = os.path.join(DaCycle['dir.output'], 'savestate.nc')
StateVector.write_to_file(filename) # write prior info because StateVector.Isoptimized == False for now
StateVector.write_to_file(filename, False) # write prior info because StateVector.Isoptimized == False for now
def sample_state(DaCycle, Samples, StateVector, ObservationOperator):
""" Sample the filter state for the inversion """
......@@ -162,7 +161,7 @@ def sample_state(DaCycle, Samples, StateVector, ObservationOperator):
logging.debug("StateVector now carries %d samples" % StateVector.nobs)
def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, isadvance=False):
def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag):
""" Perform all actions needed to sample one cycle """
......@@ -190,7 +189,7 @@ def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, isadvan
# Add model-data mismatch to all samples, this *might* use output from the ensemble in the future??
Samples.add_model_data_mismatch()
Samples.add_model_data_mismatch(DaCycle.DaSystem['obs.sites.rc'])
filename = Samples.write_sample_info() #LU observations.nc
# Write filename to DaCycle, and to output collection list
......@@ -201,11 +200,6 @@ def sample_step(DaCycle, Samples, StateVector, ObservationOperator, lag, isadvan
run_forecast_model(DaCycle, ObservationOperator)
# Add model-data mismatch to all samples, this *might* use output from the ensemble in the future??
#Samples.add_model_data_mismatch()
#msg = "Added Model Data Mismatch to all samples " ; logging.debug(msg)
# Read forecast model samples that were written to NetCDF files by each member. Add them to the exisiting
# Observation object for each sample loop. This data fill be written to file in the output folder for each sample cycle.
......@@ -280,7 +274,7 @@ def advance(DaCycle, Samples, StateVector, ObservationOperator):
ObservationOperator.get_initial_data()
sample_step(DaCycle, Samples, StateVector, ObservationOperator, 0, True) #LU w srodku zmienia zawartosc obiektu samples
sample_step(DaCycle, Samples, StateVector, ObservationOperator, 0) #LU w srodku zmienia zawartosc obiektu samples
#LU ale z drugiej strony dodaje tez pozniej samples, to tak jakby chcial na nowo dodac ...
#LU a to dlatego ze samples jest inicjalizowane na nowo.
#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?
......@@ -293,7 +287,7 @@ def advance(DaCycle, Samples, StateVector, ObservationOperator):
logging.debug("Appended Observation filename to DaCycle for collection ")
Samples.write_obs_to_file()
Samples.write_obs_to_file(DaCycle['dir.output'], DaCycle['time.sample.stamp'])
def save_and_submit(DaCycle, StateVector):
......@@ -302,7 +296,7 @@ def save_and_submit(DaCycle, StateVector):
savedir = DaCycle['dir.output']
filename = os.path.join(savedir, 'savestate.nc') #LU to jest state vector po zoptymalizowaniu.
StateVector.write_to_file(filename)
StateVector.write_to_file(filename, True)
DaCycle.RestartFileList.append(filename) # write optimized info because StateVector.Isoptimized == False for now
DaCycle.finalize()
......
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