Skip to content

Commit

Permalink
Merge branch 'pytroll:main' into add_support_mersi1
Browse files Browse the repository at this point in the history
  • Loading branch information
yukaribbba authored May 21, 2024
2 parents 9f36465 + 233f698 commit f48d740
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 112 deletions.
2 changes: 1 addition & 1 deletion continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies:
- eccodes>=2.20
- pytest<8.0.0
- pytest-cov
- pytest-lazy-fixture
- fsspec
- botocore>=1.33
- s3fs
Expand All @@ -59,6 +58,7 @@ dependencies:
- ephem
- bokeh
- pip:
- pytest-lazy-fixtures
- trollsift
- trollimage>=1.23
- pyspectral
Expand Down
2 changes: 1 addition & 1 deletion doc/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies:
- pooch
- pyresample
- pytest
- pytest-lazy-fixture
- python-eccodes
- python-geotiepoints
- rasterio
Expand All @@ -34,4 +33,5 @@ dependencies:
- xarray-datatree
- pip:
- graphviz
- pytest-lazy-fixtures
- .. # relative path to the satpy project
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ hvplot = ["hvplot", "geoviews", "cartopy", "holoviews"]
overlays = ["pycoast", "pydecorate"]
satpos_from_tle = ["skyfield", "astropy"]
tests = ["behave", "h5py", "netCDF4", "pyhdf", "imageio",
"rasterio", "geoviews", "trollimage", "fsspec", "bottleneck",
"rioxarray", "pytest", "pytest-lazy-fixture", "defusedxml",
"s3fs", "eccodes", "h5netcdf", "xarray-datatree",
"skyfield", "ephem", "pint-xarray", "astropy", "dask-image", "python-geotiepoints", "numba"]
"rasterio", "geoviews", "trollimage", "fsspec", "bottleneck",
"rioxarray", "pytest", "pytest-lazy-fixtures", "defusedxml",
"s3fs", "eccodes", "h5netcdf", "xarray-datatree",
"skyfield", "ephem", "pint-xarray", "astropy", "dask-image", "python-geotiepoints", "numba"]

