Tempest Extremes
Tempest Extremes is a popular software for detecting and tracking tropical cyclones and other weather systems in climate datasets. It is written by Paul Ullrich and released under a BSD 2-clause license.
For an overview of the functionalities, installation, and usage see the Tempest Extremes section of the documentation.
- class tctrack.tempest_extremes.TETracker(detect_parameters, stitch_parameters=None)[source]
Bases:
TCTrackerClass containing bindings to the Tempest Extremes code.
- detect_parameters
Class containing the parameters for the detection step
- Type:
- stitch_parameters
Class containing the parameters for the stitching step
- Type:
TEStitchParameters | None
- property global_metadata: dict
Read-only property containing metadata for tctrack / tracker instance.
- Raises:
AttributeError – If _global_metadata has not been initialized.
- Type:
dict
- property time_metadata: TCTrackerTimeMetadata
Read-only property containing time metadata for this Tracker run.
- Raises:
AttributeError – If _time_metadata has not been initialized.
- Type:
dict
- to_netcdf(output_file)
Write track trajectories to CF-compliant NetCDF trajectory file.
Reads in trajectories based on the parameters set for a specific implementation of the class and writes them to a CF-Conventions compliant NetCDF trajectory file using cf-python. Trajectories are assumed to contain as a minimum data for
lat,lon, andtimestep.An ancillary field variable is added to the output file indicating any tracks that start/end within 1 day of the input dataset boundaries.
- Parameters:
output_file (
str) – filename for the output netCDF file Note: This will be placed in the local directory unless a full path is given- Return type:
None
Warning
- UserWarning
If there are no trajectories read in from the tracker outputs by
read_trajectories()meaning no NetCDF output file can be written.
References
CF-Conventions v1.1 - H.4. Trajectory Data cf-python documentation
Examples
Instantiate a
TCTrackersubclass instance with appropriate parameters, run the relevant methods to generate cyclone track trajectories, and then save the results to a CF-compliant trajectory file:>>> my_tracker = TCTracker(...) >>> ... >>> my_tracker.to_netcdf("my_netcdf_file.nc")
- property variable_metadata: dict
Read-only property containing NetCDF metadata for variables.
- Raises:
AttributeError – If _variable_metadata has not been initialized.
- Type:
dict
- detect()[source]
Call the DetectNodes utility of Tempest Extremes.
This will make a system call out to the DetectNodes method from Tempest Extremes (provided it has been installed as an external dependency). DetectNodes will be run according to the parameters in the
detect_parametersattribute that were set when theTETrackerinstance was created.The output file is a plain text file containing each of the TC candidates at each time from the input files. If
output_dirisNonethis will be a temporary file lasting the lifetime of theTETrackerinstance. Ifout_headerisTruethe first two lines of the file will be a header describing the structure of the data. After this each time is listed in the format:<year> <month> <day> <count> <hour> <i> <j> <lon> <lat> <var1> <var2> ... ... <i> <j> <lon> <lat> <var1> <var2> ...countis the number of nodes at that time.i,jare the grid indices of the node.var1,var2, etc., are scalar variables as defined byoutput_commands(typically, psl, orog).
- Returns:
dict of subprocess output corresponding to stdout, stderr, and returncode.
- Return type:
dict- Raises:
FileNotFoundError – If the DetectNodes executeable from TempestExtremes cannot be found.
RuntimeError – If Tempest Extremes DetectNodes returns a non-zero exit code.
References
TempestExtremes Documentation and the DetectNodes Source
Examples
To set the parameters, instantiate a
TETrackerinstance and run DetectNodes:>>> my_params = TEDetectParameters(...) >>> my_tracker = TETracker(detect_parameters=my_params) >>> result = my_tracker.detect()
- stitch()[source]
Call the StitchNodes utility in Tempest Extremes.
This will make a system call out to the StitchNodes method from Tempest Extremes (provided it has been installed as an external dependency). StitchNodes will be run according to the parameters in the
stitch_parametersattribute that were set when theTETrackerinstance was created.The output is a file containing the data for each node of each trajectory. If
output_dirisNonethis will be a temporary file lasting the lifetime of theTETrackerinstance. The format of the file depends on theout_file_formatparameter. The default"gfdl"output is a plain-text “nodefile” format which contains a number of track trajectories, each of which in the form.start <N> <year> <month> <day> <hour> <i> <j> <var1> <var2> ... <year> <month> <day> <hour> ... <i> <j> <var1> <var2> ... <year> <month> <day> <hour>Nis number of nodes in the trajectory (and number of lines below header).i,jare grid indices.var1,var2, etc., are scalar variables as defined byin_fmt(typically, lon, lat, psl, orog).hourmay instead be seconds ifout_secondsisTrue.
- Returns:
dict of subprocess output corresponding to stdout, stderr, and returncode.
- Return type:
dict- Raises:
FileNotFoundError – If the StitchNodes executeable from TempestExtremes cannot be found.
RuntimeError – If Tempest Extremes StitchNodes returns a non-zero exit code.
References
TempestExtremes Documentation and the StitchNodes Source
Examples
To set the parameters, instantiate a
TETrackerinstance and perform stitching:>>> my_params = TEStitchParameters(...) >>> my_tracker = TETracker(stitch_parameters=my_params) >>> result = my_tracker.stitch()
- read_trajectories()[source]
Parse outputs from Tempest Extremes to list of
tctrack.core.Trajectory.The file to be read and its properties are based on the values in the
stitch_parametersattribute.- Returns:
A list of
tctrack.core.Trajectoryobjects.- Return type:
list[Trajectory]
- set_metadata()[source]
Set the global and variable (reading from input files) metadata attributes.
Reads metadata for each variable listed in
detect_parameters.output_commandsfrom the input NetCDF files defined indetect_parameters.in_data(matching the NetCDF variable name). These will be stored in thevariable_metadataattribute as a dictionary ofTCTrackerMetadataobjects. This will be called from theto_netcdf()method.- Raises:
ValueError – If a variable is not found in the input files.
- Return type:
None
Examples
To read in the metadata for
pslfrominputs.nc:>>> detect_params = TEDetectParameters( >>> in_data=["inputs.nc"], >>> output_commands=[TEOutputCommand(var="psl", operator="min", dist=0)], >>> ) >>> tracker = TETracker(detect_params, stitch_params) >>> tracker.set_metadata() >>> tracker.variable_metadata { "psl": TCTrackerMetadata( properties={ "standard_name": "air_pressure_at_sea_level", "long_name": "Sea Level Pressure", "units": "Pa", }, constructs=[<CF CellMethod: area: point>], ), }
- run_tracker(output_file)[source]
Run TempestExtremes tracker to obtain tropical cyclone track trajectories.
This first runs
detect()to get TC candidates at each time. Then these are combined into trajectories usingstitch(). The output is then saved as a CF-compliant NetCDF trajectory file.- Parameters:
output_file (
str) – Filename to which the tropical cyclone trajectories are saved.- Raises:
FileNotFoundError –
If the TempestExtremes executables cannot be found. - If the stitch output file does not exist.
RuntimeError – If the TempestExtremes commands return a non-zero exit code.
Examples
To create the tracker instance, then use run_tracker to perform the detection, stitching, and generate output.
>>> detect_params = TEDetectParameters(...) >>> stitch_params = TEStitchParameters(...) >>> my_tracker = TETracker(detect_params, stitch_params) >>> my_tracker.run_tracker()
- class tctrack.tempest_extremes.TEDetectParameters(in_data, out_header=False, output_dir='', output_file='nodes.txt', search_by_min=None, search_by_max=None, closed_contours=None, merge_dist=0.0, time_filter=None, lat_name='lat', lon_name='lon', min_lat=0.0, max_lat=0.0, min_lon=0.0, max_lon=0.0, regional=False, output_commands=None)[source]
Bases:
TCTrackerParametersDataclass containing values used by the detection operation of TE.
See also
TEContourThe class used to define contour criteria
TEOutputCommandThe class used to define additional outputs
References
TempestExtremes Documentation and the DetectNodes Source
-
in_data:
list[str] List of strings of NetCDF input files.
-
out_header:
bool= False Include header at the top of the output file?
-
output_dir:
str= '' File path of the directory to output intermediate files. If left empty, it will use a temporary directory that will last only for the lifetime of the
TETrackerinstance.
-
output_file:
str= 'nodes.txt' Name of output nodefile to write to in the
output_dirdirectory.
-
search_by_min:
str|None= None Input variable in NetCDF files for selecting candidate points (defined as local minima). If
None, then uses"PSL"in Tempest Extremes.
-
search_by_max:
str|None= None Input variable in NetCDF files for selecting candidate points (defined as local maxima).
-
closed_contours:
list[TEContour] |None= None Criteria for candidates to be eliminated if they do not have a closed contour as a list of separate
TEContourcriteria.
-
merge_dist:
float= 0.0 DetectNodes merges candidate points with a distance (in degrees) shorter than the specified value. Among two candidates within the merge distance, only the candidate with the lowest value of the search_by_min field or highest value of the search_by_max field are retained.
-
time_filter:
str|None= None “3hr”, “6hr”, “daily”. Alternatively, can be a regex for the datetime using format “YYYY-MM-DD HH:MM:SS”.
- Type:
Filter for the input data frequency. Options are
-
lat_name:
str= 'lat' String for the latitude dimension in the NetCDF files.
-
lon_name:
str= 'lon' String for the longitude dimension in the NetCDF files.
-
min_lat:
float= 0.0 Minimum latitude for candidate points.
-
max_lat:
float= 0.0 Maximum latitude for candidate points. If max_lat and min_lat are equal then these arguments are ignored.
-
min_lon:
float= 0.0 Minimum longitude for candidate points.
-
max_lon:
float= 0.0 Maximum longitude for candidate points. If
max_lonandmin_lonare equal then these arguments are ignored.
-
regional:
bool= False Should lat-lon grid be periodic in longitude.
-
output_commands:
list[TEOutputCommand] |None= None Criteria for any additional columns to be added to the output. Criteria are provided as a list of separate
TEOutputCommandcriteria.
- class tctrack.tempest_extremes.TEStitchParameters(output_dir='', output_file='trajectories.txt', in_file=None, in_list=None, in_fmt=None, allow_repeated_times=False, caltype='standard', time_begin=None, time_end=None, max_sep=5, max_gap=0, min_time=1, min_endpoint_dist=0, min_path_dist=0, threshold_filters=None, prioritize=None, add_velocity=False, out_file_format='gfdl', out_seconds=False)[source]
Bases:
TCTrackerParametersDataclass containing values used by the stitch operation of TE.
References
TempestExtremes Documentation and the StitchNodes Source
-
output_dir:
str= '' File path of the directory to output intermediate files. If left empty, it will use the
TEDetectParameters.output_dirvalue if one is provided. Otherwise, it will use a temporary directory that will last only for the lifetime of theTETrackerinstance.
-
output_file:
str= 'trajectories.txt' The output filename to write the trajectories to in the
output_dirdirectory.
-
in_file:
str|None= None Filepath of the DetectNodes output file. If this and
in_listareNone, it will be determined fromTEDetectParameters.output_dirandTEDetectParameters.output_file. Called “in” in TempestExtremes.
-
in_list:
str|None= None File containing a list of input files to be processed together. This is unadvised to use at present as it is likely to be changed.
-
in_fmt:
list[str] |None= None List of the variables in the order they appear in the input file. If
None, it will be["lon", "lat", ...], ending in variables defined inTEDetectParameters.output_commands.
-
allow_repeated_times:
bool= False If
False, an error is thrown if there are multiple sections in the input nodefile with the same time.
-
caltype:
str= 'standard' The type of calendar to use. Options are
"standard"(365 days with leap years),"noleap","360_day".
-
time_begin:
str|None= None Starting date/time for stitching trajectories. Earlier times will be ignored.
-
time_end:
str|None= None Ending date/time for stitching trajectories. Later times will be ignored.
-
max_sep:
float= 5 The maximum distance allowed between candidates (degrees). Called “range” in TempestExtremes.
-
max_gap:
int|str= 0 The number of missing points allowed between candidates, as an integer. Or as a string for the maximum time (inclusive) between points, e.g.
"24hr".
-
min_time:
int|str= 1 The minimum required length of a path. Either as an integer for the number of candidates, or a string for total duration, e.g.
"24h".
-
min_endpoint_dist:
float= 0 The minimum required distance between the first and last candidates (degrees).
-
min_path_dist:
float= 0 The minimum required acumulated distance along the path (degrees).
-
threshold_filters:
list[TEThreshold] |None= None Filters for paths based on the number of nodes that satisfy a threshold. Uses a list of
TEThresholdobjects. Called “thresholdcmd” in TempestExtremes.
-
prioritize:
str|None= None The variable to use to determine the precedence (lowest to highest) of nodes for matching to the next position.
-
add_velocity:
bool= False Whether to include the velocity components (m/s) of the movement of the TC to the output file.
-
out_file_format:
str= 'gfdl' Format of the output file.
"gfdl","csv", or"csvnohead". SeeTETracker.stitch()for details.
-
out_seconds:
bool= False For GFDL output file types, determines whether to report the sub-daily time in seconds (
True) or hours (False).
-
output_dir:
- class tctrack.tempest_extremes.TEContour[source]
Bases:
TypedDictData required for checking a contour of a single variable during detection.
Points will be eliminated in a detection search if they fail this criterion. The closed contour is determined by breadth first search: if any paths exist from the candidate point (or nearby minima/maxima if minmaxdist is specified) that reach the specified distance before achieving the specified delta then we say no closed contour is present. Each contour takes the form of a
dictwith keys"var","delta","dist", and"minmaxdist".See also
TETracker.detectThe DetectNodes call from the TETracker object
TEDetectParametersThe detection parameter class
References
TempestExtremes Documentation and the DetectNodes Source
Examples
To add a contour requirement on
"psl"with a change of200.0within5.5degrees of the candidate we create a TEContour as follows:>>> TEContour(var="psl", delta=200.0, dist=5.5, minmaxdist=0.0) {'var': 'psl', 'delta': 200.0, 'dist': 5.5, 'minmaxdist': 0.0}
-
var:
str Name of the variable to contour in NetCDF files.
-
delta:
float Amount by which the field must change from the pivot value. If positive (negative) the field must increase (decrease) by this value along the contour.
-
dist:
float Lesser-circle radius (degrees) from the pivot within which the criteria must be satisfied.
-
minmaxdist:
float Lesser-circle radius away from the candidate to search for the minima/maxima. If delta is positive (negative), the pivot is a local minimum (maximum).
- class tctrack.tempest_extremes.TEOutputCommand[source]
Bases:
TypedDictData required to specify an additional column in the detection output.
Each output command takes the form of a
dictwith keys"var","op", and"dist".See also
TETracker.detectThe DetectNodes call from the TETracker object
TEDetectParametersThe detection parameter class
References
TempestExtremes Documentation and the DetectNodes Source
Examples
To add an output column with the minimum
"psl"at the candidate point:>>> TEOutputCommand(var="psl", operator="min", dist=0.0) {'var': 'psl', 'operator': 'min', 'dist': 0.0}
-
var:
str Name of the variable to write in output files.
-
operator:
str Operator that is applied over all points within the specified distance of the candidate (options include
"max","min","avg","maxdist", and"mindist").
-
dist:
float Lesser-circle radius (degrees) from the candidate within which the operator is applied.
- class tctrack.tempest_extremes.TEThreshold[source]
Bases:
TypedDictData required for a threshold filter for a track trajectory when stitching.
Any storm track trajectories that do not satisfy the threshold value for a given number of points will be filtered out. Each condition is of the form “var,op,value,count” and multiple conditions are separated by “;”.
See also
TETracker.stitchThe StitchNodes call from the TETracker object.
TEStitchParametersThe stitching parameter class.
References
TempestExtremes Documentation and the StitchNodes Source
Examples
To add a filter requiring latitude
"lat"to be less than 40 degrees for 10 or more points in each track trajectory:>>> TEThreshold(var="lat", op="<=", value=40, count=10) {"var": "lat", "op": "<=", "value": 40, "count": 10},
-
var:
str Name of the variable being tested. Called “col” in TempestExtremes.
-
op:
str Operator used for the comparison (options include >,>=,<,<=,=,!=,|>=,|<=).
-
value:
float Value on the right-hand-side of the comparison.
-
count:
int|str Either the minimum number of points where the threshold must be satisfied or the instruction
"all","first", or"last"."all"for all points along the path,"first"for just the first point, and"last"for only the last point.