Commit 1c13b8c2 authored by Florentie, Liesbeth's avatar Florentie, Liesbeth
Browse files

added date to optimizer.nc file

parent 1fcf3cf1
......@@ -207,6 +207,7 @@ class TotalColumnObservations(Observations):
av_kernel = ncf.get_variable('averaging_kernel').take(subselect, axis=0)
pressure = ncf.get_variable('pressure_levels').take(subselect, axis=0)
dates = ncf.get_variable('date').take(subselect, axis=0)
dates = array([dtm.datetime(*d) for d in dates])
if 'pressure_weight' in self.additional_variables and 'pressure_weight' in ncf.variables:
h = ncf.get_variable('pressure_weight').take(subselect, axis=0)
......@@ -228,7 +229,7 @@ class TotalColumnObservations(Observations):
# Note that the mdm is initialized here equal to the measurement uncertainty. This value is used in add_model_data_mismatch to calculate the mdm including model error!
for n in range(len(ids)):
# Check for every sounding if time is between start and end time (relevant for first and last days of window)
if self.startdate <= dtm.datetime(*dates[n]) <= self.enddate:
if self.startdate <= dates[n] <= self.enddate:
self.datalist.append(TotalColumnSample(ids[n], code, dates[n], obs[n], None, lats[n], lons[n], unc[n], prior[n], prior_profile[n,:], \
av_kernel[n,:], pressure=pressure[n,:],level_def=level_def,psurf=psurf[n],h=h[n]))
......@@ -355,7 +356,7 @@ class TotalColumnObservations(Observations):
dimsoundings = f.add_dim('soundings', len(self.datalist))
dimlevels = f.add_dim('levels', self.getvalues('pressure').shape[1])
dimdate = f.add_dim('epoch_dimension', self.getvalues('xdate').shape[1])
dimdate = f.add_dim('epoch_dimension', 7)
dimchar = f.add_dim('char', 20)
savedict = io.std_savedict.copy()
......@@ -365,11 +366,12 @@ class TotalColumnObservations(Observations):
savedict['values'] = self.getvalues('id').tolist()
f.add_data(savedict)
data = [[d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond] for d in self.getvalues('xdate') ]
savedict = io.std_savedict.copy()
savedict['dtype'] = "int"
savedict['name'] = "date"
savedict['dims'] = dimsoundings + dimdate
savedict['values'] = self.getvalues('xdate').tolist()
savedict['values'] = data
f.add_data(savedict)
savedict = io.std_savedict.copy()
......@@ -459,7 +461,7 @@ class TotalColumnObservations(Observations):
dimid = f.add_dim('obs', None) #len(self.datalist))
dim200char = f.add_dim('string_of200chars', 200)
dim10char = f.add_dim('string_of10chars', 10)
dimcalcomp = f.add_dim('calendar_components', 6)
dimcalcomp = f.add_dim('calendar_components', 7)
dimmembers = f.add_dim('members', self.getvalues('simulated').shape[1])
if len(self.datalist) == 0:
......@@ -476,13 +478,13 @@ class TotalColumnObservations(Observations):
savedict['comment'] = "Unique observation identifier."
f.add_data(savedict)
data = [[d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond] for d in self.getvalues('xdate') ]
savedict = io.std_savedict.copy()
savedict['dtype'] = "int"
savedict['name'] = "date_components"
savedict['units'] = "integer components of UTC date/time"
savedict['dims'] = dimid + dimcalcomp
logging.debug(self.getvalues('xdate')[:,:6].shape)
savedict['values'] = self.getvalues('xdate')[:,:6].tolist()
savedict['values'] = data
savedict['comment'] = "Calendar date components as integers. Times and dates are UTC."
savedict['order'] = "year, month, day, hour, minute, second"
f.add_data(savedict)
......
......@@ -81,6 +81,7 @@ class CO2Optimizer(Optimizer):
# lat and lon
self.latitude = np.zeros(self.nobs, float)
self.longitude = np.zeros(self.nobs, float)
self.date = np.zeros((self.nobs, 6), float)
# species mask
self.speciesmask = {}
......@@ -94,6 +95,7 @@ class CO2Optimizer(Optimizer):
allsites = [] # collect all obs for n=1,..,nlag
alllats = [] # collect all latitudes for n=1,..,nlag
alllons = [] # collect all longitudes for n=1,..,nlag
alldates = [] # collect all date vectors for n=1,..,nlag
allobs = [] # collect all obs for n=1,..,nlag
allmdm = [] # collect all mdm for n=1,..,nlag
allids = [] # collect all model samples for n=1,..,nlag
......@@ -127,6 +129,7 @@ class CO2Optimizer(Optimizer):
allsites.extend(sample.getvalues('code'))
alllats.extend(sample.getvalues('lat'))
alllons.extend(sample.getvalues('lon'))
alldates.extend([[d.year, d.month, d.day, d.hour, d.minute, d.second] for d in sample.getvalues('xdate')])
allmdm.extend(sample.getvalues('mdm'))
allids.extend(sample.getvalues('id'))
......@@ -148,6 +151,7 @@ class CO2Optimizer(Optimizer):
self.sitecode = allsites
self.latitude[:] = np.array(alllats)
self.longitude[:] = np.array(alllons)
self.date[:,:] = np.array(alldates)
self.X_prime = self.X_prime - self.x[:, np.newaxis] # make into a deviation matrix
self.HX_prime = self.HX_prime - self.Hx[:, np.newaxis] # make a deviation matrix
......@@ -245,6 +249,7 @@ class CO2Optimizer(Optimizer):
dimobs = f.add_obs_dim(self.nobs)
dimstate = f.add_dim('nstate', self.nparams * self.nlag)
dim200char = f.add_dim('string_of200chars', 200)
dimdate = f.add_dim('calendar_components', 6)
# Add data, first the ones that are written both before and after the optimization
savedict = io.std_savedict.copy()
......@@ -296,6 +301,15 @@ class CO2Optimizer(Optimizer):
savedict['missing_value'] = '!'
f.add_data(savedict)
savedict = io.std_savedict.copy()
savedict['name'] = 'date_components'
savedict['dims'] = dimobs + dimdate
savedict['units'] = "integer components of UTC date/time"
savedict['missing_value'] = -999.9
savedict['order'] = "year, month, day, hour, minute, second"
savedict['values'] = self.date
f.add_data(savedict)
savedict = io.std_savedict.copy()
savedict['name'] = 'latitude'
savedict['dims'] = dimobs
......
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