[project.scripts]
satpy_retrieve_all_aux_data = "satpy.aux_download:retrieve_all_cmd"
Expand Down Expand Up @@ -132,7 +132,7 @@ line-length = 120
[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
# In the future, add "B", "S", "N"
select = ["A", "D", "E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20"]
select = ["A", "D", "E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20", "NPY"]

[tool.ruff.lint.per-file-ignores]
"satpy/tests/*" = ["S101"] # assert allowed in tests
Expand Down
29 changes: 15 additions & 14 deletions satpy/tests/reader_tests/_li_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import xarray as xr

from satpy.tests.reader_tests.test_netcdf_utils import FakeNetCDF4FileHandler
from satpy.tests.utils import RANDOM_GEN

# mapping of netcdf type code to numpy data type:
TYPE_MAP = {
Expand All @@ -44,7 +45,7 @@ def l2_le_schema(settings=None):
nfilters = settings.get("num_filters", 2)

def rand_u16(num):
return np.random.randint(low=0, high=np.iinfo(np.uint16).max - 1, size=num, dtype=np.uint16)
return RANDOM_GEN.integers(low=0, high=np.iinfo(np.uint16).max - 1, size=num, dtype=np.uint16)

return {
"providers": settings.get("providers", {}),
Expand Down Expand Up @@ -100,7 +101,7 @@ def rand_u16(num):
"scale_factor": 0.004,
"add_offset": 0.0,
"long_name": "L2 filter results",
"default_data": lambda: np.random.randint(low=0, high=255, size=(nobs, nfilters), dtype=np.uint8)
"default_data": lambda: RANDOM_GEN.integers(low=0, high=255, size=(nobs, nfilters), dtype=np.uint8)
},
"epoch_time": {
"format": "f8",
Expand Down Expand Up @@ -212,13 +213,13 @@ def l2_lef_schema(settings=None):
"long_name": "Radiance of Flash",
"standard_name": "radiance",
"units": "mW.m-2.sr-1",
"default_data": lambda: np.clip(np.round(np.random.normal(500, 100, nobs)), 1, 2 ** 16 - 1)
"default_data": lambda: np.clip(np.round(RANDOM_GEN.normal(500, 100, nobs)), 1, 2 ** 16 - 1)
},
"event_filter_qa": {
"format": "u1",
"shape": ("events",),
"long_name": "L2 event pre-filtering quality assurance value",
"default_data": lambda: np.random.randint(1, 2 ** 8 - 1, nobs)
"default_data": lambda: RANDOM_GEN.integers(1, 2 ** 8 - 1, nobs)
},
"epoch_time": {
"format": "f8",
Expand All @@ -232,21 +233,21 @@ def l2_lef_schema(settings=None):
"shape": ("events",),
"long_name": "Time offset from epoch time",
"units": "seconds",
"default_data": lambda: np.random.uniform(1, 2 ** 31 - 1, nobs)
"default_data": lambda: RANDOM_GEN.uniform(1, 2 ** 31 - 1, nobs)
},
"detector_row": {
"format": "u2",
"shape": ("events",),
"long_name": "Detector row position of event pixel",
"units": "1",
"default_data": lambda: np.random.randint(1, 1000, nobs)
"default_data": lambda: RANDOM_GEN.integers(1, 1000, nobs)
},
"detector_column": {
"format": "u2",
"shape": ("events",),
"long_name": "Detector column position of event pixel",
"units": "1",
"default_data": lambda: np.random.randint(1, 1000, nobs)
"default_data": lambda: RANDOM_GEN.integers(1, 1000, nobs)
},
}
}
Expand Down Expand Up @@ -328,7 +329,7 @@ def l2_lfl_schema(settings=None):
"long_name": "Radiance of Flash",
"standard_name": "radiance",
"units": "mW.m-2.sr-1",
"default_data": lambda: np.round(np.random.normal(500, 100, nobs))
"default_data": lambda: np.round(RANDOM_GEN.normal(500, 100, nobs))
},
"flash_duration": {
"format": "u2",
Expand All @@ -343,15 +344,15 @@ def l2_lfl_schema(settings=None):
"shape": ("flashes",),
"long_name": "L2 filtered flash confidence",
"standard_name": "flash_filter_confidence",
"default_data": lambda: np.clip(np.round(np.random.normal(20, 10, nobs)), 1, 2 ** 7 - 1)
"default_data": lambda: np.clip(np.round(RANDOM_GEN.normal(20, 10, nobs)), 1, 2 ** 7 - 1)
},
"flash_footprint": {
"format": "u2",
"shape": ("flashes",),
"long_name": "Flash footprint size",
"standard_name": "flash_footprint",
"units": "L1 grid pixels",
"default_data": lambda: np.maximum(1, np.round(np.random.normal(5, 3, nobs)))
"default_data": lambda: np.maximum(1, np.round(RANDOM_GEN.normal(5, 3, nobs)))
},
"flash_id": {
"format": "u4",
Expand All @@ -367,7 +368,7 @@ def l2_lfl_schema(settings=None):
"units": "seconds since 2000-01-01 00:00:00.0",
"standard_name": "time",
"precision": "1 millisecond",
"default_data": lambda: np.random.uniform(stime, etime, nobs)
"default_data": lambda: RANDOM_GEN.uniform(stime, etime, nobs)
},
"l1b_geolocation_warning": {
"format": "i1",
Expand Down Expand Up @@ -437,7 +438,7 @@ def l2_af_schema(settings=None):
"flash_accumulation": {
"format": "u2",
"shape": ("pixels",),
"default_data": lambda: np.clip(np.round(np.random.normal(1, 2, nobs)), 1, 2 ** 16 - 1)
"default_data": lambda: np.clip(np.round(RANDOM_GEN.normal(1, 2, nobs)), 1, 2 ** 16 - 1)
},
"mtg_geos_projection": mtg_geos_projection(),
"x": fci_grid_definition("X", nobs),
Expand Down Expand Up @@ -495,7 +496,7 @@ def l2_afr_schema(settings=None):
"long_name": "Area averaged flash radiance accumulation",
"grid_mapping": "mtg_geos_projection",
"coordinate": "sparse: x y",
"default_data": lambda: np.random.randint(low=1, high=6548, size=(120), dtype=np.int16)
"default_data": lambda: RANDOM_GEN.integers(low=1, high=6548, size=(120), dtype=np.int16)
},
"accumulation_start_times": {
"format": "f4",
Expand Down Expand Up @@ -538,7 +539,7 @@ def fci_grid_definition(axis, nobs):
"standard_name": standard_name,
"units": "radian",
"valid_range": np.asarray([1, 5568]),
"default_data": lambda: np.clip(np.round(np.random.normal(2000, 500, nobs)), 1, 2 ** 16 - 1)
"default_data": lambda: np.clip(np.round(RANDOM_GEN.normal(2000, 500, nobs)), 1, 2 ** 16 - 1)
}


Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/modis_tests/test_modis_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import dask
import numpy as np
import pytest
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy import Scene, available_readers
from satpy.tests.utils import CustomScheduler, make_dataid
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/modis_tests/test_modis_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import dask.array as da
import numpy as np
import pytest
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy import Scene, available_readers
from satpy.tests.utils import CustomScheduler, make_dataid
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/modis_tests/test_modis_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import numpy as np
import pytest
from pyresample import geometry
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy import Scene, available_readers

Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_abi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import numpy.typing as npt
import pytest
import xarray as xr
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy import DataQuery
from satpy.readers.abi_l1b import NC_ABI_L1B
Expand Down
17 changes: 9 additions & 8 deletions satpy/tests/reader_tests/test_epic_l1b_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import pytest

