Skip to content
Snippets Groups Projects
Commit 396e0df5 authored by JJDHooghiem's avatar JJDHooghiem
Browse files

molefractionsample and totalcolumnsample moved to baseclass and inherit from...

molefractionsample and totalcolumnsample moved to baseclass and inherit from new observation object. Added the appropriate imports to obs_column_xco2 and obs_gvp_co2.py.
parent 44767d80
Branches master_cleanup
No related tags found
No related merge requests found
......@@ -278,11 +278,15 @@ class Observations(object):
Write selected additional information contained in the Observations object to a file for later processing.
"""
#FLAG this doesn't do anything should we remove this from the baseclass
#FLAG add documenation
def getvalues(self, name, constructor=array):
#FLAG add documenation
"""getvalues.
:param name:
:param constructor: datatype that can be initialized by passing a list
"""
result = constructor([getattr(o, name) for o in self.datalist])
if isinstance(result, ndarray):
return result.squeeze()
......@@ -291,39 +295,139 @@ class Observations(object):
################### End Class Observations ###################
################### Begin Classes for Sample ###################
class Observation(object):
""" Observation."""
def __init__(self,idx,xdate,obs=0.0,simulated=0.0,lat=-999.,lon=-999.,height=0.0,mdm=0.0,hphr=0.0,resid=0.0,species='co2',flag=0,loc_L=0,may_localize=False,may_reject=False,sdev=0.0):
"""__init__.
:param idx: Observation id by which it can distinguished from the others
:param xdate: datetime of the observation
:param obs: observed value
:param simulated: nd.array, (nmembers,), simulated values of the ensemble
:param lat: float, latitude
:param lon: float, longitude
:param height: float, height
:param mdm: float, model-data-mismatch
:param hphr: float, Mole fraction prior uncertainty from fluxes and (HPH) and model data mismatch (R)
:param resid: float, Mole fraction residuals
:param species: species string, e.g. co2 or co2c13
:param flag: float, observation flag that specifies whether to assimilate, 0, or ignore, 99. Wil be moddifed by the kalman filter. 1 means assimilated 2 means rejected
:param loc_L: localization length
:param may_localize: If the observation may be localized
:param may_reject: If the observation may be rejected
:param sdev:
"""
#FLAG should we add the rejection_threshold here?
self.id = idx
self.xdate = xdate
self.obs = obs
self.simulated = simulated
self.lat = lat
self.lon = lon
self.height = height
self.mdm = mdm
self.hphr = hphr
self.resid = resid
self.species = species.strip()
self.flag = flag
self.loc_L = loc_L # Whether sample may be localized in optimizer
self.may_localize = may_localize # Whether sample may be rejected if outside threshold
self.may_reject = may_reject
self.sdev = sdev
return
class MoleFractionSample(Observation):
"""MoleFractionSample."""
def __init__(self, idx, xdate, code='XXX', obs=0.0, simulated=0.0, resid=0.0, hphr=0.0, mdm=0.0, flag=0, height=0.0, lat= -999., lon= -999.,
evn='0000', species='co2', samplingstrategy=1, sdev=0.0, fromfile='none.nc', loc_L=0,may_reject=False,u=None,v=None,blh=None,q=None,p=None,T=None):
"""__init__.
:param idx:
:param xdate:
:param code: dataset identifier, i.e., co2_lef_tower_insitu_1_99
:param obs:
:param simulated:
:param resid:
:param hphr:
:param mdm:
:param flag:
:param height:
:param lat:
:param lon:
:param evn: Obspack Number within distrution (string), e.g., obspack_co2_1_PROTOTYPE_v0.9.2_2012-07-26_99_82536
:param species:
:param samplingstrategy:
:param sdev:
:param fromfile:
:param loc_L:
:param u: float, eastward or longitudinal wind component
:param v:
:param blh:
:param q:
:param p:
:param T:
"""
super().__init__(idx,xdate,obs,simulated,lat,lon,height,mdm,hphr,resid,species,flag,loc_L,may_localize,may_reject,sdev)
self.code = code.strip()
self.evn = evn
#FLAG seems to be always true
self.masl = True
self.mag = not self.masl
self.samplingstrategy = samplingstrategy #
self.fromfile = fromfile
self.u = u
self.v = v
self.blh = blh
self.q = p
self.p = p
self.T = T
class TotalColumnSample(Observation):
"""TotalColumnSample."""
def __init__(self, idx, codex, xdate, obs=0.0, simulated=0.0, lat=-999., lon=-999., mdm=0.0, prior=0.0, prior_profile=0.0, av_kernel=0.0, pressure=0.0, \
level_def = "pressure_boundary", psurf = float('nan'), resid=0.0, hphr=0.0, flag=0, species='co2', sdev=0.0, h=0.0, moderr=0.0, loc_L=0, may_localize=False,may_reject=False):
"""__init__.
:param idx:
:param codex: Retrieval ID
:param xdate:
:param obs:
:param simulated:
:param lat: :param lon:
:param mdm:
:param prior :A priori column value used in retrieval
:param prior_profile: A priori profile used in retrieval
:param av_kernel:
:param pressure: Pressure levels of retrieval
:param level_def:Are prior and averaging kernel defined as layer averages?
:param psurf: Surface pressure (only needed if level_def is "layer_average")
:param resid:
:param hphr:
:param flag:
:param species:
:param sdev:
:param h: Sounding pressure level weights
:param moderr: Model error, NaN unless mdm_calculation = read_from_file
:param loc_L:
:param may_localize:
:param may_reject:
"""
super().__init__(idx,xdate,obs,simulated,lat,lon,height,mdm,hphr,resid,species,flag,loc_L,may_localize,may_reject,sdev)
self.code = codex
self.prior = prior
self.prior_profile = prior_profile
self.av_kernel = av_kernel
self.pressure = pressure
self.level_def = level_def
self.psurf = psurf
#FLAG poor name
self.h = h
self.modelunc = moderr
################### Begin Class MoleFractionSample ###################
class MoleFractionSample(object):
"""
Holds the data that defines a mole fraction Sample in the data assimilation framework. Sor far, this includes all
attributes listed below in the __init__ method. One can additionally make more types of data, or make new
objects for specific projects.
"""
def __init__(self, idx, xdate, code='XXX', obs=0.0, simulated=0.0, resid=0.0, hphr=0.0, mdm=0.0, flag=0, height=0.0, lat= -999., lon= -999., evn='0000', species='co2', samplingstrategy=1, sdev=0.0, fromfile='none.nc'):
self.code = code.strip() # dataset identifier, i.e., co2_lef_tower_insitu_1_99
self.xdate = xdate # Date of obs
self.obs = obs # Value observed
self.simulated = simulated # Value simulated by model
self.resid = resid # Mole fraction residuals
self.hphr = hphr # Mole fraction prior uncertainty from fluxes and (HPH) and model data mismatch (R)
self.mdm = mdm # Model data mismatch
self.may_localize = True # Whether sample may be localized in optimizer
self.may_reject = True # Whether sample may be rejected if outside threshold
self.flag = flag # Flag
self.height = height # Sample height in masl
self.lat = lat # Sample lat
self.lon = lon # Sample lon
self.id = idx # Obspack ID within distrution (integer), e.g., 82536
self.evn = evn # Obspack Number within distrution (string), e.g., obspack_co2_1_PROTOTYPE_v0.9.2_2012-07-26_99_82536
self.sdev = sdev # standard deviation of ensemble
self.masl = True # Sample is in Meters Above Sea Level
self.mag = not self.masl # Sample is in Meters Above Ground
self.species = species.strip()
self.samplingstrategy = samplingstrategy
self.fromfile = fromfile # netcdf filename inside ObsPack distribution, to write back later
################### End Class MoleFractionSample ###################
......
......@@ -34,52 +34,11 @@ sys.path.append('../../')
identifier = 'CarbonTracker total column-averaged mole fractions'
version = '0.0'
from da.observations.obs_baseclass import Observations
from da.observations.obs_baseclass import Observations, TotalColumnSample
import da.tools.io4 as io
import da.tools.rc as rc
################### Begin Class TotalColumnSample ###################
class TotalColumnSample(object):
"""
Holds the data that defines a total column sample in the data assimilation framework. Sor far, this includes all
attributes listed below in the __init__ method. One can additionally make more types of data, or make new
objects for specific projects.
This file may contain OCO-2 specific parts...
"""
def __init__(self, idx, codex, xdate, obs=0.0, simulated=0.0, lat=-999., lon=-999., mdm=None, prior=0.0, prior_profile=0.0, av_kernel=0.0, pressure=0.0, \
level_def = "pressure_boundary", psurf = float('nan'), resid=0.0, hphr=0.0, flag=0, species='co2', sdev=0.0, h=0.0, moderr=0.0, loc_L=0):
self.id = idx # Sounding ID
self.code = codex # Retrieval ID
self.xdate = xdate # Date of obs
self.obs = obs # Value observed
self.simulated = simulated # Value simulated by model, fillvalue = -9999
self.lat = lat # Sample lat
self.lon = lon # Sample lon
self.mdm = mdm # Model data mismatch
self.prior = prior # A priori column value used in retrieval
self.prior_profile = prior_profile # A priori profile used in retrieval
self.av_kernel = av_kernel # Averaging kernel
self.pressure = pressure # Pressure levels of retrieval
self.level_def = level_def # Are prior and averaging kernel defined as layer averages?
self.psurf = psurf # Surface pressure (only needed if level_def is "layer_average")
self.h = h # Sounding pressure level weights
self.modelunc = moderr # Model error, NaN unless mdm_calculation = read_from_file
self.loc_L = loc_L # localization length
self.resid = resid # Mole fraction residuals
self.hphr = hphr # Mole fraction prior uncertainty from fluxes and (HPH) and model data mismatch (R)
self.may_localize = True # Whether sample may be localized in optimizer
self.may_reject = True # Whether sample may be rejected if outside threshold
self.flag = flag # Flag
self.sdev = sdev # standard deviation of ensemble
self.species = species.strip()
################### End Class TotalColumnSample ###################
################### Begin Class TotalColumnObservations ###################
......
......@@ -33,7 +33,7 @@ sys.path.append('../../')
identifier = 'CarbonTracker CO2 mole fractions'
version = '2.0'
from da.observations.obs_baseclass import Observations
from da.observations.obs_baseclass import Observations, MoleFractionSample
import da.tools.io4 as io
import da.tools.rc as rc
......@@ -563,45 +563,5 @@ class ObsPackObservations(Observations):
################### End Class CtObservations ###################
################### Begin Class MoleFractionSample ###################
#FLAG: this MoleFractionSample is a direct copy from the obs_baseclass class.
class MoleFractionSample(object):
"""
Holds the data that defines a mole fraction Sample in the data assimilation framework. Sor far, this includes all
attributes listed below in the __init__ method. One can additionally make more types of data, or make new
objects for specific projects.
"""
def __init__(self, idx, xdate, code='XXX', obs=0.0, simulated=0.0, resid=0.0, hphr=0.0, mdm=0.0, flag=0, height=0.0, lat= -999., lon= -999.,
evn='0000', species='co2', samplingstrategy=1, sdev=0.0, fromfile='none.nc', loc_L=0):
self.code = code.strip() # dataset identifier, i.e., co2_lef_tower_insitu_1_99
self.xdate = xdate # Date of obs
self.obs = obs # Value observed
self.simulated = simulated # Value simulated by model
self.resid = resid # Mole fraction residuals
self.hphr = hphr # Mole fraction prior uncertainty from fluxes and (HPH) and model data mismatch (R)
self.mdm = mdm # Model data mismatch
self.may_localize = True # Whether sample may be localized in optimizer
self.loc_L = loc_L # localization length for observation
self.may_reject = True # Whether sample may be rejected if outside threshold
self.flag = flag # Flag
self.height = height # Sample height in masl
self.lat = lat # Sample lat
self.lon = lon # Sample lon
self.id = idx # Obspack ID within distrution (integer), e.g., 82536
self.evn = evn # Obspack Number within distrution (string), e.g., obspack_co2_1_PROTOTYPE_v0.9.2_2012-07-26_99_82536
self.sdev = sdev # standard deviation of ensemble
self.masl = True # Sample is in Meters Above Sea Level
self.mag = not self.masl # Sample is in Meters Above Ground
self.species = species.strip()
self.samplingstrategy = samplingstrategy
self.fromfile = fromfile # netcdf filename inside ObsPack distribution, to write back later
################### End Class MoleFractionSample ###################
if __name__ == "__main__":
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment