tempest_helper

Loading data

tempest_helper.get_trajectories(tracked_file, nc_file, time_period, column_names)

Load the trajectories from the file output by TempestExtremes.

Parameters:
  • tracked_file (str) – The path to the file produced by TempestExtremes.

  • nc_file – The path to a netCDF file that the tracking was run on.

  • time_period (int) – The time period in hours between time points in the data.

  • column_names (dict) – the names of the column variables within the tracked_file, to be used as storm[] keys

Returns:

The loaded trajectories.

Return type:

list

Saving data

tempest_helper.save_trajectories_netcdf(directory, savefname, storms, calendar, time_units, variable_units, frequency, um_suiteid, resolution_code, cmd_detect, cmd_stitch, column_names, startperiod='', endperiod='')

Create netcdf file for the tracks. May need metadata from a model nc file, so may need to create at a time when these are available

Parameters:
  • directory (str) – directory path

  • savefname (str) – filename to save netcdf file to

  • storms (list) – The loaded trajectories.

  • calendar (str) – netcdf calendar type

  • time_units (str) – units string for the time coordinate

  • variable_units (str) – units for the different variables

  • frequency (str) –

  • um_suiteid (str) – UM suiteid for netcdf metadata

  • resolution_code (str) – String describing model resolution

  • cmd_detect (str) – the TempestExtremes detect command string

  • cmd_stitch (str) – the TempestExtremes stitch command string

  • column_names (dict) – output variable names derived from the Tempest command

  • startperiod (str) – An optional time string for the start of this data

  • endperiod (str) – AN optional time string for the end of this data period

Plotting data

tempest_helper.plot_trajectories_cartopy(storms, filename, title='')

Use Cartopy to plot the loaded trajectories and save them in the specified file.

Parameters:
  • storms (list) – The loaded trajectories.

  • filename (str) – The full path to save the plot as.

  • title (str) – An optional title to include on the plot.

Analysing data

tempest_helper.count_hemispheric_trajectories(storms)

From a loaded trajectory count the number of storms whose first point is in the southern hemisphere (latitude < 0.0) and those in the northern hemisphere (latitude >= 0.0).

Parameters:

storms (list) – The storm trajectories loaded from TempestExtremes.

Returns:

Integer numbers of the trajectories in the southern and then northern hemispheres.

Return type:

tuple

tempest_helper.count_trajectories(storms)

From a loaded trajectory count the number of storms.

Parameters:

storms (list) – The storm trajectories loaded from TempestExtremes.

Returns:

The number of trajectories.

Return type:

int

Utilities

These functions are used by other functions, but have been exposed here in case they are useful to users.

tempest_helper.convert_date_to_step(cube, year, month, day, hour, time_period)

Calculate the step number, with the first time in a file have a step number of one. All calendars are handled.

Parameters:
  • cube (iris.cube.Cube) – A cube loaded from a data file from the current period.

  • year (int) – The current year.

  • month (int) – The current month.

  • day (int) – The current day of month.

  • hour (int) – The current hour.

  • time_period (int) – The time period in hours between time points in the data.

Returns:

The time index at the specified time point.

Return type:

int

tempest_helper.fill_trajectory_gaps(storm, step, lon, lat, grid_x, grid_y, cube, time_period, new_var, miss_val=-99)

Fill the gap by linearly interpolating the last latitude, longitude, time and other values from the last of these values up to step. The trajectory is passed in to the storm attribute and is a standard tempest_helper dictionary. Longitudes and their interpolation may wrap around the 0/360 degree numerical discontinuity. The longitudes output are between 0 and 359 degrees.

Parameters:
  • storm (dict) – Details of the current storm.

  • step (int) – The integer number of time points of the current point since the start of the file.

  • lon (float) – The longitude of the current point in the storm in degrees.

  • lat (float) – The latitude of the current point in the storm in degrees.

  • grid_x (int) – The i index of the current point in the storm

  • grid_y (int) – The j index of the current point in the storm

  • cube (iris.cube.Cube) – A cube loaded from a data file from the current period.

  • time_period (int) – The time period in hours between time points in the data.

  • new_var (dict) – The other variables contained in the storm at the current point.

  • miss_val (int) – value used for missing data

tempest_helper.storms_overlap_in_time(storm_x, storms_y)

Find the subset of list storms_y that have some overlap in time with storm_x

Parameters:
  • storm_x (dict) – Storm dictionary.

  • storms_y (list) – List of storm dictionaries

Returns:

The list of storms that overlap in time with storm_x.

Return type:

list

tempest_helper.storm_overlap_in_space(storm_c, storms_y, distance_threshold=0.5)

Find if any of the storms that have any overlap in space with storm_c. Expect at most one. There is some overlap in time already determined.

Parameters:
  • storm_c (dict) – Storm dictionary.

  • storms_y (list) – List of storm dictionaries which overlap storm_c in time

  • distance_threshold (float) – maximum distance (degrees) for storms to be apart but identified as overlapping in space

Returns:

Either None, or a dictionary including storm information about the overlap.

Return type:

None or dict

tempest_helper.write_track_line(storm, no_lines, new_length, column_names)

Produce a line of Tempest txt file output matching the track file format

Parameters:
  • storm (dict) – Storm dictionary.

  • no_lines (int) – Number of time values to read from the storm

  • new_length (int) – The new length of the storm

  • column_names (dict) – The names of the storm keys (columns of output file)

Returns:

string and list of strings: the first is the new header line for this storm the second is a list of lines to be written to the track txt file

Return type:

str, list

tempest_helper.remove_duplicates_from_track_files(tracked_file_Tm1, tracked_file_T, tracked_file_Tm1_adjust, tracked_file_T_adjust, storms_match, column_names)

Rewrite the .txt track files, removing the matching storms from the previous timestep which have been found in the current timestep and adding them to this current timestep

Parameters:
  • tracked_file_Tm1 (str) – The path to the track file from the previous timestep.

  • tracked_file_T (str) – The path to the track file from the current timestep.

  • tracked_file_Tm1_adjust (str) – The path to the updated track file for the previous time for output.

  • tracked_file_T_adjust (str) – The path to the updated track file for the current timestep for output.

  • storms_match (list) – The storms which have been found to match with a later time

  • column_names (dict) – the keys for the storm columns in the output file

Unit tests