from satpy.readers.epic_l1b_h5 import CALIB_COEFS

b317_data = np.random.uniform(low=0, high=5200, size=(100, 100))
b688_data = np.random.uniform(low=0, high=5200, size=(100, 100))
sza_data = np.random.uniform(low=0, high=100, size=(100, 100))
vaa_data = np.random.uniform(low=-180, high=180, size=(100, 100))
lon_data = np.random.uniform(low=-90, high=90, size=(100, 100))
lat_data = np.random.uniform(low=-180, high=180, size=(100, 100))
mas_data = np.random.choice([0, 1], size=(100, 100))
from satpy.tests.utils import RANDOM_GEN

b317_data = RANDOM_GEN.uniform(low=0, high=5200, size=(100, 100))
b688_data = RANDOM_GEN.uniform(low=0, high=5200, size=(100, 100))
sza_data = RANDOM_GEN.uniform(low=0, high=100, size=(100, 100))
vaa_data = RANDOM_GEN.uniform(low=-180, high=180, size=(100, 100))
lon_data = RANDOM_GEN.uniform(low=-90, high=90, size=(100, 100))
lat_data = RANDOM_GEN.uniform(low=-180, high=180, size=(100, 100))
mas_data = RANDOM_GEN.choice([0, 1], size=(100, 100))


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_fci_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pytest
import xarray as xr
from netCDF4 import default_fillvals
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy.readers.fci_l1c_nc import FCIL1cNCFileHandler
from satpy.tests.reader_tests.test_netcdf_utils import FakeNetCDF4FileHandler
Expand Down
4 changes: 2 additions & 2 deletions satpy/tests/reader_tests/test_generic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import pytest
import xarray as xr

from satpy.tests.utils import make_dataid
from satpy.tests.utils import RANDOM_GEN, make_dataid


class TestGenericImage(unittest.TestCase):
Expand Down Expand Up @@ -62,7 +62,7 @@ def setUp(self):
a__[:10, :10] = 0
a__ = da.from_array(a__, chunks=(50, 50))

r_nan__ = np.random.uniform(0., 1., size=(self.y_size, self.x_size))
r_nan__ = RANDOM_GEN.uniform(0., 1., size=(self.y_size, self.x_size))
r_nan__[:10, :10] = np.nan
r_nan__ = da.from_array(r_nan__, chunks=(50, 50))

Expand Down
11 changes: 6 additions & 5 deletions satpy/tests/reader_tests/test_goci2_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import numpy as np
import pytest
import xarray as xr
from pytest_lazyfixture import lazy_fixture
from pytest_lazy_fixtures import lf as lazy_fixture

from satpy import Scene
from satpy.tests.utils import RANDOM_GEN

