Create a store for writing to a netCDF file.
(
target,
engine: T_NetcdfEngine,
*,
format: T_NetcdfTypes | None,
mode: NetcdfWriteModes,
autoclose: bool,
invalid_netcdf: bool,
auto_complex: bool | None,
)
| 46 | |
| 47 | |
| 48 | def get_writable_netcdf_store( |
| 49 | target, |
| 50 | engine: T_NetcdfEngine, |
| 51 | *, |
| 52 | format: T_NetcdfTypes | None, |
| 53 | mode: NetcdfWriteModes, |
| 54 | autoclose: bool, |
| 55 | invalid_netcdf: bool, |
| 56 | auto_complex: bool | None, |
| 57 | ) -> AbstractWritableDataStore: |
| 58 | """Create a store for writing to a netCDF file.""" |
| 59 | try: |
| 60 | store_open = WRITEABLE_STORES[engine] |
| 61 | except KeyError as err: |
| 62 | raise ValueError(f"unrecognized engine for to_netcdf: {engine!r}") from err |
| 63 | |
| 64 | if format is not None: |
| 65 | format = format.upper() # type: ignore[assignment] |
| 66 | |
| 67 | kwargs = dict(autoclose=True) if autoclose else {} |
| 68 | if invalid_netcdf: |
| 69 | if engine == "h5netcdf": |
| 70 | kwargs["invalid_netcdf"] = invalid_netcdf |
| 71 | else: |
| 72 | raise ValueError( |
| 73 | f"unrecognized option 'invalid_netcdf' for engine {engine}" |
| 74 | ) |
| 75 | if auto_complex is not None: |
| 76 | kwargs["auto_complex"] = auto_complex |
| 77 | |
| 78 | return store_open(target, mode=mode, format=format, **kwargs) |
| 79 | |
| 80 | |
| 81 | def _validate_dataset_names(dataset: Dataset) -> None: |
no test coverage detected
searching dependent graphs…