Skip to content

Commit

Permalink
fix ruff format errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahAlidoost committed Nov 15, 2024
1 parent d03b0f4 commit ab1cbc3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/zampy/datasets/land_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def load(
else:
# Convert to Dask array if not already
if not isinstance(da.data, da.Array):
dask_array = da.from_array(da.values, chunks='auto')
dask_array = da.from_array(da.values, chunks="auto")
else:
dask_array = da.data
# Use Dask's unique function
Expand Down Expand Up @@ -256,7 +256,7 @@ def extract_netcdf_to_zampy(file: Path) -> xr.Dataset:
else:
# Convert to Dask array if not already
if not isinstance(da.data, da.Array):
dask_array = da.from_array(da.values, chunks='auto')
dask_array = da.from_array(da.values, chunks="auto")
else:
dask_array = da.data
# Use Dask's unique function
Expand Down
19 changes: 9 additions & 10 deletions tests/generate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
"era5_surface_pressure_2020-1.nc",
"era5_surface_solar_radiation_downwards_2020-1.nc",
"era5_surface_thermal_radiation_downwards_2020-1.nc",
],
],
"era5-land": [
"era5-land_dewpoint_temperature_2020-1.nc",
"era5-land_air_temperature_2020-1.nc"],
"era5-land_air_temperature_2020-1.nc",
],
"eth-canopy-height": "ETH_GlobalCanopyHeight_10m_2020_N51E003_Map.tif",
"fapar-lai": "satellite-lai-fapar_2020-1.zip",
"land-cover": "land-cover_LCCS_MAP_300m_2020.zip",
"prism-dem-90": "Copernicus_DSM_30_N50_00_E000_00.tar",
}


def _subset_ncfile(input_file, output_file):
ds = xr.open_dataset(input_file)
subset = ds.isel(
Expand All @@ -38,24 +40,21 @@ def _subset_ncfile(input_file, output_file):


def _subset_tiffile(input_file, output_file):
da = xr.open_dataarray(
input_file, engine="rasterio", chunks={"x": 200, "y": 200}
)
da = xr.open_dataarray(input_file, engine="rasterio", chunks={"x": 200, "y": 200})
subset = da.isel(
x=slice(0, min(4, da.x.size)),
y=slice(0, min(4, da.y.size)),
)
subset.rio.to_raster(output_file)


def _subset_zipfile_include_ncfiles(input_file, output_dir):
format = input_file.suffix.lstrip('.')
format = input_file.suffix.lstrip(".")
zip_file_name = input_file.stem
temp_dir = output_dir / zip_file_name
temp_dir.mkdir(parents=True, exist_ok=True)

shutil.unpack_archive(
input_file, extract_dir=output_dir, format=format
)
shutil.unpack_archive(input_file, extract_dir=output_dir, format=format)
ncfiles = output_dir.glob("*.nc")

for ncfile in ncfiles:
Expand All @@ -82,7 +81,7 @@ def _subset_zipfile_include_ncfiles(input_file, output_dir):


def _subset_tarfile_include_tiffiles(input_file, output_dir):
format = input_file.suffix.lstrip('.')
format = input_file.suffix.lstrip(".")
zip_file_name = input_file.stem
temp_dir = output_dir / zip_file_name
temp_dir.mkdir(parents=True, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_cams.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [57.5, 58.5, 59.5]
expected_lon = [0., 1., 2.]
expected_lon = [0.0, 1.0, 2.0]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0. , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_era5_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0. , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_eth_canopy_height.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0. , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
10 changes: 3 additions & 7 deletions tests/test_datasets/test_fapar_lai.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def test_ingest(self, dummy_dir):
"""Test ingest function."""

lai_dataset = FaparLAI()
lai_dataset.ingest(
download_dir=data_folder, ingest_dir=dummy_dir
)
lai_dataset.ingest(download_dir=data_folder, ingest_dir=dummy_dir)

ds = xr.open_mfdataset((dummy_dir / "fapar-lai").glob("*.nc"))
assert isinstance(ds, xr.Dataset)
Expand All @@ -101,9 +99,7 @@ def test_load(self, dummy_dir):
variable = ["leaf_area_index"]

lai_dataset = FaparLAI()
lai_dataset.ingest(
download_dir=data_folder, ingest_dir=dummy_dir
)
lai_dataset.ingest(download_dir=data_folder, ingest_dir=dummy_dir)

ds = lai_dataset.load(
ingest_dir=dummy_dir,
Expand All @@ -115,7 +111,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0.0 , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datasets/test_land_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_load(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0.0 , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_land_cover_without_flag_values(self, dummy_dir):

# we assert the regridded coordinates
expected_lat = [59.7, 59.8, 59.9]
expected_lon = [0.0 , 0.1, 0.2]
expected_lon = [0.0, 0.1, 0.2]

np.testing.assert_allclose(ds.latitude.values, expected_lat)
np.testing.assert_allclose(ds.longitude.values, expected_lon)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datasets/test_prism_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def test_load(self, dummy_dir):
)

# we assert the regridded coordinates
expected_lat = [59.7 , 59.95]
expected_lon = [0.0 , 0.25]
expected_lat = [59.7, 59.95]
expected_lon = [0.0, 0.25]

np.testing.assert_allclose(ds["latitude"].values, expected_lat)
np.testing.assert_allclose(ds["longitude"].values, expected_lon)
Expand Down

0 comments on commit ab1cbc3

Please sign in to comment.