emodpy_malaria.weather.weather_data module#
Weather data module implementing functionality for working with binary weather files (.bin.json).
- class emodpy_malaria.weather.weather_data.WeatherData(data: ndarray, metadata: WeatherMetadata | None = None)[source]#
Bases:
object
Functionality for working with binary weather files (.bin.json).
- property metadata: WeatherMetadata#
Metadata property, exposing weather metadata object.
- property data: ndarray#
Raw data, reshaped in one row per node weather time series.
- classmethod from_dict(node_series: Dict[int, ndarray[float32] | List[float]], same_nodes: Dict[int, List[int]] | None = None, attributes: WeatherAttributes | None = None) WeatherData [source]#
Creates a WeatherData object from a dictionary mapping nodes and node weather time series. The method identifies unique node weather time series and produces a corresponding node-offset dictionary.
- Parameters:
node_series – Dictionary with node ids as keys and weather time series as values (don’t have to be unique).
same_nodes – (Optional) Dictionary, mapping nodes from ‘node_series’ dictionary to additional nodes which series are the same. Keys are node ids, values are lists of node ids.
attributes – (Optional) Attributes used to initiate weather metadata. If not provided, defaults are used.
- Returns:
WeatherData object.
- to_dict(only_unique_series=False, copy_data: bool = True) Dict[int, ndarray[float32]] [source]#
Create a node-to-series dictionary from the current object. This method can be used to edit weather data.
- Parameters:
only_unique_series – (Optional) A flag controlling whether the output dictionary will contain series for all nodes (if set to true) or only unique series.
copy_data – (Optional) Flag indicating whether to copy data numpy array to prevent unintentional changes.
- Returns:
A dictionary with node ids and keys and node weather time series as values.
- classmethod from_csv(file_path: str | Path, info: DataFrameInfo | None = None, attributes: WeatherAttributes | None = None) WeatherData [source]#
Creates a WeatherData object from a csv file. Used for creating or editing weather files. The method identifies unique node weather time series and produces a corresponding node-offset dictionary.
- Parameters:
file_path – The csv file path from which weather data is loaded (expected columns: node, step, value).
info – (Optional) Dataframe info object describing dataframe columns and content.
attributes – (Optional) Attributes used to initiate weather metadata. If not provided, defaults are used.
- Returns:
WeatherData object.
- to_csv(file_path: str | Path, info: DataFrameInfo | None = None) DataFrame [source]#
Creates a csv file and stores node ids, time steps and weather node weather time series as separate columns.
- Parameters:
file_path – The csv file path into which weather data will be stored.
info – (Optional) Dataframe info object describing dataframe columns and content.
- Returns:
Dataframe created as an intermediate object used to save data to a csv file.
- classmethod from_dataframe(df: pd.DateFrame, info: DataFrameInfo = None, attributes: WeatherAttributes = None) WeatherData [source]#
Creates WeatherData object from the Pandas dataframe. The dataframe is expected to contain node ids, time steps and weather node weather time series as separate columns.
- Parameters:
df – Dataframe containing nodes and weather time series (expected columns: node, step, value).
info – (Optional) Dataframe info object describing dataframe columns and content.
attributes – (Optional) Attributes used to initiate weather metadata. If not provided, defaults are used.
- Returns:
WeatherData object.
- to_dataframe(info: DataFrameInfo | None = None) DataFrame [source]#
Creates a dataframe containing node ids, time steps and weather time series as separate columns.
- Parameters:
info – (Optional) Dataframe info object describing dataframe columns and content.
- Returns:
Dataframe containing node ids and weather time series.
- classmethod from_file(file_path: str | Path) WeatherData [source]#
Create WeatherData object by reading weather data from binary (.bin) and metadata (.bin.json) files.
- Parameters:
file_path – The weather binary (.bin) file path. The metadata file path is constructed by appending “.json”.
- Returns:
WeatherData object.
- class emodpy_malaria.weather.weather_data.DataFrameInfo(node_column: str | None = None, step_column: str | None = None, value_column: str | None = None, only_unique_series: bool = False)[source]#
Bases:
object
The object containing info about dataframe columns and content. Used to pass dataframe info between methods working with weather dataframes.
- property node_column#
- property step_column#
- property value_column#
- classmethod detect_columns(df, column_candidates: Dict[str, List[str]] | None = None) DataFrameInfo [source]#
Auto-detect required column names (nodes, time-steps and weather time series) for the DataFrameInfo object.
- Parameters:
df – The dataframe containing nodes, time-steps and weather time series.
column_candidates – (Optional) Dictionary of candidate column names to be used instead of defaults.
- Returns:
DataFrameInfo object with detected column names.