weather_data
Weather data module implementing functionality for working with binary weather files (.bin.json).
DataFrameInfo
The object containing info about dataframe columns and content. Used to pass dataframe info between methods working with weather dataframes.
Source code in emodpy_malaria/weather/weather_data.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
__eq__(other)
Equality operator for DataFrameInfo objects.
Source code in emodpy_malaria/weather/weather_data.py
__init__(node_column=None, step_column=None, value_column=None, only_unique_series=False)
Initializes dataframe info object. If no info is provided the defaults are used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_column
|
str
|
(Optional) Node column name. The default is "nodes". |
None
|
step_column
|
str
|
(Optional) Step column name. |
None
|
value_column
|
str
|
(Optional) Value column name. |
None
|
only_unique_series
|
bool
|
(Optional) Flag indicating weather only distinct weather time series are needed. |
False
|
Source code in emodpy_malaria/weather/weather_data.py
__str__()
detect_columns(df, column_candidates=None)
classmethod
Auto-detect required column names (nodes, time-steps and weather time series) for the DataFrameInfo object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The dataframe containing nodes, time-steps and weather time series. |
required |
column_candidates
|
Dict[str, List[str]]
|
(Optional) Dictionary of candidate column names to be used instead of defaults. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrameInfo
|
DataFrameInfo object with detected column names. |
Source code in emodpy_malaria/weather/weather_data.py
WeatherData
Functionality for working with binary weather files (.bin.json).
Source code in emodpy_malaria/weather/weather_data.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
data
property
Raw data, reshaped in one row per node weather time series.
metadata
property
Metadata property, exposing weather metadata object.
__eq__(other)
Equality operator for WeatherData objects.
__init__(data, metadata=None)
Instantiate a weather object from data numpy array and a weather metadata object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Numpy array of unique weather time series, in the order they appear in a .bin file. Shape can either be a single dimension array, or a 2d array having series stored as rows. This means that the number of rows corresponds to the number of unique series and number of columns corresponds to a series length (e.g. 365). |
required |
metadata
|
WeatherMetadata
|
(Optional) WeatherMetadata object containing metadata from .bin.json. |
None
|
Source code in emodpy_malaria/weather/weather_data.py
from_csv(file_path, info=None, attributes=None)
classmethod
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:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
The csv file path from which weather data is loaded (expected columns: node, step, value). |
required |
info
|
DataFrameInfo
|
(Optional) Dataframe info object describing dataframe columns and content. |
None
|
attributes
|
WeatherAttributes
|
(Optional) Attributes used to initiate weather metadata. If not provided, defaults are used. |
None
|
Returns:
| Type | Description |
|---|---|
WeatherData
|
WeatherData object. |
Source code in emodpy_malaria/weather/weather_data.py
from_dataframe(df, info=None, attributes=None)
classmethod
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:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DateFrame
|
Dataframe containing nodes and weather time series (expected columns: node, step, value). |
required |
info
|
DataFrameInfo
|
(Optional) Dataframe info object describing dataframe columns and content. |
None
|
attributes
|
WeatherAttributes
|
(Optional) Attributes used to initiate weather metadata. If not provided, defaults are used. |
None
|
Returns:
| Type | Description |
|---|---|
WeatherData
|
WeatherData object. |
Source code in emodpy_malaria/weather/weather_data.py
from_dict(node_series, same_nodes=None, attributes=None)
classmethod
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:
| Name | Type | Description | Default |
|---|---|---|---|
node_series
|
Dict[int, Union[ndarray[float32], List[float]]]
|
Dictionary with node ids as keys and weather time series as values (don't have to be unique). |
required |
same_nodes
|
Dict[int, List[int]]
|
(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. |
None
|
attributes
|
WeatherAttributes
|
(Optional) Attributes used to initiate weather metadata. If not provided, defaults are used. |
None
|
Returns:
| Type | Description |
|---|---|
WeatherData
|
WeatherData object. |
Source code in emodpy_malaria/weather/weather_data.py
from_file(file_path)
classmethod
Create WeatherData object by reading weather data from binary (.bin) and metadata (.bin.json) files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
The weather binary (.bin) file path. The metadata file path is constructed by appending ".json". |
required |
Returns:
| Type | Description |
|---|---|
WeatherData
|
WeatherData object. |
Source code in emodpy_malaria/weather/weather_data.py
to_csv(file_path, info=None)
Creates a csv file and stores node ids, time steps and weather node weather time series as separate columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
The csv file path into which weather data will be stored. |
required |
info
|
DataFrameInfo
|
(Optional) Dataframe info object describing dataframe columns and content. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataframe created as an intermediate object used to save data to a csv file. |
Source code in emodpy_malaria/weather/weather_data.py
to_dataframe(info=None)
Creates a dataframe containing node ids, time steps and weather time series as separate columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
DataFrameInfo
|
(Optional) Dataframe info object describing dataframe columns and content. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataframe containing node ids and weather time series. |
Source code in emodpy_malaria/weather/weather_data.py
to_dict(only_unique_series=False, copy_data=True)
Create a node-to-series dictionary from the current object. This method can be used to edit weather data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only_unique_series
|
bool
|
(Optional) A flag controlling whether the output dictionary will contain series for all nodes (if set to true) or only unique series. |
False
|
copy_data
|
bool
|
(Optional) Flag indicating whether to copy data numpy array to prevent unintentional changes. |
True
|
Returns: A dictionary with node ids and keys and node weather time series as values.
Source code in emodpy_malaria/weather/weather_data.py
to_file(file_path)
Create weather binary (.bin) and metadata (.json) files, containing weather data and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
The weather binary (.bin) file path. The metadata file path is constructed by adding ".json". |
required |
Returns:
| Type | Description |
|---|---|
NoReturn
|
None. |
Source code in emodpy_malaria/weather/weather_data.py
validate()
Validate data and metadata relationship.