Source code for pycif.plugins.datastreams.meteos.lmdz_massflx_old.read
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from .....utils.netcdf import readnc
[docs]
def read(
self,
name,
varnames,
dates,
tracdir,
tracfile,
interpol_flx=False,
tracer=None,
model=None,
filetypes=["defstoke", "fluxstoke", "fluxstokev", "phystoke"],
**kwargs
):
"""Cache the LMDZ physics time step from the ``defstoke.nc`` file.
For each requested date, locates the corresponding
``defstoke.<year>.m<month>.nc`` file in ``tracdir`` (or the
``defstoke_file`` override if set, falling back further to a
dateless ``defstoke.nc``) and, the first time this is called, reads
``dtvr``/``istdyn`` from it to compute and cache ``self.offtstep``
(the LMDZ physics time step), used elsewhere for mass-flux
accumulation bookkeeping.
Args:
self: the meteo datastream Plugin (receives the cached
``offtstep`` attribute).
name: unused (kept for interface consistency).
varnames: unused (kept for interface consistency).
dates: list of dates for which to locate the ``defstoke`` file.
tracdir: directory holding the ``defstoke`` file.
tracfile: unused (kept for interface consistency).
interpol_flx (bool): unused (kept for interface consistency).
tracer: unused (kept for interface consistency).
model: unused (kept for interface consistency).
filetypes ([str]): unused here (kept for interface consistency);
only ``"defstoke"`` is actually processed by this function.
Returns:
None. ``self.offtstep`` is set as a side effect, once.
"""
filetype = "defstoke"
for date in dates:
meteo_file = f"{filetype}.an{date.year}.m{date.month:02d}.nc"
target = os.path.join(tracdir, meteo_file)
# If the 'defstoke_file' input argument is provided
target = getattr(self, "defstoke_file", target)
if not os.path.isfile(target):
# Trying without the date in filename
target = os.path.join(tracdir, "defstoke.nc")
# Loading information on time steps
if not hasattr(self, "offtstep"):
variables = readnc(target, ["dtvr", "istdyn"])
offtstep = variables[0][0, 0] * variables[1][0, 0]
self.offtstep = offtstep