metrics.metricAbstract

This package contains the base class for metrics. It’s an abstract class with a abstract method “analyze”. MSSS and CRPSS are child classes of this one. Most methods use CDO commands.

metricAbstract Module

class metrics.metricAbstract.MetricAbstract(tmpDir='./tmp', output='/', output_plots='/', baseDir='/', result_grid=None, observation='HadCrut', leadtimes_mode='yearly', decadals='1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000', months=None)[source]

Abstract class for calculating any metric of decadal runs with CDO Every reusable function which uses CDO commands should go in here.

analyze()[source]

Abstract Method to calculate a metric Must be implemented in child classes

_remapFiles(ensList, flag='')[source]

Multiprocessing for remapping files remap observations and model files

Parameters:ensList – list of files
Returns:list of remapped files
remapFile(*arg, **kwargs)[source]

Remaps a single file width CDO’s remapcon

:param inputfile

getEnsembleMean(fileList)[source]
Todo :Multiprocessing

Should do ensmean in multiprocessing!!! At the moment only single approach

Parameters:fileList – dict of filelists
Returns:dict of ensemble means
_getEnsembleMean(fileList, flag='ENSMEAN')[source]

Calculates ensemble Mean

Parameters:fileList – list of files
Returns:ensemble mean file
tempSmoothing(ensList, startyear, endyear)[source]

Multiprocessing approach for temporal smoothing Starts a process for every file in ensList

Parameters:
  • ensList – List of files
  • startyear – int
  • endyear – int
Returns:

list of temporal smoothed files

_tempSmoothing(fileName, startyear, endyear)[source]

Temporal smoothing. I.e. timmean over year 2-9

Parameters:
  • fileName – filepath
  • startyear – first year to select (int)
  • endyear – last year to select (int)
Returns:

temp smoothed file

removeSeasonalCycle(fn)[source]

Subtracts the seasonal cycle of monthly data

getAnomalies(ensMeanList, crossMean)[source]

Subtracts cross-validated mean from ensembles

Parameters:
  • ensMEanList – dict with filenames
  • crossMean – dict width cross-val means
Returns:

dict width cross-validated anomalies

getCrossValMean(ensMeanList, flag)[source]

Calculates cross-validated means (averages through forecast times, excluding the forecast in question)

Parameters:
  • ensMeanList – Dict of filnames
  • flag – String value added to new filenames
Returns:

dict with cross-validated means

getVariance(list, flag)[source]

Calculate “variance”

Deprecated :

Not used in goddard metrics –> should not be used

Parameters:
  • list – filelist
  • flag – string for filenames
Returns:

kind of standard deviation of anomalies

createConstantFile(gridFile, flag='')[source]

Creates a constant field with value 1

Parameters:gridFile – grid description file (txt)
Returns:filename
getEnsembleStd(ensList)[source]

Calculates the mean ensemble STD for a given dictionary Keys in dict have to be the starting years

Parameters:ensList – dict with ensembles
Returns:file with mean ensemble std
_getEnsembleVar(fileList)[source]

Calculates the ensemble Variance of a given file list (ensembles)

Note :CDO norally divides by n here this is changed to n-1
Parameters:fileList – List of files
Returns:file with ensemble variance
printValues(variable, msg)[source]

Method for debugging. Prints our values of a list, dict or file.

Note :

Printing is only activated for TESTDATA

Todo :

Maybe extend for numpy arrays

Parameters:
  • variable – variable to print
  • msg – name of variable
printFileValue(filename, msg)[source]

Method for debugging. Prints a specific value of a given netCDF File.

Parameters:
  • filename
  • msg – additional message to print out. Like the name of the variable
calcMissingValueMask(observations)[source]

Calculates a missing value mask using the observations. At the moment all gridpoints are masked at missing value where at least one value is missing

Todo :find a less strict solution. Maybe 10% available?

DONE!

Parameters:observations – dict with all observations

:return netcdf file with missing values mask 1/0

sellonlatbox(fileList)[source]

Method to select a lon-lat-box using CDO

Parameters:fileList – list with files of single file
Returns:new filelist
_sellonlatbox(file)[source]

Single process for selecting lon-lat-box with cdo

Param :file
Returns:new file
fieldMean(fileList)[source]

Multiprocess Method to calc fieldmean

Parameters:fileList
Returns:fieldmean list
_fieldMean(fn)[source]

Single process calculating fieldmean using CDO

Parameters:fn
Returns:fieldmean fn
multiProcessCdo(fileList, cdo_command, arguments='')

Multi Process Wrapper for “single” cdo commands like “fldmeam” with 1 input and 1 output file

_singleProcessCdo(fn, cdo_command, arguments='')

Single Process Wrapper for “single” cdo commands like “fldmeam” with 1 input and 1 output file

_plotField(fileName, vmin, vmax)[source]

@deprecated: use the static Plotter class instead Plot any field variable

Parameters:
  • fileName – filepath
  • vmin – min value for colorbar
  • vmax – max value for colorbar
applyMissingValueMask(start, end, outputDirList)[source]

Multiply results with a missing value mask

Todo :

At the moment all files in the outputdir are multiplied. This should be changed

Parameters:
  • start – startyear
  • end – endyear
Returns:

list of changed files

detrendTimeSeries(fn, keepMean=True)[source]

Subtracts trend of a timeseries. If keepMean is True the mean is kept

getMissingMaskForFieldMean()

If we calculate field mean we have to take the missing values of the observations into account. In this method the missing field mask of all observations is calculated. DON’T mix it up with calcMissingValueMask

applyMissingMaskForFieldMean(fileList, missmask)

Apply missing value mask to a list of files

_applyMissingMaskForFieldMean(data, missmask)

Apply missing value mask to a file

getLevelIntersection(fn1, fn2, fn3=None)

Takes 2 3d netcdf files and calculates common levels

Returns:list of common levels

Table Of Contents

Previous topic

metrics.crpss

Next topic

FindFiles

This Page