PYSURFEX documentation

Python API to SURFEX (pysurfex)

An API in python to the external surface model SURFEX.
  • Prepare input and namelists to a SURFEX binary

  • Create atmospheric forcing for offline SURFEX runs

  • Read SURFEX output

  • Quality control of observations with titanlib

  • Optimal interpolation with gridpp

  • Monitor the observations usage

See online documentation in https://metno.github.io/pysurfex/

Installation of pregenerated packages from pypi (pip)

All releases will trigger an autmomatic pre-built package on pypi which can be installed by pip

pip3 install pysurfex

User installation:

pip3 install pysurfex --user

Run pysurfex from pre-built container

Releases also trigger an update of the pysurfex container in the github container registry. Below is an example to run pgd without any arguments.

podman run -it ghcr.io/metno/pysurfex:latest pgd

Installation on debian based Linux system

The following depencies are needed. Install the non-standard ones e.g. with pip or your system installation system.

General dependencies (from pypi)

numpy
pyproj
pyyaml
f90nml

To read NetCDF files:

NetCDF4
cfunits

To read grib files:

eccodes

from ECMWF https://software.ecmwf.int/wiki/display/ECC/Releases installed with ENABLE_PYTHON=ON

To read FA files:

falfilfa4py
epygram

To plot:

matplotlib

To get observations from frost.met.no API:

requests

For Quality control of observations

titanlib

For optimal interpolation and observation operators

gridpp

For testing:

pytest

Install pysurfex

An environment manager like miniconda or micromamba is recommended to ensure consistency between the packages. After installing this you need to set it up for the current session or permanently add it to your shell. Now it is easy to create a suitable environment for pysurfex. Below is a recipie for micromamba.

# Install micromamba (linux, https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html)
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)

# specify a installation location for micromamba and add it to your path afterwards. Default it will install in $HOME/.local/bin
export PATH=$HOME/.local/bin:$PATH  # Use your PATH

# initialize your shell (needed in all shells), e.g:
eval "$(micromamba shell hook --shell bash)"

micromamba create env pysurfex
micromamba activate pysurfex
micromamba install python==3.12 poetry

Download the source code, then install pysurfex by executing the following inside the extracted folder:

poetry install

If not already in a conda/manba environment, this will install pysurfex in a poetry environment and this environment can be activated interactively by:

poetry shell

or

Run pysurfex client applications

poetry run [command]
# e.g.
poetry run python # will run python inside the pysurfex poetry environment

Examples

See https://metno.github.io/pysurfex/#examples

Examples

All examples here assume you have an installation or that you have a working poetry environment.

You can use pysurfex with poetry from inside a container if you set the variable CONTAINER in the examples.

If you have a system-wide installation you can run pysurfex entry points directly:

# Run pgd entry point
pgd

# Use empty env variables in examples
export LOCAL=""
export CONTAINER=""
export POETRY=""

This is how you run the pgd entry point with poetry

# Run pgd entry point
poetry run pgd

# Use empty env variables in examples
export LOCAL=""
export CONTAINER=""
export POETRY="poetry run"

This is how to create an apptainer container on ECMWF-atos and run it.

# Load singularity/apptainer
module load apptainer/1.1.8
# First time creation
singularity pull /scratch/$USER/pysurfex.sif docker://ghcr.io/metno/pysurfex:latest
# Run pgd entry point
singularity exec /scratch/$USER/pysurfex.sif poetry run pgd

 # Assume set in variables with local bindings
export LOCAL="/local/"
# X11 not working yet
# export CONTAINER="singularity exec --bind .:$LOCAL --env=QT_X11_NO_MITSHM=1 --bind=/tmp/.X11-unix:/tmp/.X11-unix:rw /scratch/$USER/pysurfex.sif"
export CONTAINER="singularity exec --bind .:$LOCAL /scratch/$USER/pysurfex.sif"
export POETRY="poetry run"

This is how to create a container with podman and run it. Podman is recommended as you can run docker containers without root/sudo.

# Run pgd entry point
podman run -it docker://ghcr.io/metno/pysurfex:latest poetry run pgd

# Assume set in a variables with local bindings
export LOCAL="/local/"
export CONTAINER="podman -v .:$LOCAL --env='DISPLAY' --env='QT_X11_NO_MITSHM=1' --volume='/tmp/.X11-unix:/tmp/.X11-unix:rw' run -it docker://ghcr.io/metno/pysurfex:latest"
export POETRY="poetry run"

Create forcing from MET-Nordic analysis

# Local address: /lustre/storeB/project/metproduction/products/yr_short/met_analysis_1_0km_nordic_@YYYY@@MM@@DD@T@HH@Z.nc
# Thredds: https://thredds.met.no/thredds/dodsC/metpparchivev3/@YYYY@/@MM@/@DD@/met_analysis_1_0km_nordic_@YYYY@@MM@@DD@T@HH@Z.nc

# Thredds example:
$CONTAINER $POETRY create_forcing -p  https://thredds.met.no/thredds/dodsC/metpparchivev3/@YYYY@/@MM@/@DD@/met_analysis_1_0km_nordic_@YYYY@@MM@@DD@T@HH@Z.nc \
 2023013010 2023013011 -d examples/domains/drammen.json -a \
 --rain-converter calcrain \
 --snow-converter calcsnow \
 --zref screen --uref screen \
 --qa-converter rh2q_mslp \
 --co2 constant \
 --dir-sw-converter analysis \
 --sca-sw constant \
 --lw-converter analysis \
 --wind-converter none \
 --wind-dir-converter none \
 --ps-converter mslp2ps \
 --output-filename FORCING.nc

Example on a Lambert conf proj domain

{
  "nam_pgd_grid": {
    "cgrid": "CONF PROJ"
  },
  "nam_conf_proj": {
   "xbeta": 0.0,
   "xlat0": 63.0,
   "xlon0": 15.0,
   "xrpk": 0.8910065241883678
  },
  "nam_conf_proj_grid": {
    "nimax": 50,
    "njmax": 50,
    "xdx": 1000.0,
    "xdy": 1000.0,
    "xlatcen": 61.5,
    "xloncen": 9.0
  }
}

Example on a system json file for ECMWF-atos

{
  "sand_dir": "/perm/sbu/soilgrid_carra2/",
  "clay_dir": "/perm/sbu/soilgrid_carra2/",
  "soilgrid_dir": "/perm/sbu/soilgrid_carra2/",
  "soc_top_dir": "/ec/res4/hpcperm/hlam/data/climate/PGD/",
  "soc_sub_dir": "/ec/res4/hpcperm/hlam/data/climate/PGD/",
  "ecoclimap_cover_dir": "/ec/res4/hpcperm/hlam/data/climate/PGD/",
  "ecoclimap_bin_dir": "/scratch/sbu/sfx_data/test_default/lib/offline/MY_RUN/ECOCLIMAP",
  "flake_dir": "/ec/res4/hpcperm/hlam/data/climate/PGD/",
  "ecoclimap_sg_cover_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/COVER/",
  "albnir_soil_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/ALBNIR_SAT/",
  "albvis_soil_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/ALBVIS_SAT/",
  "albnir_veg_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/ALBNIR_SAT",
  "albvis_veg_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/ALBVIS_SAT/",
  "tree_height_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/HT/",
  "lai_dir": "/ec/res4/hpcperm/hlam/data/climate/ECOCLIMAP-SG/LAI_SAT/",
  "oro_dir": "/perm/sbu/gmted_carra2/"
}

Run SURFEX binaries

  • Assume that you have your surfex binaries in PATH and that they are called PGD, PREP, OFFLINE and SODA

  • Assume that you have system paths defined in a file called system.json

  • Assume that you have a namelist directory consistent with your SURFEX version

If you want to modify local input and run in containers you have to bind the local data to the container similar to the rte.json and system.json below.

 mkdir tutorial
 cd tutorial

 # Example namelists
$CONTAINER $POETRY create_namelist --assemble-file ${LOCAL}examples/assemble.yml --namelist-defs ${LOCAL}examples/surfex_namelists.yml --output OPTIONS.nam_pgd pgd
$CONTAINER $POETRY create_namelist --assemble-file ${LOCAL}examples/assemble.yml --namelist-defs ${LOCAL}examples/surfex_namelists.yml --output OPTIONS.nam_prep prep
$CONTAINER $POETRY create_namelist --assemble-file ${LOCAL}examples/assemble.yml --namelist-defs ${LOCAL}examples/surfex_namelists.yml --output OPTIONS.nam_offline offline

 # Use only one openMP thread
 export OMP_NUM_THREADS=1

 # Create PGD
 $CONTAINER $POETRY pgd --domain ${LOCAL}examples/domains/drammen.json -s ${LOCAL}system.json -n ${LOCAL}OPTIONS.nam_pgd -o PGD.nc --binary PGD

 # Create PREP (from namelist values)
 $CONTAINER $POETRY prep -s ${LOCAL}system.json -n ${LOCAL}OPTIONS.nam_prep --pgd PGD.nc -o PREP.nc  --validtime 2021010103 --binary PREP

 # Use forcing created above.

 # Run Offline
 $CONTAINER $POETRY offline  -s ${LOCAL}system.json -n ${LOCAL}OPTIONS.nam_offline --pgd PGD.nc --prep PREP.nc -o SURFOUT.nc --binary OFFLINE --forcing $PWD

Plot MEPS data from thredds

You can plot data interpolated to surfex points using matplotlib. It is also possible to plot directly from a containes as demonstrated below.

$CONTAINER $POETRY plot_points \
--variable air_temperature_2m \
-g examples/domains/drammen.json \
--inputtype netcdf \
--inputfile https://thredds.met.no/thredds/dodsC/meps25epsarchive/2023/04/13/meps_det_2_5km_20230413T06Z.nc \
--validtime 2023041307 \
--basetime 2023041306

Classes

class pysurfex.platform_deps.SystemFilePaths(system_file_paths)[source]

Matches files and paths depending on possibly system specific settings.

User can provide a default system dir to nest dependencies.

class pysurfex.platform_deps.SystemFilePathsFromFile(system_file_paths)[source]

System file paths.

class pysurfex.observation.Observation(obstime, lon, lat, value, elev=nan, stid='NA', varname=None, sigmao=1.0)[source]

Observation class.

class pysurfex.binary_input.InputDataToSurfexBinaries[source]

Abstract input data.

class pysurfex.binary_input.OutputDataFromSurfexBinaries[source]

Abstract output data.

class pysurfex.binary_input.JsonOutputData(data)[source]

Output data.

class pysurfex.binary_input.JsonOutputDataFromFile(file)[source]

JSON output data.

class pysurfex.binary_input.JsonInputData(data)[source]

JSON input data.

class pysurfex.binary_input.JsonInputDataFromFile(file)[source]

JSON input data.

class pysurfex.binary_input.InputDataFromNamelist(nml, input_data, program, platform, basetime=None, validtime=None)[source]

Binary input data for offline executables.

class pysurfex.interpolation.Interpolation(operator, geo_in, geo_out)[source]

Interpolation.

class pysurfex.interpolation.ObsOperator(operator, geo, dataset, grid_values, max_distance=5000)[source]

Obs operator. Class to convert a field to an observation point.

class pysurfex.variable.Variable(var_type, var_dict, initial_basetime, prefer_forecast=True)[source]

New combined variable.

