emod_api.weather.weather module

emod-api Weather module - Weather, Metadata, and WeatherNode objects along with IDREF and CLIMATE_UPDATE constants.

class emod_api.weather.weather.WeatherNode(node_id: int, data)[source]

Bases: object

Represents information for a single node: ID and timeseries data.

property id: int

Node ID

property data

Time series data for this node.

class emod_api.weather.weather.Metadata(node_ids: List[int], datavalue_count: int, author: str | None = None, created: datetime | None = None, frequency: str | None = None, provenance: str | None = None, reference: str | None = None)[source]

Bases: object

Metadata:

  • [DateCreated]

  • [Author]

  • [OriginalDataYears]

  • [StartDayOfYear]

  • [DataProvenance]

  • IdReference

  • NodeCount

  • DatavalueCount

  • UpdateResolution

  • NodeOffsets

property author: str

Author of this file.

property creation_date: datetime

Creation date of this file.

property datavalue_count: int

Number of data values in each timeseries, should be > 0.

property id_reference: str

‘Schema’ for node IDs. Commonly Legacy, Gridded world grump2.5arcmin, and Gridded world grump30arcsec.

Legacy usually indicates a 0 or 1 based scheme with increasing ID numbers.

Gridded world grump2.5arcmin and Gridded world grump30arcsec encode latitude and longitude values in the node ID with the following formula:

latitude  = (((nodeid - 1) & 0xFFFF) * resolution) -  90
longitude = ((nodeid >> 16)          * resolution) - 180
# nodeid = 90967271 @ 2.5 arcmin resolution
# longitude = -122.1667, latitude = 47.5833
property node_count: int
property node_ids: List[int]
property provenance: str
property update_resolution: str
property nodes: Dict[int, int]

WeatherNodes offsets keyed by node id.

write_file(filename: str) None[source]
classmethod from_file(filename: str)[source]

Read weather metadata file. Metadata’ and ‘NodeOffsets’ keys required. DatavalueCount’, ‘UpdateResolution’, and ‘IdReference’ required in ‘Metadata’.

class emod_api.weather.weather.Weather(filename: str | None = None, node_ids: List[int] | None = None, datavalue_count: int | None = None, author: str | None = None, created: datetime | None = None, frequency: str | None = None, provenance: str | None = None, reference: str | None = None, data: array | None = None)[source]

Bases: object

property data: array

Raw data as numpy array[node index, time step].

property metadata: Metadata
property author: str
property creation_date: datetime
property datavalue_count: int

>= 1

property id_reference: str
property node_count: int

>= 1

property node_ids: List[int]
property provenance: str
property update_resolution: str
property nodes: Dict[int, WeatherNode]

WeatherNodes indexed by node id.

write_file(filename: str) None[source]

Writes data to filename and metadata to filename.json.

classmethod from_csv(filename: str, var_column: str = 'airtemp', id_column: str = 'node_id', step_column: str = 'step', author: str | None = None, provenance: str | None = None)[source]

Create weather from CSV file with specified variable column, node id column, and time step column.

Note

  • Column order in the CSV file is not significant, but columns names must match what is passed to this function.

  • Because a CSV might hold air temperature (may be negative and well outside 0-1 values), relative humidity (must _not_ be negative, must be in the interval [0-1]), or rainfall (must _not_ be negative, likely > 1), this function does not validate incoming data.