Commit 87e320a9 authored by Luijkx, Ingrid's avatar Luijkx, Ingrid
Browse files

Merge branch 'new_da_structure' of https://git.wur.nl/ctdas/CTDAS into new_da_structure

parents 1580463d a3856133
......@@ -68,14 +68,17 @@ class ObservationOperator(object):
self.dacycle = dacycle
self.outputdir = dacycle['dir.output']
def prepare_run(self):
def prepare_run(self,samples):
""" Prepare the running of the actual forecast model, for example compile code """
import os
# Define the name of the file that will contain the modeled output of each observation
self.simulated_file = os.path.join(self.outputdir, 'samples_simulated.%s.nc' % self.dacycle['time.sample.stamp'])
# For each sample type, define the name of the file that will contain the modeled output of each observation
self.simulated_file = [None] * len(samples)
for i in range(len(samples)):
self.simulated_file[i] = os.path.join(self.outputdir, '%s_output.%s.nc' % (samples[i].get_samples_type(),self.dacycle['time.sample.stamp']))
del i
#self.simulated_file = os.path.join(self.outputdir, 'samples_simulated.%s.nc' % self.dacycle['time.sample.stamp'])
self.forecast_nmembers = int(self.dacycle['da.optimizer.nmembers'])
def validate_input(self):
......@@ -85,7 +88,7 @@ class ObservationOperator(object):
def save_data(self):
""" Write the data that is needed for a restart or recovery of the Observation Operator to the save directory """
def run(self):
def run(self,samples):
"""
This Randomizer will take the original observation data in the Obs object, and simply copy each mean value. Next, the mean
value will be perturbed by a random normal number drawn from a specified uncertainty of +/- 2 ppm
......@@ -96,58 +99,61 @@ class ObservationOperator(object):
# Create a flask output file to hold simulated values for later reading
f = io.CT_CDF(self.simulated_file, method='create')
logging.debug('Creating new simulated observation file in ObservationOperator (%s)' % self.simulated_file)
dimid = f.createDimension('obs_num', size=None)
dimid = ('obs_num',)
savedict = io.std_savedict.copy()
savedict['name'] = "obs_num"
savedict['dtype'] = "int"
savedict['long_name'] = "Unique_Dataset_observation_index_number"
savedict['units'] = ""
savedict['dims'] = dimid
savedict['comment'] = "Unique index number within this dataset ranging from 0 to UNLIMITED."
f.add_data(savedict,nsets=0)
dimmember = f.createDimension('nmembers', size=self.forecast_nmembers)
dimmember = ('nmembers',)
savedict = io.std_savedict.copy()
savedict['name'] = "flask"
savedict['dtype'] = "float"
savedict['long_name'] = "mole_fraction_of_trace_gas_in_air"
savedict['units'] = "mol tracer (mol air)^-1"
savedict['dims'] = dimid + dimmember
savedict['comment'] = "Simulated model value created by RandomizerObservationOperator"
f.add_data(savedict,nsets=0)
# Open file with x,y,z,t of model samples that need to be sampled
f_in = io.ct_read(self.dacycle['ObsOperator.inputfile'],method='read')
# Get simulated values and ID
ids = f_in.get_variable('obs_num')
obs = f_in.get_variable('observed')
mdm = f_in.get_variable('modeldatamismatch')
# Loop over observations, add random white noise, and write to file
for i,data in enumerate(zip(ids,obs,mdm)):
f.variables['obs_num'][i] = data[0]
f.variables['flask'][i,:] = data[1]+np.random.randn(self.forecast_nmembers)*data[2]
f.close()
f_in.close()
# Report success and exit
logging.info('ObservationOperator finished successfully, output file written (%s)' % self.simulated_file)
for j,sample in enumerate(samples):
f = io.CT_CDF(self.simulated_file[j], method='create')
logging.debug('Creating new simulated observation file in ObservationOperator (%s)' % self.simulated_file)
dimid = f.createDimension('obs_num', size=None)
dimid = ('obs_num',)
savedict = io.std_savedict.copy()
savedict['name'] = "obs_num"
savedict['dtype'] = "int"
savedict['long_name'] = "Unique_Dataset_observation_index_number"
savedict['units'] = ""
savedict['dims'] = dimid
savedict['comment'] = "Unique index number within this dataset ranging from 0 to UNLIMITED."
f.add_data(savedict,nsets=0)
dimmember = f.createDimension('nmembers', size=self.forecast_nmembers)
dimmember = ('nmembers',)
savedict = io.std_savedict.copy()
savedict['name'] = "flask"
savedict['dtype'] = "float"
savedict['long_name'] = "mole_fraction_of_trace_gas_in_air"
savedict['units'] = "mol tracer (mol air)^-1"
savedict['dims'] = dimid + dimmember
savedict['comment'] = "Simulated model value created by RandomizerObservationOperator"
f.add_data(savedict,nsets=0)
# Open file with x,y,z,t of model samples that need to be sampled
f_in = io.ct_read(self.dacycle['ObsOperator.inputfile.'+sample.get_samples_type()],method='read')
# Get simulated values and ID
ids = f_in.get_variable('obs_num')
obs = f_in.get_variable('observed')
mdm = f_in.get_variable('modeldatamismatch')
# Loop over observations, add random white noise, and write to file
for i,data in enumerate(zip(ids,obs,mdm)):
f.variables['obs_num'][i] = data[0]
f.variables['flask'][i,:] = data[1]+np.random.randn(self.forecast_nmembers)*data[2]
f.close()
f_in.close()
# Report success and exit
logging.info('ObservationOperator finished successfully, output file written (%s)' % self.simulated_file)
del sample
del j
def run_forecast_model(self):
self.prepare_run()
def run_forecast_model(self,samples):
self.prepare_run(samples)
self.validate_input()
self.run()
self.run(samples)
self.save_data()
......
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