class pysurfex.cmd_parsing.LoadFromFile(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Load arguments from a file.

class pysurfex.pseudoobs.SentinelObservationSet(filename, validtime, fg_geo, grid_sm_fg, label='sentinel', step=2, fg_threshold=1.0)[source]

JSON observation set.

class pysurfex.pseudoobs.CryoclimObservationSet(filenames, validtime, fg_geo, snow_fg, gelevs_fg, perm_snow=None, perm_snow_geo=None, slope=None, slope_geo=None, label='cryo', step=2, fg_threshold=0.4, new_snow_depth=0.1, glaf=None, laf_threshold=0.1, cryo_varname='classed_value_c')[source]

JSON observation set.

class pysurfex.bufr.BufrObservationSet(bufrfile, variables, valid_dtg, valid_range, lonrange=None, latrange=None, label='bufr', use_first=False, sigmao=None)[source]

Create observation data set from bufr observations.

class pysurfex.geo.Geo(lons, lats)[source]

Geometry.

class pysurfex.geo.SurfexGeo(proj, lons, lats)[source]

Abstract surfex geometry class.

Parameters:
  • ABC (_type_) – _description_

  • Geo (_type_) – _description_

class pysurfex.geo.ConfProj(from_json)[source]

Conf proj.

class pysurfex.geo.ConfProjFromHarmonie(env=None)[source]

Conf proj.

class pysurfex.geo.LonLatVal(from_json)[source]

LonLatVal.

class pysurfex.geo.Cartesian(from_json)[source]

Cartesian.

class pysurfex.geo.LonLatReg(from_json)[source]

LonLatReg.

class pysurfex.geo.IGN(from_json, recreate=False)[source]

IGN.

class pysurfex.read.ReadData(geo, var_name)[source]

Read data class.

class pysurfex.read.ConvertedInput(geo, var_name, converter)[source]

Converted input.

Parameters:
  • geo (surfex.Geo) – Surfex geometry

  • var_name (str) – Variable name

  • converter (surfex.Converter) – Converter

class pysurfex.read.ConstantValue(geo, var_name, var_dict)[source]

Constant value converter.

class pysurfex.read.Converter(name, initial_time, defs, conf, fileformat)[source]

Converter.

Main interface to read a field is done through a converter. The converter name is default “None” to read a plain field without any conversion.

class pysurfex.file.SurfexIO(filename, geo, extension)[source]

Abstract Surfex IO class.

Used for internal surfex file format files.

class pysurfex.file.SurfexSurfIO(surfexfile, csurf_filetype, input_file=None, symlink=True, archive_file=None)[source]

Surfex surf file.

Class for surfex restart files.

class pysurfex.file.PGDFile(csurf_filetype, cpgdfile, input_file=None, symlink=True, archive_file=None, lfagmap=False, masterodb=False)[source]

PGD file.

class pysurfex.file.PREPFile(csurf_filetype, cprepfile, input_file=None, symlink=True, archive_file=None, lfagmap=False, masterodb=False)[source]

PREP file.

class pysurfex.file.SURFFile(csurf_filetype, csurffile, archive_file=None, input_file=None, lfagmap=False, masterodb=False)[source]

SURFOUT file.

class pysurfex.file.SurfexFileVariable(varname, validtime=None, patches=1, layers=1, basetime=None, interval=None, datatype='float', tiletype='FULL')[source]

Surfex Variable.

class pysurfex.file.AsciiSurfexFile(filename, geo=None)[source]

Input from an ASCII surfex file (.txt).

class pysurfex.file.NCSurfexFile(filename, geo=None)[source]

NetCDF surfex file (restart type).

class pysurfex.file.FaSurfexFile(filename, geo=None, masterodb=False, lfagmap=True)[source]

FA surfex file.

class pysurfex.file.SurfFileTypeExtension(csurf_filetype, masterodb=False, lfagmap=True)[source]

Extension of a surfex file.

class pysurfex.file.NetCDFSurfexFile(filename, geo)[source]

Reading surfex NetCDF time series output.

class pysurfex.file.TexteSurfexFile(filename, geo)[source]

Reading surfex TEXTE output.

class pysurfex.file.ForcingFileNetCDF(fname, geo)[source]

Forcing netCDF file.

class pysurfex.grib.Grib(fname)[source]

Grib class.

class pysurfex.grib.Grib2Variable(discipline, pca, pnr, typ, lev, tsp=-1)[source]

Grib2 variable.

class pysurfex.obs.ObservationSet(observations, label='', sigmao=None)[source]

Set of observations.

class pysurfex.obs.NetatmoObservationSet(filenames, variable, target_time, dt=3600, re=True, lonrange=None, latrange=None, label='netatmo', sigmao=None)[source]

Observation set from netatmo.

class pysurfex.obs.MetFrostObservations(varname, stations=None, level=None, num_tries=3, wmo=None, providers=None, xproviders=None, blacklist=None, validtime=None, dt=3600, lonrange=None, latrange=None, unit=None, label='frost', sigmao=None)[source]

Observations from MET-Norway obs API (frost).

class pysurfex.obs.JsonObservationSet(filename, label='json', var=None, sigmao=None)[source]

JSON observation set.

class pysurfex.obs.ObservationFromTitanJsonFile(an_time, filename, label='', sigmao=None)[source]

Observation set from titan json file.

class pysurfex.obs.ObsSetFromVobs(fname, validtime, varname=None, label='vobs', sigmao=None)[source]

Create observation set from vobs files.

class pysurfex.timeseries.TimeSeries(times, values, lons, lats, stids, varname='NA')[source]

Time series.

class pysurfex.timeseries.TimeSeriesFromConverter(var, geo, converter, start, end, interval=3600, cache=None, stids_file=None)[source]

Time-Series from a converter.

class pysurfex.namelist.NamelistGenerator(program, nml, macros=None, micro='@')[source]

Namelist class.

class pysurfex.namelist.NamelistGeneratorFromNamelistFile(program, nml_file, macros=None, micro='@')[source]

Namelist class.

class pysurfex.namelist.NamelistGeneratorAssemble(program, definitions, assemble, macros=None, micro='@')[source]

Namelist class.

class pysurfex.namelist.NamelistGeneratorAssembleFromFiles(program, definitions, assemble, macros=None, micro='@')[source]

Namelist class.

class pysurfex.run.BatchJob(rte, wrapper='')[source]

Batch job.

class pysurfex.run.SURFEXBinary(binary, batch, iofile, settings, input_data, **kwargs)[source]

SURFEX binary class.

class pysurfex.run.PerturbedOffline(binary, batch, io, pert_number, settings, input_data, surfout=None, archive_data=None, pgdfile=None, print_namelist=False, negpert=False)[source]

Pertubed offline.

class pysurfex.run.Masterodb(pgdfile, prepfile, surffile, settings, input_data, binary=None, archive_data=None, print_namelist=True, batch=None)[source]

Masterodb.

class pysurfex.forcing.SurfexForcing[source]

Surfex forcing class.

class pysurfex.forcing.SurfexNetCDFForcing(filename, geo)[source]

NetCDF surfex forcing.

class pysurfex.forcing.SurfexOutputForcing(base_time, geo, ntimes, var_objs, time_step_intervall)[source]

Main output class for SURFEX forcing.

class pysurfex.forcing.NetCDFOutput(base_time, geo, fname, ntimes, var_objs, att_objs, att_time, cache, time_step, fmt='netcdf', diskless_write=False)[source]

Forcing in NetCDF format.

class pysurfex.forcing.AsciiOutput(base_time, geo, fname, ntimes, var_objs, att_objs, att_time, cache, time_step)[source]

Forcing in ASCII format.

class pysurfex.obsoul.ObservationDataSetFromObsoul(content, an_time=None, label='', obnumber=None, obtypes=None, subtypes=None, neg_dt=None, pos_dt=None, sigmao=None)[source]

Observation set from obsoul file.

class pysurfex.obsoul.ObservationDataSetFromObsoulFile(filename, an_time=None, neg_dt=None, pos_dt=None, label='', obnumber=None, obtypes=None, subtypes=None, sigmao=None)[source]

Observation set from obsoul file.

class pysurfex.titan.QualityControl(name)[source]

Quality control abstract class.

class pysurfex.titan.Plausibility(minval=None, maxval=None)[source]

Plausibilty.

class pysurfex.titan.FirstGuess(geo_in, fg_field, negdiff=None, posdiff=None, max_distance=5000, operator='bilinear')[source]

First guess check.

class pysurfex.titan.Fraction(geo_in, fraction_field, minval=None, maxval=None, max_distance=5000, operator='bilinear')[source]

Fraction test.

class pysurfex.titan.Sct(num_min=5, num_max=100, inner_radius=50000, outer_radius=150000, num_iterations=5, num_min_prof=20, min_elev_diff=200, min_horizonal_scale=10000, vertical_scale=200, pos=4, neg=8, eps2=0.5, cmin=0.9, cmax=1.1, missing_elev_to_zero=False)[source]

Spatial consistency check.

class pysurfex.titan.Buddy(diff_elev_max=200000.0, adjust_for_elev_diff=True, distance_lim=1000000.0, priorities=1, buddies_min=1, thresholds=1.0, obs_to_check=1)[source]

Buddy test.

class pysurfex.titan.Climatology(an_time, minval=None, maxval=None, offset=0)[source]

Climatology QC test.

class pysurfex.titan.Redundancy(an_time)[source]

Redundancy.

class pysurfex.titan.Blacklist(blacklist)[source]

Blacklist.

class pysurfex.titan.DomainCheck(domain_geo, max_distance=5000)[source]

Domain check.

class pysurfex.titan.NoMeta[source]

Check for missing meta data.

class pysurfex.titan.QCDataSet(analysis_time, observations, flags, lafs, providers, passed_tests=None, fg_dep=None, an_dep=None, remove_invalid_elevs=False)[source]

QC data set.

class pysurfex.titan.TitanDataSet(var, settings, tests, datasources, an_time, test_flags=None)[source]

Titan QC data set.

class pysurfex.titan.Departure(operator, geo, dataset, grid_values, mode, max_distance=5000)[source]

Departure. Difference between an observation and a value.

class pysurfex.verification.ObsDataFromSurfexConverter(converter, var, stationlist, validtime, cache=None, label='converter')[source]

Create verif data from pysurfex converter.

class pysurfex.verification.VerifVariable(name, unit=None)[source]

Verif variable.

class pysurfex.verification.VerifDataFromFile(filename, fmt='netcdf')[source]

Create VerifData from a verif file.

Parameters:

VerifData (_type_) – _description_

class pysurfex.netcdf.Netcdf(filename)[source]

Netcdf input.

class pysurfex.netcdf.Axis(*values)[source]

Axis.

class pysurfex.netcdf.NetCDFReadVariable(name, level=None, units=None, member=None)[source]

NetCDF read variable.

class pysurfex.netcdf.NetCDFFileVariable(file_handler, var)[source]

NetDF file variable.

class pysurfex.fa.Fa(fname)[source]

Fichier Arpege.

Class methods

SystemFilePaths.__init__(system_file_paths)[source]

Construct SystemFilePaths.

Parameters:

system_file_paths (_type_) – _description_

static SystemFilePaths.substitute_string(setting, system_variables=None, micro='@')[source]

Substitute setting if string with OS values of values from system_variables.

Parameters:
  • setting (str) – if setting is string it can be subst

  • system_variables (dict) – Arbitrary settings to substitute @NAME@ = system_variables={“NAME”: “Value”}

  • micro (str, optional) – Micro character. Default to “@”

Returns:

A setting possibly substituted if type is str

Return type:

setting

SystemFilePaths.save_as(fname)[source]

Save as a file.

Parameters:

fname (str) – File name

SystemFilePathsFromFile.__init__(system_file_paths)[source]

System file path from a file.

Parameters:

system_file_paths (_type_) – _description_

Observation.print_obs()[source]

Print observation.

static Observation.vectors2obs(obstime, lon, lat, stid, elev, value, varname, sigmao)[source]

Convert vectors to observations.

Parameters:
  • obstime (_type_) – _description_

  • lon (_type_) – _description_

  • lat (_type_) – _description_

  • stid (_type_) – _description_

  • elev (_type_) – _description_

  • value (_type_) – _description_

  • varname (_type_) – _description_

  • sigmao (float) – Observation error

Returns:

Observation object.

Return type:

Observation

static Observation.obs2vectors(my_obs)[source]

Convert observations to vectors.

Parameters:

my_obs (Observation) – Observation object

Returns:

_description_

Return type:

tuple

static Observation.format_lon(lon)[source]

Format longitude.

static Observation.format_lat(lat)[source]

Format latitude.

static Observation.get_posid(lon, lat, pos_decimals=5)[source]

Get pos id.

Parameters:
  • lon (_type_) – _description_

  • lat (_type_) – _description_

  • pos_decimals (int, optional) – _description_. Defaults to 5.

Returns:

_description_

Return type:

_type_

abstractmethod InputDataToSurfexBinaries.__init__()[source]

Construct.

abstractmethod InputDataToSurfexBinaries.prepare_input()[source]

Prepare input.

abstractmethod OutputDataFromSurfexBinaries.__init__()[source]

Construct.

abstractmethod OutputDataFromSurfexBinaries.archive_files()[source]

Archive files.

JsonOutputData.__init__(data)[source]

Output data from dict.

Parameters:

data (dict) – Output data.

JsonOutputData.archive_files()[source]

Archive files.

JsonOutputDataFromFile.__init__(file)[source]

Construct from json file.

JsonOutputDataFromFile.archive_files()[source]

Archive files.

JsonInputData.__init__(data)[source]

Construct input data.

Parameters:

data (dict) – Input data.

JsonInputData.prepare_input()[source]

Prepare input.

JsonInputData.add_data(data)[source]

Add data.

Parameters:

data (dict) – Data to add

JsonInputDataFromFile.__init__(file)[source]

Construct JSON input data.

Parameters:

file (str) – JSON file name

JsonInputDataFromFile.prepare_input()[source]

Prepare input.

static InputDataFromNamelist.get_nml_value2(nml, block, key, indices=None)[source]

Get namelist value.

Parameters:
  • nml (nmlf90.Namelist) – Namelist

  • block (str) – Namelist block

  • key (str) – Namelist key

  • indices (list, optional) – Indices to read. Defaults to None.

Returns:

Namelist setting

Return type:

setting (any)

static InputDataFromNamelist.get_nml_value(nml, block, key, indices=None)[source]

Get namelist value.

Parameters:
  • nml (nmlf90.Namelist) – Namelist

  • block (str) – Namelist block

  • key (str) – Namelist key

  • indices (list, optional) – Indices to read. Defaults to None.

Returns:

Namelist setting

Return type:

setting (any)

static InputDataFromNamelist.get_nml_value_from_string(nml, string, sep='#', indices=None)[source]

Get namelist value from a string.

Parameters:
  • nml (nmlf90.Namelist) – Namelist

  • string (str) – Namelist identifier

  • sep (str, optional) – _description_. Defaults to “#”.

  • indices (list, optional) – Indices to read. Defaults to None.

Returns:

Namelist setting

Return type:

setting (any)

InputDataFromNamelist.substitute(key, val, macros=None, micro='@', check_parsing=False)[source]

Substitute patterns.

Parameters:
  • key (str) – _description_

  • val (str) – _description_

  • macros (dict, optional) – Macros. Defaults to None.

  • micro (str, optional) – Micro character. Defaults to “@”.

  • check_parsing (bool, optional) – Caheck if values were substituted.

Returns:

Substituted key=value

Return type:

dict

InputDataFromNamelist.read_macro_setting(macro_defs, key, default=None, sep='#')[source]

Read a macro setting.

Parameters:
  • macro_defs (dict) – Macro definition

  • key (str) – Macro setting to get.

  • default (str, optional) – Default value. Defaults to None.

  • sep (str, optional) – Namelist key separator. Defaults to “#”.

Returns:

setting (any)

InputDataFromNamelist.extend_macro(key, val, macros, sep='#')[source]

Extend entries from macro.

Parameters:
  • key (_type_) – _description_

  • val (_type_) – _description_

  • macros (dict) – Macros

  • sep (str, optional) – Namelist key separator. Defaults to “#”.

Raises:
  • NotImplementedError – _description_

  • NotImplementedError – _description_

Returns:

Key, value dictionary

Return type:

dict

InputDataFromNamelist.process_macro(key, val, macros, sep='#', indices=None)[source]

Process macro.

Parameters:
  • key (str) – Key

  • val (str) – Value

  • macros (dict) – Macros

  • sep (str, optional) – Namelist key separator. Defaults to “#”.

  • indices (list, optional) – Process macro from namelist indices.

Raises:

NotImplementedError – Only 2 dimensions are implemented

Returns:

Key, value dictionary

Return type:

dict

InputDataFromNamelist.matching_value(data, val, sep='#', indices=None)[source]

Match the value. Possibly also read namelist value.

Parameters:
  • data (dict) – Data to check keys for

  • val (str) – Key to find

  • sep (str, optional) – Namelist separator. Defaults to “#”.

  • indices (list, optional) – Indices in namelist

Raises:

RuntimeError – “Malformed input data”

Returns:

Matching entry in data.

Return type:

dict

InputDataFromNamelist.process_data(sep='#')[source]

Process input definitions on files to map.

Parameters:

sep (str, optional) – Namelist separator. Defaults to “#”.

Returns:

A dict with mapped local names and target files.

Return type:

mapped_data (dict)

Interpolation.__init__(operator, geo_in, geo_out)[source]

Construct an intrpolation object.

Parameters:
  • operator (str) – Operator

  • geo_in (surfex.geo.Geo) – Input geometry

  • geo_out (surfex.geo.Geo) – Output geometry

Raises:

RuntimeError – You can not interpolate without specifying an output geometry

Interpolation.interpolate(field2d, undefined=None)[source]

Do interpolation.

Parameters:
  • field2d (np.ndarray) – Two dimensional field to interpolate

  • undefined (float, optional) – Undefined value if field2d is None. Defaults to None.

Raises:
  • RuntimeError – Input domain and ouput domain differ.

  • RuntimeError – You try to interpolate a missing field!

  • NotImplementedError – Interpolation method not implemented

Returns:

interpolated_field

Return type:

np.array

static Interpolation.distance(lon1, lat1, lon2, lat2)[source]

Compute distance.

Computes the great circle distance between two points using the haversine formula. Values can be vectors.

Parameters:
  • lon1 (float) – lon1

  • lat1 (float) – lat1

  • lon2 (float) – lon2

  • lat2 (float) – lat2

Returns:

Circle distance

Return type:

cval(float)

Interpolation.alpha_grid_rot()[source]

Calculate alpha.

ObsOperator.__init__(operator, geo, dataset, grid_values, max_distance=5000)[source]

Construct the observation operator.

Parameters:
  • operator (str) – Interpolation operator.

  • geo (surfex.Geo) – Surfex geometry.

  • dataset (QCDataSet) – QC data set.

  • grid_values (np.darray) – Values in the grid.

  • max_distance (int, optional) – Max allowed deviation in meters from grid borders. Defaults to 5000.

ObsOperator.get_obs_value(pos=None)[source]

Get the observed value.

Parameters:

pos (int, optional) – Position. Defaults to None.

Raises:

NotImplementedError – Specific position not implemented yet!

Returns:

Observation value for index.

Return type:

float

ObsOperator.is_in_grid(index)[source]

Check if index is in grid.

Parameters:

index (int) – Index to check.

Returns:

True if inside

Return type:

bool

Variable.__init__(var_type, var_dict, initial_basetime, prefer_forecast=True)[source]

Construct variable.

Parameters:
  • var_type (str) – Variable type.

  • var_dict (dict) – Variable definitions

  • initial_basetime (datetime) – Initial basetime

  • prefer_forecast (bool, optional) – Prefer forecasts instead of analysis. Defaults to True.

Raises:
  • RuntimeError – Initial base time not set

  • RuntimeError – No filepattern provided

  • RuntimeError – variable must have attribute

  • RuntimeError – You can not have larger offset than the frequency of forecasts

Variable.substitute_macros(setting, micro='@')[source]

Substitute macros.

Parameters:
  • setting (str) – Setting

  • micro (str) – Micro character

Variable.get_filename(validtime, previoustime=None)[source]

Get the filename.

Parameters:
  • validtime (datetime.datetime) – Valid time.

  • previoustime (datetime.datetime, optional) – Previous valid time. Defaults to None.

Returns:

Parsed filename

Return type:

str

Variable.get_filehandler(validtime, cache=None, previoustime=None)[source]

Get the file handler.

Parameters:
  • validtime (datetime.datetime) – Valid time.

  • cache (surfex.Cache, optional) – Cache. Defaults to None.

  • previoustime (datetime.datetime, optional) – Previous valid time. Defaults to None.

Raises:

NotImplementedError – Variable type not implemented

Returns:

Filehandler and file name

Return type:

tuple

Variable.read_var_field(validtime, cache=None)[source]

Read points for a variable.

Parameters:
  • validtime (datetime.datetime) – Valid time

  • cache (surfex.Cache, optional) – Cache. Defaults to None.

Returns:

A numpy array with point values for variable

Return type:

numpy.darray

Raises:

NotImplementedError – “Field not defined for point data”

Variable.read_var_points(var, geo, validtime, previoustime=None, cache=None)[source]

Read points for a variable.

Parameters:
  • var (object) – Variable object

  • geo (surfex.Geo) – Surfex geometry

  • validtime (datetime.datetime) – Valid time

  • previoustime (datetime.datetime, optional) – Previous valid time for accumulated variables. Defaults to None.

  • cache (surfex.Cache, optional) – Cache. Defaults to None.

Returns:

A numpy array with point values for variable

Return type:

numpy.darray

Variable.set_var(validtime=None)[source]

Set the variable.

Parameters:

validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Raises:
  • NotImplementedError – Variable not implemented

  • RuntimeError – You must provide name

  • RuntimeError – grib1 needs type or levelType

Returns:

accumulated, instant, var

Return type:

tuple

Variable.read_variable(geo, validtime, cache=None)[source]

Read the variable.

Parameters:
  • geo (surfex.Geometry) – Geometry to read

  • validtime (datetime.datetime) – Valid time.

  • cache (surfex.cache) – Cache. Defaults to None

Raises:

RuntimeError – Negative accumulated value found

Returns:

Field read and interpolated.

Return type:

np.darray

Variable.print_variable_info()[source]

Print variable.

Variable.deaccumulate(field, previous_field, instant)[source]

Deaccumulate variable.

Parameters:
  • field (_type_) – _description_

  • previous_field (_type_) – _description_

  • instant (_type_) – _description_

Raises:

ValueError – _description_

Returns:

_description_

Return type:

_type_

Variable.get_basetime(validtime, previoustime=None, allow_different_basetime=False)[source]

Get the basetime of the file.

Parameters:
  • validtime (datetime.datetime) – Valid time

  • previoustime (datetime.datetime, optional) – Previous valid time. Defaults to None.

  • allow_different_basetime (bool, optional) – Allow different base times. Defaults to False.

Raises:
  • RuntimeError – “Negative offset does not make sense here”

  • NotImplementedError – _description_

Returns:

Base time.

Return type:

datetime.datetime

Variable.rotate_geographic_wind(interpolator)[source]

Rotate wind.

Parameters:

interpolator (_type_) – _description_

static BufrObservationSet.td2rh(t_d, temp, kelvin=True)[source]

Convert dew point to temperature.

Parameters:
  • t_d (float) – Dew point temperature

  • temp (float) – Temperature

  • kelvin (bool, optional) – Kelvin. Defaults to True.

Raises:
  • RuntimeError – Dew point temperature is probably not Kelvin

  • RuntimeError – Temperature is probably not Kelvin

Returns:

Relative humidity (percent)

Return type:

float

static BufrObservationSet.inside_window(obs_dtg, valid_dtg, valid_range)[source]

Check if inside window.

Parameters:
  • obs_dtg (as_datetime) – Observation datetime

  • valid_dtg (as_datetime) – Valid datetime

  • valid_range (as_timedelta) – Window

Returns:

True if inside window

Return type:

bool

Geo.__init__(lons, lats)[source]

Construct geometry.

Parameters:
  • lons (np.ndarray) – Longitudes

  • lats (np.ndarray) – Latitudes

Raises:

Exception – _description_

Geo.identifier()[source]

Create identifier.

Geo.is_identical(geo_to_check)[source]

Check if geometries are identical.

Parameters:

geo_to_check (surfex.Geo) – Geo to check.

Returns:

True if identical.

Return type:

bool

Geo.write_proj_info()[source]

Write proj info.

Returns:

Do nothing for now.

Return type:

None

SurfexGeo.__init__(proj, lons, lats)[source]

Construct a surfex geometry.

Parameters:
  • proj (str) – Proj string

  • lons (np.ndarray) – Lons

  • lats (np.ndarray) – Lats

abstractmethod SurfexGeo.update_namelist(nml)[source]

Update namelist.

Parameters:

nml (_type_) – _description_

Returns:

_description_

Return type:

_type_

abstractmethod SurfexGeo.subset(geo)[source]

Find subset of geo.

Parameters:

geo (surfex.Geo) – Geometry to check.

ConfProj.__init__(from_json)[source]

Construct conf proj geo.

Parameters:

from_json (dict) – Domain definition

Raises:
  • KeyError – Missing keys1

  • KeyError – Missing keys2

  • KeyError – Missing keys3

  • KeyError – Missing keys4

ConfProj.update_namelist(nam_nml)[source]

Update namelist.

Parameters:

nam_nml (NamelistGenerator) – Namelist object.

Returns:

Namelist object.

Return type:

nam_nml (NamelistGenerator)

ConfProj.subset(geo)[source]

Find subset of geo.

Parameters:

geo (surfex.Geo) – Geometry to check.

Returns:

lons, lats

Return type:

(list, list)

ConfProjFromHarmonie.__init__(env=None)[source]

Create geo from Harmonuie environment.

Parameters:

env (dict, optional) – Environment dict. Defaults to None.

LonLatVal.__init__(from_json)[source]

Construct a LonLatVal geometry.

Used also for points/observations.

Parameters:

from_json (dict) – Domain description,

Raises:
  • KeyError – Missing key

  • KeyError – Missing keys

LonLatVal.update_namelist(nam_nml)[source]

Update namelist.

Parameters:

nam_nml (NamelistGenerator) – Namelist object.

Returns:

Namelist object.

Return type:

nml (NamelistGenerator)

Cartesian.__init__(from_json)[source]

Construct Cartesian geometry.

Parameters:

from_json (_type_) – _description_

Raises:
  • KeyError – Missing key

  • KeyError – Missing keys

Cartesian.update_namelist(nam_nml)[source]

Update namelist.

Parameters:

nam_nml (NamelistGenerator) – Namelist object.

Returns:

Namelist object.

Return type:

nam_nml (NamelistGenerator)

LonLatReg.__init__(from_json)[source]

Construct the LonLatReg geometry.

Parameters:

from_json (dict) – Domain definition.

Raises:
  • KeyError – Missing key

  • KeyError – Missing keys

  • ZeroDivisionError – nlon and/or nlat is 0

LonLatReg.update_namelist(nam_nml)[source]

Update namelist.

Parameters:

nam_nml (NamelistGenerator) – Namelist object.

Returns:

Namelist object.

Return type:

nml (NamelistGenerator)

IGN.__init__(from_json, recreate=False)[source]

Construct a IGN geometry.

Parameters:
  • from_json (dict) – Domain definition.

  • recreate (bool, optional) – Recreate the cached mask. Defaults to False.

Raises:
  • NotImplementedError – Projection not implemented

  • KeyError – Missing key

  • KeyError – Missing keys

static IGN.get_coord(pin, pdin, coord, recreate=False)[source]

Get the IGN coordinates.

Parameters:
  • pin (list) – _description_

  • pdin (list) – _description_

  • coord (list) – _description_

  • recreate (bool, optional) – _description_. Defaults to False.

Returns:

Output coordinates

Return type:

list

static IGN.ign_mask(pxall, pyall, xxx, yyy, recreate)[source]

Create the IGN mask.

Parameters:
  • pxall (_type_) – _description_

  • pyall (_type_) – _description_

  • xxx (_type_) – _description_

  • yyy (_type_) – _description_

  • recreate (_type_) – _description_

Raises:

Exception – _description_

Returns:

_description_

Return type:

_type_

IGN.update_namelist(nam_nml)[source]

Update namelist.

Parameters:

nam_nml (NamelistGenerator) – Namelist object.

Returns:

Namelist object.

Return type:

nam_nml (NamelistGenerator)

ReadData.__init__(geo, var_name)[source]

Construct readData object.

abstractmethod ReadData.read_time_step(validtime, cache)[source]

To be implemented.

abstractmethod ReadData.print_info()[source]

To be implemented.

ConvertedInput.__init__(geo, var_name, converter)[source]

Construct converted input.

Parameters:
  • geo (_type_) – _description_

  • var_name (_type_) – _description_

  • converter (_type_) – _description_

ConvertedInput.read_time_step(validtime, cache)[source]

Read time step.

Parameters:
  • validtime (_type_) – _description_

  • cache (_type_) – _description_

Returns:

_description_

Return type:

_type_

ConvertedInput.print_info()[source]

Print info.

ConstantValue.__init__(geo, var_name, var_dict)[source]

Set a field to a constant value.

Parameters:
  • geo (surfex.Geo) – Geometry object

  • var_name (str) – Variable name

  • var_dict (dict) – Variable definition

Raises:

RuntimeError – Constant value must have a value!

ConstantValue.print_info()[source]

Print info.

Converter.__init__(name, initial_time, defs, conf, fileformat)[source]

Initialize the converter.

Parameters:
  • name (str) – Converter name

  • initial_time (as_datetime) – The valid time you want to read

  • defs (dict) – A dictionary defining the variables

  • conf (dict) – A dictionary defining the converter

  • fileformat (str) – File format

Raises:
  • KeyError – Missing definitions

  • NotImplementedError – Converter not implemented

Converter.print_info()[source]

Print info.

Converter.create_variable(fileformat, defs, var_dict)[source]

Create a variable.

Parameters:
  • fileformat (str) – Fileformat

  • defs (dict) – defs

  • var_dict (dict) – Variable dictionary

Raises:

RuntimeError – Variable is not set

Returns:

The read field

Return type:

field

static Converter.mslp2ps(mslp, altitude, temp)[source]

Calcaulate ps from mslp.

Parameters:
  • mslp (np.ndarray) – Mean sea level pressure

  • altitude (np.ndarray) – Altitude

  • temp (np.ndarray) – Temperature

Returns:

Surface pressure

Return type:

np.ndarray

static Converter.saturation_mixing_ratio(total_press, temperature)[source]

Calculate sat mixing ratio.

Parameters:
  • total_press (np.ndarray) – Pressure

  • temperature (np.ndarray) – Temperature

Returns:

saturation mixing ratio

Return type:

(np.ndarray)

static Converter.mixing_ratio(partial_press, total_press, molecular_weight_ratio=0.622)[source]

Calculate mixing ratio.

Parameters:
  • partial_press (np.ndarray) – Partial pressure

  • total_press (np.ndarray) – Total pressure

  • molecular_weight_ratio (float, optional) – Molecular weight ratio. Defaults to 0.622

Returns:

mixing ratio

Return type:

(np.ndarray)

static Converter.specific_humidity_from_dewpoint(pressure, dewpoint)[source]

Calculate q from Td.

Parameters:
  • pressure (np.ndarray) – Pressure

  • dewpoint (np.ndarray) – Temperature

Returns:

specific humidity

Return type:

(np.ndarray)

static Converter.mixing_ratio_from_specific_humidity(specific_humidity)[source]

Calculate mixing ratio from q.

Parameters:

specific_humidity (np.ndarray) – Specific humidity

Returns:

mixing ratio

Return type:

(np.ndarray)

static Converter.specific_humidity_from_mixing_ratio(mixing_ratio)[source]

Calculate q from mixing ratio.

Parameters:

mixing_ratio (np.ndarray) – Mixing ratio

Returns:

Specific humidity

Return type:

(np.ndarray)

static Converter.saturation_vapor_pressure(temperature_kelvin)[source]

Calculate esat.

Parameters:

temperature_kelvin (np.ndarray) – Absolute temperature

Returns:

stauration vapor pressure

Return type:

(np.ndarray)

Converter.read_time_step(geo, validtime, cache)[source]

Read time step.

Parameters:
  • geo (Geo) – Geometry_

  • validtime (as_datetime) – Validtime

  • cache (Cache) – Cache

Raises:
  • KeyError – Could not found climatological mean for month

  • NotImplementedError – _description_

  • RuntimeError – “Alpha is different for the 2 wind vectors!

Returns:

Read and converted field

Return type:

field (np.ndarray)

SurfexIO.__init__(filename, geo, extension)[source]

Construct a surfex IO object.

Parameters:
  • filename (str) – Name of file

  • geo (surfex.Geometry) – Geometry

  • extension (str) – File extension

abstractmethod SurfexIO.field(var, validtime=None)[source]

Abstract method to read field.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Raises:

NotImplementedError – Must be implemented by child class.

abstractmethod SurfexIO.points(var, geo_out, validtime=None, interpolation='bilinear')[source]

Abstract method to read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geometry) – Surfex geometry to interpolate to.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type.. Defaults to “nearest”.