# NOTE:
# The following fixtures are not defined in this file, but are used and injected by Pytest:
Expand Down Expand Up @@ -78,7 +79,7 @@ def _create_bad_lon_lat():
@pytest.fixture(scope="session")
def ac_file(tmp_path_factory):
"""Create a fake atmospheric correction product."""
data = np.random.random((10, 10))
data = RANDOM_GEN.random((10, 10))
RhoC = xr.Dataset(
{"RhoC_555": (["number_of_lines", "pixels_per_line"], data)},
coords={"number_of_lines": np.arange(10), "pixels_per_line": np.arange(10)},
Expand All @@ -102,7 +103,7 @@ def ac_file(tmp_path_factory):
@pytest.fixture(scope="module")
def iop_file(tmp_path_factory):
"""Create a fake IOP product."""
data = np.random.random((10, 10))
data = RANDOM_GEN.random((10, 10))
a = xr.Dataset(
{"a_total_555": (["number_of_lines", "pixels_per_line"], data)},
coords={"number_of_lines": np.arange(10), "pixels_per_line": np.arange(10)},
Expand All @@ -124,7 +125,7 @@ def iop_file(tmp_path_factory):
@pytest.fixture(scope="module")
def generic_file(tmp_path_factory):
"""Create a fake ouput product like Chl, Zsd etc."""
data = np.random.random((10, 10))
data = RANDOM_GEN.random((10, 10))
geophysical_data = xr.Dataset(
{"Chl": (["number_of_lines", "pixels_per_line"], data)},
coords={"number_of_lines": np.arange(10), "pixels_per_line": np.arange(10)},
Expand All @@ -141,7 +142,7 @@ def generic_file(tmp_path_factory):
@pytest.fixture(scope="module")
def generic_bad_file(tmp_path_factory):
"""Create a PP product with lon/lat base name missing."""
data = np.random.random((10, 10))
data = RANDOM_GEN.random((10, 10))
geophysical_data = xr.Dataset(
{"PP": (["number_of_lines", "pixels_per_line"], data)},
coords={"number_of_lines": np.arange(10), "pixels_per_line": np.arange(10)},
Expand Down
7 changes: 4 additions & 3 deletions satpy/tests/reader_tests/test_hrit_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from satpy.readers import FSFile
from satpy.readers.hrit_base import HRITFileHandler, decompress, get_xritdecompress_cmd, get_xritdecompress_outfile
from satpy.tests.utils import RANDOM_GEN

# NOTE:
# The following fixtures are not defined in this file, but are used and injected by Pytest:
Expand Down Expand Up @@ -145,9 +146,9 @@ def create_stub_hrit(filename, open_fun=open, meta=mda):
lines = meta["number_of_lines"]
cols = meta["number_of_columns"]
total_bits = lines * cols * nbits
arr = np.random.randint(0, 256,
size=int(total_bits / 8),
dtype=np.uint8)
arr = RANDOM_GEN.integers(0, 256,
size=int(total_bits / 8),
dtype=np.uint8)
with open_fun(filename, mode="wb") as fd:
fd.write(b" " * meta["total_header_length"])
bytes_data = arr.tobytes()
Expand Down
8 changes: 4 additions & 4 deletions satpy/tests/reader_tests/test_insat3d_img_l1b_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
open_dataset,
open_datatree,
)
from satpy.tests.utils import make_dataid
from satpy.tests.utils import RANDOM_GEN, make_dataid

# NOTE:
# The following fixtures are not defined in this file, but are used and injected by Pytest:
Expand All @@ -30,10 +30,10 @@
alb_units = "%"
temp_units = "K"
chunks_1km = (1, 46, 1126)
values_1km = np.random.randint(0, 1000, shape_1km, dtype=np.uint16)
values_1km = RANDOM_GEN.integers(0, 1000, shape_1km, dtype=np.uint16)
values_1km[0, 0, 0] = 0
values_4km = np.random.randint(0, 1000, shape_4km, dtype=np.uint16)
values_8km = np.random.randint(0, 1000, shape_8km, dtype=np.uint16)
values_4km = RANDOM_GEN.integers(0, 1000, shape_4km, dtype=np.uint16)
values_8km = RANDOM_GEN.integers(0, 1000, shape_8km, dtype=np.uint16)

values_by_resolution = {1000: values_1km,
4000: values_4km,
Expand Down
Loading

0 comments on commit f48d740

Please sign in to comment.