bakaano.utils

Shared spatial utilities for preprocessing and raster alignment.

Role: Provide common geospatial helpers (clip, reproject, align, etc.).

class bakaano.utils.Utils(working_dir, study_area)[source]

Bases: object

align_rasters(input_ras, israster=True)[source]

Reproject/align rasters or xarray grids to the DEM reference grid.

Parameters:
  • input_ras – Raster path (if israster=True) or xarray/DataArray.

  • israster (bool) – Whether input_ras is a file path.

Returns:

Reprojected data aligned to the DEM grid.

Return type:

xarray.DataArray

clip(raster_path, dst_crs='EPSG:4326', out_path=None, save_output=False, crop_type=False)[source]

Clips the source raster (src_path) using the extent of the clip raster (clip_path) and saves the clipped data to a new file (dst_path).

Parameters:
  • raster_path (str) – Path to the raster file.

  • dst_crs (str) – Target CRS for clipping.

  • out_path (str, optional) – Output path for the clipped raster.

  • save_output (bool) – Whether to write the clipped raster to disk.

  • crop_type (bool) – If True, crop strictly to shape; else to bounds.

Returns:

Clipped raster array (bands, y, x).

Return type:

np.ndarray

concat_nc(clim_dir, dataset_str)[source]

Concatenate NetCDF files and clip to the study area.

Parameters:
  • clim_dir (pathlib.Path) – Directory containing NetCDF files.

  • dataset_str (str) – Glob pattern to match files.

Returns:

Concatenated and clipped dataset.

Return type:

xarray.Dataset

get_bbox(dst_crs)[source]

Compute and store the study area bounding box.

Parameters:

dst_crs (str) – Target CRS (e.g., "EPSG:4326").

process_existing_file(file_path)[source]

Check whether a file already exists.

Parameters:

file_path (str) – File path to check.

Returns:

True if file exists, else False.

Return type:

bool

reproject_raster(input_ras, out_ras)[source]

Reproject a raster to EPSG:4326.

Parameters:
  • input_ras (str) – Path to input raster.

  • out_ras (str) – Path to output raster.

save_to_scratch(output_file_path, array_to_save)[source]

Save an array as a GeoTIFF aligned to the DEM profile.

Parameters:
  • output_file_path (str) – Destination GeoTIFF path.

  • array_to_save (np.ndarray) – 2D array to write.