Raises:

NotImplementedError – Must be implemented by child class.

static SurfexIO.interpolate_field(field, geo_in, geo_out, interpolation='bilinear')[source]

Interpolate a field to points.

Parameters:
  • field (np.darray) – Field to interpolate

  • geo_in (surfex.Geo) – Input geometry

  • geo_out (surfex.Geo) – Target geometry

  • interpolation (str, optional) – Interpolation type. Defaults to “bilinear”.

Returns:

(np.array, surfex.Interpolator)

Return type:

tuple

Symlink the input file.

SurfexSurfIO.copy_input()[source]

Copy the input file.

SurfexSurfIO.archive_output_file()[source]

Archive the output file.

SurfexFileVariable.print_var()[source]

Print variable information.

AsciiSurfexFile.__init__(filename, geo=None)[source]

Construct the ASCII object.

Parameters:
  • filename (str) – Filename

  • geo (surfex.geo.Geo, optional) – Geometry, Defaults to None.

AsciiSurfexFile.get_geo()[source]

Get the geometry object.

Raises:
  • FileNotFoundError – _description_

  • RuntimeError – No grid found

  • NotImplementedError – _description_

Returns:

Surfex geometry

Return type:

surfex.Geometry

AsciiSurfexFile.read(read_par, read_tile, datatype)[source]

