Converts a Variable into another 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
(var, needs_copy=True, name=None)
| 542 | # Function below is copied from conventions.encode_cf_variable. |
| 543 | # The only change is to raise an error for object dtypes. |
| 544 | def encode_zarr_variable(var, needs_copy=True, name=None): |
| 545 | """ |
| 546 | Converts a Variable into another Variable which follows some |
| 547 | of the CF conventions: |
| 548 | |
| 549 | - Nans are masked using _FillValue (or the deprecated missing_value) |
| 550 | - Rescaling via: scale_factor and add_offset |
| 551 | - datetimes are converted to the CF 'units since time' format |
| 552 | - dtype encodings are enforced. |
| 553 | |
| 554 | Parameters |
| 555 | ---------- |
| 556 | var : Variable |
| 557 | A variable holding un-encoded data. |
| 558 | |
| 559 | Returns |
| 560 | ------- |
| 561 | out : Variable |
| 562 | A variable which has been encoded as described above. |
| 563 | """ |
| 564 | |
| 565 | var = conventions.encode_cf_variable(var, name=name) |
| 566 | var = ensure_dtype_not_object(var, name=name) |
| 567 | |
| 568 | # zarr allows unicode, but not variable-length strings, so it's both |
| 569 | # simpler and more compact to always encode as UTF-8 explicitly. |
| 570 | # TODO: allow toggling this explicitly via dtype in encoding. |
| 571 | # TODO: revisit this now that Zarr _does_ allow variable-length strings |
| 572 | coder = coding.strings.EncodedStringCoder(allows_unicode=True) |
| 573 | var = coder.encode(var, name=name) |
| 574 | var = coding.strings.ensure_fixed_length_bytes(var) |
| 575 | |
| 576 | return var |
| 577 | |
| 578 | |
| 579 | def _validate_datatypes_for_zarr_append(vname, existing_var, new_var): |
no test coverage detected
searching dependent graphs…