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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
institution
property
writable
¶
institution: str
Get or set the institution attribute of the dataset.
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
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
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
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 |
|
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
397 398 399 400 401 402 403 404 |
|
get_dim_names
¶
Gets the name of all dimensions in the data set.
Source code in src/efts_io/wrapper.py
425 426 427 |
|
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
431 432 433 434 435 436 437 438 439 440 441 |
|
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
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 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
get_ensemble_size
¶
get_ensemble_size() -> int
Return the length of the ensemble size dimension.
Source code in src/efts_io/wrapper.py
511 512 513 |
|
get_lead_time_count
¶
get_lead_time_count() -> int
Length of the lead time dimension.
Source code in src/efts_io/wrapper.py
515 516 517 |
|
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
519 520 521 |
|
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
527 528 529 530 531 532 533 534 535 536 537 |
|
get_station_count
¶
get_station_count() -> int
Return the number of stations in the data set.
Source code in src/efts_io/wrapper.py
539 540 541 |
|
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
543 544 545 546 547 |
|
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
549 550 551 552 |
|
put_lead_time_values
¶
Set the values of the lead time dimension.
Source code in src/efts_io/wrapper.py
523 524 525 |
|
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
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 |
|
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
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
to_netcdf
¶
Write the data set to a netCDF file.
Source code in src/efts_io/wrapper.py
282 283 284 285 286 287 288 289 |
|
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
314 315 316 317 318 319 320 321 322 323 |
|
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
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 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 |
|
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
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 |
|
nan_full
¶
Create a full array of NaNs with the given shape.
Source code in src/efts_io/wrapper.py
704 705 706 707 708 |
|
open_efts
¶
open_efts(
ncfile: Any, writein: bool = False
) -> EftsDataSet
Open an EFTS NetCDF file.
Source code in src/efts_io/wrapper.py
693 694 695 696 697 698 699 700 701 |
|
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
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 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 |
|