LagTrack is a 3D lagrangian particle tracking code written in Matlab designed to compute the trajectory of non-spherical particles in realistic atmospheric conditions. Characteristics of LagTrack include:
- The implementation of the method of Bagheri and Bonadonna (2016) to estimate the drag coefficient of non-spherical particles over a wide range of Reynolds number
- For larger particles (i.e. volcanic ballistic projectiles), the implementation of the Eject! approach (Mastin et al., 2001)
- Modules to retrieve input parameters (e.g. topography from SRTM, atmospheric conditions from varios NOAA and ECMWF datasets)
- Modules to plot and analyse the results
- Modules to automatize inversion and sensitivity analyses
- The ability to use the code through a user-friendly GUI or via the command line
Functions are written to be used both as part of the GUI and as standalone. The main GUI is opened using:
LagTrack
Note that the GUI requires the GUI Layout toolbox. A summary of all functions is printed with the command:
help LagTrack_functions
- Table of content
- Input parameters
- Running the model
- Results
- Additional information
- Known issues
- Roadmap
- Notes to myself
- References
The DEM is automatically retrieved using the how-convenient readhgt function from F. Beauducel. SRTM3 tiles are retrieved.
Using the GUI:
downloadSRTM
Using the command line:
downloadSRTM(latMin, latMax, lonMin, lonMax, scalingFactor, name, )
latMin
,latMax
: Minimum and maximum latitudes in decimal degrees. Negative in southern hemispherelonMin
,lonMax
: Minimum and maximum longitudes in decimal degrees. Negative in western hemispherescalingFactor
: Resolution to interpolate the DEM (m). This is obsolete (but still required for now), as the code will automatically attempt retrieving SRTM1 dataname
: Name of the DEM dataset stored ininput/dem/
The raw SRTM files are stored in input/dem/_rawdata
. Example for downloading the topography around Sakurajima volcano and downsampling the resolution by a factor 2:
downloadSRTM(31.5, 31.65, 130.55, 130.75, 2, 'sakurajima')
The DEM format in LagTrack is a Matlab structure containing called dem
and containing the following fields, where m and n are the number of cells in the y and x dimensions, respectively. Adopt this convention to use a DEM obtained from a different source in LagTrack.
X
: [m×n] matrix of longitudesY
: [m×n] matrix of latitudes. In the Matlab matrix,dem.Y(1,:)
should be the southernmost points anddem.Y(end,:)
the northernmostZ
: [m×n] matrix of elevations (m asl). The orientation should be the same asdem.Y
For calculations of particles trajectories that do not require a DEM, LagTrack can create an empty calculation grid specifying only an elevation used to stop the particle:
makeDefaultGrid(alt, name)
alt
: Mean elevation of the grid (m asl)name
: Name of the grid stored ininput/dem/
Atmospheric data in LagTrack can be retrieved from the NCEP/NCAR Reanalysis 1, the NCEP-DOE Reanalysis 2, the ECMWF Era-Interim and the ECMWF Era-5 datasets. To access Era-Interim data, it is assumed that the procedure described here has been followed. To test the installation, run the following command in Matlab. If no message is output, then the ECMWF library is working properly:
!python -c "from ecmwfapi import ECMWFDataServer"
Using the GUI:
downloadATM
Using the command line:
downloadATM(latMin, latMax, lonMin, lonMax, yearMin, yearMax, monthMin, monthMax, name, dataset, varargin)
latMin
,latMax
: Minimum and maximum latitudes in decimal degrees. Negative in southern hemispherelonMin
,lonMax
: Minimum and maximum longitudes in decimal degrees. Negative in western hemisphereyearMin
,yearMax
: Minimum and maximum years to retrieve (e.g. 2017). For a single year,yearMin
=yearMax
monthMin
,monthMax
: Minimum and maximum months to retrieve (e.g. 02 for Feb). For a single month,monthMin
=monthMax
name
: Name of the atmospheric dataset stored ininput/wind/
dataset
: Reanalysis dataset, accepts'ERA5'
,'Interim'
,'Reanalysis1'
and'Reanalysis2'
- If using
'ERA5'
, an additional optional parameter can be passed representing the number of hours between two data points (accepts1
,2
,3
,4
,6
,8
,10
,12
,24
, where6
represents one data point every 6 hours, i.e. 4 data points per day) (default=6
)
The format of atmospheric data in LagTrack is a Matlab structure called atm
and containing the following fields:
lat
,lon
: Latitude and longitude vectors.lat
is a [m×1] vector andlon
is a [n×1] vector, where m and n are the number of points along latitude and longitude, respectivelylevel
: Geopotential height (mb). [l×1] vector, where l is the number of levelstime
: Date vector of each data point in number of days from January 0, 0000 (see Matlab functiondatenum
). [t×1] vector, where t is the number of data point in timetemp
: Temperature (deg K). [m×n×l×t] matrixalt
: Altitude (m asl). [m×n×l×t] matrixhumid
: Relative humidity (%). [m×n×l×t] matrixu
,v
: U and V components of wind (m/s). Each is a [m×n×l×t] matrixrhoair
: Atmosphere density (kg/m2). [m×n×l×t] matrixmuair
: Atmosphere dynamic viscosity viscosity (Pa s). [m×n×l×t] matrix
Post-processing of the atmospheric dataset should be automatic upon successful completion of the download step. To manually post-process wind data, use:
processATM(name, dataset, latMin, latMax, lonMin, lonMax, yearMin, yearMax, monthMin, monthMax)
rhoair
and muair
must be provided in the NetCDF file. rhoair
and muair
are automatically computed by the processATM
function.
Era-Interim: There are two possible options. To access data in batch access mode outside of LagTrack, use the python template provided in code/functions/dependencies/ecmwf-api-client-python/download_ECMWF_tmp.py
. Otherwise, NetCDF should be manually downloaded for each separate month from here and placed in the folder input/wind/windName/
. NetCDF files should contain the following variables: latitude
, longitude
, time
, level
, u
, v
, z
, t
and r
. More details on the procedure is available here.
Reanalysis 1/2: Reanalysis 1 and Reanalysis 2 must be retrieved for entire years at pressure levels. Variables to be retrieved are Air temperature
, Geopotential height
, Relative humidity
, u-wind
and v-wind
. The yearly NetCDF files must be placed in the folders input/wind/_Reanalysis1_Rawdata/
or input/wind/_Reanalysis2_Rawdata/
.
As an alternative to Reanalysis dataset, LagTrack also offers to create a user-defined wind field in a US 1976 standard atmosphere:
makeStandardAtm(uwind, vwind, name)
uwind
,vwind
: Trigonometric u and v components of the wind (m/s)name
: Name of the dataset stored ininput/wind/
Vertical wind velocity is rarely implemented in Reanalysis datasets, but its inclusion is already implemented in the architecture of LagTrack. All vertical velocities are set to w=0
but the formatting of WRF output has been successfully achieved.
In LagTrack, each particle belongs to a run. Multiple particles can depend on a same run. Each particle is a Matlab structure containing various fields described below. The following list describes the structure's fields, whose descriptions are also applicable in the main GUI. It is possible to create an empty particle P
containing all fields by typing:
P = LagTrack
run_name
: Run name to which particles are associatedrun_mode
: Forward (1
) or backward (2
) runs (see next section)vent
: Structure containing vent propertieslat
,lon
: Vent latitude and longitude (decimal degree)alt
: Vent elevation (m asl)
date
: Eruption date (number of days since Jan 0, 0000 - see the Matlab functiondatenum
)path
: Structure containing paths to input parametersnc
: Path to the atmospheric datadem
: Path to the dem
part
: Structure containing the particle's aerodynamical propertiesname
: Particle namediam
: Particle diameter (m)dens
: Particle density (kg/m3)flat
: Flatness (0-1)elon
: Elongation (0-1)
rel
: Structure containing the particle's release propertiesx
,y
: Horizontal displacement (m) of release point relative to the vent; positive towards N and E, negative towards S and Wz
: Release elevation (m relative to vent)t
: Time offset (s relative todate
)vx
,vy
: Initial release velocities along the x and y axes (m/s). Use a value of -1 to set particle's initial velocities to be equal to the u and v components of windvz
: Initial vertical velocity (m/s), positive upwards, negative downwards. Must not be null
adv
: Structure containing advanced propertiessolution
: Accepts 'euler' or 'analytical'dt
: Time step (s)drag
: Region of reduced drag (m) around initial particle release pointinterp
: Interpolation of the atmospheric data. Accepts 'subset' (default; only a subset of the domain is interpolated), 'complete' (the entire domain is interpolated) and 'none' (no interpolation)method
: Interpolation method. Accepts 'linear', 'nearest', 'pchip', 'cubic' and 'spline' (seeinterpn
Matlab function)range
: If the interpolation iis set to 'subset', defines a range of points in each direction around the current particle location to interpolate the atmospheric dataskip
: Number ofdt
between interpolationsmach
: Threshold of mach number above which the drag models described in the Eject! manual (Mastin et al., 2001) is preferred over the method of Bagheri and Bonadonna (2016).
LagTrack can be used calculate the trajectory of particles either in a forward or backward mode.
- In forward mode (
run_mode = 1
), particles are release in the atmosphere at the coordinates [vent.lat
,vent.lon
,vent.alt
] (±rel.x
,rel.y
, andrel.z
) at timedate
(±rel.t
) and their trajectories are computed by advancing in time (dt = dt
) and with a gravity force oriented downwards (g = -9.81
) until the particle intersects the DEM; - In backward mode (
run_mode = 2
), particles are release in the atmosphere at the coordinates [vent.lat
,vent.lon
] (±rel.x
,rel.y
) at the DEM elevation at this location (±rel.z
) at timedate
(±rel.t
) and their trajectories are computed backwards in time (dt = -dt
) and with a gravity force oriented upwards (g = 9.81
) until the particle intersects the altitude defined byvent.alt
.
It is possible to create a default particle with the command:
P = LagTrack
Details of particles requirements can be displayed in Matlab with the command:
help LagTrack_particle
The trajectory of particles is computed with the function get_trajectory
, where part
is a particle previously defined:
get_trajectory(part)
It is possible to run several particles in one command by grouping the into a cell array, in which case they are run in parallel using the Parallel Computing Toolbox (if available):
get_trajectory({part1, part2, partn})
Upon run completion, each particle is saved as a .mat
file in project/runName/particleName.mat
. Three fields are appended to the original structure:
run_check
: Status of the run1
if completed normally0
if the particle landed outside of the domain or did not hit the ground before the end of the atmospheric dataset
timestamp
: Time of impact with the groundtraj
: Structure containing the particle's properties at each time step
Field | Value |
---|---|
x , y , z , t |
x and y offsets from release point, altitude and time of each iteration |
lat , lon |
Latitude and longitude |
dis , disP |
True and projected distance (m) |
bear |
Bearing |
xi , yi , zi , ti |
x, y, z and time indices relative to the atmospheric data |
xd , yd |
x and y indices relative to the DEM |
u , v , w |
Velocity components of the particle |
uf , vf , wf |
Velocity components of the wind |
Particles can be visualised using the functions map_part
and plot_part
. These functions open GUIs and take no input arguments.
LagTrack has been initially developed using Matlab 2014b and has been tested to run on all versions up to 2018b.
Function | Description | Credit |
---|---|---|
readhgt |
Downloads SRTM data | François Beauducel |
ll2utm , utm2ll |
Latitude/longitude to and from UTM coordinates | François Beauducel |
GUI Layout toolbox |
GUI tools | David Sampson |
lat_lon_proportions |
Constrains map proportions | Jonathan Sullivan |
Java is used in some fancy components of the GUI, but it is known to cause issues with some OS/Matlab configurations. Commenting lines 198-202 of codes/functions/GUI_util/check_var.m
can sometime solve problems:
if typ == 0
jEdit.Border = javax.swing.border.LineBorder(java.awt.Color(1,0,0),1,false);
else
jEdit.Border = javax.swing.border.LineBorder(java.awt.Color(.65,.65,.65),1,false);
end
The expected type of error is:
Error in check_var>change_frame (line 201)
jEdit.Border = javax.swing.border.LineBorder(java.awt.Color(.65,.65,.65),1,false);
Error in check_var (line 10)
if isempty(tmp); change_frame(jEdit,src,0,err); part.run_name = -9999; else; change_frame(jEdit,src,1,' '); part.run_name =
tmp; end
Error while evaluating UIControl Callback.
- Implement various drag models
- Make inclusion of vertical velocity smoother
Download cdo - for instance from homebrew:
brew tap moffat/sciencebits
brew install cdo
Merge using mergetime
(assuming that files were split per year):
cdo -b 64 mergetime *.nc out.nc
Spatial subset based on bounding box. Note that there should be no space after commas.
cdo sellonlatbox,99.9,100.1,14.9,15.1 in.nc out.nc