lagranto package¶
Examples¶
In a first step, let’s simply read the trajectories:
>>> from dypy.lagranto import Tra
>>> filename = 'lsl_20110123_10'
>>> trajs = Tra()
>>> trajs.load_ascii(filename)
or to read a netcdf file:
>>> filename = 'lsl_20110123_10.4'
>>> trajs.load_netcdf(filename)
- The proprieties of the trajectories can be shown as follow::
>>> print(trajs) 24 trajectories with 41 time steps. Available fields: time/lon/lat/p/Q/RH/TH/BLH total duration: -14400.0 minutes >>> print(trajs.variables()) ['time', 'lon', 'lat', 'p', 'Q', 'RH', 'TH', 'BLH'] >>> print(trajs['Q'].shape) (24, 41)
DocStrings¶
-
class
dypy.lagranto.
Tra
(filename='', typefile=None, usedatetime=True)[source]¶ Class to work with LAGRANTO output
Read trajectories from a LAGRANTO file and return a structured numpy array
Parameters: - filename (string) – File containing lagranto trajectories
- usedatetime (bool) – Read times as datetime objects, default True
- filetype – Depreciated
Returns: structured array – trajs(ntra,ntime) with variables as tuple.
Return type: Examples
>>> filename = 'mylslfile.nc' >>> trajs = Tra() >>> trajs.load_netcdf(filename) >>> trajs['lon'][0,:] # return the longitudes for the first trajectory.
- Author : Nicolas Piaget, ETH Zurich , 2014
- Sebastiaan Crezee, ETH Zurich , 2014
-
concatenate
(trajs, time=False)[source]¶ To concatenate trajectories together
Returns: Return a new Tra (trajectories) object Return type: Tra Parameters: time (bool, default False) – if True concatenate along the time dimension
-
duration
¶ time duration in minutes
-
initial
¶ give the initial time of the trajectories
-
load_ascii
(filename, usedatetime=True, msv=-999.999, gz=False)[source]¶ Load trajectories from an ascii file
Parameters:
- usedatetime: bool, default True
- If true return the dates as datetime object
- msv: float, default -999.999
- Change <msv> value into np.nan
- gzip: bool, default False
- If true read from gzip file
-
load_netcdf
(filename, usedatetime=True, msv=-999, unit='hours', exclude=None, date=None)[source]¶ Load trajectories from a netcdf
Parameters: - filename (string,) – path to a netcdf file containing trajectories
- usedatetime (bool, default True) – If True then return time as datetime object
- msv (float, default -999) – Define the missing value
- unit (string, default hours) – Define the units of the times (hours, seconds or hhmm)
- exclude (list of string, default empty) – Define a list of variables to exclude from reading
- date (datetime or list) – Can be used to select particular dates, for example to read in a single timestep
-
write_ascii
(filename)[source]¶ Write the trajectories in an ASCII format
Parameters:
- filename : string
- filename where the trajectories are written
- mode : string, default w
- define the mode for opening the file. By default in write mode (‘w’), append (a) is another option
-
write_netcdf
(filename, exclude=[], unit='hours')[source]¶ Write the trajectories in a netCDF file
Parameters: - trajs (Tra) – A Tra instance
- filename (string) – The name of the output file
- exclude (list, optional) – A list of variables to exclude
- unit (string, optional) – The unit of the dates, can be hours, seconds or hhmm
-
class
dypy.lagranto.
LagrantoRun
(dates, workingdir='.', outputdir='.', startf='startf.4', lslname='lsl_{:%Y%m%d%H}.4', tracevars='', field='', version='cosmo', linkfiles=None, nprocesses=10, sdate=None, fresh=False)[source]¶ Perform Lagranto calculation
Parameters: - dates (list) – list of (startdate, enddate) tuple
- workingdir (string, optional) – path to the model output directory, default to current
- outputdir (string, optional) – path to the trajectory utput directory, defautl to current
- startf (string, optional) – name of the startf to use (or to create), default to startf.4
- lslname (string, optional) – name of the lsl file, define its type, default to lsl_{:%Y%m%d%H}.4
- tracevars (string, optional) – name of a tracevars file as used by trace, default to none
- field (string, optional) – name of a single field to trace, default to none
- version (string, optional) – name of the model version to use, currently only cosmo (default)
- linkfiles (function, optional) – function used to overwrite link_files in run. Should be used if COSMO output is not standard netcdf
- nprocesses (int, optional) – Number of processes used when running in parallel, default to 10
- sdate (datetime object,) – Starting date of the simulation; useful if files are named in forecast mode
- fresh (bool, optional) – Fresh start. Remove output directory first.
-
run
(caltra_kw={}, trace_kw={}, **kwargs)[source]¶ run caltra and trace
if kwargs are provided they are passed to the link_files function