(self, name: str, var)
| 538 | return self._acquire() |
| 539 | |
| 540 | def open_store_variable(self, name: str, var): |
| 541 | import netCDF4 |
| 542 | |
| 543 | dimensions = var.dimensions |
| 544 | attributes = {k: var.getncattr(k) for k in var.ncattrs()} |
| 545 | data = indexing.LazilyIndexedArray(NetCDF4ArrayWrapper(name, self)) |
| 546 | encoding: dict[str, Any] = {} |
| 547 | if isinstance(var.datatype, netCDF4.EnumType): |
| 548 | encoding["dtype"] = np.dtype( |
| 549 | data.dtype, |
| 550 | metadata={ |
| 551 | "enum": var.datatype.enum_dict, |
| 552 | "enum_name": var.datatype.name, |
| 553 | }, |
| 554 | ) |
| 555 | else: |
| 556 | encoding["dtype"] = var.dtype |
| 557 | _ensure_fill_value_valid(data, attributes) |
| 558 | # netCDF4 specific encoding; save _FillValue for later |
| 559 | filters = var.filters() |
| 560 | if filters is not None: |
| 561 | encoding.update(filters) |
| 562 | chunking = var.chunking() |
| 563 | if chunking is not None: |
| 564 | if chunking == "contiguous": |
| 565 | encoding["contiguous"] = True |
| 566 | encoding["chunksizes"] = None |
| 567 | else: |
| 568 | encoding["contiguous"] = False |
| 569 | encoding["chunksizes"] = tuple(chunking) |
| 570 | encoding["preferred_chunks"] = dict( |
| 571 | zip(var.dimensions, chunking, strict=True) |
| 572 | ) |
| 573 | # TODO: figure out how to round-trip "endian-ness" without raising |
| 574 | # warnings from netCDF4 |
| 575 | # encoding['endian'] = var.endian() |
| 576 | pop_to(attributes, encoding, "least_significant_digit") |
| 577 | # save source so __repr__ can detect if it's local or not |
| 578 | encoding["source"] = self._filename |
| 579 | encoding["original_shape"] = data.shape |
| 580 | |
| 581 | return Variable(dimensions, data, attributes, encoding) |
| 582 | |
| 583 | def get_variables(self): |
| 584 | return FrozenDict( |
no test coverage detected