Decodes a variable which may hold CF encoded information. This includes variables that have been masked and scaled, which hold CF style time variables (this is almost always the case if the dataset has been serialized) and which have strings encoded as character arrays. Pa
(
name: Hashable,
var: Variable,
concat_characters: bool = True,
mask_and_scale: bool = True,
decode_times: bool | CFDatetimeCoder = True,
decode_endianness: bool = True,
stack_char_dim: bool = True,
use_cftime: bool | None = None,
decode_timedelta: bool | CFTimedeltaCoder | None = None,
)
| 107 | |
| 108 | |
| 109 | def decode_cf_variable( |
| 110 | name: Hashable, |
| 111 | var: Variable, |
| 112 | concat_characters: bool = True, |
| 113 | mask_and_scale: bool = True, |
| 114 | decode_times: bool | CFDatetimeCoder = True, |
| 115 | decode_endianness: bool = True, |
| 116 | stack_char_dim: bool = True, |
| 117 | use_cftime: bool | None = None, |
| 118 | decode_timedelta: bool | CFTimedeltaCoder | None = None, |
| 119 | ) -> Variable: |
| 120 | """ |
| 121 | Decodes a variable which may hold CF encoded information. |
| 122 | |
| 123 | This includes variables that have been masked and scaled, which |
| 124 | hold CF style time variables (this is almost always the case if |
| 125 | the dataset has been serialized) and which have strings encoded |
| 126 | as character arrays. |
| 127 | |
| 128 | Parameters |
| 129 | ---------- |
| 130 | name : str |
| 131 | Name of the variable. Used for better error messages. |
| 132 | var : Variable |
| 133 | A variable holding potentially CF encoded information. |
| 134 | concat_characters : bool |
| 135 | Should character arrays be concatenated to strings, for |
| 136 | example: ["h", "e", "l", "l", "o"] -> "hello" |
| 137 | mask_and_scale : bool |
| 138 | Lazily scale (using scale_factor and add_offset) and mask |
| 139 | (using _FillValue). If the _Unsigned attribute is present |
| 140 | treat integer arrays as unsigned. |
| 141 | decode_times : bool or CFDatetimeCoder |
| 142 | Decode cf times ("hours since 2000-01-01") to np.datetime64. |
| 143 | decode_endianness : bool |
| 144 | Decode arrays from non-native to native endianness. |
| 145 | stack_char_dim : bool |
| 146 | Whether to stack characters into bytes along the last dimension of this |
| 147 | array. Passed as an argument because we need to look at the full |
| 148 | dataset to figure out if this is appropriate. |
| 149 | use_cftime : bool, optional |
| 150 | Only relevant if encoded dates come from a standard calendar |
| 151 | (e.g. "gregorian", "proleptic_gregorian", "standard", or not |
| 152 | specified). If None (default), attempt to decode times to |
| 153 | ``np.datetime64[ns]`` objects; if this is not possible, decode times to |
| 154 | ``cftime.datetime`` objects. If True, always decode times to |
| 155 | ``cftime.datetime`` objects, regardless of whether or not they can be |
| 156 | represented using ``np.datetime64[ns]`` objects. If False, always |
| 157 | decode times to ``np.datetime64[ns]`` objects; if this is not possible |
| 158 | raise an error. |
| 159 | |
| 160 | .. deprecated:: 2025.01.1 |
| 161 | Please pass a :py:class:`coders.CFDatetimeCoder` instance initialized with ``use_cftime`` to the ``decode_times`` kwarg instead. |
| 162 | decode_timedelta : None, bool, or CFTimedeltaCoder |
| 163 | Decode cf timedeltas ("hours") to np.timedelta64. |
| 164 | |
| 165 | Returns |
| 166 | ------- |
searching dependent graphs…