99.. autosummary::
1010 :toctree: ../generated/
1111
12- postprocess_import
1312 check_input_frames
1413 prepare_interpolator
1514 memoize
2221
2322import numpy as np
2423
25- from pysteps .xarray_helpers import convert_input_to_xarray_dataset
26-
2724
2825def _add_extra_kwrds_to_docstrings (target_func , extra_kwargs_doc_text ):
2926 """
@@ -44,76 +41,6 @@ def _add_extra_kwrds_to_docstrings(target_func, extra_kwargs_doc_text):
4441 return target_func
4542
4643
47- def postprocess_import (fillna = np .nan , dtype = "double" ):
48- """
49- Postprocess the imported precipitation data.
50- Operations:
51- - Allow type casting (dtype keyword)
52- - Set invalid or missing data to predefined value (fillna keyword)
53- This decorator replaces the text "{extra_kwargs}" in the function's
54- docstring with the documentation of the keywords used in the postprocessing.
55- The additional docstrings are added as "Other Parameters" in the importer function.
56-
57- Parameters
58- ----------
59- dtype: str
60- Default data type for precipitation. Double precision by default.
61- fillna: float or np.nan
62- Default value used to represent the missing data ("No Coverage").
63- By default, np.nan is used.
64- If the importer returns a MaskedArray, all the masked values are set to the
65- fillna value. If a numpy array is returned, all the invalid values (nan and inf)
66- are set to the fillna value.
67-
68- """
69-
70- def _postprocess_import (importer ):
71- @wraps (importer )
72- def _import_with_postprocessing (* args , ** kwargs ):
73- precip , quality , metadata = importer (* args , ** kwargs )
74-
75- _dtype = kwargs .get ("dtype" , dtype )
76-
77- accepted_precisions = ["float32" , "float64" , "single" , "double" ]
78- if _dtype not in accepted_precisions :
79- raise ValueError (
80- "The selected precision does not correspond to a valid value."
81- "The accepted values are: " + str (accepted_precisions )
82- )
83-
84- if isinstance (precip , np .ma .MaskedArray ):
85- invalid_mask = np .ma .getmaskarray (precip )
86- precip .data [invalid_mask ] = fillna
87- else :
88- # If plain numpy arrays are used, the importers should indicate
89- # the invalid values with np.nan.
90- _fillna = kwargs .get ("fillna" , fillna )
91- if _fillna is not np .nan :
92- mask = ~ np .isfinite (precip )
93- precip [mask ] = _fillna
94-
95- return convert_input_to_xarray_dataset (
96- precip .astype (_dtype ), quality , metadata
97- )
98-
99- extra_kwargs_doc = """
100- Other Parameters
101- ----------------
102- dtype: str
103- Data-type to which the array is cast.
104- Valid values: "float32", "float64", "single", and "double".
105- fillna: float or np.nan
106- Value used to represent the missing data ("No Coverage").
107- By default, np.nan is used.
108- """
109-
110- _add_extra_kwrds_to_docstrings (_import_with_postprocessing , extra_kwargs_doc )
111-
112- return _import_with_postprocessing
113-
114- return _postprocess_import
115-
116-
11744def check_input_frames (
11845 minimum_input_frames = 2 , maximum_input_frames = np .inf , just_ndim = False
11946):
0 commit comments