hypergas.plume_utils module
Some utils used for creating plume mask and gas emission rates.
- class hypergas.plume_utils.CustomControl(html, position='bottomleft')[source]
Bases:
MacroElementPut any HTML on the map as a Leaflet Control.
Adopted from https://github.com/python-visualization/folium/pull/1662.
- hypergas.plume_utils.a_priori_mask_data(ds, gas, lon_target, lat_target, pick_plume_name, wind_source, only_plume=True, az_max=30, dist_max=180, filename=None)[source]
Read a priori plume masks and connect them by conditions.
- Parameters:
ds (
Dataset) – L2 dataset.gas (str) – The gas field to be masked.
lon_target (float) – The longitude of plume source.
lat_target (float) – The latitude of plume source.
pick_plume_name (str) – The plume name (plume0, plume1, ….).
wind_source (str) – “ERA5” or “GEOS-FP”.
az_max (float) – Maximum of azimuth of minimum rotated rectangle. (Default: 30).
dist_max (float) – Maximum of dilation distance (meter).
filename (str) – The L2 HTML filename.
- Returns:
- hypergas.plume_utils.azimuth_mrr(mrr)[source]
Azimuth of plume’s minimum_rotated_rectangle.
- hypergas.plume_utils.cm_mask_data(ds, gas, lon_target, lat_target, data_crop_length=2500, limit_crop_length=1000, limit_percentile=90)[source]
Create plume mask using Carbon Mapper’s method.
- hypergas.plume_utils.crop_to_valid_region(da, y_target, x_target, data_crop_length, pixel_res)[source]
Crop a DataArray around a target location to ensure a square result, centered on the target, and adjusted to fit within bounds if necessary.
- hypergas.plume_utils.get_index_nearest(lons, lats, lon_target, lat_target)[source]
Get the pixel index closest to the target.
- Parameters:
lons (
numpy.ndarray) – 2D longitudes of pixels.lats (
numpy.ndarray) – 2D latitudes of pixels.lon_target (float) – The longitude of target.
lat_target (float) – The latitude of target.
- Returns:
y_nearest (int) – The nearest y index.
x_nearest (int) – The nearest x index.
- hypergas.plume_utils.get_wind_azimuth(u, v)[source]
Calculate the wind azimuth angle based on the horizontal wind components.
The function computes the azimuth (direction) of the wind vector from its u (east-west) and v (north-south) components. The azimuth is measured in radians and degrees, following meteorological convention.
- Parameters:
- Returns:
azim_rad (float) – Wind azimuth in radians, measured clockwise from the north.
azim (float) – Wind azimuth in degrees, measured clockwise from the north.
- hypergas.plume_utils.plot_mask(filename, ds, gas, mask, lon_target, lat_target, pick_plume_name, only_plume=True)[source]
Plot masked data and export to L3 HTML file.
- Parameters:
filename (str) – The L2 HTML file name.
ds (
Dataset) – The dataset includes the gas field and RGB data.gas (str) – The gas name to be plotted.
mask (
numpy.ndarray) – The plume boolean mask.lon_target (float) – The longitude of target.
lat_target (float) – The latitude of target.
pick_plume_name (str) – Which plume to be plotted (e.g., “plume0”, “plume1”, …).
- Returns:
plume_html_filename (str) – The plume html filename.
- hypergas.plume_utils.plot_wind(m, wdir, wspd, arrow_img='./imgs/arrow.png')[source]
Plot the wind arrow png by rotate the north arrow.
- hypergas.plume_utils.select_connect_masks(masks, y_target, x_target, az_max=30, dist_max=180)[source]
Select connected masks by dilation and limit the minimum rectangle angle difference
- Parameters:
- Returns:
Connected plume mask (
DataArray.)
- hypergas.plume_utils.target_inside_mask(ds, gas_mask_varname, y_target, x_target, lon_target, lat_target)[source]
Move the target if it is not inside the mask.
- Parameters:
- Returns:
y_target (int)
x_target (int) – If the input target index is not included in the mask, it will be updated using the mask pixel closest to the target.