General Utilities
el_paso.utils
Attributes
Classes
el_paso.utils.Hashabledict
A dictionary subclass that is hashable.
This class enables a dictionary to be used in sets or as keys in other dictionaries by providing a custom hash implementation based on its contents.
Source code in el_paso/utils.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
Methods:
__hash__
__hash__
Computes a hash value for the dictionary.
The hash is computed based on the frozensets of the dictionary's keys
and values. This ensures that two Hashabledict instances with the same
key-value pairs will have the same hash, regardless of the order of
insertion.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The hash value of the dictionary. |
Source code in el_paso/utils.py
282 283 284 285 286 287 288 289 290 291 292 293 | |
Functions:
el_paso.utils.assert_n_dim
assert_n_dim
Asserts that a variable's data has a specific number of dimensions.
Raises a ValueError if the provided variable's data does not match the
expected number of dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
Variable
|
The variable instance to check. |
required |
n_dims
|
int
|
The expected number of dimensions. |
required |
name_in_file
|
str
|
The name of the variable, used in the error message. |
required |
Source code in el_paso/utils.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
el_paso.utils.datenum_to_datetime
datenum_to_datetime
Converts a MATLAB datenum value to a timezone-aware datetime object.
This function leverages pandas to convert the datenum (days since year 0) into a UTC-aware datetime object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datenum_val
|
float
|
The MATLAB datenum value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
The converted datetime object with UTC timezone. |
Source code in el_paso/utils.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
el_paso.utils.datetime_to_datenum
datetime_to_datenum
Converts a datetime object to a MATLAB datenum value.
This function calculates the datenum value, which represents the number of days since year 0, including a fractional component for the time of day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datetime_val
|
datetime
|
The datetime object to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The corresponding MATLAB datenum value. |
Source code in el_paso/utils.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
el_paso.utils.enforce_utc_timezone
enforce_utc_timezone
Ensures a datetime object has UTC timezone information.
If the provided datetime object is naive (lacks timezone info), it is assigned the UTC timezone. If it already has a timezone, it is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime object to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
The datetime object with |
Source code in el_paso/utils.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
el_paso.utils.extract_version
extract_version
Extracts the version string from a file name.
The function looks for a version string pattern _v* (e.g., '_v1.2.3' or '_v1_2-3')
located just before the file extension. It returns the base file name and a
parsed version object. If no version is found, it returns the original file name
and a default version '0'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str | Path
|
The name or path of the file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, Version]
|
tuple[str, version_pkg.Version]: A tuple containing:
- The base file name without the version string.
- The parsed version object ( |
Source code in el_paso/utils.py
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 | |
el_paso.utils.fill_str_template_with_time
fill_str_template_with_time
Fills a string template with time-based placeholders.
This function replaces common time-based placeholders in a string with
the corresponding values from a datetime object. The placeholders
are case-sensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_str
|
str
|
The input string containing placeholders like 'yyyymmdd', 'YYYYMMDD', 'YYYY', 'MM', and 'DD'. |
required |
time
|
datetime
|
The datetime object to use for filling the template. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string with all placeholders replaced by their time values. |
Source code in el_paso/utils.py
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 | |
el_paso.utils.get_file_by_version
get_file_by_version
Filters a list of file paths to find a specific version or the latest one.
If a specific version string (e.g., 'v1.2.3') is provided, the function returns
the file that matches exactly. If the version parameter is 'latest', it
returns the file with the highest version number among all provided file paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_paths
|
Iterable[T]
|
An iterable of file paths (as strings or |
required |
version
|
str
|
The specific version string to match (e.g., 'v1.2.3') or 'latest' to retrieve the most recent version. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
T | None: The file path that matches the criteria, or |
Source code in el_paso/utils.py
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 | |
el_paso.utils.load_cdf_data
load_cdf_data
Load all zVariables from an existing CDF file.
Source code in el_paso/utils.py
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 | |
el_paso.utils.load_h5_data
load_h5_data
Load all datasets and dataset attributes from an HDF5 file.
Source code in el_paso/utils.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
el_paso.utils.load_mat_data
load_mat_data
Load an existing MATLAB file.
Source code in el_paso/utils.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
el_paso.utils.load_netcdf_data
load_netcdf_data
Load all variables and variable metadata from a NetCDF file.
Source code in el_paso/utils.py
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 | |
el_paso.utils.make_dict_hashable
make_dict_hashable
Converts a standard dictionary into a hashable one.
If the input is None, it is returned as is. Otherwise, a new Hashabledict
instance is created and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dict_input
|
dict | None
|
The dictionary to convert. |
required |
Returns:
| Type | Description |
|---|---|
Hashabledict | None
|
Hashabledict | None: The new hashable dictionary, or |
Source code in el_paso/utils.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
el_paso.utils.normalize_file_format
normalize_file_format
Return a normalized file extension for the requested monthly format.
Source code in el_paso/utils.py
417 418 419 420 421 422 423 424 425 426 427 | |
el_paso.utils.show_process_bar_for_map_async
show_process_bar_for_map_async
Displays a progress bar for a multiprocessing.pool.MapResult object.
This function creates a tqdm progress bar that tracks the completion of
a parallel map operation. It polls the MapResult's internal state to
update the progress bar until the operation is complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_result
|
MapResult
|
The result object from |
required |
chunksize
|
int
|
The chunk size used in the |
required |
Source code in el_paso/utils.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
el_paso.utils.timed_function
timed_function
A decorator that logs the execution time of a function.
This decorator measures the time it takes for a decorated function to execute and logs the result to a logger at the INFO level. The log message can be prefixed with an optional function name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func_name
|
str | None
|
An optional name to use in the log message. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable[[Callable[P, R]], Callable[P, R]]
|
A decorator that wraps the target function with timing logic. |
Source code in el_paso/utils.py
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 | |
el_paso.utils.write_cdf_file
write_cdf_file
Write a CDF file, resolving standard variable paths and embedding metadata.
Source code in el_paso/utils.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
el_paso.utils.write_h5_file
write_h5_file
Write an HDF5 file with hierarchical groups from slash-delimited paths.
Source code in el_paso/utils.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
el_paso.utils.write_mat_file
write_mat_file
Write a MATLAB file, resolving standard variable paths and flattening hierarchy.
Data variables are stored under their flattened canonical names (/ → __).
Per-variable metadata is stored in a parallel metadata struct whose field
names mirror the data variable names, matching how HDF5 stores attrs per dataset.
Source code in el_paso/utils.py
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 465 466 467 468 469 | |
el_paso.utils.write_netcdf_file
write_netcdf_file
Create and write a NetCDF file from a data dictionary.
Source code in el_paso/utils.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |