weather
Weather file creation, reading, and conversion for EMOD simulations.
Main features:
- Create EMOD weather files from CSV, DataFrame, or dictionary data.
- Read existing EMOD weather files into Python objects.
- Convert between EMOD binary weather format and tabular formats.
- Configure EMOD climate model settings.
DataFrameInfo
Column name configuration for weather DataFrames.
Source code in emodpy_malaria/weather/weather_data.py
detect_columns(df, column_candidates=None)
classmethod
Auto-detect node, step, and value column names from a DataFrame.
Source code in emodpy_malaria/weather/weather_data.py
WeatherAttributes
Metadata attributes for EMOD weather files.
Manages the key/value pairs stored in the "Metadata" section of a
.bin.json file. Provides sensible defaults when no explicit values
are given.
Source code in emodpy_malaria/weather/weather_metadata.py
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 | |
WeatherData
Binary weather data and its metadata for a single weather variable.
Source code in emodpy_malaria/weather/weather_data.py
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 | |
__init__(data, metadata=None)
Create from a NumPy array of unique time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
float32 array. Shape |
required |
metadata
|
WeatherMetadata
|
If omitted, auto-generated with node IDs 1..N. |
None
|
Source code in emodpy_malaria/weather/weather_data.py
from_base_weather(base, attributes=None)
classmethod
Create from an Weather instance.
Source code in emodpy_malaria/weather/weather_data.py
from_csv(file_path, info=None, attributes=None)
classmethod
Load from a CSV with node, step, and value columns.
Source code in emodpy_malaria/weather/weather_data.py
from_dataframe(df, info=None, attributes=None)
classmethod
Create from a pandas DataFrame with node, step, and value columns.
Source code in emodpy_malaria/weather/weather_data.py
from_dict(node_series, same_nodes=None, attributes=None)
classmethod
Create from a {node_id: time_series} dictionary.
Identifies unique series and builds a compact binary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_series
|
dict[int, Union[ndarray, list[float]]]
|
Node ID to time series mapping. |
required |
same_nodes
|
dict[int, list[int]]
|
Optional mapping of nodes in node_series to additional node IDs that share the same data. |
None
|
attributes
|
WeatherAttributes
|
Optional metadata attributes. |
None
|
Source code in emodpy_malaria/weather/weather_data.py
from_file(file_path)
classmethod
Read from a .bin / .bin.json file pair.
Source code in emodpy_malaria/weather/weather_data.py
to_base_weather()
Create an Weather instance.
Useful for interoperability with code that expects the emod-api
Weather object. Note: shared offsets are expanded — each node
gets its own copy of the data in the returned object.
Source code in emodpy_malaria/weather/weather_data.py
to_csv(file_path, info=None)
Write to CSV and return the DataFrame.
Source code in emodpy_malaria/weather/weather_data.py
to_dataframe(info=None)
Convert to a DataFrame with node, step, and value columns.
Source code in emodpy_malaria/weather/weather_data.py
to_dict(only_unique_series=False, copy_data=True)
Export as {node_id: series} dictionary.
Source code in emodpy_malaria/weather/weather_data.py
to_file(file_path)
Write .bin and .bin.json files.
Source code in emodpy_malaria/weather/weather_data.py
WeatherMetadata
Bases: WeatherAttributes
Weather metadata with node offsets and count fields.
Wraps Metadata for core node-offset
computation and basic .bin.json parsing, extending it with rich
metadata attributes and shared-offset (deduplication) support.
Source code in emodpy_malaria/weather/weather_metadata.py
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 334 335 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 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
from_file(file_path)
classmethod
Read a .bin.json file.
Uses Metadata.from_file() for core parsing (node offsets, datavalue count), then augments with any additional attributes present in the file.
Source code in emodpy_malaria/weather/weather_metadata.py
to_base_metadata()
Create an Metadata instance.
Useful for interoperability with code that expects the emod-api
Metadata object. Note: shared offsets are expanded — each
node gets its own sequential offset in the returned object.
Source code in emodpy_malaria/weather/weather_metadata.py
to_file(file_path)
Write the rich .bin.json metadata file.
Produces a superset of the format written by
Metadata.write_file(), including
additional attributes like Tool, WeatherSchemaVersion,
Resolution, etc.
Source code in emodpy_malaria/weather/weather_metadata.py
WeatherSet
A set of weather files for all (or a subset of) EMOD weather variables.
Source code in emodpy_malaria/weather/weather_set.py
20 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 334 335 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 | |
from_csv(file_path, node_column=None, step_column=None, weather_columns=None, attributes=None, notes=None)
classmethod
Create from a CSV file containing all weather variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Union[str, Path]
|
Path to the CSV file. |
required |
node_column
|
str
|
Column name for node IDs. |
None
|
step_column
|
str
|
Column name for time steps. |
None
|
weather_columns
|
dict[WeatherVariable, str]
|
|
None
|
attributes
|
WeatherAttributes
|
Optional metadata attributes. |
None
|
notes
|
str
|
Free-text note stored in the weather file metadata. Use this to record where the original data came from and how it was processed. |
None
|
Source code in emodpy_malaria/weather/weather_set.py
from_dataframe(df, node_column=None, step_column=None, weather_columns=None, attributes=None, notes=None)
classmethod
Create from a DataFrame containing all weather variables as columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with node, step, and weather variable columns. |
required |
node_column
|
str
|
Column name for node IDs. |
None
|
step_column
|
str
|
Column name for time steps. |
None
|
weather_columns
|
dict[WeatherVariable, str]
|
|
None
|
attributes
|
WeatherAttributes
|
Optional metadata attributes. |
None
|
notes
|
str
|
Free-text note stored in the weather file metadata. Use this to record where the original data came from and how it was processed. |
None
|
Source code in emodpy_malaria/weather/weather_set.py
from_files(dir_path, prefix='', file_names=None)
classmethod
Load from existing .bin / .bin.json file pairs in a directory.
Source code in emodpy_malaria/weather/weather_set.py
make_file_paths(dir_path=None, prefix='', suffix='{}.bin', weather_variables=None, weather_names=None)
classmethod
Generate conventional EMOD weather file paths.
Source code in emodpy_malaria/weather/weather_set.py
select_weather_files(dir_path, prefix='*', suffix='*{}*.bin', weather_variables=None, weather_names=None)
classmethod
Find weather files in a directory by name pattern.
Source code in emodpy_malaria/weather/weather_set.py
to_csv(file_path, node_column=None, step_column=None, weather_columns=None)
Export all variables to a single CSV.
Source code in emodpy_malaria/weather/weather_set.py
to_dataframe(node_column=None, step_column=None, weather_columns=None)
Export all variables to a single DataFrame.
Source code in emodpy_malaria/weather/weather_set.py
to_files(dir_path, file_names=None)
Write all .bin / .bin.json file pairs to a directory.
Source code in emodpy_malaria/weather/weather_set.py
WeatherVariable
Bases: Enum
Weather variables required by EMOD.
Each variable corresponds to a pair of binary (.bin) and metadata
(.bin.json) files that EMOD reads when Climate_Model is set to
CLIMATE_BY_DATA.
Source code in emodpy_malaria/weather/weather_variable.py
list(exclude=None)
classmethod
Return all weather variables, optionally excluding some.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
'WeatherVariable | list[WeatherVariable] | None'
|
Variable(s) to exclude from the list. |
None
|
Source code in emodpy_malaria/weather/weather_variable.py
validate_types(value_dict, value_types=None)
classmethod
Validate that dict keys are WeatherVariable and values match the given type(s).
Source code in emodpy_malaria/weather/weather_variable.py
csv_to_weather(csv_data, node_column='nodes', step_column='steps', weather_columns=None, attributes=None, weather_dir=None, weather_file_names=None)
Convert a CSV file or DataFrame to EMOD weather files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_data
|
Union[str, Path, DataFrame]
|
Path to CSV file or a pandas DataFrame containing weather data with node, step, and weather variable columns. |
required |
node_column
|
str
|
Column name for node IDs. |
'nodes'
|
step_column
|
str
|
Column name for time step indices. |
'steps'
|
weather_columns
|
dict[WeatherVariable, str]
|
|
None
|
attributes
|
WeatherAttributes
|
Optional metadata attributes for the output files. |
None
|
weather_dir
|
Union[str, Path]
|
If specified, write |
None
|
weather_file_names
|
dict[WeatherVariable, str]
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
WeatherSet
|
WeatherSet containing the parsed weather data. |
Source code in emodpy_malaria/weather/__init__.py
set_climate_by_data(config, *, air_temperature_filename, rainfall_filename, relative_humidity_filename, update_resolution=ClimateUpdateResolution.CLIMATE_UPDATE_DAY, air_temperature_offset=0.0, air_temperature_variance=0.0, rainfall_scale_factor=1.0, enable_rainfall_stochasticity=False, relative_humidity_scale_factor=1.0, relative_humidity_variance=0.0)
Configure CLIMATE_BY_DATA mode to read weather from binary files.
EMOD reads four .bin / .bin.json file pairs for air temperature,
land temperature, rainfall, and relative humidity.
Enable_Climate_Stochasticity is set automatically when any
variance is non-zero or rainfall stochasticity is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
object
|
The EMOD config object ( |
required |
air_temperature_filename
|
str
|
Path to air temperature |
required |
rainfall_filename
|
str
|
Path to rainfall |
required |
relative_humidity_filename
|
str
|
Path to relative humidity |
required |
update_resolution
|
Union[ClimateUpdateResolution, str]
|
Climate update frequency. |
CLIMATE_UPDATE_DAY
|
air_temperature_offset
|
float
|
Additive offset applied to all air temperature values (Celsius). |
0.0
|
air_temperature_variance
|
float
|
Standard deviation (Celsius) for Gaussian noise on daily air temperature. If set to 0, relative humidity does not vary from the data. Set this to > 0 to enable stochasticity. |
0.0
|
rainfall_scale_factor
|
float
|
Multiplicative factor applied to all rainfall values. |
1.0
|
enable_rainfall_stochasticity
|
bool
|
When True, draw daily rainfall from an exponential distribution with mean equal to the data value. |
False
|
relative_humidity_scale_factor
|
float
|
Multiplicative factor applied to all relative humidity values. |
1.0
|
relative_humidity_variance
|
float
|
Standard deviation (fraction) for Gaussian noise on daily relative humidity. If set to 0, relative humidity does not vary from the data. Set this to > 0 to enable stochasticity. |
0.0
|
Source code in emodpy_malaria/weather/weather_config.py
set_climate_constant(config, *, air_temperature=27.0, rainfall=10.0, relative_humidity=0.75, update_resolution=ClimateUpdateResolution.CLIMATE_UPDATE_DAY, air_temperature_variance=0.0, relative_humidity_variance=0.0, enable_rainfall_stochasticity=False)
Configure CLIMATE_CONSTANT mode with user-specified base values.
EMOD uses these constant values (plus optional stochastic noise) for every node on every time step, ignoring any weather files.
Base_Land_Temperature is set equal to air_temperature — EMOD
requires it but does not use it for malaria simulations.
Enable_Climate_Stochasticity is set automatically when any
variance is non-zero or rainfall stochasticity is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
object
|
The EMOD config object ( |
required |
air_temperature
|
float
|
Base air temperature in Celsius. |
27.0
|
rainfall
|
float
|
Base rainfall in mm/update_resolution. |
10.0
|
relative_humidity
|
float
|
Base relative humidity (0.0 -- 1.0). |
0.75
|
update_resolution
|
Union[ClimateUpdateResolution, str]
|
Climate update frequency. |
CLIMATE_UPDATE_DAY
|
air_temperature_variance
|
float
|
Standard deviation (Celsius) for Gaussian noise on daily air temperature. |
0.0
|
relative_humidity_variance
|
float
|
Standard deviation (fraction) for Gaussian noise on daily relative humidity. |
0.0
|
enable_rainfall_stochasticity
|
bool
|
Draw daily rainfall from an exponential distribution with mean equal to the base value. |
False
|
Source code in emodpy_malaria/weather/weather_config.py
weather_to_csv(weather_dir, weather_file_prefix='', weather_file_names=None, csv_file=None, node_column='nodes', step_column='steps', weather_columns=None)
Convert EMOD weather files to a CSV file or DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weather_dir
|
Union[str, Path]
|
Directory containing |
required |
weather_file_prefix
|
str
|
File name prefix for auto-detection (e.g.
|
''
|
weather_file_names
|
dict[WeatherVariable, str]
|
Explicit |
None
|
csv_file
|
Union[str, Path]
|
If specified, write the output DataFrame to this path. |
None
|
node_column
|
str
|
Column name for node IDs in the output. |
'nodes'
|
step_column
|
str
|
Column name for time step indices in the output. |
'steps'
|
weather_columns
|
dict[WeatherVariable, str]
|
|
None
|
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, WeatherAttributes]
|
Tuple of (DataFrame, WeatherAttributes). |