Read the file.

Parameters:
  • read_par (str) – Parameter to read

  • read_tile (str) – Tile to read

  • datatype (str) – Datatype

Raises:
  • NotImplementedError – Datatype not implemented

  • RuntimeError – Could not read datatype

Returns:

Values read

Return type:

numpy.array

AsciiSurfexFile.points(var, geo_out, validtime=None, interpolation='nearest')[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geo) – Surfex geometry for points.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type. Defaults to “nearest”.

Returns:

Interpolated points

Return type:

np.darray

NCSurfexFile.__init__(filename, geo=None)[source]

Construct NC file object.

Parameters:
  • filename (str) – File name

  • geo (surfex.Geo, optional) – Surfex geometry. Defaults to None.

NCSurfexFile.get_geo()[source]

Get geometry in file.

Raises:

NotImplementedError – Grid not implemented

Returns:

Surfex geometry in file

Return type:

surfex.Geometry

NCSurfexFile.field(var, validtime=None)[source]

Read field.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • validtime (_type_, optional) – Valid time. Defaults to None.

  • validtime – _description_. Defaults to None.

Raises:

RuntimeError – Mismatch in times in file and the wanted time

Returns:

Field, surfex.Geo in read file

Return type:

np.darray

NCSurfexFile.points(var, geo_out, validtime=None, interpolation='nearest')[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geo) – Surfex geometry for points.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type. Defaults to “nearest”.

