#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
HYCOM utilities
"""
import logging
import os
from ...__init__ import SLOOP_SRC_DIR, SloopError
[docs]class SloopHycomError(SloopError):
pass
LOGGER = logging.getLogger(__name__)
_THISDIR = os.path.dirname(__file__)
#: HYCOM vconf
HYCOM3D_VCONF = ["manga", "med", "indien", "gijon"]
#: HYCOM platform root dir
HYCOM3D_DIR = os.path.join(SLOOP_SRC_DIR, 'HYCOM')
#: HYCOM initial and open boundary root dir
HYCOM3D_IBC_DIR = os.path.join(HYCOM3D_DIR, 'ChaineFrontieresOuvertes')
#: HYCOM gen_inicon_hycom.F file
HYCOM3D_IBC_GEN_INICON = os.path.join(
HYCOM3D_IBC_DIR, 'INTERP-VER/gen_inicon_hycom.F')
#: HYCOM vconf which needs particular gen_inicon_hycom.F file
HYCOM3D_IBC_GEN_INICON_VCONF = ["med", "indien"]
#: HYCOM inicon executable
HYCOM3D_IBC_INICON = os.path.join(HYCOM3D_IBC_DIR, 'INTERP-VER/inicon')
#: HYCOM regridcdf executable
HYCOM3D_IBC_REGRIDCDF = os.path.join(HYCOM3D_IBC_DIR, 'INTERP-HOR/regridcdf')
#: HYCOM 3D model directory
HYCOM3D_MODEL_DIR = os.path.join(HYCOM3D_DIR, 'Modele3D')
#: HYCOM 3D model executable
HYCOM3D_MODEL_EXE = os.path.join(
HYCOM3D_MODEL_DIR, 'MAKELIB.', 'main')
#: HYCOM 3D model dimensions.h.template
HYCOM3D_MODEL_DIMENSIONSH_TEMPLATE = os.path.join(
HYCOM3D_MODEL_DIR, 'COMMUNS./dimensions.h.template')
#: HYCOM rivers directory
HYCOM3D_RIVERS_DIR = os.path.join(HYCOM3D_DIR, 'Rivers')
#: HYCOM rivers flow climatology
HYCOM3D_RIVERS_FLOW_CLIM = os.path.join(HYCOM3D_RIVERS_DIR, "hycom_rivers.d")
#: HYCOM rivers hydro climatology
HYCOM3D_RIVERS_HYDRO_CLIM = os.path.join(
HYCOM3D_RIVERS_DIR, "fleuves_climato_hydro")
#: HYCOM 3D model defstretch.f/F
HYCOM3D_MODEL_DEFSTRETCH_FILES = {
"generic": os.path.join(
HYCOM3D_MODEL_DIR, 'UTIL./defstretch.f.generic'),
"med": os.path.join(
HYCOM3D_MODEL_DIR, 'UTIL./defstretch.F.med')
}
#: HYCOM spnudge root dir
HYCOM3D_SPNUDGE_DIR = os.path.join(HYCOM3D_DIR, 'Assimilation', 'Spectral_Nudging')
#: HYCOM demerliac executable
HYCOM3D_SPNUDGE_DEMERLIAC = os.path.join(
HYCOM3D_SPNUDGE_DIR, 'demerliac')
#: HYCOM filter executable
HYCOM3D_SPNUDGE_SPECTRAL = os.path.join(
HYCOM3D_SPNUDGE_DIR, 'lissage_spectral_fft')
#: HYCOM postproduction root dir
HYCOM3D_POSTPROD_DIR = os.path.join(HYCOM3D_DIR, 'PostProduction')
#: HYCOM postproduction time filtering executable
HYCOM3D_POSTPROD_FILTER = os.path.join(
HYCOM3D_POSTPROD_DIR, 'cdfTraitementTemporel3D')
#: HYCOM postproduction file conversion executable
HYCOM3D_POSTPROD_INTERPOLATION = os.path.join(
HYCOM3D_POSTPROD_DIR, 'cdfHycomTodataSHOMouSOAP')
#: HYCOM postproduction temperature conversion executable
HYCOM3D_POSTPROD_TEMPCONVERSION = os.path.join(
HYCOM3D_POSTPROD_DIR, 'temppot2tempis_postProd')
#: HYCOM postproduction traductions noms longs
HYCOM3D_POSTPROD_LONGNAMES = "PARAMETERS{rank}./traductions_noms_longs_{postprod}"
#: HYCOM postproduction traductions noms standards
HYCOM3D_POSTPROD_STDNAMES = "PARAMETERS{rank}./traductions_noms_standards_2"
#: HYCOM postproduction traductions units
HYCOM3D_POSTPROD_UNITS = "PARAMETERS{rank}./traductions_unites"
#: HYCOM sigma to stmt_fns*.h files
HYCOM3D_SIGMA_TO_STMT_FNS = {
'0': os.path.join(HYCOM3D_MODEL_DIR, 'COMMUNS./stmt_fns_SIGMA0_7term.h'),
'2': os.path.join(HYCOM3D_MODEL_DIR, 'COMMUNS./stmt_fns_SIGMA2_17term.h'),
}
#: HYCOM mapping for stmt_fns.h files
HYCOM3D_CONTEXT_TO_STMT_FNS = {
'ibc_hor': os.path.join(HYCOM3D_IBC_DIR, 'INTERP-HOR/stmt_fns.h'),
'ibc_ver': os.path.join(HYCOM3D_IBC_DIR, 'INTERP-VER/stmt_fns.h'),
'model': os.path.join(HYCOM3D_MODEL_DIR, 'COMMUNS./stmt_fns.h')
}
#: HYCOM mask file
HYCOM3D_MASK_FILE = 'FORCING{rank}./regional.mask.nc'
#: HYCOM grid a file
HYCOM3D_GRID_AFILE = 'FORCING{rank}./regional.grid.a'
#: HYCOM grid b file
HYCOM3D_GRID_BFILE = 'FORCING{rank}./regional.grid.b'
#: HYCOM depth a file
HYCOM3D_DEPTH_AFILE = "FORCING{rank}./regional.depth.a"
#: HYCOM depth b file
HYCOM3D_DEPTH_BFILE = "FORCING{rank}./regional.depth.b"
#: HYCOM isosigma a file
HYCOM3D_ISOSIGMA_AFILE = 'FORCING{rank}./iso.sigma.a'
#: HYCOM isosigma b file
HYCOM3D_ISOSIGMA_BFILE = 'FORCING{rank}./iso.sigma.b'
#: HYCOM regricdf tabindicesT
HYCOM3D_REGRIDCDF_TABINDICEST = 'FORCING{rank}./tabindicesT'
#: HYCOM blkdat.input parameters file
HYCOM3D_BLKDAT_INPUT_FILE = "PARAMETERS{rank}./blkdat.input"
#: HYCOM blkdat.input parameters file
HYCOM3D_BLKDAT_CMO_INPUT_FILE = "PARAMETERS{rank}./blkdat_cmo.input"
#: HYCOM blkdat_cmo.input parameters file
HYCOM3D_BLKDAT_CMO_INPUT_FILES = {
"spinup":"PARAMETERS{rank}./blkdat_cmo_A.input",
"forecast":"PARAMETERS{rank}./blkdat_cmo_P.input",
"spnudge_free":"PARAMETERS{rank}./blkdat_cmo_spnudge_free.input",
"spnudge_relax":"PARAMETERS{rank}./blkdat_cmo_spnudge_relax.input",
"free": "PARAMETERS{rank}./blkdat_cmo_A.input",
}
#: HYCOM savefield.input parameters file
HYCOM3D_SAVEFIELD_INPUT_FILE = "PARAMETERS{rank}./savefield.input"
#: HYCOM blkdat_cmo.input parameters file
HYCOM3D_SAVEFIELD_INPUT_FILES = {
"spinup":["PARAMETERS{rank}./savefield_C.input",
"PARAMETERS{rank}./savefield_A.input"],
"forecast":["PARAMETERS{rank}./savefield_C.input",
"PARAMETERS{rank}./savefield_P.input"],
"spnudge_free":["PARAMETERS{rank}./savefield_Assim_SN.input"],
"spnudge_relax":["PARAMETERS{rank}./savefield_C.input",
"PARAMETERS{rank}./savefield_A.input"],
"free":["PARAMETERS{rank}./savefield_C.input",
"PARAMETERS{rank}./savefield_A.input"],
}
#: HYCOM defstrech.input parameters file
HYCOM3D_DEFSTRECH_INPUT_FILE = "PARAMETERS{rank}./defstrech*.input"
#: HYCOM MPI tiling file
HYCOM3D_PATCH_INPUT_FILE = "SPLIT{rank}./patch.input"
#: HYCOM ports.input parameters file
HYCOM3D_PORTS_INPUT_FILE = "PARAMETERS{rank}./ports.input"
#: HYCOM run.input.tpl parameters file
HYCOM3D_RUN_INPUT_TPL_FILE = "PARAMETERS{rank}./run.input.tpl"
#: HYCOM post-production configuration files
HYCOM3D_POSTPROD_CFG_FILE = "PARAMETERS{rank}./postprod.cfg"
#: HYCOM post-production configuration specs file
HYCOM3D_POSTPROD_INI_FILE = os.path.join(_THISDIR, "postprod.ini")
#: HYCOM post-production configuration output files
HYCOM3D_POSTPROD_CONFIG_FILE = "PARAMETERS{rank}./postprod_{postprod}.cfg"
#: HYCOM check promises
HYCOM3D_PROMISES = "PARAMETERS{rank}./promises.cfg"
#: HYCOM rivers configuration specs file
HYCOM3D_RIVERS_INI = os.path.join(_THISDIR, "rivers.ini")
#: HYCOM rivers configuration file
HYCOM3D_RIVERS_CFG = 'FORCING{rank}./nest/rivers.cfg'
#: HYCOM spectral nudging parameters json file
HYCOM3D_SPNUDGE_JSON_FILE = "PARAMETERS{rank}./spnudging_parameters.json"
#: From standard_name to name
HYCOM3D_STANDARD_NAME_TO_NAME = {
'sea_water_potential_temperature': 'temp',
'sea_water_salinity': 'saln',
'sea_surface_height_above_geoid': 'ssh',
}
#: Required environment variables for each context
REQUIRED_ENV_VARIABLES = {
# Pre- and post-processing tasks
'prepost': [
'FC', 'LDF', 'CC', 'FFLAGS', 'LDFLAGS', 'CPPFLAGS', 'MAKE',
'MODEL_FFLAGS', 'MODEL_CFLAGS', 'MODEL_LDFLAGS'
],
# Model
'modelcompile': [
'HOME_MODELE_SRC', 'MPIDIR',
'FFLAGS', 'CPP', 'CPPFLAGS', 'LDFLAGS', 'CCFLAGS',
'FC', 'CC', 'MAKE'
],
'modelrun': [
'HOME_MODELE_SRC', 'MPIDIR',
],
}
REQUIRED_JOB_OPTIONS = {
'prepost': [
'submitcmd', 'queue', 'time'
],
'modelrun': [
'submitcmd', 'queue', 'time'
],
'recdata': [
'submitcmd', 'queue', 'refill', 'time'
],
}
#: Patterns of geographic constant files
HYCOM3D_GEO_CONSTANT_PATTERNS = {
"nest": [
"FORCING{rank}./nest/debitmeso.list",
HYCOM3D_RIVERS_CFG,
"FORCING{rank}./nest/rivers.list",
"FORCING{rank}./nest/rmu.[ab]"
],
"tide": [
"FORCING{rank}./tide/tide.list",
"FORCING{rank}./tide/forcing.*tide.[ab]"
],
"regional": [
HYCOM3D_GRID_AFILE,
HYCOM3D_GRID_BFILE,
HYCOM3D_DEPTH_AFILE,
HYCOM3D_DEPTH_BFILE,
HYCOM3D_MASK_FILE,
HYCOM3D_REGRIDCDF_TABINDICEST,
HYCOM3D_ISOSIGMA_AFILE,
HYCOM3D_ISOSIGMA_BFILE
],
"run": ([
HYCOM3D_BLKDAT_INPUT_FILE,
HYCOM3D_BLKDAT_CMO_INPUT_FILE,
HYCOM3D_DEFSTRECH_INPUT_FILE,
HYCOM3D_PORTS_INPUT_FILE,
HYCOM3D_RUN_INPUT_TPL_FILE,
HYCOM3D_SPNUDGE_JSON_FILE
]+list(HYCOM3D_BLKDAT_CMO_INPUT_FILES.values())),
"postprod": [
HYCOM3D_POSTPROD_CFG_FILE,
HYCOM3D_POSTPROD_CONFIG_FILE.format(
rank="{rank}", postprod="*")
],
"savefield": (
[HYCOM3D_SAVEFIELD_INPUT_FILE] +
list(set(p for pp in HYCOM3D_SAVEFIELD_INPUT_FILES.values()
for p in pp))
),
"split": [
HYCOM3D_PATCH_INPUT_FILE
],
"promises": [
HYCOM3D_PROMISES
],
}
#: Patterns of non-geographic constant files
HYCOM3D_NOT_GEO_CONSTANT_PATTERNS = {
"naming": [
"PARAMETERS{rank}./traductions_*",
]
}
#: Hycom3d specifications for the :mod:`xoa.cf` module use
HYCOM3D_CF_SPECS = {
"data_vars": {
"temp": {
"name": "temp"
},
"sal": {
"name": "saln"
},
"ssh": {
"name": "ssh"
},
"sigmatheta": {
"name": "thdd",
},
"ps": {
"alt_name": ["preatm", "prmsl"],
"attrs": {
"standard_name": ["air_pressure_at_mean_sea_level"],
"long_name": ["Pressure reduced to MSL"],
"header": "pression atmospherique"
}
},
"tair": {
"alt_name": ["airtmp", "t2m"],
"attrs": {
"units": "degree Celsius",
"standard_name": [
"air_temperature",
"air_temperature_at_2m"
],
"long_name": "2 metre temperature",
"header": "temperature de surface"
}
},
}
}
HYCOM3D_PARAM = {
"preatm": {
"name": [
"preatm",
"prmsl"
],
"attrs": {
"units": "Pa",
"standard_name": "air_pressure_at_mean_sea_level",
"long_name": "Pressure reduced to MSL",
"header": "pression atmospherique"
}
},
"airtmp": {
"name": [
"airtmp",
"t2m"
],
"attrs": {
"units": "degree Celsius",
"standard_name": [
"air_temperature",
"air_temperature_at_2m"
],
"long_name": "2 metre temperature",
"header": "temperature de surface",
"diurnal": "True"
}
},
"vapmix": {
"name": [
"vapmix"
],
"attrs": {
"units": "kg kg-1",
"standard_name": [
"water_vapor_mixing_ratio"
],
"long_name": "water vapor mixing ratio",
"header": "vapeur"
}
},
"shwflx": {
"name": [
"shwflx",
"ssr"
],
"attrs": {
"units": "W m-2 s-1",
"standard_name": [
"short_wave_fluxes"
],
"long_name": "surface net solar radiation",
"header": "flux radiatifs Short Wave",
"diurnal": "True"
}
},
"radflx": {
"name": [
"radflx",
"str",
],
"attrs": {
"units": "W m-2 s-1",
"standard_name": [
"radiative_fluxes"
],
"long_name": "total radiative fluxes",
"header": "flux radiatifs IR",
"diurnal": "True"
}
},
"precip": {
"name": [
"precip",
"tp"
],
"attrs": {
"units": "m s-1",
"standard_name": [
"precipitations"
],
"long_name": "Total Precipitation",
"header": "precipitations"
}
},
"wndspd": {
"name": [
"wndspd",
"si10"
],
"attrs": {
"units": "m s-1",
"standard_name": [
"wind_speed"
],
"long_name": "10 metre wind speed",
"header": "module du vent"
}
},
"tauewd": {
"name": [
"tauewd",
"ewss"
],
"attrs": {
"units": "N m-2",
"standard_name": [
"zonal_wind_stress"
],
"long_name": "zonal wind stress",
"header": "vent - composante zonale"
}
},
"taunwd": {
"name": [
"taunwd",
"nsss"
],
"attrs": {
"units": "N m-2",
"standard_name": [
"meridional_wind_stress"
],
"long_name": "meridional wind stress",
"header": "vent - compostante meridienne"
}
}
}
RESTART_FIELDS = [
"restdate",
"saln", "temp", "th3d",
"h", "dpmixl", "umbbiais",
"vmbbiais", "ut", "vt", "ptide",
"uflxbam", "vflxbam", "difs"
]
_CACHE = {}
[docs]def get_constant_patterns(geo):
"""Get dict of HYCOM3D constant file glob patterns for each pack
A file pattern typically contains the `{rank}` subsitution pattern
Parameters
----------
geo: bool
Bounded to a geograhpical area?
"""
return HYCOM3D_GEO_CONSTANT_PATTERNS if geo else HYCOM3D_NOT_GEO_CONSTANT_PATTERNS
[docs]def get_cf_specs():
"""Get a :class:`xoa.cf.CFSpecs` object for Hycom3D"""
if "cf_specs" not in _CACHE:
import xoa.cf
_CACHE["cf_specs"] = xoa.cf.CFSpecs(HYCOM3D_CF_SPECS)
return _CACHE["cf_specs"]