TrackGenerator package¶
Submodules¶
TrackGenerator.TrackGenerator module¶
TrackGenerator
– Tropical cyclone track generation¶
This module contains the core objects for tropical cyclone track generation.
Track generation can be run in parallel using MPI if the mpi4py library is found and TCRM is run using the mpirun command. For example, to run with 10 processors:
$ mpirun -n 10 python main.py cairns.ini
TrackGenerator
can be correctly initialised and started by
calling run()
with the location of a configuration file:
>>> import TrackGenerator
>>> TrackGenerator.run('cairns.ini')
Alternatively, it can be run from the command line:
$ python TrackGenerator.py cairns.ini
Track format¶
Tracks are stored in netCDF4 format files, making use of the compound variable types and heirarchical group structure available in this version of netCDF. Each event is contained as a separate group in the file, and each file contains a simulation ‘year’ (though in the case of multi-year simulations, multiple years are contained in the file).
Here’s an example that shows the group structure in a track file. The track file contains five tracks, each with only two variables - ‘time’ and ‘track’:
>>> from netCDF4 import Dataset
>>> rootgrp = Dataset("tracks.00001.nc", "r")
>>> print rootgrp.groups
OrderedDict([(u'tracks', <netCDF4.Group object at 0x04B92E88>)])
>>> def walktree(top):
>>> values = top.groups.values()
>>> yield values
>>> for value in top.groups.values():
>>> for children in walktree(value):
>>> yield children
>>> print rootgrp
<type 'netCDF4.Dataset'>
root group (NETCDF4 file format):
created_on: 2015-09-23 14:12:20
created_by: u12161
dimensions:
variables:
groups: tracks
>>> for children in walktree(rootgrp):
>>> for child in children:
>>> print child
<type 'netCDF4.Group'>
group /tracks:
dimensions:
variables:
groups: tracks-0000, tracks-0001, tracks-0002, tracks-0003, tracks-0004
<type 'netCDF4.Group'>
group /tracks racks-0000:
dimensions: time
variables: time, track
groups:
<type 'netCDF4.Group'>
group /tracks racks-0001:
dimensions: time
variables: time, track
groups:
<type 'netCDF4.Group'>
group /tracks racks-0002:
dimensions: time
variables: time, track
groups:
<type 'netCDF4.Group'>
group /tracks racks-0003:
dimensions: time
variables: time, track
groups:
<type 'netCDF4.Group'>
group /tracks racks-0004:
dimensions: time
variables: time, track
groups:
The ‘time’ variable is an unlimited dimension representing the length of the track in hours since genesis.
The ‘track’ variable is a compound variable akin to a
numpy.recarray
. Here’s an example of the summary of a ‘track’
variable (taking the last track from the previous example):
>>> print child.variables['track']
<type 'netCDF4.Variable'>
compound track(time)
long_name: Tropical cyclone track data
time_units: hours since 1900-01-01 00:00
calendar: julian
lon_units: degrees east
lat_units: degrees north
pressure_units: hPa
speed_units: m/s
length_units: km
trackId: (5, 1)
compound data type: {'names':[u'CycloneNumber',u'Datetime',u'TimeElapsed',
u'Longitude',u'Latitude',u'Speed',
u'Bearing',u'CentralPressure',
u'EnvPressure',u'rMax'],
'formats':['<i4','<f8','<f4','<f8','<f8','<f8',
'<f8','<f8','<f8','<f8'],
'offsets':[0,8,16,24,32,40,48,56,64,72],
'itemsize':80}
path = /tracks racks-0004
unlimited dimensions: time
current shape = (220,)
A thorough explanation of the netcdf4-python API is given on the Unidata Github page.
-
class
SamplePressure
(mslp_file, var='slp')¶ Bases:
object
Provide a method to get a 3-d interpolated mean sea level pressure at a given location
- Parameters
mslp_file (str) – path to a 3-d (time, lat, lon) MSLP netcdf file.
var (str) – Variable name (assumed ‘slp’)
-
get_pressure
(coords)¶ Interpolate daily long term mean sea level pressure at the given coordinates.
- Parameters
coords (list) – [day of year, latitude, longitude]
- Return type
float
- Returns
long term MSLP
-
class
Simulation
(index, seed, jumpahead, ntracks, outfile)¶ Bases:
object
Simulation parameters.
This is used to set the PRNG state before ntracks are simulated.
- Parameters
index (int) – the simulation index number.
seed (int) – the initial seed used for the PRNG.
jumpahead (int) – the amount to jump ahead from the initial seed in the PRNG stream.
ntracks (int) – the number of tracks to be generated during the simulation.
outfile (str) – the filename where the tracks will be saved to.
-
class
TrackGenerator
(processPath, gridLimit, gridSpace, gridInc, mslp, landfall, innerGridLimit=None, dt=1.0, maxTimeSteps=360, sizeMean=46.5, sizeStdDev=0.5)¶ Bases:
object
Generates tropical cyclone tracks based on the empirical probability distributions of speed, bearing, pressure and maximum radius.
- Parameters
processPath (string) – the location of the empirical probability distribution files.
gridLimit (
dict
) – the domain where the tracks will be generated. Thedict
should contain the keysxMin
,xMax
,yMin
andyMax
. The x variable bounds the longitude and the y variable bounds the latitude.gridSpace (
dict
) – the grid spacing of the domain. This is used to chop the domain into cells. Thedict
should contain the keysx
andy
.gridInc (
dict
) – the increments for the grid to be used byStatInterface.GenerateStats
when insufficient observations exist in the cell being analysed.landfall (
LandfallDecay
) – the object that calculates the decay rate of a tropical cyclone after it has made landfall. The object should have the methodsonLand()
andpChange()
.innerGridLimit (
dict
) – an optional domain limit that can be used to cull tropical cyclone paths. Thedict
should contain the keysxMin
,xMax
,yMin
andyMax
. The x variable bounds the longitude and the y variable bounds the latitude.dt (float) – the time step used the the track simulation.
maxTimeSteps (int) – the maximum number of tropical cyclone time steps that will be simulated.
sizeMean (float (default: 46.5.0)) – the fallback average tropical cyclone size to use when the empirical distribution data cannot be loaded from file.
sizeStdDev (float (default: 0.5)) – the fallback standard deviation of the tropical cyclone size to use when the empirical distribution data cannot be loaded from file.
-
dumpAllCellCoefficients
()¶ Dump all cell coefficients to a netcdf file to permit further analysis.
-
generateTracks
(nTracks, simId, initLon=None, initLat=None, initSpeed=None, initBearing=None, initPressure=None, initEnvPressure=None, initRmax=None, initDay=None)¶ Generate tropical cyclone tracks from a single genesis point.
If the initial conditions for speed, pressure, and bearing are not provided then they will be drawn randomly from the empirical distributions that were calculated from historical data (see
loadInitialConditionDistributions()
).If the genesis point (initLon, initLat) is not provided, then an origin will be randomly chosen using the empirical genesis point distribution calculated by
StatInterface.SamplingOrigin
. However, if this random point (or the initial point given) falls outside the domain defined bygridLimit
then no tracks will be generated.- Parameters
nTracks (int) – the number of tracks to generate from the genesis point.
initLon (float) – the longitude of the genesis point.
initLat (float) – the latitude of the genesis point.
initSpeed (float) – the initial speed of the tropical cyclone.
initBearing (float) – the initial bearing of the tropical cyclone.
initPressure (float) – the initial pressure of the tropical cyclone.
initEnvPressure (float) – the initial environment pressure.
initRmax (float) – the initial maximum radius of the tropical cyclone.
:rtype
numpy.array
:return: the tracks generated.
-
generateTracksToFile
(outputFile, nTracks, simId, initLon=None, initLat=None, initSpeed=None, initBearing=None, initPressure=None, initEnvPressure=None, initRmax=None, initDay=None)¶ Generate tropical cyclone tracks from a single genesis point and save the tracks to a file.
This is a helper function that calls
generateTracks()
.- Parameters
outputFile (str) – the filename of the file where the tracks will be saved. If outputFile has the shp extension then it will be saved to a shp file. Otherwise, the tracks will be saved in csv format.
-
loadCellStatistics
()¶ Load the cell statistics for speed, bearing, pressure, and pressure rate of change from netcdf files.
This method loads the statistics from the files
speed_stats.nc pressure_stats.nc bearing_stats.nc pressure_rate_stats.nc
in the
processPath
directory.
-
loadInitialConditionDistributions
()¶ Load the tropical cyclone empirical distribution data for initial bearing, initial speed, and initial pressure. The method will try to load the files
all_cell_cdf_init_bearing.nc all_cell_cdf_init_speed.nc all_cell_cdf_init_pressure.nc
from the
processPath
directory. If it can’t find those files then it will fallback to the csv versions of those files. Note: the csv file names do not end with .csv.The empirical distribution data will be used to initialise tropical cyclone tracks with random values when
initBearing
,initSpeed
, andinitPressure
are not provided togenerateTracks()
.
-
balanced
(iterable)¶ Balance an iterator across processors.
This partitions the work evenly across processors. However, it requires the iterator to have been generated on all processors before hand. This is only some magical slicing of the iterator, i.e., a poor man version of scattering.
-
logistic
(loc=0.0, scale=1.0)¶ Sample from a logistic distribution.
-
lognorm
(xi, loc=0.0, scale=1.0)¶ Sample from a lognormal distribution.
-
nct
(df, nc, loc=0.0, scale=1.0)¶ Sample from a non-central T distribution.
-
normal
(mean=0.0, stddev=1.0)¶ Sample from a Normal distribution.
-
ppf
(q, cdf)¶ Percentage point function (aka. inverse CDF, quantile) of an empirical CDF.
This is used to sample from an empirical distribution.
-
run
(configFile, callback=None)¶ Run the tropical cyclone track generation.
This will attempt to perform the simulation in parallel but also provides a sane fallback mechanism.
- Parameters
configFile (str) – the filename of the configuration file to load the track generation configuration from.
-
uniform
(a=0.0, b=1.0)¶ Sample from a uniform distribution.
TrackGenerator.trackLandfall module¶
trackLandfall
– calculate central pressure for over-land TCs¶
Determines the decay rate of a cyclone after it makes landfall. Based on the central pressure deficit at landfall and the time over land, calculate the revised pressure deficit.
References:
Vickery, P. J. and L. A. Twisdale (1995). Wind-Field and Filling Models for Hurricane Wind-Speed Predictions. Journal of Structural Engineering 121(11): 1700-1709.
Powell, M., G. Soukup, S. Cocke, S. Gulati, N. Morriseau-Leroy, S. Hamid, N. Dorst and L. Axe (2005). State of Florida hurricane loss projection model: Atmospheric science component. Journal of Wind Engineering and Industrial Aerodynamics, 93(8): 651-674.
-
class
LandfallDecay
(configFile, dt)¶ Bases:
object
Description: Calculates the decay rate of a tropical cyclone after it has made landfall. Based on the work of on the model of Vickery & Twisdale (1995) and employed in the Florida Hurricane Loss model of Powell et al. (2005). The model is tuned for Florida conditions, and so may require some further tuning for the region of interest.
- Parameters
configFile (str) – Configuration file
dt (float) – time step of the generated cyclone tracks
Members: dt - time step of the generated cyclone tracks landMask - 2D array of 0/1 indicating ocean/land respectively (any positive non-zero value can be used to indicate land points)
Methods: onLand - Determine if a cyclone centred at (cLon, cLat) is over land or not. pChange - If the cyclone centre is over land, then this function determines the filling as a function of the time elapsed since the storm made landfall.
-
onLand
(cLon, cLat)¶ Determine if a cyclone centred at (cLon, cLat) is over land or not.
- Parameters
cLon (float) – TC longitude
cLat (float) – TC latitude
- Return type
boolean
- Returns
True if TC is over land, False otherwise
-
pChange
(pCentre, pEnv)¶ If the cyclone centre is over land, then this function determines the filling as a function of the time elapsed since the storm made landfall. a0 and a1 control the filling rate of the cyclone. Larger values increase the filling rate (i.e. cyclones decay faster). An additional random perturbation is applied to induce some additional variability. Original (V&T1995 values) for a0=0.006, a1=0.00046, eps=random.normal(0.0,0.0025)
- Parameters
pCentre (float) – TC central pressure (hPa)
pEnv (float) – TC environmental pressure (hPa)
- Return type
float
- Returns
revised central pressure
Module contents¶
TrackGenerator
– Tropical cyclone track generation¶
This module contains the core objects for tropical cyclone track generation.
Track generation can be run in parallel using MPI if the mpi4py library is found and TCRM is run using the mpirun command. For example, to run with 10 processors:
$ mpirun -n 10 python main.py cairns.ini
TrackGenerator
can be correctly initialised and started by
calling run()
with the location of a configuration file:
>>> import TrackGenerator
>>> TrackGenerator.run('cairns.ini')
Alternatively, it can be run from the command line:
$ python TrackGenerator.py cairns.ini
Note the absence of a ‘-c’ flag (c.f. the normal TCRM command line arguments).