Returns:

Interpolated points

Return type:

np.darray

FaSurfexFile.__init__(filename, geo=None, masterodb=False, lfagmap=True)[source]

Construct the surfex FA file.

Parameters:
  • filename (str) – File name.

  • geo (surfex.Geo, optional) – Surfex geometry. Defaults to None.

  • masterodb (bool, optional) – _description_. Defaults to False.

  • lfagmap (bool, optional) – _description_. Defaults to True.

FaSurfexFile.field(var, validtime=None)[source]

Read field from FA file.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Returns:

Field, surfex.Geo in read file

Return type:

np.darray

FaSurfexFile.points(var, geo_out, validtime=None, interpolation='nearest')[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geo) – Surfex geometry for points.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type. Defaults to “nearest”.

Returns:

Interpolated points, surfex.Interpolator

Return type:

tuple

SurfFileTypeExtension.__init__(csurf_filetype, masterodb=False, lfagmap=True)[source]

Construct an extension object.

Parameters:
  • csurf_filetype (str) – Surfex file type.

  • masterodb (bool, optional) – File created with masterodb. Defaults to False.

  • lfagmap (bool, optional) – File created with lfagmap=True. Defaults to True.

NetCDFSurfexFile.__init__(filename, geo)[source]

Construct a NetCDF surfex time series file.

Parameters:
  • filename (str) – Name of file.

  • geo (surfex.Geometry) – Surfex geometry for time series.

NetCDFSurfexFile.read(var, times)[source]

Read a field, return a 2D array.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • times (list) – List of datetime.datetime objects

Raises:
  • ValueError – times must be list or tuple

  • ValueError – patches must be list or tuple

  • ValueError – patches must be list or tuple

  • RuntimeError – Variable not found!

  • NotImplementedError – Dimension not implemented

  • RuntimeError – Mismatch in points

Returns:

(np.array. surfex.Geometry)

Return type:

(tuple)

NetCDFSurfexFile.field(var, validtime=None)[source]

Read field.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Returns:

(np.array, surfex.Geometry)

Return type:

tuple

NetCDFSurfexFile.points(var, geo_out, validtime=None, interpolation='nearest')[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geometry) – Surfex geometry to interpolate to.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type.. Defaults to “nearest”.

Returns:

points, surfex.Interpolator

Return type:

tuple

TexteSurfexFile.__init__(filename, geo)[source]

Construct the Texte file.

Parameters:
  • filename (str) – Filename

  • geo (surfex.Geometry) – Geometry

TexteSurfexFile.read(variable, times)[source]

Read file.

Parameters:
  • variable (SurfexFileVariable) – Variable in surfex file.

  • times (list) – List of datetime.datetime to read.

Raises:
  • RuntimeError – Basetime must be set for TEXTE

  • RuntimeError – Interval must be set for TEXTE

  • RuntimeError – times must be list or tuple

  • RuntimeError – Dimension of domain does not match end of line

Returns:

(np.array, surfex.Geometry)

Return type:

tuple

TexteSurfexFile.field(var, validtime=None)[source]

Read field.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Returns:

(np.array, surfex.Geometry)

Return type:

tuple

TexteSurfexFile.points(var, geo_out, validtime=None, interpolation='nearest')[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geometry) – Geometry in file.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type. Defaults to “nearest”.

Returns:

(np.array, surfex.Interpolator)

Return type:

tuple

ForcingFileNetCDF.__init__(fname, geo)[source]

Construct forcing netcdf file.

Parameters:
  • fname (str) – File name.

  • geo (surfex.Geo) – Surfex input geometry.

ForcingFileNetCDF.read_field(variable, times)[source]

Read file.

Parameters:
  • variable (_type_) – _description_

  • times (_type_) – _description_

Raises:
  • RuntimeError – You must set time!

  • RuntimeError – No points found

  • RuntimeError – Valid time not found in file!

Returns:

field, geo

Return type:

tuple

ForcingFileNetCDF.field(var, validtime=None)[source]

Read field.

Parameters:
  • var (_type_) – _description_

  • validtime (list, optional) – Validtime. Defaults to None.

Returns:

field, geo

Return type:

tuple

ForcingFileNetCDF.points(var, geo_out, validtime=None, interpolation=None)[source]

Read points.

Parameters:
  • var (SurfexFileVariable) – Variable in surfex file.

  • geo_out (surfex.Geo) – Surfex geometry for points.

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation type. Defaults to “nearest”.

Returns:

Interpolated points, surfex.Interpolator

Return type:

tuple

Grib.__init__(fname)[source]

Construct grib object.

Parameters:

fname (str) – File name.

Grib.field(gribvar, time)[source]

Read field in grib file.

Parameters:
  • gribvar (GribVariable1/2) – Grib variable to read.

  • time (datetime.datetime) – Valid time to read.

Returns:

Field

Return type:

np.ndarray

Raises:
  • NotImplementedError – NotImplementedError

  • RuntimeError – If eccodes not available

static Grib.read_geo_info(gid, keys)[source]

Set geo keys in dict.

Parameters:
  • gid (int) – grib id

  • keys (dict) – Geometry keys

Returns:

Geometry

Return type:

dict

static Grib.read_field_in_message(gid, time)[source]

Get field.

Parameters:
  • gid (int) – grib id

  • time (str) – time

Returns:

Field object

Return type:

Field

Grib.points(gribvar, geo, validtime=None, interpolation='bilinear')[source]

Read a 2-D field and interpolates it to requested positions.

Parameters:
  • gribvar (GribVariable1/2) – Grib variable

  • geo (surfex.Geo) – Surfex geometry

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

  • interpolation (str, optional) – Interpolation method. Defaults to “bilinear”.

Returns:

vector with interpolated values

Return type:

np.array

Grib.__init__(fname)[source]

Construct grib object.

Parameters:

fname (str) – File name.

Grib2Variable.__init__(discipline, pca, pnr, typ, lev, tsp=-1)[source]

Construct a grib2 variable.

Parameters:
  • discipline (int) – discipline

  • pca (int) – parameterCatergory

  • pnr (int) – parameterNumber

  • typ (int) – levelType

  • lev (int) – level

  • tsp (int, optional) – typeOfStatisticalProcessing. Defaults to -1.

Grib2Variable.matches(gid)[source]

Check if matches.

Parameters:

gid (int) – Grib ID

Raises:

ModuleNotFoundError – If not eccodes found

Returns:

True if matches

Return type:

bool

Grib2Variable.is_accumulated()[source]

Check if accumulated.

Grib2Variable.print_keys()[source]

Print keys.

Grib2Variable.generate_grib_id()[source]

Generate grib2 ID.

ObservationSet.__init__(observations, label='', sigmao=None)[source]

Create an observation set.

Parameters:
  • observations (list) – Observation objects.

  • label (str, optional) – Name of set. Defaults to “”.

  • sigmao (float, optional) – Observation error relative to normal background error. Defaults to None.

ObservationSet.get_stid_index(stid)[source]

Get station ID index.

Parameters:

stid (str) – Station ID.

Returns:

Found index

Return type:

int

ObservationSet.get_pos_index(lon, lat)[source]

Get position index.

Parameters:
  • lon (float) – Longitude

  • lat (float) – Latitude

Returns:

Found position index.

Return type:

int

ObservationSet.get_obs()[source]

Get observations.

Returns:

times, lons, lats, stids, elevs,

values, varnames, sigmaos

Return type:

(list, list , list, list, list, list, list)

ObservationSet.matching_obs(my_obs)[source]

Match the observations.

Parameters:

my_obs (Observation) – Observation to match.

Returns:

True if found

Return type:

bool

ObservationSet.points(geo, validtime=None)[source]

Extract points from observations.

Parameters:
  • geo (surfex.Geo) – Surfex geometry

  • validtime (datetime.datetime, optional) – Valid time. Defaults to None.

Returns:

Values in points.

Return type:

np.ndarray

ObservationSet.write_json_file(filename, indent=None)[source]

Write a json file.

Parameters:
  • filename (str) – Name of file

  • indent (int, optional) – Indentation in file. Defaults to None.

ObservationSet.get_data_set(varname)[source]

Get data set.

Parameters:

varname (_type_) – _description_

Returns:

_description_

Return type:

_type_

JsonObservationSet.__init__(filename, label='json', var=None, sigmao=None)[source]

Construct an observation data set from a json file.

Parameters:
  • filename (str) – Filename

  • label (str, optional) – Label of set. Defaults to “json”.

  • var (str, optional) – Variable name. Defaults to None.

  • sigmao (float, optional) – Observation error relative to normal background error. Defaults to None.

Raises:

RuntimeError – Varname is not found

ObservationFromTitanJsonFile.__init__(an_time, filename, label='', sigmao=None)[source]

Constuct obs set from a titan json file.

Parameters:
  • an_time (_type_) – _description_

  • filename (_type_) – _description_

  • label (str, optional) – _description_. Defaults to “”.

  • sigmao (float, optional) – Observation error relative to normal background error. Defaults to None.

ObsSetFromVobs.__init__(fname, validtime, varname=None, label='vobs', sigmao=None)[source]

Constuct obs set from vobs file.

Parameters:
  • fname (_type_) – File name

  • validtime (_type_) – Valid time

  • varname (str, optional) – Variable name. Defaults to “”.

  • label (str, optional) – _description_. Defaults to “vobs”.

  • sigmao (float, optional) – Observation error relative to normal background error. Defaults to None.

static ObsSetFromVobs.read_vfld(fnam)[source]

Read vfld file.

ObsSetFromVobs.__init__(fname, validtime, varname=None, label='vobs', sigmao=None)[source]

Constuct obs set from vobs file.

Parameters:
  • fname (_type_) – File name

  • validtime (_type_) – Valid time

  • varname (str, optional) – Variable name. Defaults to “”.

  • label (str, optional) – _description_. Defaults to “vobs”.

  • sigmao (float, optional) – Observation error relative to normal background error. Defaults to None.

TimeSeries.__init__(times, values, lons, lats, stids, varname='NA')[source]

Construct time series.

Parameters:
  • times (_type_) – _description_

  • values (_type_) – _description_

  • lons (_type_) – _description_

  • lats (_type_) – _description_

  • stids (_type_) – _description_

  • varname (str, optional) – _description_. Defaults to “NA”.

TimeSeries.write_json(filename, indent=None)[source]

Write json file.

Parameters:
  • filename (_type_) – _description_

  • indent (_type_, optional) – _description_. Defaults to None.

NamelistGenerator.__init__(program, nml, macros=None, micro='@')[source]

Construct a base namelists class.

Parameters:
  • program (str) – Which surfex binary you want to run [“pgd”, “prep”, “offline”, “soda”]

  • nml (f90nml.Namelist) – A parsed fortran namelist

  • assemble (dict) – Assembly order. Defines the configuration

  • macros (dict, optional) – Macros

  • micro (str, optional) – Micro character

NamelistGenerator.get_namelist()[source]

Get namelist.

static NamelistGenerator.lower_case_namelist_dict(dict_in)[source]

Lower case namelist.

Parameters:

dict_in (dict) – Namelist dictionary to lower case

Returns:

Namelist in lower case

Return type:

dict

