Source Receptor Matrix Tools
InMAPSourceReceptorMatrices.connect_to_isrm!
— Functionconnect_to_isrm!(; region="us-east-2", creds = nothing, url="s3://inmap-model/isrm_v1.2.1.zarr/")
Connects to AWS, opens the INMAP source receptor matrix with zopen
(from Zarr.jl)
InMAPSourceReceptorMatrices.run_sr
— Functionrun_sr(source_emis::DataFrame, [cell_variables]) -> receptor_emis::DataFrame
Runs the source receptor matrix for the given source emissions, where each row represents an emitter. Note that source_emis
must have the following columns:
latitude <: Number
- latitude of the sourcelongitude <: Number
- longitude of the sourcelayer_idx <: Integer
- layer index ∈ {1,2,3}, for effective emission heights at ground level (emissions between 0 and 57 m), low level (57–379 m), and high level (>379 m) respectively<emis_type> <: Number
- the average emissions rate, in μg / s, for emission type<emis_type>
∈{PM2_5, NOx, SO2, VOC, NH3}
. There can be between 1 and 5 of these columns.- (optional)
source_idx <: Int64
- which grid cell index corresponds to the source. If given,latitude
andlongitude
no longer used.
Returns the receptor_emis
table which contains columns for each of the PM types created by the source emissions, as well as columns for each of the variables in cell_variables
, and a column for geometry_longlat
, which contains the (lon, lat)
geometry of each grid cell.
InMAPSourceReceptorMatrices.SRM
— FunctionSRM(emis_type) -> srm::Array{Float32, 3}
Returns source receptor matrix retrieved from fs
, with emis_type
∈ ("PrimaryPM25", "SOA", "pNO3", "pSO4", "pNH4")
Note that these are huge (52411 x 52411 x 3) and will require ~60-70GB of RAM to hold onto. Index via (receptor, source, layer)
. Care should be taken if multiple stored in memory. May take 5-10 minutes to fetch from AWS.
To create a sparse SRM for only a select group of source locations, see make_sparse_srm
. (that will still call SRM
, but will call garbage collection before returning the sparse matrix)
InMAPSourceReceptorMatrices.SparseSRM
— FunctionSparseSRM(emis_type, source_idxs, [layer_idxs]; threshold=0.0)
Make a sparse source receptor matrix, indexable via (receptor, source, layer)
.
emis_type
- The emission type for which to make the sparse matrix, ∈ ("PrimaryPM25", "SOA", "pNO3", "pSO4", "pNH4")source_idxs
- A vector of source indexes for which to add the pollution effects to the matrixlayer_idxs
- A vector of layer_idxs for which tothreshold=0.0
- The threshold, in units (μg / m³) / (μg / s), above which to add the value to the sparse matrix. Adds every nonzero value by default.
SparseSRM(srm, source_idxs, [layer_idxs]; threshold=0.0)
Make a sparse source receptor matrix from an SRM (Array{Float32, 3}
).
emis_type
- The emission type for which to make the sparse matrix.source_idxs
- A vector of source indexes for which to add the pollution effects to the matrixlayer_idxs
- A vector of layer_idxs for which tothreshold=0.0
- The threshold, in units (μg / m³) / (μg / s), above which to add the value to the sparse matrix. Adds every nonzero value by default.
InMAPSourceReceptorMatrices.compute_receptor_emis
— Functioncompute_receptor_emis(srm, source_idx(s), layer_idx(s), val(s)) -> receptor_emis::Vector
Compute the emissions at each receptor from srm
for each source specified by source_idx
and layer_idx
, which correspond to val(s)
compute_receptor_emis(srm, source_emis::Matrix) -> receptor_emis::Vector
Compute the emissions at each receptor from srm
for source_emis
, a NSR x 3
matrix containing annual average emission rates at each grid cell and layer, in units of micrograms per second.
srm
can be any of the following types:
Cell Data
InMAPSourceReceptorMatrices.get_isrm_variable_summary
— Functionget_isrm_variable_summary() -> summary::DataFrame
Returns a summary of the variables in the source receptor matrix
InMAPSourceReceptorMatrices.get_isrm_cell_data
— Functionget_isrm_cell_data(vars::AbstractVector{<:AbstractString}; geometry=true) -> cell_data::DataFrame
To see list of available variables, see get_isrm_variable_summary
get_isrm_cell_data(var::AbstractString) -> v::Vector
Fetch the grid-cell data for the variable var
.
InMAPSourceReceptorMatrices.get_isrm_fs
— Functionget_isrm_fs() -> fs
Return the AWS file system.
Geometry
InMAPSourceReceptorMatrices.longlat2isrm
— Functionlonglat2isrm() -> trans
Returns a Proj.Transformation
for converting from (lon, lat) to the LCC coordinate system used by ISRM:
+proj=lcc +lat_1=33.000000 +lat_2=45.000000 +lat_0=40.000000 +lon_0=-97.000000 +x_0=0 +y_0=0 +a=6370997.000000 +b=6370997.000000 +to_meter=1.
InMAPSourceReceptorMatrices.isrm2longlat
— Functionisrm2longlat() -> trans
Returns a Proj.Transformation
for converting to (lon, lat) from the LCC coordinate system used by ISRM:
+proj=lcc +lat_1=33.000000 +lat_2=45.000000 +lat_0=40.000000 +lon_0=-97.000000 +x_0=0 +y_0=0 +a=6370997.000000 +b=6370997.000000 +to_meter=1.
InMAPSourceReceptorMatrices.get_isrm_cell_geom
— Functionget_isrm_cell_geom() -> geom::Vector{Box{2, Float64}}
InMAPSourceReceptorMatrices.get_isrm_cell_geom_longlat
— Functionget_isrm_cell_geom_longlat(geom::Vector{Box{2, Float64}}) -> geom::Vector{Quadrangle{2, Float64}}
Returns the cell geometry of the SRM in longlat form.
InMAPSourceReceptorMatrices.get_cell_idxs
— Functionget_cell_idxs(longlats, cell_geom::Vector; threshold = 1000) -> cell_idxs
get_cell_idxs(longs, lats, cell_geom::Vector; threshold = 1000) -> cell_idxs
Return the indices of the closest cells (in cell_geom
) for each of the longs and lats supplied. If there is no grid cell within threshold
meters from the point in cell_geom
, gives an index of 0. cell_geom
can either be the original geometry (represented as Box
es), or the longlat geometry (represented as Quadrangle
s).