Commit 90a8d549 authored by Espen Sollum's avatar Espen Sollum
Browse files

Various changes added before rebase

parent c5c03866
......@@ -59,8 +59,8 @@ mode:
name: forward
version: std
perturb_obsvect: True
# obserror: 0.01
obserror: 0.25
obserror: 0.01
# obserror: 0.25
#####################################################################
#####################################################################
......
......@@ -41,9 +41,13 @@ def ini_data(plugin, **kwargs):
components = plugin.components
for comp in components.attributes:
component = getattr(components, comp)
for trcr in component.parameters.attributes:
tracer = getattr(component.parameters, trcr)
#ESO
print ("component", components)
# for trcr in component.parameters.attributes:
for trcr in component.attributes:
# tracer = getattr(component.parameters, trcr)
tracer = getattr(component, trcr)
tracer.dir = getattr(tracer, 'dir',
getattr(component, 'dir',
getattr(
......
......@@ -40,6 +40,7 @@ def control2native(self, mod_input, di, df, mode,
ddi = min(di, df)
ddf = min(di, df)
# If this type of input is not considered in the control vector,
# return nothing
# It will then be handled as a fixed input
......@@ -67,8 +68,9 @@ def control2native(self, mod_input, di, df, mode,
if cdates[0] < ddi:
cdates[0] = ddi
# Translates only control variables corresponding to the
# simulation period
# Translates only control variables corresponding to the
# simulation period
for x in variables:
tmp = np.reshape(
variables[x][tracer.xpointer:tracer.xpointer + tracer.dim],
......
......@@ -28,9 +28,10 @@ def init_bprod(cntrlv, options={}, **kwargs):
components = cntrlv.components
for comp in components.attributes:
component = getattr(components, comp)
for trcr in component.parameters.attributes:
tracer = getattr(component.parameters, trcr)
# for trcr in component.parameters.attributes:
# tracer = getattr(component.parameters, trcr)
for trcr in component.attributes:
tracer = getattr(component, trcr)
# Deals with horizontal correlations if any
if hasattr(tracer, 'hcorrelations') and tracer.hresol == 'hpixels':
corr = tracer.hcorrelations
......
......@@ -4,6 +4,7 @@ from pycif.utils import dates
from .utils.dimensions import hresol2dim, vresol2dim
from .utils.scalemaps import map2scale, vmap2vaggreg
import pdb
def init_xb(cntrlv, **kwargs):
"""Initializes the prior control vector. Loops over all components and
......@@ -15,7 +16,7 @@ def init_xb(cntrlv, **kwargs):
datei (datetime): end date of the inversion window
"""
datei = getattr(cntrlv, 'datei')
datef = getattr(cntrlv, 'datef')
......@@ -30,10 +31,13 @@ def init_xb(cntrlv, **kwargs):
# Else, carry on initializing
components = cntrlv.components
# pdb.set_trace()
for comp in components.attributes:
component = getattr(components, comp)
for trcr in component.parameters.attributes:
tracer = getattr(component.parameters, trcr)
# for trcr in component.parameters.attributes:
# tracer = getattr(component.parameters, trcr)
for trcr in component.attributes:
tracer = getattr(component, trcr)
# Deals with temporal resolution of the control component
# A negative period is equivalent to no period
......
......@@ -106,4 +106,4 @@ def native2control(self, datastore, di, df,
import code
code.interact(local=dict(locals(), **globals()))
\ No newline at end of file
......@@ -14,8 +14,11 @@ def sqrtbprod(controlvect, chi, **kwargs):
components = controlvect.components
for comp in components.attributes:
component = getattr(components, comp)
for trcr in component.parameters.attributes:
tracer = getattr(component.parameters, trcr)
# for trcr in component.parameters.attributes:
# tracer = getattr(component.parameters, trcr)
# ESO
for trcr in component.attributes:
tracer = getattr(component, trcr)
x_pointer = tracer.xpointer
x_dim = tracer.dim
......
......@@ -4,11 +4,14 @@
from . import lmdz
from . import chimere
from . import dummy
from . import flexpart
from pycif.utils.classes.domains import Domain
Domain.register_plugin('LMDZ', 'std', lmdz)
Domain.register_plugin('CHIMERE', 'std', chimere)
Domain.register_plugin('dummy', 'std', dummy)
Domain.register_plugin('FLEXPART', 'std', flexpart)
del lmdz
del chimere
del flexpart
......@@ -6,6 +6,7 @@ import lmdz_bin
import dummy_txt
import dummy_nc
import chimere
import flexpart
from pycif.utils.classes.fluxes import Fluxes
Fluxes.register_plugin('LMDZ', 'sflx', lmdz_sflx)
......@@ -13,3 +14,4 @@ Fluxes.register_plugin('LMDZ', 'bin', lmdz_bin)
Fluxes.register_plugin('dummy', 'nc', dummy_nc)
Fluxes.register_plugin('dummy', 'txt', dummy_txt)
Fluxes.register_plugin('CHIMERE', 'AEMISSIONS', chimere)
Fluxes.register_plugin('FLEXPART', 'nc', flexpart)
......@@ -63,10 +63,10 @@ def parse_tracers(self,
raise e
# Otherwise, create the monitor from observations
if hasattr(self, 'workdir'):
workdir = self.workdir
fic_monitor = workdir + '/obs/monit_standard.nc'
if hasattr(self, 'workdir'):
workdir = self.workdir
fic_monitor = workdir + '/obs/monit_standard.nc'
# If the measurement definition is empty in the Yaml,
# return an empty datastore
......
import shutil
from types import MethodType
import pandas as pd
from pycif.utils import path
from pycif.utils.check import verbose
from .ini_periods import ini_periods
import pdb
requirements = {'domain': {'name': 'FLEXPART', 'version': 'std', 'empty': False},
'fluxes': {'name': 'FLEXPART', 'version': 'nc',
'empty': True, 'any': False}}
def ini_data(plugin, **kwargs):
"""Initializes FLEXPART
Args:
plugin (dict): dictionary defining the plugin
**kwargs (dictionary): possible extra parameters
Returns:
loaded plugin and directory with executable
"""
# pdb.set_trace()
# Initializes default values
# Period of sub-simulations: default = 1 month
if not hasattr(plugin.plugin, 'periods'):
plugin.periods = '1MS'
else:
plugin.periods = plugin.plugin.periods
return plugin
......@@ -83,7 +83,7 @@ def make_input(self, mod_input, di, df, mode, runsubdir, workdir,
tracer.dir, tracer.fic))
target = "{}/dep_{}.nc".format(runsubdir, spec)
path.link(source, target)
finf = '{}/chemical_scheme.nml'.format(self.chemistry.dirchem_ref)
target = '{}/chemical_scheme.nml'.format(runsubdir)
path.link(finf, target)
......
from types import MethodType
from .execute import execute
requirements = {'obsvect': {'any': True, 'empty': False,
'name': 'standard', 'version': 'std'},
'controlvect': {'any': True, 'empty': False,
'name': 'standard', 'version': 'std'},
'obsoperator': {'any': True, 'empty': True,
'name': 'standard', 'version': 'std'},
'minimizer': {'any': True, 'empty': True,
'name': 'm1qn3', 'version': 'std'},
'simulator': {'any': True, 'empty': True,
'name': 'gausscost', 'version': 'std'}
}
def ini_data(plugin, **kwargs):
"""Initializes the variational inversions. It means that all sub-modules
and plugins required to run the inversion are built at this step.
Args:
plugin (pycif.classes.plugins): the plugin to initialize
Returns:
dict with all options and sub-modules
"""
if not hasattr(plugin, 'minimizer'):
raise Exception("A variational inversion was asked with no "
"optimization method")
# Initializing the simulator from the minimizer
if not hasattr(plugin.minimizer, 'simulator'):
raise Exception("You are trying to run a minimizer without simulator")
plugin.simulator = plugin.minimizer.simulator
return plugin
......@@ -5,7 +5,7 @@ def check_inputs(inputs, mode):
"""Check the consistency of inputs given to the observation operator.
"""
if mode not in ['tl', 'fwd', 'adj']:
if mode not in ['tl', 'fwd', 'adj','footprint']:
verbose("The following running mode is not accepted by the "
"observation operator: {}".format(mode))
raise Exception
......
......@@ -7,6 +7,7 @@ from pycif.utils.check import verbose
from pycif.utils.datastores.dump import dump_datastore, read_datastore
from check import check_inputs
import pdb
def obsoper(self, inputs, mode,
run_id=0, datei=datetime.datetime(1979, 1, 1),
......@@ -56,7 +57,7 @@ def obsoper(self, inputs, mode,
Returns:
observation or control vector depending on the running mode
"""
# Check that inputs are consistent with the mode to run
check_inputs(inputs, mode)
......@@ -100,6 +101,10 @@ def obsoper(self, inputs, mode,
controlvect = self.controlvect
obsvect = self.obsvect
subsimu_dates = model.subsimu_dates
print "obsoper/model", model
print "obsoper/mode", mode
pdb.set_trace()
if mode in ['fwd', 'tl']:
controlvect = inputs
......@@ -117,21 +122,36 @@ def obsoper(self, inputs, mode,
controlvect.dx = 0 * controlvect.x
subsimu_dates = subsimu_dates[::-1]
#import code
#code.interact(local=dict(locals(), **globals()))
elif mode == 'footprint':
print "obsoper; footprint"
obsvect = inputs
controlvect.dx = 0 * controlvect.x
subsimu_dates = subsimu_dates[::-1]
read_only = getattr(self, 'read_only', False)
print "read_only", read_only
# Loop through model periods and runs the model
self.missingperiod = False
for di, df in zip(subsimu_dates[:-1], subsimu_dates[1:]):
# Create a sub-path for each period
runsubdir = rundir + min(di, df).strftime("%Y-%m-%d_%H-%M")
_, created = path.init_dir(runsubdir)
# ESO: copy data to above directory
# If the sub-directory was already created,
# the observation operator considers that the sub-simulation
# was already properly run, thus passing to next sub-periods
# Compute the sub-simulation anyway if some previous periods
# were missing (as stored in self.missingperiod)
do_simu = created \
do_simu = (created \
or not getattr(self, 'autorestart', False) \
or self.missingperiod
or self.missingperiod) and not read_only
self.missingperiod = do_simu
# Some verbose
......@@ -139,9 +159,12 @@ def obsoper(self, inputs, mode,
.format(model.plugin.name, di, df))
verbose("Running mode: {}".format(mode))
verbose("Sub-directory: {}".format(runsubdir))
print "do_simu", do_simu
print "read_only", read_only
# Prepare observations for the model
model.dataobs = obsvect.obsvect2native(di, df, mode, runsubdir, workdir)
if not read_only:
model.dataobs = obsvect.obsvect2native(di, df, mode, runsubdir, workdir)
# If the simulation was already carried out, pass to next steps
# If a sub-period was missing, following ones will be recomputed even
......@@ -171,8 +194,9 @@ def obsoper(self, inputs, mode,
continue
# Run the model
model.run(runsubdir, mode, workdir,
do_simu=do_simu, **kwargs)
if not read_only:
model.run(runsubdir, mode, workdir,
do_simu=do_simu, **kwargs)
# Read outputs
model.outputs2native(runsubdir, mode)
......@@ -220,3 +244,6 @@ def obsoper(self, inputs, mode,
if mode == 'adj':
return controlvect
if mode == 'footprint':
return controlvect
......@@ -46,7 +46,8 @@ def simul(self, chi, grad=True, run_id=-1, **kwargs):
# Computes forward simulations
controlvect.x = controlvect.sqrtbprod(chi, **kwargs)
obsvect = obsoper.obsoper(controlvect, 'fwd',
# obsvect = obsoper.obsoper(controlvect, 'fwd',
obsvect = obsoper.obsoper(controlvect, 'footprint',
datei=self.datei, datef=self.datef,
workdir=self.workdir, run_id=run_id,
reload_results=reload_results,
......
......@@ -237,15 +237,6 @@ class Plugin(object):
return getattr(
importlib.import_module(subclass[0], 'pycif.utils.classes'),
subclass[1])
@classmethod
def print_registered(cls):
"""Print all registered plugins.
"""
print cls.registered
@classmethod
def load_registered(cls, name, version, plg_type, plg_orig=None):
......
......@@ -10,6 +10,7 @@ from .baseclass import Plugin
from pycif.utils.check import verbose
from pycif.utils.check import init_log, error, verbose
import pdb
class Setup(Plugin):
......@@ -38,6 +39,12 @@ class Setup(Plugin):
cls.load_setup(setup, level=0)
# Run the mode
# Initialize every plugin, requirements and data
cls.load_setup(setup, level=0)
# Run the mode
if getattr(getattr(setup, 'mode', None), 'loaded_requirements', False):
return setup.mode.execute(**args)
......@@ -45,6 +52,10 @@ class Setup(Plugin):
verbose('pycif has correctly been initialized '
'but no execution mode was specified')
else:
verbose('pycif has correctly been initialized '
'but no execution mode was specified')
@classmethod
def from_yaml(cls, def_fic):
"""Generates a dictionary including all pyCIF parameters
......
......@@ -97,7 +97,7 @@ def calc_cellarea(i, j, zlonc, zlatc, srsQuery):
srsArea.ImportFromProj4(
'+proj=laea +lat_0=80 +lon_0={} +x_0=0 +y_0=0 '
'+ellps=WGS84 +units=m +no_defs '
.format(zlatc[i, j], zlonc[i, j])
.format(zlatc[i, j], zlonc[i, j])
)
transf = osr.CoordinateTransformation(srsQuery, srsArea)
......
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