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: MacroElement

Put 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:

  • mask (DataArray) – The Boolean mask of pixels.

  • lon_mask (DataArray) – Plume longitude.

  • lat_mask (DataArray) – Plume latitude.

  • lon_target (float) – Longitude of target.

  • lat_target (float) – Latitude of target.

  • plume_html_filename (str) – Exported plume html filename.

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.

Parameters:
  • data_crop_length (float) – The length (m) for cropping data.

  • limit_crop_length (float) – The length (m) for calculating the plume enhancement threshold.

  • limit_percentile (float) – The percentile (%) for the plume enhancement threshold.

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.

Parameters:
  • da (DataArray) – The to be cropped DataArray.

  • y_target (int) – The yindex of target.

  • x_target (int) – The xindex of target.

  • data_crop_length (float) – The crop radius (m).

  • pixel_res (float) – The pixel resolution (m).

Returns:

The cropping index (ymin, ymax, xmin, xmax.)

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:
  • u (float) – Zonal wind component (positive toward the east).

  • v (float) – Meridional wind component (positive toward the north).

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:
  • masks (DataArray) – 2D a priori mask from L2 data.

  • y_target (float) – yindex of source target.

  • x_target (float) – xindex of source target.

  • az_max (float) – maximum of azimuth of minimum rotated rectangle. (Default: 30).

  • dist_max (float) – maximum of dilation distance (meter).

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:
  • ds (Dataset) – The dataset includes the gas field and geolocations.

  • gas_mask_varname (str) – The mask name of gas.

  • y_target (int) – The y index of target.

  • x_target (int) – The x index of target.

  • lon_target (float) – The longitude of target.

  • lat_target (float) – The latitude of target.

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.