diff --git a/da/ctgridded/dasystem.py b/da/ctgridded/dasystem.py index 1f07b80939bf7462818f93b5a51ac52ca048f9b8..90634946f0b93933d6dde935b4dbe1503a153845 100755 --- a/da/ctgridded/dasystem.py +++ b/da/ctgridded/dasystem.py @@ -18,21 +18,49 @@ import datetime from da.baseclasses.dasystem import DaSystem -class CtDaSystem(DaSystem): +class CtGriddedDaSystem(DaSystem): """ Information on the data assimilation system used. This is normally an rc-file with settings. """ + def __init__(self,rcfilename): + """ + Initialization occurs from passed rc-file name, items in the rc-file will be added + to the dictionary + """ + + self.Identifier = 'CarbonTracker Gridded CO2' # the identifier gives the platform name + + self.LoadRc(rcfilename) + + msg = 'Data Assimilation System initialized: %s'%self.Identifier ; logging.debug(msg) + + + def Initialize(self): """ - Initialize the object + Initialize the object. Note that we might move this module to the StateVector instead ??! """ import da.tools.io4 as io + import numpy as np + + + mapfile = os.path.join(self['regionsfile']) + ncf = io.CT_Read(mapfile,'read') + self.regionmap = ncf.GetVariable('regions') + dummy = ncf.close() + + msg = "Regions map on 1x1 degree was read from file %s"%self['regionsfile'] ; logging.debug(msg) + + # dictionary for region <-> map conversions - mapfile = os.path.join(self['datadir'],self['regionsfile']) - ncf = io.CT_Read(mapfile,'read') - self.regionmap = ncf.GetVariable('budget_region') - dummy = ncf.close() + nregions = self.regionmap.max() + self.regiondict = {} + for r in range(1,nregions+1): + sel = (self.regionmap.flat == r).nonzero() + if len(sel[0])>0: + self.regiondict[r]=sel + msg = "A dictionary to map grids to states and vice versa was created" ; logging.debug(msg) def Validate(self): """ @@ -43,7 +71,6 @@ class CtDaSystem(DaSystem): 'obs.input.fname', 'ocn.covariance', 'nparameters', - 'bio.covariance', 'deltaco2.prefix', 'regtype']