wrapper
¶
A thin wrapper around xarray for reading and writing Ensemble Forecast Time Series (EFTS) data sets.
EftsDataSet
¶
Convenience class for access to a Ensemble Forecast Time Series in netCDF file.
Source code in src/efts_io/wrapper.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
institution
property
writable
¶
institution: str
Get or set the institution attribute of the dataset.
stf2_int_datatype
property
writable
¶
stf2_int_datatype: str
The type of integer to save to in the STF 2.x netcdf convention: 'i4' or 'i8'.
stf_convention_version
property
writable
¶
stf_convention_version: float
Get or set the STF_convention_version attribute of the dataset.
stf_nc_spec
property
writable
¶
stf_nc_spec: str
Get or set the STF_nc_spec attribute of the dataset.
append_history
¶
Append a new entry to the history
attribute with a timestamp.
message: The message to append. timestamp: If not provided, the current UTC time is used.
Source code in src/efts_io/wrapper.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
create_data_variables
¶
Create data variables in the data set.
var_defs_dict["variable_1"].keys() dict_keys(['name', 'longname', 'units', 'dim_type', 'missval', 'precision', 'attributes'])
Source code in src/efts_io/wrapper.py
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 |
|
get_all_series
¶
Return a multivariate time series, where each column is the series for one of the identifiers.
Source code in src/efts_io/wrapper.py
417 418 419 420 421 422 423 424 |
|
get_dim_names
¶
Gets the name of all dimensions in the data set.
Source code in src/efts_io/wrapper.py
445 446 447 |
|
get_ensemble_for_stations
¶
get_ensemble_for_stations(
variable_name: str = "rain_sim",
identifier: Optional[str] = None,
dimension_id: str = ENS_MEMBER_DIMNAME,
start_time: Timestamp = None,
lead_time_count: Optional[int] = None,
) -> DataArray
Not yet implemented.
Source code in src/efts_io/wrapper.py
451 452 453 454 455 456 457 458 459 460 461 |
|
get_ensemble_forecasts
¶
get_ensemble_forecasts(
variable_name: str = "rain_sim",
identifier: Optional[str] = None,
dimension_id: Optional[str] = None,
start_time: Optional[Timestamp] = None,
lead_time_count: Optional[int] = None,
) -> DataArray
Gets an ensemble forecast for a variable.
Source code in src/efts_io/wrapper.py
463 464 465 466 467 468 469 470 471 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 |
|
get_ensemble_size
¶
get_ensemble_size() -> int
Return the length of the ensemble size dimension.
Source code in src/efts_io/wrapper.py
531 532 533 |
|
get_lead_time_count
¶
get_lead_time_count() -> int
Length of the lead time dimension.
Source code in src/efts_io/wrapper.py
535 536 537 |
|
get_lead_time_values
¶
get_lead_time_values() -> ndarray
Return the values of the lead time dimension.
Source code in src/efts_io/wrapper.py
539 540 541 |
|
get_single_series
¶
get_single_series(
variable_name: str = "rain_obs",
identifier: Optional[str] = None,
dimension_id: Optional[str] = None,
) -> DataArray
Return a single point time series for a station identifier.
Source code in src/efts_io/wrapper.py
547 548 549 550 551 552 553 554 555 556 557 |
|
get_station_count
¶
get_station_count() -> int
Return the number of stations in the data set.
Source code in src/efts_io/wrapper.py
559 560 561 |
|
get_stations_varname
¶
get_stations_varname() -> str
Return the name of the variable that has the station identifiers.
Source code in src/efts_io/wrapper.py
563 564 565 566 567 |
|
get_time_dim
¶
get_time_dim() -> ndarray
Return the time dimension variable as a vector of date-time stamps.
Source code in src/efts_io/wrapper.py
569 570 571 572 |
|
put_lead_time_values
¶
Set the values of the lead time dimension.
Source code in src/efts_io/wrapper.py
543 544 545 |
|
save_to_stf2
¶
save_to_stf2(
path: str,
variable_name: Optional[str] = None,
var_type: StfVariable = StfVariable.STREAMFLOW,
data_type: StfDataType = StfDataType.OBSERVED,
ens: bool = False,
timestep: str = "days",
data_qual: Optional[DataArray] = None,
) -> None
Save to file.
Source code in src/efts_io/wrapper.py
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 |
|
set_mandatory_global_attributes
¶
set_mandatory_global_attributes(
title: str = "not provided",
institution: str = "not provided",
catchment: str = "not provided",
source: str = "not provided",
comment: str = "not provided",
history: str = "not provided",
append_history: bool = False,
) -> None
Sets mandatory global attributes for an EFTS dataset.
Source code in src/efts_io/wrapper.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
to_netcdf
¶
Write the data set to a netCDF file.
Source code in src/efts_io/wrapper.py
287 288 289 290 291 292 293 294 |
|
writeable_to_stf2
¶
writeable_to_stf2() -> bool
Check if the dataset can be written to a netCDF file compliant with STF 2.0 specification.
This method checks if the underlying xarray dataset or dataarray has the required dimensions and global attributes as specified by the STF 2.0 convention.
Returns:
-
bool
(bool
) –True if the dataset can be written to a STF 2.0 compliant netCDF file, False otherwise.
Source code in src/efts_io/wrapper.py
319 320 321 322 323 324 325 326 327 328 329 |
|
byte_array_to_string
¶
byte_array_to_string(x: ndarray) -> str
Convert a byte array to a string.
Source code in src/efts_io/wrapper.py
57 58 59 60 |
|
byte_stations_to_str
¶
byte_stations_to_str(byte_names: ndarray) -> ndarray
Convert byte array of station names to string array.
Source code in src/efts_io/wrapper.py
63 64 65 |
|
byte_to_string
¶
Convert a byte to a string.
Source code in src/efts_io/wrapper.py
46 47 48 49 50 51 52 53 54 |
|
create_efts
¶
create_efts(
fname: str,
time_dim_info: Dict,
data_var_definitions: List[Dict[str, Any]],
stations_ids: List[int],
station_names: Optional[List[str]] = None,
nc_attributes: Optional[Dict[str, str]] = None,
optional_vars: Optional[dict[str, Any]] = None,
lead_length: int = 48,
ensemble_length: int = 50,
lead_time_tstep: str = "hours",
) -> EftsDataSet
Create a new EFTS dataset.
Source code in src/efts_io/wrapper.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
load_from_stf2_file
¶
Load data from an STF 2.0 netcdf file to an xarray representation.
Parameters:
-
file_path
(str
) –file path
-
time_zone_timestamps
(bool
) –should we try to recognise the time zone and include it in each xarray time stamp?
Returns:
-
_type_
(Dataset
) –xarray Dataset
Source code in src/efts_io/wrapper.py
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 |
|
nan_full
¶
Create a full array of NaNs with the given shape.
Source code in src/efts_io/wrapper.py
724 725 726 727 728 |
|
open_efts
¶
open_efts(
ncfile: Any, writein: bool = False
) -> EftsDataSet
Open an EFTS NetCDF file.
Source code in src/efts_io/wrapper.py
713 714 715 716 717 718 719 720 721 |
|
xr_efts
¶
xr_efts(
issue_times: Iterable[ConvertibleToTimestamp],
station_ids: Iterable[str],
lead_times: Optional[Iterable[int]] = None,
lead_time_tstep: str = "hours",
ensemble_size: int = 1,
station_names: Optional[Iterable[str]] = None,
latitudes: Optional[Iterable[float]] = None,
longitudes: Optional[Iterable[float]] = None,
areas: Optional[Iterable[float]] = None,
nc_attributes: Optional[Dict[str, str]] = None,
) -> Dataset
Create an xarray Dataset for EFTS data.
Source code in src/efts_io/wrapper.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 |
|