lair.air.hrrr#

HRRR winds at a point.

Documentation: https://mesowest.utah.edu/html/hrrr/zarr_documentation/html/python_data_loading.html

Module Attributes

PROJECTION

HRRR Projection

Functions

create_s3_chunk_url(zarr_id, chunk_id[, prefix])

Create the s3 chunk url for a zarr id.

create_s3_group_url(zarr_id[, prefix])

Create the s3 group url for a zarr id.

create_s3_subgroup_url(zarr_id[, prefix])

Create the s3 subgroup url for a zarr id.

decompress_chunk(zarr_id, compressed_data)

Decompress s3 chunk data.

generate_zarr_ids(times, level_type, ...)

Generate ZarrId instance for multiple times and variables

get_nearest_point(longitude, latitude, ...)

Get the nearest point to a given latitude and longitude.

get_value(s3, zarr_id, chunk_id, nearest_point)

Get an array of values from am s3 zarr chunk.

retrieve_object(s3, s3_url)

Retrieve object from s3.

Classes

Winds(lat, lon, times)

Class to download HRRR winds at a point.

ZarrId(run_hour, level_type, var_level, ...)

Class to store information about a HRRR zarr file.

lair.air.hrrr.PROJECTION: CRS = <Projected CRS: +proj=lcc +ellps=WGS84 +a=6371229 +b=6371229 +lon_ ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Lambert Conic Conformal (2SP) Datum: unknown - Ellipsoid: unknown - Prime Meridian: Greenwich #

HRRR Projection

class lair.air.hrrr.ZarrId(run_hour: datetime, level_type: Literal['sfc', 'prs'], var_level: str, var_name: str, model_type: Literal['anl', 'fcst'])[source]#

Class to store information about a HRRR zarr file.

Attributes

run_hour

(dt.datetime) run hour of the model

level_type

(‘sfc’ | ‘prs’) vertical level

var_level

(str) variable level

var_name

(str) variable name

model_type

(‘anl’ | ‘fcst’) analysis or forecast

Methods

format_chunk_id(chunk_id)

Format chunk_id for zarr url.

format_chunk_id(chunk_id)[source]#

Format chunk_id for zarr url.

Parameters:
chunk_idint

chunk_id

Returns:
str

formatted chunk_id

__init__(run_hour: datetime, level_type: Literal['sfc', 'prs'], var_level: str, var_name: str, model_type: Literal['anl', 'fcst']) None#
class lair.air.hrrr.Winds(lat: float, lon: float, times: list[datetime])[source]#

Class to download HRRR winds at a point.

Attributes

lat

(float) latitude of point

lon

(float) longitude of point

times

(list[dt.datetime]) list of times to download

nearest_point

(xr.Dataset) nearest point to lat, lon

chunk_id

(float) chunk id of nearest point

zarr_ids

(dict[str, list[ZarrId]]) dictionary of zarr ids with var as key

data

(pd.DataFrame) wind data

__init__(lat: float, lon: float, times: list[datetime]) None#
lair.air.hrrr.create_s3_group_url(zarr_id: ZarrId, prefix: bool = True) str[source]#

Create the s3 group url for a zarr id.

  • Start of the zarr array data format

  • Includes metadata such as the grid

Parameters:
zarr_idZarrId

ZarrId instance

prefixbool

include prefix

Returns:
str

s3 group url

lair.air.hrrr.create_s3_subgroup_url(zarr_id: ZarrId, prefix: bool = True) str[source]#

Create the s3 subgroup url for a zarr id.

  • Where the actual data variable is stored

  • While subgroups are part of the zarr spec, there’s not necessarily a good reason for the data in this case to have this extra level of nesting

Parameters:
zarr_idZarrId

ZarrId instance

prefixbool

include prefix

Returns:
str

s3 subgroup url

lair.air.hrrr.create_s3_chunk_url(zarr_id: ZarrId, chunk_id, prefix: bool = False) str[source]#

Create the s3 chunk url for a zarr id.

  • Contains just the data for the chunk (no metadata)

  • Current APIs (zarr, xarray) don’t support reading zarr data by chunks, so we have to write relatively low-level code to load data on this level

Parameters:
zarr_idZarrId

ZarrId instance

chunk_idint # TODO check this

chunk id

prefixbool

include prefix

Returns:
str

s3 chunk url

lair.air.hrrr.get_nearest_point(longitude: float, latitude: float, chunk_index: Dataset) Dataset[source]#

Get the nearest point to a given latitude and longitude.

Parameters:
longitudefloat

longitude of point

latitudefloat

latitude of point

chunk_indexxr.Dataset

chunk index dataset

Returns:
xr.Dataset

nearest point

lair.air.hrrr.retrieve_object(s3, s3_url: str)[source]#

Retrieve object from s3.

Parameters:
s3boto3.resource

s3 resource

s3_urlstr

s3 url

Returns:
bytes

compressed object data

lair.air.hrrr.generate_zarr_ids(times: list[datetime], level_type: str, variables: list[Tuple[str, str]], model_type: Literal['anl', 'fcst'])[source]#

Generate ZarrId instance for multiple times and variables

Parameters:
times[dt.datetime]

list of datetime objects with hour specified [UTC]

level_typestr

veritical level

variables[(str, str)]

list of tuples: (var_name, var_level)

model_typestr

‘anl’ | ‘fcst’

Returns:
ids[ZarrId]

dictionary of zarr ids with var as key

lair.air.hrrr.decompress_chunk(zarr_id: ZarrId, compressed_data: bytes)[source]#

Decompress s3 chunk data.

Parameters:
zarr_idZarrId

ZarrId instance

compressed_databytes

compressed data

Returns:
np.array

decompressed chunk

lair.air.hrrr.get_value(s3, zarr_id: ZarrId, chunk_id, nearest_point: Dataset)[source]#

Get an array of values from am s3 zarr chunk.

Parameters:
s3boto3.resource

s3 resource

zarr_idZarrId

ZarrId instance

chunk_idfloat

chunk id

nearest_pointxr.Dataset

nearest point

Returns:
np.array

array of values