Skip to content

Commit baf799f

Browse files
committed
Make note about idempotent-ish make_datasets.py script
1 parent 556fe3c commit baf799f

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

tests/datasets/masking/find_fill_value/make_datasets.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/usr/bin/env python3
22

3+
"""
4+
Make some datasets for testing fill values.
5+
Because of how xarray preprocesses variables to apply masks,
6+
it is easier to construct these datasets using the plain netCDF4 library,
7+
save the datasets to disk, and then load them using xarray.
8+
This guarantees that the behaviour in the tests will replicate real-world use.
9+
10+
Running this script will overwrite any datasets already constructed in this directory.
11+
This operation should result in byte-for-byte identical datasets each time it is run.
12+
However each netCDF4 dataset will encode the versions of the
13+
netCDF4, hdf5 and other relevant libraries used to construct the dataset.
14+
If the versions have changed, the script will create new files that git thinks have changed.
15+
"""
16+
317
import pathlib
418

519
import netCDF4
@@ -8,8 +22,10 @@
822
here = pathlib.Path(__file__).parent
923

1024

11-
def make_float_with_fill_value() -> None:
12-
ds = netCDF4.Dataset(here / "float_with_fill_value.nc", "w", "NETCDF4")
25+
def make_float_with_fill_value(
26+
output_path: pathlib.Path = here / "float_with_fill_value.nc"
27+
) -> None:
28+
ds = netCDF4.Dataset(output_path, "w", "NETCDF4")
1329
ds.createDimension("x", 2)
1430
ds.createDimension("y", 2)
1531

@@ -20,8 +36,10 @@ def make_float_with_fill_value() -> None:
2036
ds.close()
2137

2238

23-
def make_float_with_fill_value_and_offset() -> None:
24-
ds = netCDF4.Dataset(here / "float_with_fill_value_and_offset.nc", "w", "NETCDF4")
39+
def make_float_with_fill_value_and_offset(
40+
output_path: pathlib.Path = here / "float_with_fill_value_and_offset.nc",
41+
) -> None:
42+
ds = netCDF4.Dataset(output_path, "w", "NETCDF4")
2543
ds.createDimension("x", 2)
2644
ds.createDimension("y", 2)
2745

@@ -34,8 +52,12 @@ def make_float_with_fill_value_and_offset() -> None:
3452
ds.close()
3553

3654

37-
def make_int_with_fill_value_and_offset() -> None:
38-
ds = netCDF4.Dataset(here / "int_with_fill_value_and_offset.nc", "w", "NETCDF4")
55+
56+
57+
def make_int_with_fill_value_and_offset(
58+
output_path: pathlib.Path = here / "int_with_fill_value_and_offset.nc",
59+
) -> None:
60+
ds = netCDF4.Dataset(output_path, "w", "NETCDF4")
3961
ds.createDimension("x", 2)
4062
ds.createDimension("y", 2)
4163

0 commit comments

Comments
 (0)