Converts a Variable into a Variable which follows some of the CF conventions: - Nans are masked using _FillValue (or the deprecated missing_value) - Rescaling via: scale_factor and add_offset - datetimes are converted to the CF 'units since time' format - dt
(
var: Variable, needs_copy: bool = True, name: T_Name = None
)
| 66 | |
| 67 | |
| 68 | def encode_cf_variable( |
| 69 | var: Variable, needs_copy: bool = True, name: T_Name = None |
| 70 | ) -> Variable: |
| 71 | """ |
| 72 | Converts a Variable into a Variable which follows some |
| 73 | of the CF conventions: |
| 74 | |
| 75 | - Nans are masked using _FillValue (or the deprecated missing_value) |
| 76 | - Rescaling via: scale_factor and add_offset |
| 77 | - datetimes are converted to the CF 'units since time' format |
| 78 | - dtype encodings are enforced. |
| 79 | |
| 80 | Parameters |
| 81 | ---------- |
| 82 | var : Variable |
| 83 | A variable holding un-encoded data. |
| 84 | |
| 85 | Returns |
| 86 | ------- |
| 87 | out : Variable |
| 88 | A variable which has been encoded as described above. |
| 89 | """ |
| 90 | ensure_not_multiindex(var, name=name) |
| 91 | |
| 92 | for coder in [ |
| 93 | CFDatetimeCoder(), |
| 94 | CFTimedeltaCoder(), |
| 95 | variables.CFScaleOffsetCoder(), |
| 96 | variables.CFMaskCoder(), |
| 97 | variables.NativeEnumCoder(), |
| 98 | variables.NonStringCoder(), |
| 99 | variables.DefaultFillvalueCoder(), |
| 100 | variables.BooleanCoder(), |
| 101 | ]: |
| 102 | var = coder.encode(var, name=name) |
| 103 | |
| 104 | for attr_name in CF_RELATED_DATA: |
| 105 | pop_to(var.encoding, var.attrs, attr_name) |
| 106 | return var |
| 107 | |
| 108 | |
| 109 | def decode_cf_variable( |
searching dependent graphs…