Tools and Utilities

Tools and Utilities wrappers used by NSAPH Gridmet package

get_atmos_url(year: int, variable='PM25') str[source]

Constructs URL to download data from the Atmospheric Composition Analysis Group given a year and a band

Parameters
  • year – year

  • variable – Gridmet band (variable)

Returns

URL for download

get_nkn_url(variable: str, year: int) str[source]

Constructs URL to download data from University of Idaho (UI) Northwest Knowledge Network given a year and a band

Parameters
  • year – year

  • variable – Gridmet band (variable)

Returns

URL for download

find_shape_file(shapes_dir: str, year: int, geography_type: str, shape_type: str) str[source]

Finds shapefile for a given type of geographies for the closest available year

Parameters
  • shapes_dir – Directory containing shape files organized as ${year}/${geo_type}/{point|polygon}

  • year – year

  • geography_type – Geography type, e.g. zip, county, etc.

  • shape_type – Shape type: polygon, point, etc.

Returns

a shape file for a given year if it exists or for the latest year before the given

get_variable(dataset: Dataset, variable: str)[source]

Extracts a variable (column) name by a variable “standard name” from NCDF4 dataset

Standard name is a name of a band as described here: https://gee.stac.cloud/WUtw2spmec7AM9rk6xMXUtStkMtbviDtHK?t=bands

A column name is a name of the column in the dataset

Parameters
  • dataset – an NCDF4 dataset

  • variable – “standard name” of a variable, e.g. “tmmx”

Returns

get_days(dataset: Dataset) List[source]

Extracts a table fo days from NCDF4 dataset

Parameters

dataset – NCDF4 dataset

Returns

List, containing days

get_affine_transform(nc_file: str, factor: int = 1)[source]

Returns affine transformation for a NCDF4 dataset.

Uses rasterio package: https://rasterio.readthedocs.io/en/latest/index.html

The Affine object is a named tuple with elements a, b, c, d, e, f corresponding to the elements in the matrix equation below, in which a pixel’s image coordinates are x, y and its world coordinates are x’, y’

See more: https://rasterio.readthedocs.io/en/latest/topics/georeferencing.html

Parameters
  • factor – factor used for disaggregation, None or 0 means no disaggregation

  • nc_file – path to file, containing dataset

Returns

Instance of affine transformation

disaggregate(layer, factor: int)[source]

Implementation of R disaggregate function with method == ‘’.

See details: https://www.rdocumentation.org/packages/raster/versions/3.4-5/topics/disaggregate

or, original source code:

https://github.com/r-forge/raster/blob/master/pkg/raster/R/disaggregate.R

Parameters
  • layer

  • factor

Returns