NamelistGeneratorFromNamelistFile.__init__(program, nml_file, macros=None, micro='@')[source]

Construct a base namelists class from a file.

Parameters:
  • program (str) – Which surfex binary you want to run [“pgd”, “prep”, “offline”, “soda”]

  • nml_file (str) – Namelist file

  • macros (dict, optional) – Macros

  • micro (str, optional) – Micro character

NamelistGeneratorAssemble.__init__(program, definitions, assemble, macros=None, micro='@')[source]

Construct a base namelists class.

Parameters:
  • program (str) – Which surfex binary you want to run [“pgd”, “prep”, “offline”, “soda”]

  • definitions (dict) – Namelist definitions

  • assemble (dict) – Assembly order. Defines the configuration

  • macros (dict, optional) – Macros

  • micro (str, optional) – Micro character

NamelistGeneratorAssemble.assemble_namelist(program)[source]

Generate the namelists for ‘target’.

Parameters:

program (str) – Which surfex binary you want to run [“pgd”, “prep”, “offline”, “soda”]

Raises:

KeyError – Key not found

Returns:

Assembled namelist

Return type:

nlres (dict)

static NamelistGeneratorAssemble.flatten_list(li)[source]

Recursively flatten a list of lists (of lists).

static NamelistGeneratorAssemble.find_num(s)[source]

Purpose: un-quote numbers.

NamelistGeneratorAssembleFromFiles.__init__(program, definitions, assemble, macros=None, micro='@')[source]

Construct a base namelists class.

Parameters:
  • program (str) – Which surfex binary you want to run [“pgd”, “prep”, “offline”, “soda”]

  • definitions (str) – Namelist definitions

  • assemble (str)) – Assembly order. Defines the configuration

  • macros (dict, optional) – Macros

  • micro (str, optional) – Micro character

BatchJob.__init__(rte, wrapper='')[source]

Construct batch job.

Parameters:
  • rte (dict) – Run time environment.

  • wrapper (str, optional) – Wrapper around command. Defaults to “”.

BatchJob.run(cmd)[source]

Run command.

Parameters:

cmd (str) – Command to run.

Raises:
  • CalledProcessError – Command failed.

  • RuntimeError – No command provided!

SURFEXBinary.__init__(binary, batch, iofile, settings, input_data, **kwargs)[source]

Surfex binary task.

Parameters:
  • binary (str) – Binary to run

  • batch (surfex.Batch) – Batch object to run command in

  • iofile (surfex.SurfexIO) – Input file to command.

  • settings (f90nml.Namelist) – Fortran namelist namelist

  • input_data (surfex.InputDataToSurfexBinaries) – Input to binary

  • kwargs (dict) – Key word arguments.

Raises:
  • FileNotFoundError – Input file not found

  • RuntimeError – Execution failed

SurfexForcing.__init__()[source]

Construct object.

SurfexNetCDFForcing.__init__(filename, geo)[source]

Construct netcdf forcing.

SurfexOutputForcing.__init__(base_time, geo, ntimes, var_objs, time_step_intervall)[source]

Construct output forcing.

Parameters:
  • base_time (_type_) – _description_

  • geo (_type_) – _description_

  • ntimes (_type_) – _description_

  • var_objs (_type_) – _description_

  • time_step_intervall (_type_) – _description_

SurfexOutputForcing._check_sanity()[source]
abstractmethod SurfexOutputForcing.write_forcing(var_objs, this_time, cache)[source]

Write forcing.

NetCDFOutput._define_forcing(geo, att_objs, att_time, cache)[source]
NetCDFOutput.finalize()[source]

Finalize the forcing. Close the file.

AsciiOutput._define_forcing(geo, att_objs, att_time, cache)[source]
AsciiOutput.finalize()[source]

Finalize forcing.

QualityControl.__init__(name)[source]

Construct base class.

abstractmethod QualityControl.set_input(size)[source]

Set input to test.

Parameters:

size (int) – Number of observations.

Raises:

NotImplementedError – Must be implemented by child class.

abstractmethod QualityControl.test(dataset, mask, code=1)[source]

The quality control test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 1.

Raises:

NotImplementedError – Must be implemented by child class.

static QualityControl.set_flags(global_flags, flags, mask, code)[source]

Set flags.

Parameters:
  • global_flags (list) – Global flags

  • flags (list) – Test flags

  • mask (list) – Active data

  • code (int) – Code to use for flagging.

Returns:

Updated global flags.

Return type:

list

Plausibility.__init__(minval=None, maxval=None)[source]

Construct plausibility test.

Parameters:
  • minval (float, optional) – Default minimum value. Defaults to None.

  • maxval (float, optional) – Default maximum value. Defaults to None.

Plausibility.set_input(size, minval=None, maxval=None)[source]

Set input.

Parameters:
  • size (size) – Observation data set size

  • minval (float, optional) – Minimum value. Defaults to None.

  • maxval (float, optional) – Maximum value. Defaults to None.

Raises:

RuntimeError – You must set minval and maxval

Plausibility.test(dataset, mask, code=102)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 102.

Raises:

ModuleNotFoundError – titanlib was not loaded properly

Returns:

Global flags.

Return type:

global_flags(list)

FirstGuess.set_input(size, posdiff=None, negdiff=None)[source]

Set input.

Parameters:
  • size (int) – Observation data set size

  • posdiff (float, optional) – Positive diff. Defaults to None.

  • negdiff (float, optional) – Negative diff. Defaults to None.

Raises:

RuntimeError – You must set negdiff and posdiff

FirstGuess.test(dataset, mask, code=108)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 108.

Returns:

Global flags.

Return type:

global_flags(list)

Raises:

ModuleNotFoundError – titanlib was not loaded properly

Fraction.set_input(size, minval=None, maxval=None)[source]

Set input.

Parameters:
  • size (int) – Observation set size.

  • minval (float, optional) – Minimum value. Defaults to None.

  • maxval (float, optional) – Maximum value. Defaults to None.

Raises:

RuntimeError – You must set min and max

Fraction.test(dataset, mask, code=151)[source]

Perform test.

Parameters:
  • dataset (QCDataSet) – QC data set.

  • mask (list) – Active data

  • code (int, optional) – Flag. Defaults to 151.

Returns:

Global flags.

Return type:

global_flags(list)

Raises:

ModuleNotFoundError – titanlib was not loaded properly

Sct.set_input(size, neg=None, pos=None, eps2=None)[source]

Set input.

Parameters:
  • size (int) – Observation set size.

  • neg (float, optional) – Minimum value. Defaults to None.

  • pos (float, optional) – Maximum value. Defaults to None.

  • eps2 (float, optional) – Epsilon 2. Defaults to None.

Sct.test(dataset, mask, code=105)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 105.

Raises:
  • ModuleNotFoundError – titanlib was not loaded properly

  • RuntimeError – Longitude is not defined!

  • RuntimeError – Latitude is not defined!

  • RuntimeError – Value is not defined!

Returns:

Global flags.

Return type:

global_flags(list)

Buddy.test(dataset, mask, code=104)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 104.

Raises:
  • ModuleNotFoundError – titanlib was not loaded properly

  • RuntimeError – Buddy check failed!

Returns:

Global flags.

Return type:

global_flags(list)

Climatology.__init__(an_time, minval=None, maxval=None, offset=0)[source]

Construct test.

Parameters:
  • an_time (datetime.datetime) – Analysis time

  • minval (float, optional) – Minimum value. Defaults to None.

  • maxval (float, optional) – Maximum value. Defaults to None.

  • offset (int, optional) – Offset. Defaults to 0.

Climatology.set_input(size, minval=None, maxval=None, offset=None)[source]

Set input.

Parameters:
  • size (int) – Observation set size.

  • minval (float, optional) – Minimum value. Defaults to None.

  • maxval (float, optional) – Maximum value. Defaults to None.

  • offset (int, optional) – Offset. Defaults to 0.

Raises:

RuntimeError – You must set min and max values!

Climatology.test(dataset, mask, code=103)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 103.

Returns:

Global flags.

Return type:

global_flags(list)

Redundancy.__init__(an_time)[source]

Construct test.

Parameters:

an_time (datetime.datetime) – Analysis time.

Redundancy.set_input(__)[source]

Set input.

Redundancy.test(dataset, mask, code=115)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 115.

Returns:

Flags.

Return type:

flags(list)

Blacklist.__init__(blacklist)[source]

Construct test.

Parameters:

blacklist (dict) – Blacklist positions/stids

Raises:
  • RuntimeError – You must set blacklist as a dict

  • RuntimeError – Blacklist must have the same length for both lons and lats

Blacklist.set_input(__)[source]

Set input.

Blacklist.test(dataset, mask, code=100)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 100.

Returns:

Flags.

Return type:

flags(list)

DomainCheck.__init__(domain_geo, max_distance=5000)[source]

Construct test.

Parameters:
  • domain_geo (surfex.Geo) – Surfex geometry

  • max_distance (int, optional) – Maximum distance to grid border. Defaults to 5000.

Raises:

RuntimeError – Domain geo was not set!

DomainCheck.set_input(size, **kwargs)[source]

Set input.

DomainCheck.test(dataset, mask, code=199)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 199.

Returns:

Flags.

Return type:

flags(list)

NoMeta.__init__()[source]

Construct test.

NoMeta.set_input(size, **kwargs)[source]

Set input.

NoMeta.test(dataset, mask, code=101)[source]

Do the test.

Parameters:
  • dataset (QCDataSet) – The data set to perform the test on.

  • mask (list) – Active data.

  • code (int, optional) – Code to use for flagging. Defaults to 101.

Returns:

Flags.

Return type:

flags(list)

QCDataSet.get_stid_index(stid)[source]

Get station ID index.

Parameters:

stid (str) – Station ID

Returns:

Index to station ID.

Return type:

int

QCDataSet.get_pos_index(lon, lat)[source]

Get position index in dict.

Parameters:
  • lon (float) – Longitude

  • lat (float) – Latitude

Returns:

Index position if found, else None.

Return type:

int

abstractmethod QCDataSet.perform_tests()[source]

Perform the test.

Raises:

NotImplementedError – Must be implemented by child class.

QCDataSet.write_output(filename, indent=None)[source]

Dump QC data to a json file.

Parameters:
  • filename (str) – Filename

  • indent (int, optional) – Indentation in file. Defaults to None.

TitanDataSet.__init__(var, settings, tests, datasources, an_time, test_flags=None)[source]

Titan Data set.

Parameters:
  • var (str) – Variable name.

  • settings (dict) – Titan test/configuration settings

  • tests (list) – Tests to perform in order.

  • datasources (list) – List of observations sets.

  • an_time (datetime.datetime) – Analysis time

  • test_flags (dict, optional) – Dictionary to set custom test flags. Defaults to None.

Raises:

ModuleNotFoundError – itanlib was not loaded properly

TitanDataSet.perform_tests()[source]

Perform the tests.

Departure.__init__(operator, geo, dataset, grid_values, mode, max_distance=5000)[source]

Construct a departure object.

Parameters:
  • operator (str) – Interpolation operator.

  • geo (surfex.Geo) – Surfex geometry.

  • dataset (QCDataSet) – QC data set.

  • grid_values (np.darray) – Values in the grid.

  • mode (str) – What kind of departure (analysis/first_guess)

  • max_distance (int, optional) – Max allowed deviation in meters from grid borders. Defaults to 5000.

Raises:

NotImplementedError – Mode not implemented

Departure.get_departure(pos=None)[source]

Get departure.

Parameters:

pos (int, optional) – Position. Defaults to None.

Returns:

Departures

Return type:

list

Departure.get_values(pos=None)[source]

Get the obs values.

Parameters:

pos (int, optional) – Position. Defaults to None.

Returns:

Observation equivalent of the input field.

Return type:

float

