|
49 | 49 | # string used by netCDF4. |
50 | 50 | _endian_lookup = {"=": "native", ">": "big", "<": "little", "|": "native"} |
51 | 51 |
|
52 | | -# according to https://github.com/DennisHeimbigner/netcdf-c/blob/ef94285ac13b011613bb5e905d49b63d2a3bb076/libsrc4/nc4type.c#L486 |
53 | | -DEFAULT_HDF_ENUM_FILL_VALUE = 0 |
54 | | -DEFAULT_UNDEFINED_ENUM_MEANING = "_UNDEFINED" |
55 | 52 | NETCDF4_PYTHON_LOCK = combine_locks([NETCDFC_LOCK, HDF5_LOCK]) |
56 | 53 |
|
57 | 54 |
|
@@ -126,31 +123,6 @@ def _getitem(self, key): |
126 | 123 | return array |
127 | 124 |
|
128 | 125 |
|
129 | | - def replace_mask(self, mask, replacing_value): |
130 | | - ds = self.datastore._acquire(needs_lock=True) |
131 | | - variable = ds.variables[self.variable_name] |
132 | | - variable[mask] = replacing_value |
133 | | - |
134 | | - |
135 | | - |
136 | | -class NetCDF4EnumedArrayWrapper(NetCDF4ArrayWrapper): |
137 | | - __slots__ = () |
138 | | - |
139 | | - def get_array(self, needs_lock=True): |
140 | | - ds = self.datastore._acquire(needs_lock) |
141 | | - variable = ds.variables[self.variable_name] |
142 | | - with suppress(AttributeError): |
143 | | - variable.set_auto_chartostring(False) |
144 | | - return variable |
145 | | - |
146 | | - def unmask(self): |
147 | | - ds = self.datastore._acquire(needs_lock=True) |
148 | | - variable = ds.variables[self.variable_name] |
149 | | - variable.set_auto_maskandscale(False) |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | 126 | def _encode_nc4_variable(var): |
155 | 127 | for coder in [ |
156 | 128 | coding.strings.EncodedStringCoder(allows_unicode=True), |
@@ -444,29 +416,8 @@ def open_store_variable(self, name: str, var): |
444 | 416 | enum_meaning = None |
445 | 417 | enum_name = None |
446 | 418 | if isinstance(var.datatype, netCDF4.EnumType): |
447 | | - # Workaround for poorly generated variables: |
448 | | - # When creating a variable typed by an enum |
449 | | - # va_va = self._acquire()[name][:] # get masked array |
450 | | - # old_fill_value = va_va.fill_value |
451 | | - # mask = va_va.mask |
452 | 419 | enum_meaning = var.datatype.enum_dict |
453 | 420 | enum_name = var.datatype.name |
454 | | - # Add a meaning to fill_value value if missing |
455 | | - # fill_value = list(var.datatype.enum_dict.values())[0] |
456 | | - # fill_value = attributes.get("_FillValue", DEFAULT_HDF_ENUM_FILL_VALUE) |
457 | | - # attributes["_FillValue"] = fill_value |
458 | | - # masked_data = indexing.LazilyIndexedArray(NetCDF4EnumedArrayWrapper(name, self)) |
459 | | - # masked_data.array.replace_mask(fill_value) |
460 | | - # masked_data.array.unmask() |
461 | | - # va_va[mask] = fill_value |
462 | | - # filtered_reversed_enum_meaning = { |
463 | | - # v: k |
464 | | - # for k, v in enum_meaning.items() |
465 | | - # if v == fill_value |
466 | | - # } |
467 | | - # # TODO: manage fill_value, see todo comment taged with [enum][missing_value] below |
468 | | - # if filtered_reversed_enum_meaning.get(fill_value) is None: |
469 | | - # enum_meaning[DEFAULT_UNDEFINED_ENUM_MEANING] = fill_value |
470 | 421 | attributes["enum_name"] = enum_name |
471 | 422 | attributes["enum_meaning"] = enum_meaning |
472 | 423 | data = indexing.LazilyIndexedArray(NetCDF4ArrayWrapper(name, self)) |
@@ -575,18 +526,6 @@ def prepare_variable( |
575 | 526 | del attrs["enum_name"] |
576 | 527 | del attrs["enum_meaning"] |
577 | 528 | fill_value = None |
578 | | - # TODO [enum][missing_value]: |
579 | | - # What should we do with fill+value on enum ? |
580 | | - # On one hand it makes sens to ensure fill_value is a valid enum |
581 | | - # value. |
582 | | - # On the other hand, HDF and netCDF4 does not enforce this. |
583 | | - # In fact with the current netcdf4 we can end up with variables that |
584 | | - # can be created but not read by ncdump if we set fill_value to a |
585 | | - # value outside the enum range but we can also have clunky files |
586 | | - # with fill_value set to None, that are readable even though |
587 | | - # the default fill_value is outside the enum range too. |
588 | | - # Also, HDF considers the value associated with 0 to be the missing |
589 | | - # value *verify this claim). |
590 | 529 | if name in self.ds.variables: |
591 | 530 | nc4_var = self.ds.variables[name] |
592 | 531 | else: |
|
0 commit comments