diff --git a/pysurfex/datetime_utils.py b/pysurfex/datetime_utils.py index 7eb68de..56d9e22 100644 --- a/pysurfex/datetime_utils.py +++ b/pysurfex/datetime_utils.py @@ -23,6 +23,11 @@ def as_datetime_string(dtg): return dtg.strftime(fmt) +def offsetaware(dtg): + """Make offset aware.""" + return dtg.replace(tzinfo=timezone.utc) + + def as_timedelta(seconds=0): """Convert seconds to timedelta.""" return timedelta(seconds=seconds) diff --git a/pysurfex/namelist.py b/pysurfex/namelist.py index df1dbfb..ce96fb6 100644 --- a/pysurfex/namelist.py +++ b/pysurfex/namelist.py @@ -24,30 +24,6 @@ def __init__(self, program, config, definitions, assemble=None, consistency=True self.program = program self.config = config self.nldict = definitions - """ - macros_defs = { - "CPGDFILE": "SURFEX#IO#CPGDFILE", - "CPREPFILE": "SURFEX#IO#CPREPFILE", - "CSURFFILE": "SURFEX#IO#CSURFFILE", - "CSURF_FILETYPE": "SURFEX#IO#CSURF_FILETYPE", - "CFORCING_FILETYPE": "SURFEX#IO#CFORCING_FILETYPE", - "CTIMESERIES_FILETYPE": "SURFEX#IO#CTIMESERIES_FILETYPE", - "XRIMAX": "SURFEX#PARAMETERS#XRIMAX", - "LSPLIT_PATCH": "SURFEX#IO#LSPLIT_PATCH", - "LFAKETREE": "SURFEX#TREEDRAG#FAKETREES", - "LECOSG": "SURFEX#COVER#SG", - "XTSTEP": "SURFEX#IO#XTSTEP", - "XTSTEP_OUTPUT ": "SURFEX#IO#XTSTEP_OUTPUT", - } - macros = {} - for macro, setting in macros_defs.items(): - vmacro = config.get_setting(setting) - logging.debug("Mapping macro %s = %s", macro, vmacro) - if vmacro is not None: - if isinstance(vmacro, tuple): - vmacro = list(vmacro) - macros.update({macro: vmacro}) - """ nobstype = 0 if program == "soda" or program == "offline": diff --git a/pysurfex/netcdf.py b/pysurfex/netcdf.py index b12acbf..16bf74c 100644 --- a/pysurfex/netcdf.py +++ b/pysurfex/netcdf.py @@ -17,7 +17,7 @@ cfunits = None -from .datetime_utils import fromtimestamp, isdatetime, utcfromtimestamp +from .datetime_utils import fromtimestamp, isdatetime, offsetaware, utcfromtimestamp from .geo import ConfProj, Geo from .interpolation import Interpolation @@ -102,6 +102,7 @@ def nc_slice( logging.debug("Time provided in call as datetime objects") times_in_var = var.datetimes for i, times_in_var_val in enumerate(times_in_var): + times_in_var_val = offsetaware(times_in_var_val) logging.debug( "i %s times_in_var %s times %s", i, times_in_var_val, times ) @@ -110,7 +111,7 @@ def nc_slice( logging.debug( "i=%s, times_in_var_val=%s tval=%s", i, times_in_var_val, tval ) - if times_in_var[i] == tval: + if times_in_var_val == tval: times_to_read.append(i) if i > 0: prev_time_steps.append(i - 1) diff --git a/pysurfex/run.py b/pysurfex/run.py index be48a8b..00e99ba 100644 --- a/pysurfex/run.py +++ b/pysurfex/run.py @@ -196,27 +196,19 @@ def __init__( negpert (bool, optional): _description_. Defaults to False. """ - self.pert_number = pert_number + pert_number = int(pert_number) settings["nam_io_varassim"]["LPRT"] = True - settings["nam_var"]["nivar"] = int(pert_number) + settings["nam_var"]["nivar"] = pert_number # Handle negative pertubations if negpert: - nvar = int(settings["nam_var"]["nvar"]) - ipert = 0 - npert = 1 - for nvi in range(0, nvar): - key = "nncv(" + str(nvi + 1) + ")" - val = int(settings["nam_var"][key]) - # Check if active - if val == 1: - npert = 1 - else: - npert = npert + 1 - for __ in range(0, npert): - ipert = ipert + 1 - key = "xtprt_m(" + str(ipert) + ")" - val = settings["nam_var"][key] - settings["nam_var"][key] = -val + nncv = settings["nam_var"]["nncv"] + nind = 0 + for nvi, nval in enumerate(nncv): + if nval == 1: + nind += 1 + if nind == pert_number: + val = settings["nam_var"]["xtprt_m"][nvi] + settings["nam_var"]["xtprt_m"][nvi] = -val SURFEXBinary.__init__( self, binary,