ObsDataFromSurfexConverter.__init__(converter, var, stationlist, validtime, cache=None, label='converter')[source]

Construct obs dataset from a converter.

Parameters:
  • converter (_type_) – _description_

  • var (_type_) – _description_

  • stationlist (_type_) – _description_

  • validtime (_type_) – _description_

  • cache (_type_, optional) – _description_. Defaults to None.

  • label (str, optional) – _description_. Defaults to “converter”.

ObsDataFromSurfexConverter.__init__(converter, var, stationlist, validtime, cache=None, label='converter')[source]

Construct obs dataset from a converter.

Parameters:
  • converter (_type_) – _description_

  • var (_type_) – _description_

  • stationlist (_type_) – _description_

  • validtime (_type_) – _description_

  • cache (_type_, optional) – _description_. Defaults to None.

  • label (str, optional) – _description_. Defaults to “converter”.

VerifVariable.__init__(name, unit=None)[source]

Construct a verif variable.

Parameters:
  • name (_type_) – _description_

  • unit (_type_, optional) – _description_. Defaults to None.

VerifVariable.__init__(name, unit=None)[source]

Construct a verif variable.

Parameters:
  • name (_type_) – _description_

  • unit (_type_, optional) – _description_. Defaults to None.

VerifVariable.__init__(name, unit=None)[source]

Construct a verif variable.

Parameters:
  • name (_type_) – _description_

  • unit (_type_, optional) – _description_. Defaults to None.

VerifVariable.__init__(name, unit=None)[source]

Construct a verif variable.

Parameters:
  • name (_type_) – _description_

  • unit (_type_, optional) – _description_. Defaults to None.

VerifDataFromFile.__init__(filename, fmt='netcdf')[source]

Construct Verif dataset from file.

Parameters:
  • filename (str) – Filename

  • fmt (str, optional) – _description_. Defaults to “netcdf”.

Raises:
  • NotImplementedError – _description_

  • FileNotFoundError – _description_

  • NotImplementedError – _description_

Netcdf.__init__(filename)[source]

Construct NetCDF.

Parameters:

filename (str) – Filename

Netcdf.field(var_name, level=None, member=None, validtime=None, units=None)[source]

Read field.

Parameters:
  • var_name (str) – Variable name

  • level (int, optional) – Level. Defaults to None.

  • member (int, optional) – Realization. Defaults to None.

  • validtime (surfex.datetime_utils.as_datetime, optional) – Validtime. Defaults to None.

  • units (str, optional) – Units. Defaults to None.

Returns:

Field, Geo

Return type:

tuple

Netcdf.points(var, geo, validtime=None, interpolation='bilinear')[source]

Read a field and interpolate it to requested positions.

Parameters:
  • var (NetCDFReadVariable) – NetCDF variable

  • geo (surfx.geo.Geo) – Geometry

  • validtime (surfex.datetime_utils.as_datetime, optional) – Validtime. Defaults to None.

  • interpolation (str, optional) – Interpolation. Defaults to “bilinear”.

Returns:

Field, Interpolator

Return type:

tuple

NetCDFReadVariable.__init__(name, level=None, units=None, member=None)[source]

Construct object.

Parameters:
  • name (_type_) – _description_

  • level (_type_, optional) – _description_. Defaults to None.

  • units (_type_, optional) – _description_. Defaults to None.

  • member (_type_, optional) – _description_. Defaults to None.

NetCDFFileVariable.__init__(file_handler, var)[source]

Construct object.

Parameters:
  • file_handler (_type_) – _description_

  • var (_type_) – _description_

NetCDFFileVariable.axis_types()

Get axis_types.

NetCDFFileVariable.dim_names()

Get dim_names.

NetCDFFileVariable.units()

Get units.

NetCDFFileVariable.lats()

Get lats.

Raises:

RuntimeError – No latitude found

Returns:

2D array of latitudes

Return type:

np.array

NetCDFFileVariable.lons()

Get lons.

Raises:

RuntimeError – No longitude found

Returns:

2D array of longitudes

Return type:

np.array

NetCDFFileVariable.datetimes()

Get datetimes.

Raises:

RuntimeError – cfunits not loaded!

Returns:

list()

NetCDFFileVariable.times()

Get times.

Returns:

1D array of times

Return type:

np.array

NetCDFFileVariable.members()

Get members.

Returns:

1D array of ensemble members

Return type:

np.array

NetCDFFileVariable.levels()

Get levels.

Returns:

1D array of levels

Return type:

np.array

static NetCDFFileVariable.is_level(axis_type)[source]

Check if is level.

Parameters:

axis_type (Axis) – Acis type

Returns:

If axis is a level type

Return type:

bool

Fa.__init__(fname)[source]

Construct a FA object.

Parameters:

fname (str) – filename

Fa.field(varname, validtime)[source]

Read a field.

Parameters:
  • varname (_type_) – _description_

  • validtime (_type_) – _description_

Raises:
  • ModuleNotFoundError – You need epygram to read FA files

  • NotImplementedError – Geometry not implemented

Returns:

np.field, surfex.Geometry

Return type:

tuple

Fa.points(varname, geo, validtime=None, interpolation='nearest')[source]

Read a 2-D field and interpolates it to requested positions.

Parameters:
  • varname (str) – Variable name

  • geo (surfex.geo.Geo) – Geometry

  • validtime (as_datetime) – Validtime

  • interpolation (str, optional) – Interpoaltion method. Defaults to “nearest”.

Returns:

field, interpolator

Return type:

tuple

Methods

pysurfex.util.deep_update(source, overrides)[source]

Update a nested dictionary or similar mapping.

Modify source in place.

Parameters:
  • source (dict) – Source data

  • overrides (dict) – Delta data to override

Returns:

Updated dict

Return type:

source(dict)

pysurfex.util.remove_existing_file(f_in, f_out)[source]

Remove existing file.

Parameters:
  • f_in (_type_) – _description_

  • f_out (_type_) – _description_

Raises:
  • FileNotFoundError – _description_

  • IsADirectoryError – _description_

pysurfex.util.parse_filepattern(file_pattern, basetime, validtime)[source]

Parse the file pattern.

Parameters:
  • file_pattern (str) – File pattern.

  • basetime (datetime.datetime) – Base time.

  • validtime (datetime.datetime) – Valid time.

Returns:

File name

Return type:

str

pysurfex.interpolation.fill_field(field_tmp, geo, radius=1)[source]

Fill field.

Parameters:
  • field_tmp (np.ndarray) – Field

  • geo (surfex.geo.Geo) – Geometry

  • radius (int, optional) – Radius. Defaults to 1.

Returns:

field, nans

Return type:

tuple

Raises:

RuntimeError – You need gridpp for fill_field

pysurfex.interpolation.grid2points(grid, points, grid_values, operator='bilinear', elev_gradient=None)[source]

Convert a grid to points.

Parameters:
  • grid (Grid) – Grid object

  • points (Points) – Points object

  • grid_values (np.ndarray) – Grid values

  • operator (str, optional) – Interpolation operator. Defaults to “bilinear”.

  • elev_gradient (float, optional) – Elevation gradient for downscaler

Raises:
  • NotImplementedError – Operator not implemented

  • RuntimeError – You need gridpp for interpolation

Returns:

Interpolated values

Return type:

np.ndarray

pysurfex.interpolation.inside_grid(grid_lons, grid_lats, p_lons, p_lats, distance=2500.0)[source]

Get number of neighbours.

Parameters:
  • grid_lons (np.ndarray) – Grid longitudes

  • grid_lats (np.ndarray) – Grid latitudes

  • p_lons (np.array) – Point longitudes

  • p_lats (np.array) – Point latitudes

  • distance (float, optional) – Max distance from points. Defaults to 2500.0.

Returns:

Boolean mask

Return type:

inside_grid(list)

pysurfex.interpolation.sum_neighbour_points(twodfield, radius)[source]

Sum up points in neighbourhood.

Parameters:
  • twodfield (np.ndarray) – Field to sum

  • radius (int) – Radius

Returns:

Array with neighbourhood sums.

Return type:

np.ndarray

pysurfex.cmd_parsing.parse_args_create_forcing(argv)[source]

Parse arguments to create forcing.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_modify_forcing(argv)[source]

Parse arguments to modify forcing.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_qc2obsmon(argv)[source]

Parse arguments for qc2obsmon.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_dump_environ(argv)[source]

Parse arguments for dum environ.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_first_guess_for_oi(argv)[source]

Parse arguments for first guess for OI.

Parameters:

argv (list) – Arguments

Returns:

Parsed keyword arguments

Return type:

kwargs (dict)

pysurfex.cmd_parsing.parse_args_surfex_binary(argv, mode)[source]

Parse the command line input arguments for surfex binary.

Parameters:
  • argv (list) – List with arguments.

  • mode (str) – Type of surfex binary

Raises:

NotImplementedError – Mode not implemented

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_create_namelist(argv)[source]

Parse the command line input arguments for creating a namelist.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_gridpp(argv)[source]

Parse the command line input arguments for gridpp.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_titan(argv)[source]

Parse the command line input arguments for titan.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_oi2soda(argv)[source]

Parse the command line input arguments for oi2soda.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_lsm_file_assim(argv)[source]

Parse the command line input arguments for land-sea-mask for assimilation.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_bufr2json(argv)[source]

Parse the command line input arguments for bufr2json.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_obs2json(argv)[source]

Parse the command line input arguments for obs2json.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_plot_points(argv)[source]

Parse the command line input arguments for plotting points.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_set_geo_from_obs_set(argv)[source]

Parse the command line input arguments for setting geo from obs set.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_set_geo_from_stationlist(argv)[source]

Parse the command line input arguments for setting geo from station list.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_merge_qc_data(argv)[source]

Parse the command line input arguments for merge of qc data.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_timeseries2json(argv)[source]

Parse the command line input arguments for time series to json.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_cryoclim_pseudoobs(argv)[source]

Parse the command line input arguments for cryoclim pseudo obs.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_sentinel_obs(argv)[source]

Parse the command line input arguments for sentinel observations.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_args_shape2ign(argv)[source]

Parse the command line input arguments for shape fiel to ign.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.cmd_parsing.parse_set_domain(argv)[source]

Parse the command line input arguments.

pysurfex.cmd_parsing.variable_parse_options(parser, name=None)[source]

Parser options for a converter.

Parameters:
  • parser (argparse) – Argument parser

  • name (str, optional) – Add name prefix to variables

pysurfex.cmd_parsing.converter_parse_options(parser, prefix='')[source]

Parser options for converter.

Parameters:
  • parser (Parser) – Arguemnt parser

  • prefix (str, optional) – Prefix. Defaults to “”

pysurfex.cmd_parsing.parse_args_variable(parent_parser, kwargs, argv, variables=None, prefix='')[source]

Parse variable arguments.

Parameters:
  • parent_parser (Parser) – Arguemnt parser

  • kwargs (dict) – Key word arguments

  • argv (list) – Arguments

  • variables (list, optional) – Variables. Defaults to None

  • prefix (str, optional) – Prefix. Defaults to “”

Returns:

Keyword arguments

Return type:

kwargs (dict)

pysurfex.datetime_utils.as_datetime(dtg, offset=False)[source]

Convert string to datetime.

pysurfex.datetime_utils.as_datetime_string(dtg)[source]

Convert string to datetime.

pysurfex.datetime_utils.offsetaware(dtg)[source]

Make offset aware.

pysurfex.datetime_utils.as_timedelta(seconds=0)[source]

Convert seconds to timedelta.

pysurfex.datetime_utils.fromtimestamp(validtime)[source]

Convert timestamp to validtime.

pysurfex.datetime_utils.utcfromtimestamp(epochtime)[source]

Convert timestamp to validtime.

pysurfex.datetime_utils.isdatetime(obj)[source]

Check if is a datetime objects.

