melodies_monet.util.sat_l2_swath_utility_tempo
Python utility for TEMPO use.
Functions
|
Apply the scattering weights and air mass factors according to Cooper et. |
Apply the scattering weights and air mass factors according to Cooper et. |
|
|
Apply the scattering weights and air mass factors according to Cooper et. |
Apply the scattering weights and air mass factors according to Cooper et. |
|
|
Grids object in sat-space to modgrid. |
|
Grids object in sat-space to modgrid. |
Calculate layer altitude above ground |
|
|
Calculates dz_m from altitude AGL (in m). |
|
Adds latitude and longitude bounds inplace. |
|
Calculates the partial column of a species from its concentration. |
|
Interpolates model vertical layers to TEMPO vertical layers |
|
Discards inplace granules from obsobj that do not match modobj's domain, or granules that are all NaN. |
Reads in paired gridded tempo and model data |
|
|
Read in paired swath data |
|
Does the complete process of regridding and applying scattering weights. |
|
Saves each swath individually |
|
Selects data containing the same scan or day. |
|
Makes modobj latitude and longitude C_contiguous, which speeds up regridding. |
|
Interpolate model to satellite swath/swaths |
- melodies_monet.util.sat_l2_swath_utility_tempo.apply_weights_mod2tempo_hcho(obsobj, modobj, species='HCHO')
Apply the scattering weights and air mass factors according to Cooper et. al, 2020, doi: https://doi.org/10.5194/acp-20-7231-2020
- Parameters:
obsobj (
xr.Dataset) – TEMPO data, including pressure and scattering weightsmodobj (
xr.Dataset) – Model data, already interpolated to TEMPO grid
- Returns:
xr.DataArray– A xr.DataArray containing the NO2 model data after applying the air mass factors and scattering weights
- melodies_monet.util.sat_l2_swath_utility_tempo.apply_weights_mod2tempo_hcho_hydrostatic(obsobj, modobj, species='HCHO')
Apply the scattering weights and air mass factors according to Cooper et. al, 2020, doi: https://doi.org/10.5194/acp-20-7231-2020, assuming the hydrostatic equation. It does not require temperature nor geometric layer thickness.
- Parameters:
obsobj (
xr.Dataset) – TEMPO data, including pressure and scattering weightsmodobj (
xr.Dataset) – Model data, already interpolated to TEMPO grid
- Returns:
xr.DataArray– A xr.DataArray containing the NO2 model data after applying the air mass factors and scattering weights
- melodies_monet.util.sat_l2_swath_utility_tempo.apply_weights_mod2tempo_no2(obsobj, modobj, species='NO2', column_type='tropospheric')
Apply the scattering weights and air mass factors according to Cooper et. al, 2020, doi: https://doi.org/10.5194/acp-20-7231-2020
- Parameters:
obsobj (
xr.Dataset) – TEMPO data, including pressure and scattering weightsmodobj (
xr.Dataset) – Model data, already interpolated to TEMPO gridcolumn_type (
str) – Whether the “tropospheric” or “total” column should be used for the calculation
- Returns:
xr.DataArray– A xr.DataArray containing the NO2 model data after applying the air mass factors and scattering weights
- melodies_monet.util.sat_l2_swath_utility_tempo.apply_weights_mod2tempo_no2_hydrostatic(obsobj, modobj, species='NO2')
Apply the scattering weights and air mass factors according to Cooper et. al, 2020, doi: https://doi.org/10.5194/acp-20-7231-2020, assuming the hydrostatic equation. It does not require temperature nor geometric layer thickness.
- Parameters:
obsobj (
xr.Dataset) – TEMPO data, including pressure and scattering weightsmodobj (
xr.Dataset) – Model data, already interpolated to TEMPO grid
- Returns:
xr.DataArray– A xr.DataArray containing the NO2 model data after applying the air mass factors and scattering weights
- melodies_monet.util.sat_l2_swath_utility_tempo.back_to_modgrid(paireddict, modobj, keys_to_merge='all', add_time=True, to_netcdf=False, path='Regridded_object_XYZ.nc', method='bilinear', grid_path=None)
Grids object in sat-space to modgrid. Designed to grid back to modgrid after applying the scattering weights and air mass factors. It is designed for a single scan.
- Parameters:
paireddict (
collections.OrderedDict[str,xr.Dataset]) – An OrderedDict with time_reference strings as keys.modobj (
xr.Dataset) – A modobj including the modgrid.keys_to_merge (
str | list[str]) – If ‘all’, all keys are assumed to be part of the same scan and merged. Else, only the keys provided are merged.add_time (
bool) – If True, add reference time as a coordinate for the scan. Can be useful to concatenate later if multiple scans are required.to_netcdf (
bool) – If True, save a netcdf with the paired datapath (
str) – The base name to save the files if to_netcdf is True. XX will be replaced with the scan number and the reference time. If to_netcdf is False, this will be ignored.method (
str) – Method of regridding used by xESMFgrid_path (
str) – If None, defaults to the model grid. Otherwise, the grid in path is used. If the method is conservative, lat_b and lon_b are required.
- Returns:
xr.Dataset– Dataset with obj2grid regridded to modobj.
- melodies_monet.util.sat_l2_swath_utility_tempo.back_to_modgrid_multiscan(paireddict, modobj, to_netcdf=False, path='Regridded_object_XYZ.nc', method='bilinear', grid_path=None)
Grids object in sat-space to modgrid. Designed to grid back to modgrid after applying the scattering weights and air mass factors. It is designed for multiple scans, and uses back_to_modgrid under the hood. Generally, back_to_modgrid should only be used if you can ensure that you are reading only one scan at a time.
- Parameters:
paireddict (
collections.OrderedDict[str,xr.Dataset]) – An OrderedDict with time_reference strings as keys.modobj (
xr.Dataset) – A modobj including the modgrid.to_netcdf (
bool) – If True, save a netcdf with the paired datapath (
str) – The base name to save the files if to_netcdf is True. XX will be replaced with the first and list times. If to_netcdf is False, this will be ignored.method (
str) – Method of regridding used by xESMF
- Returns:
xr.Dataset– Dataset with obj2grid regridded to modobj.
- melodies_monet.util.sat_l2_swath_utility_tempo.calc_altitude_from_thickness(dz_m)
Calculate layer altitude above ground
- Parameters:
data (
xr.DataArray) – DataArray containing dz_m- Returns:
Model altitude in satellite space
- melodies_monet.util.sat_l2_swath_utility_tempo.calc_dz_m_from_altitude(altitude)
Calculates dz_m from altitude AGL (in m).
- Parameters:
altitude (
xr.DataArray) – DataArray containing the layer interface altitude AGL at the interface.- Returns:
xr.DataArray– DataArray containing the layer thickness (dz_m) in m.
- melodies_monet.util.sat_l2_swath_utility_tempo.calc_grid_corners(ds, lat='latitude', lon='longitude')
Adds latitude and longitude bounds inplace. If the grid is rectilinear, it should be quite precise. If it is curvilinear, is a rough estimate.
- Parameters:
ds (
xr.Dataset) – Dataset to which the latitude and longitude will be added.lat (
str) – name of the lat variable.lon (
str) – name of the lon variable.
- Returns:
None
- melodies_monet.util.sat_l2_swath_utility_tempo.calc_partialcolumn(modobj, var='NO2')
Calculates the partial column of a species from its concentration.
- Parameters:
modobj (
xr.Dataset) – Model datavar (
str) – variable to calculate the partial column from
- Returns:
xr.DataArray– DataArray containing the partial column of the species.
- melodies_monet.util.sat_l2_swath_utility_tempo.interp_vertical_mod2swath(obsobj, modobj, variables='NO2_col')
Interpolates model vertical layers to TEMPO vertical layers
- Parameters:
modobj (
xr.Dataset) – Model data (as provided by MONETIO)obsobj (
xr.Dataset) – TEMPO data (as provided by MONETIO). Must include pressure.variables (
str | list[str]) – Variables to interpolate.
- Returns:
xr.Dataset– Model data (interpolated to TEMPO vertical layers
- melodies_monet.util.sat_l2_swath_utility_tempo.is_nonpairable(obsobj, k, modobj)
Discards inplace granules from obsobj that do not match modobj’s domain, or granules that are all NaN. If the domain is small, it can considerably speed up the regridding process.
- Parameters:
obsobj (
dict[str,xr.Dataset]) – tempo datamodobj (
xr.Dataset) – model data
- Returns:
collections.OrderedDict[str,xr.Dataset]
- melodies_monet.util.sat_l2_swath_utility_tempo.read_paired_gridded_tempo_model(path)
Reads in paired gridded tempo and model data
- Parameters:
path (
strorglobobject)- Returns:
xr.Dataset– combined dataset with paired tempo and gridded data.
- melodies_monet.util.sat_l2_swath_utility_tempo.read_paired_swath(path)
Read in paired swath data
- Parameters:
path (
strorglobobject)- Returns:
collections.OrderedDict[str,xr.Dataset]– OrderedDict with datasets containing every swath
- melodies_monet.util.sat_l2_swath_utility_tempo.regrid_and_apply_weights(obsobj, modobj, pair=True, verbose=True, method='conservative', weights=None, species=['NO2'], tempo_sp='NO2')
Does the complete process of regridding and applying scattering weights.
- Parameters:
obsobj (
xr.Dataset | collections.OrderedDict) – TEMPO observationsmodobj (
xr.Dataset) – Model outputpair (
boolean) – If True, returns paired data.verbose (
boolean) – If True, let’s the user know when each timestamp is being regridded. Only has an effect if the input is an OrderedDictmethod (
str) – Choose regridding method. Can be “conservative”, “conservative_normed”, “bilinear” or “patch”. Check xesmf documentation for details.weights (
None | str) – If present, a weightfile (as in “weights”) is applieddiscard_useless (
boolean) – If True, satellite granules that don’t match the model domain are not used.tempo_sp (
str) – NO2 for the NO2 product, HCHO for the HCHO product
- Returns:
xr.Dataset | collections.OrderedDict– Model with regridded data. If obsobj is of type collections.OrderedDict, an OrderedDict is returned.
- melodies_monet.util.sat_l2_swath_utility_tempo.save_paired_swath(moddict, path='Paired_swath_XYZ.nc')
Saves each swath individually
- Parameters:
moddict (
collections.OrderedDict[str,xr.Dataset]) – Ordered dict containing all of the paired model and swath.path (
str) – Path to save the swath. If XYZ is present, it will be replaced by the date, number of scan and number of granule.
- Returns:
None
- melodies_monet.util.sat_l2_swath_utility_tempo.select_by_keys(data_names, period='per_scan')
Selects data containing the same scan or day. It does so by file name, so it is important that the standard naming is not altered.
- Parameters:
data_names (
list[str]) – list containing the names of the files to select from.selection_criteria (
str) – str with the selection criteria. If “all”, the function does nothing. If “per_scan”, it will return a list of lists[str], with each inner list containing one complete scan. If “per_day”, it will return a list of lists[str], with each inner list containing one complete day.
- Returns:
list[str] | list[list[str]]– A sorted list of strings if “all” is provided, a list[list[str]] if a different criteria is provided.
- melodies_monet.util.sat_l2_swath_utility_tempo.speedup_regridding(dset, variables='all')
Makes modobj latitude and longitude C_contiguous, which speeds up regridding. It makes the changes inplace
- Parameters:
dset (
xr.Dataset) – Dataset containing latitude and longitude- Returns:
None
- melodies_monet.util.sat_l2_swath_utility_tempo.tempo_interp_mod2swath(obsobj, modobj, method='conservative', weights=None)
Interpolate model to satellite swath/swaths
- Parameters:
obsobj (
xr.Dataset) – satellite with swath data.modobj (
xr.Dataset) – model data (with no2 col calculated)method (
str) – Choose regridding method. Can be “conservative”, “conservative_normed”, “bilinear” or “patch”. Check xesmf documentation for details.weights (
str) – Path to the weightfile. If present, the weights won’t be calculated again.
- Returns:
xr.Dataset– Regridded model data at swath or swaths. If type is xr.Dataset, a single swath is returned. If type is collections.OrderedDict, it returns an OrderedDict in which each time represents the reference time of the swath.