MCPcopy
hub / github.com/pydata/xarray / encode_cf_variable

Function encode_cf_variable

xarray/conventions.py:68–106  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

66
67
68def 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
109def decode_cf_variable(

Calls 5

ensure_not_multiindexFunction · 0.85
CFDatetimeCoderClass · 0.85
CFTimedeltaCoderClass · 0.85
pop_toFunction · 0.85
encodeMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…