Source code for pycif.plugins.datastreams.meteos.tm5_meteo.read
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from .....utils.netcdf import readnc
# JvP 20210517: added import statements, MODULE_NAME module level logger
import logging
import sys
import subprocess
MODULE_NAME = __name__[__name__.index('TM5'):] if 'TM5' in __name__ else __name__
logger = logging.getLogger(MODULE_NAME)
# Original read function by A. Berchet
[docs]
def read_AB(
self,
name,
tracdir,
tracfile,
varnames,
dates,
interpol_flx=False,
tracer=None,
model=None,
filetypes=["defstoke", "fluxstoke", "fluxstokev", "phystoke"],
**kwargs
):
"""Reads meteorology and links to the working directory
Args:
meteo (dictionary): dictionary defining the domain. Should include
dirmeteo to be able to read the meteorology
datei (datetime.datetime): initial date for the inversion window
datef (datetime.datetime): end date for the inversion window
workdir (str): path to the working directory where meteo files
should be copied
logfile (str): path to the log file
filetypes ([str]): list of file radicals to copy in the working
directory
**kwargs (dictionary): extra arguments
Return:
????????
Notes: At some point, include option to compute mass fluxes for LMDz,
with different physics What is needed to do that? Possible only on CCRT?
Flexibility to define new domains Can be very heavy and not necessarily
relevant
"""
for date in dates:
for filetype in filetypes:
meteo_file = "{}.an{}.m{:02d}.nc".format(
filetype, date.year, date.month
)
if filetype == "defstoke" and not os.path.isfile(
"{}/{}".format(tracdir, meteo_file)
):
meteo_file = filetype + ".nc"
target = "{}/{}".format(tracdir, meteo_file)
# Loading information on time steps
if filetype == "defstoke" and not hasattr(self, "offtstep"):
vars = readnc(target, ["dtvr", "istdyn"])
offtstep = vars[0][0, 0] * vars[1][0, 0]
self.offtstep = offtstep
# New read function by J.C.A. van Peet
[docs]
def read( self, name, tracdir, tracfile, varnames, dates, interpol_flx=False,
tracer=None, model=None, filetypes=["defstoke", "fluxstoke", "fluxstokev", "phystoke"],
**kwargs ):
"""
PURPOSE
No idea...
VERSION HISTORY
2.0 17-05-2021 by J.C.A. van Peet
Made this placeholder function that just issues an error message...
1.0 28-04-2021 by A. Berchet
Original code (see above)
"""
# Set the name of this function
PROG_NAME = MODULE_NAME+".read"
# Local logger
logger = logging.getLogger(PROG_NAME)
logger.setLevel(logging.DEBUG)
logger.debug("")
logger.debug("*"*30)
logger.debug(PROG_NAME+" => Just a placeholder function...")
logger.debug(" 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 read