deafrica_tools.methane_convention#
Functions
|
Convert Sentinel-5P TROPOMI methane XCH4 from ppb into methane mass products. |
|
Ensure input is an xarray.DataArray. |
|
Estimate methane emission rate using a simple Integrated Mass Enhancement approach. |
|
Calculate approximate area of each lat/lon grid cell in m². |
|
Plot Sentinel-5P methane conversion products using a flexible grid layout. |
|
Plot a smooth methane ppb density curve and mark the selected quantile. |
|
Rename latitude/longitude dimensions or coordinates to lat/lon. |
- deafrica_tools.methane_convention.convert_ch4(ch4_ppb, surface_pressure, area_m2=None, background=None, background_quantile=0, spatial_dims=('lat', 'lon'), clip_negative=True, valid_mask=None)#
Convert Sentinel-5P TROPOMI methane XCH4 from ppb into methane mass products.
- Outputs include:
background methane concentration in ppb
methane enhancement in ppb
methane column amount in mol/m²
methane mass per unit area in kg/m²
methane mass per unit area in g/m²
methane mass per unit area in tonnes/km²
methane mass per pixel in tonnes
total methane mass over the AOI in tonnes
total methane mass over the AOI in kg
mean methane mass per unit area
valid observation area
- Parameters:
ch4_ppb (xarray.DataArray) – Sentinel-5P methane XCH4 in ppb.
surface_pressure (xarray.DataArray) – Surface pressure in Pascals.
area_m2 (xarray.DataArray, optional) – Pixel area in m². If None, it will be calculated from lat/lon.
background ("quantile", None, float, int, or xarray.DataArray) –
Background methane option.
”quantile”: subtract spatial quantile background.
None: no background removed. Converts total methane column.
number: subtract fixed background in ppb.
DataArray: subtract custom background.
background_quantile (float) – Quantile used when background=”quantile”. Example: 0.05 means 5th percentile.
spatial_dims (tuple) – Spatial dimensions, usually (“lat”, “lon”).
clip_negative (bool) – If True, negative methane enhancement values are set to zero.
valid_mask (xarray.DataArray, optional) – Boolean mask where True means valid pixel. Use this for cloud mask, QA mask, or combined masks.
- Returns:
Methane mass conversion products.
- Return type:
xarray.Dataset
- deafrica_tools.methane_convention.ensure_dataarray(data, variable_name=None)#
Ensure input is an xarray.DataArray.
If a Dataset is provided, variable_name must be supplied.
- deafrica_tools.methane_convention.estimate_ch4_emission_rate(total_tonnes, wind_speed_m_s, plume_length_m)#
Estimate methane emission rate using a simple Integrated Mass Enhancement approach.
Q = wind speed × total plume mass / plume length
- Parameters:
total_tonnes (xarray.DataArray or float) – Total excess methane mass in tonnes.
wind_speed_m_s (float) – Effective wind speed in m/s.
plume_length_m (float) – Plume length in metres.
- Returns:
Emission rates in kg/s, kg/h, tonnes/h, tonnes/day, and kt/year.
- Return type:
xarray.Dataset
- deafrica_tools.methane_convention.gridcell_area_m2(lat, lon)#
Calculate approximate area of each lat/lon grid cell in m².
This version uses cell edges, which is more robust than using only np.gradient. Returns an xarray.DataArray with dims (‘lat’, ‘lon’).
- deafrica_tools.methane_convention.plot_data(ch4_mass, plot_vars=None, time_index=0, time_dim='time', cmap='RdYlGn_r', max_cols=3, figsize_per_plot=(6, 5), title='Sentinel-5P Methane Conversion Products')#
Plot Sentinel-5P methane conversion products using a flexible grid layout.
The number of rows and columns is automatically calculated from the number of variables in plot_vars.
- Parameters:
ch4_mass (xarray.Dataset) – Output dataset from the methane conversion function.
plot_vars (list, optional) – List of variables to plot.
time_index (int) – Time index to plot if the variables contain a time dimension.
time_dim (str) – Name of the time dimension.
cmap (str) – Matplotlib colour map.
max_cols (int) – Maximum number of columns in the plot layout.
figsize_per_plot (tuple) – Width and height for each subplot.
title (str) – Main figure title.
- Returns:
Matplotlib figure and axes.
- Return type:
fig, axes
- deafrica_tools.methane_convention.plot_density(ch4_ppb, quantile=0.05, time_dim='time', time_index=0, max_points=200000, bins=50, title='Methane ppb Density Plot and 5th Percentile Background')#
Plot a smooth methane ppb density curve and mark the selected quantile.
The vertical line shows the selected quantile value in ppb. The point shows where the quantile meets the density curve.
- Parameters:
ch4_ppb (xarray.DataArray) – Sentinel-5P methane XCH4 in ppb.
quantile (float) – Quantile to identify. Example: 0.05 means the 5th percentile.
time_dim (str) – Name of the time dimension.
time_index (int) – Timestep to plot if time dimension exists.
max_points (int) – Maximum number of valid points used for plotting.
bins (int) – Number of histogram bins.
title (str) – Plot title.
- Returns:
Quantile value in ppb.
- Return type:
float
- deafrica_tools.methane_convention.rename_latlon(ds)#
Rename latitude/longitude dimensions or coordinates to lat/lon.