pysurfex.datetime_utils.as_datetime_args(year=None, month=None, day=None, hour=0, minute=0, second=0)[source]

Set datetime object from args.

pysurfex.datetime_utils.get_decade(dt) str[source]

Return the decade given a datetime object.

pysurfex.geo.get_geo_object(from_json)[source]

Get a surfex geometry object from a dictionary.

Parameters:

from_json (dict) – Domain definition.

Raises:
  • NotImplementedError – Grid not implemented

  • KeyError – Missing grid information cgrid

  • KeyError – nam_pgd_grid not set!

Returns:

Surfex geometry.

Return type:

surfex.Geo

pysurfex.geo.get_geo_object_from_json_file(fname)[source]

Get a surfex geometry object from a dictionary.

Parameters:

fname (str) – Domain definition file.

Returns:

Surfex geometry.

Return type:

surfex.Geo

pysurfex.geo.shape2ign(catchment, infile, output, ref_proj, indent=None)[source]

Read a shape file and convert to IGN geo.

Parameters:
  • catchment (_type_) – _description_

  • infile (_type_) – _description_

  • output (_type_) – _description_

  • ref_proj (_type_) – _description_

  • indent (_type_, optional) – _description_. Defaults to None.

pysurfex.read.kwargs2converter(**kwargs)[source]

Create a converter object from keyword arguments.

Parameters:

kwargs (dict) – keyword arguments

Raises:
  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • RuntimeError – _description_

  • NotImplementedError – _description_

Returns:

A converter object

Return type:

Converter

pysurfex.read.get_multi_converters(parser, multivars, argv)[source]

Get multi converter.

Parameters:
  • parser (Parser) – Argument parser

  • multivars (list) – The variables

  • argv (list) – Argument list

Returns:

A dictionary with converters if several variables

or a converter object

Return type:

converters (dict)

pysurfex.file.guess_file_format(fname, ftype=None)[source]

Guess the file format.

Parameters:
  • fname (str) – Filename

  • ftype (str, optional) – Filetype if known/wished. Defaults to None.

Raises:
  • RuntimeError – Can not-auto decide filetype for files

  • RuntimeError – Filetype and/or format not set

Returns:

fileformat, filetype

Return type:

tuple

pysurfex.input_methods.get_datasources(obs_time, settings)[source]

Get data sources.

Main data source interface setting data ObservationSet objects based on settings dictionary

Parameters:
  • obs_time (datetime.datetime) – Observation time

  • settings (dict) – Settings

Raises:
  • NotImplementedError – Unknown observation file format

  • NotImplementedError – Only one file reading implemented

  • RuntimeError – No filenames or filepattern found

  • RuntimeError – You must set variable name

  • RuntimeError – You must set varname to read NETATMO JSON files

  • RuntimeError – You must set variable name

Returns:

List of observation data sets

Return type:

datasources(list)

pysurfex.run.create_working_dir(workdir, enter=True)[source]

Create working dir.

pysurfex.run.clean_working_dir(workdir)[source]

Clean working dir.

pysurfex.forcing.write_formatted_array(file, array, columns, fileformat)[source]

Write a formatted array.

pysurfex.forcing.run_time_loop(options, var_objs, att_objs)[source]

Run time loop.

pysurfex.forcing.set_forcing_config(**kwargs)[source]

Set the forcing config.

pysurfex.forcing.modify_forcing(**kwargs)[source]

Modify forcing.

pysurfex.titan.define_quality_control(test_list, settings, an_time, domain_geo=None, blacklist=None)[source]

Define different QC test from a dict.

Parameters:
  • test_list (list) – List of tests

  • settings (dict) – Test settings

  • an_time (datetime.datetime) – Analysis time

  • domain_geo (surfex.Geo) – Geo object

  • blacklist (dict) – Optional blacklist. Needd for blacklist test

Raises:
  • NotImplementedError – Test not implemented

  • RuntimeError – You must set the name of fg file and variable

  • RuntimeError – You must set the name of fraction file and variable

  • RuntimeError – You must set both fraction_field and fraction_geo

  • RuntimeError – You must set both fg_field and fg_geo

Returns:

List of QualityControl objects

Return type:

tests(list)

pysurfex.titan.merge_json_qc_data_sets(an_time, filenames, qc_flag=None, skip_flags=None)[source]

Merge QC data sets from json files.

Parameters:
  • an_time (datetime.datetime) – Analysis time.

  • filenames (list) – List of filenames.

  • qc_flag (int, optional) – QC code to merge. Defaults to None.

  • skip_flags (list, optional) – List of QC flags to skip. Defaults to None.

Returns:

QCDataSet

Return type:

QCDataSet

pysurfex.obsmon.open_db(dbname)[source]

Open database.

Parameters:

dbname (str) – File name.

Raises:

RuntimeError – Need SQLite

Returns:

A connection

Return type:

sqlite3.connect

pysurfex.obsmon.close_db(conn)[source]

Close data base connection.

Parameters:

conn (sqlite3.connect) – Data base connection.

pysurfex.obsmon.create_db(conn, modes, stat_cols)[source]

Create data base.

Parameters:
  • conn (sqlite3.connect) – Data base connection.

  • modes (_type_) – _description_

  • stat_cols (_type_) – _description_

pysurfex.obsmon.populate_usage_db(conn, dtg, varname, observations)[source]

Populate usage.

Parameters:
  • conn (_type_) – _description_

  • dtg (_type_) – _description_

  • varname (_type_) – _description_

  • observations (_type_) – _description_

pysurfex.obsmon.rmse(predictions, targets)[source]

Root mean square error.

Parameters:
  • predictions (_type_) – _description_

  • targets (_type_) – _description_

Returns:

_description_

Return type:

_type_

pysurfex.obsmon.absbias(predictions)[source]

Absolute bias.

Parameters:

predictions (_type_) – _description_

Returns:

_description_

Return type:

_type_

pysurfex.obsmon.mean(predictions)[source]

Mean.

Parameters:

predictions (_type_) – _description_

Returns:

_description_

Return type:

_type_

pysurfex.obsmon.calculate_statistics(observations, modes, stat_cols)[source]

Statistics.

Parameters:
  • observations (_type_) – _description_

  • modes (_type_) – _description_

  • stat_cols (_type_) – _description_

Raises:

NotImplementedError – _description_

Returns:

_description_

Return type:

_type_

pysurfex.obsmon.populate_obsmon_db(conn, dtg, statistics, modes, stat_cols, varname)[source]

Populate obsmon.

Parameters:
  • conn (_type_) – _description_

  • dtg (_type_) – _description_

  • statistics (_type_) – _description_

  • modes (_type_) – _description_

  • stat_cols (_type_) – _description_

  • varname (_type_) – _description_

Raises:

RuntimeError – _description_

pysurfex.obsmon.write_obsmon_sqlite_file(**kwargs)[source]

Write obsmon sqlite file.

pysurfex.cli.run_surfex_binary(mode, **kwargs)[source]

Run a surfex binary.

pysurfex.cli.run_gridpp(**kwargs)[source]

Gridpp.

pysurfex.cli.run_titan(**kwargs)[source]

Titan.

pysurfex.cli.run_oi2soda(**kwargs)[source]

Oi2soda.

pysurfex.cli.set_geo_from_stationlist(**kwargs)[source]

Set geometry from station list.

pysurfex.cli.sentinel_obs(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.qc2obsmon(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.prep(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.plot_points(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

Raises:
  • NotImplementedError – “Inputype is not implemented”

  • RuntimeError – “No geo is set”

  • RuntimeError – “No field read”

  • ModuleNotFoundError – “Matplotlib is needed to plot”

pysurfex.cli.pgd(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.perturbed_offline(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.offline(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_oi2soda(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_modify_forcing(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_merge_qc_data(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.gridpp(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.dump_environ(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.first_guess_for_oi(argv=None)[source]

First guess for OI.

Parameters:

argv (list) – Arguments

pysurfex.cli.cryoclim_pseudoobs(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.create_namelist(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

Raises:
  • FileNotFoundError – “File not found:”

  • RuntimeError – “Geo is needed for PGD”

pysurfex.cli.create_lsm_file_assim(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

Raises:

FileNotFoundError – Domain file not found

pysurfex.cli.create_forcing(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.bufr2json(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.obs2json(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_set_domain_from_harmonie(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

Raises:
  • FileNotFoundError – File not found

  • RuntimeError – Domain not provided

pysurfex.cli.cli_set_geo_from_obs_set(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_set_geo_from_stationlist(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.cli_shape2ign(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.soda(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.cli.titan(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.verification.parse_args_converter2ds(argv)[source]

Parse the command line input arguments for setting a .

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.verification.converter2ds(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

Raises:
  • FileExistsError – _description_

  • RuntimeError – “No geo information”

pysurfex.verification.parse_args_ds2verif(argv)[source]

Parse the command line input arguments for setting a .

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.verification.ds2verif(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.verification.parse_args_concat_datasets(argv)[source]

Parse the command line input arguments for setting a .

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.verification.concat_datasets(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.verification.concat_datasets_verif(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.verification.parse_args_vfld2ds(argv)[source]

Parse the command line input arguments for setting a .

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.verification.vfld2ds(argv=None)[source]

Command line interface.

Parameters:

argv (list, optional) – Arguments. Defaults to None.

pysurfex.verification.parse_args_converter2harp(argv)[source]

Get args for converter2harp.

Parse the command line input arguments for creating SQLite tables for HARP from a converter.

Parameters:

argv (list) – List with arguments.

Returns:

Parsed arguments.

Return type:

dict

pysurfex.verification.converter2harp_cli(argv=None)[source]

Create harp data froma converter.

Parameters:

argv (list, optional) – Argument list. Defaults to None

pysurfex.verification.converter2harp(converter, **kwargs)[source]

Create harp data froma converter.

Parameters:
  • converter (Converter) – Converter object

  • kwargs (dict) – Key-word arguments

pysurfex.netcdf.read_first_guess_netcdf_file(input_file, var)[source]

Read netCDF first guess file.

Parameters:
  • input_file (_type_) – _description_

  • var (_type_) – _description_

Raises:
  • NotImplementedError – Only conf proj implemented when reading geo from file

  • RuntimeError – cfunits not loaded!

Returns:

geo, validtime, background, glafs, gelevs

Return type:

tuple

pysurfex.netcdf.oi2soda(dtg, t2m=None, rh2m=None, s_d=None, s_m=None, output=None)[source]

Convert analysis to ASCII obs file for SODA.

Parameters:
  • dtg (surfex.datetime_utils) – Analysis time

  • t2m (dict, optional) – Screen level temperature var and file name. Defaults to None.

  • rh2m (dict, optional) – Screen level relative humidiy var and file name. Defaults to None.

  • s_d (dict, optional) – Snow depth var and file name. Defaults to None.

  • s_m (dict, optional) – Soil moisture var and file name. Defaults to None.

  • output (str, optional) – Output file name. Defaults to None.

Raises:
  • RuntimeError – You must specify at least one file to read from

  • RuntimeError – Mismatch in ?? dimension

pysurfex.netcdf.read_cryoclim_nc(infiles, cryo_varname='classed_value_c')[source]

Read crycoclim netCDF file.

Parameters:
  • infiles (list) – Input files.

  • cryo_varname (str, optional) – Variable name in cryo file. Defaults to “classed_value_c”

Raises:

RuntimeError – “No files were read properly”

Returns:

grid_lons, grid_lats, grid_snow_class

Return type:

tuple

pysurfex.netcdf.read_sentinel_nc(infiles)[source]

Read sentinel nc files.

Parameters:

infiles (list) – Input files.

Raises:

RuntimeError – “No files were read properly”

Returns:

longitudes, latitudes, soil moisture

Return type:

tuple

  • ref:

    README

Indices and tables