Skip to content
Snippets Groups Projects
Commit ef0e9b4a authored by Woude, Auke van der's avatar Woude, Auke van der
Browse files

Added flags to the statevector baseclass

parent d8f86c47
No related branches found
No related tags found
No related merge requests found
......@@ -338,7 +338,10 @@ class StateVector(object):
def write_to_file(self, filename, qual):
"""
:param filename: the full filename for the output NetCDF file
:type filename: str | path
:rtype: None
:param qual: the qualification of the file: prior or optimized
:type qual: str
Write the StateVector information to a NetCDF file for later use.
In principle the output file will have only one two datasets inside
......@@ -350,17 +353,12 @@ class StateVector(object):
:meth:`~da.baseclasses.statevector.StateVector.read_from_file`
"""
#import da.tools.io4 as io
#import da.tools.io as io
if qual == 'prior':
f = io.CT_CDF(filename, method='create')
logging.debug('Creating new StateVector output file (%s)' % filename)
#qual = 'prior'
else:
f = io.CT_CDF(filename, method='write')
logging.debug('Opening existing StateVector output file (%s)' % filename)
#qual = 'opt'
dimparams = f.add_params_dim(self.nparams)
dimmembers = f.add_members_dim(self.nmembers)
......@@ -394,6 +392,7 @@ class StateVector(object):
def interpolate_mean_ensemble(self, initdir, date, qual='opt', readensemble=True):
#FLAG: add documentation
# deduce window length of source run:
all_dates = os.listdir(initdir)
for i, dstr in enumerate(all_dates):
......@@ -423,6 +422,7 @@ class StateVector(object):
logging.debug('Ensemble for %s will be interpolated from %s and %s' %(date.strftime('%Y-%m-%d'), datemin.strftime('%Y-%m-%d'),datemax.strftime('%Y-%m-%d')))
# Read ensemble from both files
#FLAG add context manager
filename1 = os.path.join(initdir, datemin.strftime('%Y%m%d'), 'savestate_%s.nc'%datemin.strftime('%Y%m%d'))
f = io.ct_read(filename1, 'read')
meanstate1 = f.get_variable('statevectormean_' + qual) # [nlag x nparameters]
......@@ -449,6 +449,7 @@ class StateVector(object):
def read_mean_from_file(self, filename, lag, date=None, initdir=None, qual='opt'):
#FLAG: add documentation
if date is None:
f = io.ct_read(filename, 'read')
meanstate = f.get_variable('statevectormean_' + qual) # [nlag x nparameters]
......@@ -463,6 +464,7 @@ class StateVector(object):
def read_ensemble_member_from_file(self, filename, lag, date=None, initdir=None, qual='opt', read_lag=0):
#FLAG: add documentation
# if date is None we can directly read mean and ensemble members. Else we will need to read 2 ensembles and interpolate
if date is None:
......@@ -531,6 +533,7 @@ class StateVector(object):
:param: lag: Which lag step of the filter to write, must lie in range [1,...,nlag]
:param: outdir: Directory where to write files
:param: endswith: Optional label to add to the filename, default is simply .nc
:param: obsoperator: Currenlty unused: The observationoperator object. Defaults to None
:rtype: None
Write ensemble member information to a NetCDF file for later use. The standard output filename is
......@@ -543,13 +546,6 @@ class StateVector(object):
can simply inherit from the StateVector baseclass and overwrite this write_members_to_file function.
"""
# These import statements caused a crash in netCDF4 on MacOSX. No problems on Jet though. Solution was
# to do the import already at the start of the module, not just in this method.
#import da.tools.io as io
#import da.tools.io4 as io
members = self.ensemble_members[lag]
for mem in members:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment