from .inputs.make_obs import make_obs
from .....utils.datastores.empty import init_empty
# JvP 20210521: added import statements, MODULE_NAME module level logger
import logging
import sys
MODULE_NAME = __name__[__name__.index('TM5'):] if 'TM5' in __name__ else __name__
logger = logging.getLogger(MODULE_NAME)
# Original outputs2native_adj function by A. Berchet
[docs]
def outputs2native_adj_AB(
self, data2dump, input_type, di, df, runsubdir, mode="fwd",
dump=True, onlyinit=False, do_simu=True, **kwargs
):
"""Produce the point_observation file prior to the simulation"""
ddi = min(di, df)
for trid in data2dump:
mod_input = trid[0]
trcr = trid[1]
if mod_input != "concs":
continue
if "data" in data2dump[trid]:
make_obs(self, data2dump[trid]["data"],
runsubdir, "fwd", trcr, do_simu)
# New outputs2native_adj function by J.C.A. van Peet
[docs]
def outputs2native_adj(self, data2dump, input_type, di, df, runsubdir,
mode="fwd", dump=True, onlyinit=False, do_simu=True,
check_transforms=False,
**kwargs):
"""
PURPOSE
Produce the point_observation file prior to the simulation
ARGS
No idea...
KWARGS
No idea...
NOTE
This function calls the function self.make_obs, which is defined in
pycif/plugins/models/TM5/io/inputs/make_obs.py.
VERSION HISTORY
2.1 22-10-2021 by J.C.A. van Peet
Updated by A. Berchet.
2.0 17-06-2021 by J.C.A. van Peet
Adapted for TM5.
1.0 ??-??-???? by A. Berchet
See original code above.
"""
# Set the name of this function
PROG_NAME = MODULE_NAME+".outputs2native_adj"
# Local logger
logger = logging.getLogger(PROG_NAME)
logger.setLevel(logging.DEBUG)
# Some debug statements...
logger.debug("")
logger.debug("*"*30)
logger.debug(PROG_NAME+" => DEBUG:")
logger.debug(f" data2dump = {data2dump}" )
logger.debug(f" input_type = {input_type}")
logger.debug(f" di = {di}" )
logger.debug(f" df = {df}" )
logger.debug(f" runsubdir = {runsubdir}" )
logger.debug(f" kwarg mode = {mode}" )
logger.debug(f" kwarg dump = {dump}" )
logger.debug(f" kwarg onlyinit = {onlyinit}" )
logger.debug(f" kwarg do_simu = {do_simu}" )
# Apparently, data2dump is a pandas data series... You can convert it to
# a numpy array using the to_numpy() method.
logger.debug(f" type(data2dump ) = {type(data2dump)}")
logger.debug(f" type(data2dump[('concs', 'CH4')] ) = {type(data2dump['concs', 'CH4'])}")
logger.debug(f" type(data2dump[('concs', 'CH4')][di] ) = {type(data2dump['concs', 'CH4'][di])}")
# logger.debug(" type(data2dump[('concs', 'CH4')][di]['lat'] ) = %s" % type(data2dump[('concs', 'CH4')][di]['lat']))
lat_as_ndarray = data2dump[('concs', 'CH4')][di]["metadata"]['lat'].to_numpy()
logger.debug(f" type(lat_as_ndarray ) = {type(lat_as_ndarray)}")
logger.debug(f" lat_as_ndarray = {lat_as_ndarray}" )
# JvP 20211022
# Added by Antoine. At first above PROG_NAME, but I moved it down here.
ddi = min(di, df)
# JvP 20211022
# Also added by Antoine. No idea why, or what it does...
if not hasattr(self, "dataobs"):
self.dataobs = {spec: init_empty() for spec in self.chemistry.acspecies.attributes}
# end if
# JvP trid = TRacer ID?
for trid in data2dump:
# trid is a 2-element tuple like ("concs", "CH4"), here you split it
# into its separate components
mod_input = trid[0]
trcr = trid[1]
# Check if the first element is "concs"
if mod_input != "concs":
continue
# end if
# Check if the pandas dataframe is part of data2dump, and if it is,
# pass it to pycif/plugins/models/TM5/io/inputs/make_obs.py.
if di in data2dump[trid]:
# JvP 20211022
# Original line:
# make_obs(self, data2dump[trid]["data"], runsubdir, "fwd", trcr, do_simu)
# Changed by Antoine into the following if-construct.
if onlyinit:
make_obs(self, data2dump[trid][di], runsubdir, "fwd", trcr, ddi, do_simu)
else:
make_obs(self, data2dump[trid][di], runsubdir, "adj", trcr, ddi, do_simu)
# end if
# end if
# JvP 20211022: Following line also added by Antoine, no idea why...
# Store values in dataobs for later use
self.dataobs[trid[1]] = data2dump[trid][di]
# end for
# Some debug statements...
logger.debug("*"*30)
logger.debug("")
#logger.debug("")
#logger.debug("*"*30)
#logger.debug(PROG_NAME+" => Computer says no!")
#logger.debug("*"*30)
#logger.debug("")
#try:
# raise RuntimeError
#except RuntimeError as e:
# #logger.exception("OOPS!")
# logger.critical(e, exc_info=True)
# #raise # => Will display the traceback on screen a second time
# sys.exit() # => Just exit.
## end try
# end function outputs2native_adj