Commit 78370143 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

new routine to read old savestate files from ct07-ct11 runs

parent bc2d93b3
......@@ -91,6 +91,52 @@ class CtStateVector(StateVector):
return fullcov
def ReadFromLegacyFile(self, filename, qual='opt'):
"""
:param filename: the full filename for the input NetCDF file
:param qual: a string indicating whether to read the 'prior' or 'opt'(imized) StateVector from file
:rtype: None
Read the StateVector information from a NetCDF file and put in a StateVector object
In principle the input file will have only one four datasets inside
called:
* `meanstate_prior`, dimensions [nlag, nparamaters]
* `ensemblestate_prior`, dimensions [nlag,nmembers, nparameters]
* `meanstate_opt`, dimensions [nlag, nparamaters]
* `ensemblestate_opt`, dimensions [nlag,nmembers, nparameters]
This NetCDF information can be written to file using
:meth:`~da.baseclasses.statevector.StateVector.WriteToFile`
"""
import da.tools.io4 as io
from da.baseclasses.statevector import EnsembleMember
f = io.CT_Read(filename, 'read')
for n in range(self.nlag):
if qual == 'opt':
MeanState = f.GetVariable('xac_%02d'%(n+1))
EnsembleMembers = f.GetVariable('adX_%02d'%(n+1))
elif qual == 'prior':
MeanState = f.GetVariable('xpc_%02d'%(n+1))
EnsembleMembers = f.GetVariable('pdX_%02d'%(n+1))
if not self.EnsembleMembers[n] == []:
self.EnsembleMembers[n] = []
logging.warning('Existing ensemble for lag=%d was removed to make place for newly read data' % (n + 1))
for m in range(self.nmembers):
NewMember = EnsembleMember(m)
NewMember.ParameterValues = EnsembleMembers[ m, :].flatten() + MeanState # add the mean to the deviations to hold the full parameter values
self.EnsembleMembers[n].append(NewMember)
f.close()
logging.info('Successfully read the State Vector from file (%s) ' % filename)
################### End Class CtStateVector ###################
......
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