Commit acac354f authored by Espen Sollum's avatar Espen Sollum
Browse files

Added a forgotten file. Minor changes elsewhere

parent 122d0b9d
......@@ -94,3 +94,4 @@ def ini_data(plugin, **kwargs):
# Initializing the product of chi by B^(1/2), only if components specified
if hasattr(plugin, 'components'):
init_bprod(plugin, **kwargs)
import numpy as np
from scipy import ndimage
from pycif.utils import dates
from .utils.dimensions import hresol2dim, vresol2dim
from .utils.scalemaps import map2scale, vmap2vaggreg
import xarray as xr
def background_xb(cntrlv, **kwargs):
"""Extends the prior control vector to include background components.
Is called if the obsvect has a background plugin.
Args:
cntrlv (Plugin): definition of the control vector.
datei (datetime): initial date of the inversion window
datei (datetime): end date of the inversion window
"""
datei = getattr(cntrlv, 'datei')
datef = getattr(cntrlv, 'datef')
# If no definition is specified for the control vector in the Yaml,
# return empty control vector
if not hasattr(cntrlv, 'components'):
return cntrlv
# Else, carry on initializing
components = cntrlv.components
for comp in components.attributes:
component = getattr(components, comp)
for trcr in component.parameters.attributes:
tracer = getattr(component.parameters, trcr)
# Keeping a pointer to the correct location in the whole control
# tracer.xpointer = cntrlv.dim
# Updating dimension
# Time stamp for initial mixing ratio scalars
cinidim = cntrlv.background.ntcini * cntrlv.background.ncini
# ESO: update tracer.dim?
# tracer.dim = tracer.ndates * tracer.hresoldim * tracer.vresoldim
# tracer.dim += cinidim
cntrlv.dim += cinidim
# Filling Xbb and uncertainties
xbb = np.ones(cinidim)
stdb = np.ones(cinidim) * \
float(cntrlv.background.cini_err)
# Appending local xb to the control vector
cntrlv.xb = np.append(cntrlv.xb, xbb)
cntrlv.std = np.append(cntrlv.std, stdb)
# Extending chi
# TODO: this is temporary solution to deal with background opt.
# would also need to change tracer.chi_dim etc.
cntrlv.chi = np.append(cntrlv.chi, np.zeros(cinidim))
cntrlv.chi_dim += cinidim
# Finished initializing controlvect
cntrlv.background.updated_controlvect = True
return cntrlv
......@@ -114,7 +114,9 @@ def init_bprod(cntrlv, options={}, **kwargs):
errscalar = glob_err/toterr
#cntrlv.std = cntrlv.std*errscalar**2
verbose("Total error scaled by "+ str(errscalar))
# TODO: rework this based on most recent flexinvert version
verbose("errsum "+ str(errsum))
# TODO: rework this based on most recent flexinvert version,
# including using xerr (time avg error)
......
......@@ -81,13 +81,13 @@ def obsoper(self, inputs, mode,
fp_header_glob = model.utils.flexpart_header.Flexpartheader()
fp_header_glob.read_header(
os.path.join(model.run_dir_glob, obsvect.datastore.head(1)['station'][0].upper(),
os.path.join(model.run_dir_glob, obsvect.datastore.head(1)['station'][0].decode().upper(),
subdir, 'header'))
if model.plugin.nested:
fp_header_nest = model.utils.flexpart_header.Flexpartheader()
fp_header_nest.read_header(
os.path.join(model.run_dir_nest, obsvect.datastore.head(1)['station'][0].upper(),
os.path.join(model.run_dir_nest, obsvect.datastore.head(1)['station'][0].decode().upper(),
subdir, 'header_nest'))
# Trajectory life time
......@@ -150,9 +150,9 @@ def obsoper(self, inputs, mode,
station = row.station
runsubdir_nest = os.path.join(
model.run_dir_nest, station.upper(), subdir)
model.run_dir_nest, station.decode().upper(), subdir)
runsubdir_glob = os.path.join(
model.run_dir_glob, station.upper(), subdir)
model.run_dir_glob, station.decode().upper(), subdir)
file_date = row.Index.strftime('%Y%m%d%H%M%S')
......
......@@ -74,7 +74,8 @@ def init_background(obsvect, **kwargs):
# Subdirectory for FLEXPART grid_initial files
subdir = row.Index.strftime("%Y%m")
station = row.station
# station = row.station
station = row.station.decode()
runsubdir_glob = os.path.join(
model.run_dir_glob, station.upper(), subdir)
file_date = row.Index.strftime('%Y%m%d%H%M%S')
......
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