A301 modules

sat_lib module

a301_extras.sat_lib.get_affine(sat_da: DataArray) Affine[source]

Creates an affine transform given a raster xarray.DataArray with x and y dimensions and coordinates

Parameters:

sat_da (satellite raster with x and y dimensions)

Returns:

affine_transform

Return type:

a affine transform with pixel dimensions and the ul corner

a301_extras.sat_lib.get_goes(timestamp: Timestamp, satellite: str | None = 'goes16', product: str | None = 'ABI-L2-MCMIP', domain: str | None = 'C', download: bool | None = True, save_dir: Path | None = None) str[source]

get a goes image guse goes_nearesttime

Parameters:
  • timestamp (pandas timestamp for image time: format pd.Timestamp('2024-12-13 22:50:35.447906'))

  • satelite (one of 'goes16', 'goes18', 'goes19' (defaults to goes16))

  • product (noaa product string from AWS list (defaults to ABI-L2-MCMIP))

  • domain (image domain one of "F" (full), "C" (conus), "M" (mesoscale))

  • download (True to save file, False to list path (defaults to True))

  • save_dir (optional directory to save image (defaults to ~/data)

Returns:

the_path

Return type:

path to netcdf file written in the save_dir folder

a301_extras.sat_lib.get_rowcol(affine_transform: ~affine.Affine, x_coords: ~numpy.array, y_coords: ~numpy.array) -> (<class 'int'>, <class 'int'>)[source]
a301_extras.sat_lib.make_bool_mask(da_fmask: DataArray) ndarray[Any, dtype[uint8]][source]

‘ turn a Landsat fmask into a boolean 1/0 array where cloud-free land pixels are 1 and all other pixels are 0 For use by skimage.exposure.equalize_hist

Parameters:
  • da_fmask (the fmask DataArray)

  • Returns (bool_mask with the same shape)

a301_extras.sat_lib.make_dataset(scene_dict: dict) Dataset[source]

given a dictionary with landsat bands stored as rioxarray, keyed by the band name, return an rioxarray dataset containing all the bands plus metadata

Parameters:

scene_dict (dictionary with keys like 'B03')

Returns:

ds_allbands

Return type:

xarray dataset with all bands from the dictionary stored as variables

a301_extras.sat_lib.make_false_color(the_ds: Dataset, band_names: list[str]) DataArray[source]

given a landsat dataset created with at least an fmask and 3 bands, return a histogram-equalized false color image with rgb mapped to the bands in the order they appear in the list band_names

example usage:

landsat_654 = make_false_color(the_ds,[‘B06’,’B05’,’B04’])

Parameters:
  • the_ds – created by make_dataset – must contain at least 3 bands and Fmask

  • band_names – list of strings with the names of the bands to be mapped to red, green and blue

Returns:

false_color

Return type:

rioxarray with shape [3,nrows,ncols] that can be converted to png

a301_extras.sat_lib.make_new_rioxarray(rawdata: ndarray, coords: dict, dims: tuple, crs: CRS, transform: Affine, attrs: dict | None = None, missing: float | None = None, name: str | None = 'name_here') DataArray[source]

create a new rioxarray from an ndarray plus components

Parameters:
  • rawdata (numpy array)

  • crs (pyproj crs for scene)

  • coords (xarray coordinate dict)

  • dims (x and y dimension names from coorcds)

  • transform (scene affine transform)

  • attrs (optional attribute dictionary)

  • missing (optional missing value)

  • name (optional variable name, defaults to "name_here")

Returns:

rio_da

Return type:

a new rioxarray

a301_extras.sat_lib.mask_image(image_da: DataArray, fmask_da: DataArray, mask_value: uint8) DataArray[source]

given an image, a bit mask, and a mask value, return the modified image with all masked values set to np.nan

Parameters:
  • image_da (a rioxarray data array with a single band image)

  • fmask_da (landsat fmask with the same bounding box)

  • mask_value (bits to mask, like 0b00100011)

Returns:

  • masked_da (a copy of image_da array)

  • with masked values set to np.nan

thermo_utils module

a301_extras.thermo_utils.calcDensHeight(df)[source]

Calculate the density scale height H_rho

Parameters:
  • df (pd.DataFrame)

  • columns (df) –

    T: vector (float)

    temperature (K)

    p: vector (float) of len(T)

    pressure (pa)

    z: vector (float) of len(T

    height (m)

Returns:

Hbar – density scale height (m)

Return type:

vector (float) of len(T)

a301_extras.thermo_utils.calcScaleHeight(df)[source]

Calculate the pressure scale height H_p

Parameters:
  • df (pd.DataFrame)

  • columns

    T: vector (float)

    temperature (K)

    p: vector (float) of len(T)

    pressure (pa)

    z: vector (float) of len(T

    height (m)

Returns:

Hbar – pressure scale height (m)

Return type:

vector (float) of len(T)

plot_utils module

a301_extras.plot_utils.make_pal(ax=None, vmin=None, vmax=None, palette='viridis')[source]

return a dictionary containing a palette and a Normalize object

Parameters:
  • vmin (minimum colorbar value (optional, defaults to minimum data value))

  • vmax (maximum colorbar value (optional, defaults to maximum data value))

  • palette (string (optional, defaults to "viridis"))

Returns:

out_dict – dictionary with key:values cmap:colormap, norm:Normalize

Return type:

dict

a301_extras.plot_utils.rowcol2latlon(tiffile, row, col)[source]

return the latitude and longitude of a row and column in a geotif

Parameters:
  • tiffile (Path object) – path to a clipped tiffile

  • row (float) – row of the pixel

  • col (float) – column of the pixel

Returns:

(lon, lat) – longitude (deg east) and latitude (deg north) on a WGS84 datum

Return type:

(float, float)