Skip to content

Commit

Permalink
Add "D" checks to ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Nov 21, 2023
1 parent 5ecf1ab commit 7591239
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions doc/source/doi_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


def doi_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
"""Create a doi role."""
if options is None:
options = {}
if content is None:
Expand All @@ -34,6 +35,7 @@ def doi_role(typ, rawtext, text, lineno, inliner, options=None, content=None):


def arxiv_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
"""Create an arxive role."""
if options is None:
options = {}
if content is None:
Expand All @@ -48,12 +50,14 @@ def arxiv_role(typ, rawtext, text, lineno, inliner, options=None, content=None):


def setup_link_role(app):
"""Set up the role link."""
app.add_role("doi", doi_role, override=True)
app.add_role("DOI", doi_role, override=True)
app.add_role("arXiv", arxiv_role, override=True)
app.add_role("arxiv", arxiv_role, override=True)


def setup(app):
"""Set up the app."""
app.connect("builder-inited", setup_link_role)
return {"version": "0.1", "parallel_read_safe": True}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ line_length = 120
[tool.ruff]
# See https://docs.astral.sh/ruff/rules/
# In the future, add "A", "B", "S", "N", "D"
select = ["E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20"]
select = ["D", "E", "W", "F", "I", "PT", "TID", "C90", "Q", "T10", "T20"]
line-length = 120
ignore = ["D417"]

[tool.ruff.per-file-ignores]
"satpy/tests/*" = ["S101"] # assert allowed in tests
Expand Down
3 changes: 1 addition & 2 deletions satpy/readers/atms_sdr_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Reader for the ATMS SDR format.
"""Reader for the ATMS SDR format.
A reader for Advanced Technology Microwave Sounder (ATMS) SDR data as it
e.g. comes out of the CSPP package for processing Direct Readout data.
Expand Down
3 changes: 1 addition & 2 deletions satpy/readers/generic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""
Reader for generic image (e.g. gif, png, jpg, tif, geotiff, ...).
"""Reader for generic image (e.g. gif, png, jpg, tif, geotiff, ...).
Returns a dataset without calibration. Includes coordinates if
available in the file (eg. geotiff).
Expand Down
3 changes: 1 addition & 2 deletions satpy/readers/gerb_l2_hr_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@


def gerb_get_dataset(ds, ds_info):
"""
Load a GERB dataset in memory from a HDF5 file or HDF5FileHandler.
"""Load a GERB dataset in memory from a HDF5 file or HDF5FileHandler.
The routine takes into account the quantisation factor and fill values.
"""
Expand Down
6 changes: 2 additions & 4 deletions satpy/readers/ici_l1b_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def _interpolate_geo(
latitude,
n_samples,
):
"""
Perform the interpolation of geographic coordinates from tie points to pixel points.
"""Perform the interpolation of geographic coordinates from tie points to pixel points.
Args:
longitude: xarray DataArray containing the longitude dataset to
Expand Down Expand Up @@ -229,8 +228,7 @@ def _interpolate_viewing_angle(
zenith,
n_samples,
):
"""
Perform the interpolation of angular coordinates from tie points to pixel points.
"""Perform the interpolation of angular coordinates from tie points to pixel points.
Args:
azimuth: xarray DataArray containing the azimuth angle dataset to
Expand Down
2 changes: 0 additions & 2 deletions satpy/readers/modis_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ModisL3GriddedHDFFileHandler(HDFEOSGeoReader):
"""File handler for MODIS HDF-EOS Level 3 CMG gridded files."""
def available_datasets(self, configured_datasets=None):
"""Automatically determine datasets provided by this file."""

# Initialise set of variable names to carry through code
handled_var_names = set()

Expand Down Expand Up @@ -112,7 +111,6 @@ def get_dataset(self, dataset_id, dataset_info):

def _get_area_extent(self):
"""Get the grid properties."""

# Now compute the data extent
upperleft = self.metadata["GridStructure"]["GRID_1"]["UpperLeftPointMtrs"]
lowerright = self.metadata["GridStructure"]["GRID_1"]["LowerRightMtrs"]
Expand Down
3 changes: 3 additions & 0 deletions satpy/readers/scatsat1_l2b.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@


class SCATSAT1L2BFileHandler(BaseFileHandler):
"""File handler for ScatSat level 2 files, as distributed by Eumetsat in HDF5 format."""

def __init__(self, filename, filename_info, filetype_info):
"""Initialize the file handler."""
super(SCATSAT1L2BFileHandler, self).__init__(filename, filename_info, filetype_info)
self.h5f = h5py.File(self.filename, "r")
h5data = self.h5f["science_data"]
Expand All @@ -44,6 +46,7 @@ def __init__(self, filename, filename_info, filetype_info):
self.longitude_scale = float(h5data.attrs["Longitude Scale"])

def get_dataset(self, key, info):
"""Get the dataset."""
h5data = self.h5f["science_data"]
stdname = info.get("standard_name")

Expand Down
6 changes: 6 additions & 0 deletions satpy/tests/reader_tests/test_abi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,29 @@ def _create_fake_rad_dataset(rad: xr.DataArray, resolution: int) -> xr.Dataset:


def generate_l1b_filename(chan_name: str) -> str:
"""Generate a l1b filename."""
return f"OR_ABI-L1b-RadC-M4{chan_name}_G16_s20161811540362_e20161811545170_c20161811545230_suffix.nc"


@pytest.fixture()
def c01_refl(tmp_path) -> xr.DataArray:
"""Load c01 reflectances."""
with _apply_dask_chunk_size():
reader = _create_reader_for_data(tmp_path, "C01", None, 1000)
return reader.load(["C01"])["C01"]


@pytest.fixture()
def c01_rad(tmp_path) -> xr.DataArray:
"""Load c01 radiances."""
with _apply_dask_chunk_size():
reader = _create_reader_for_data(tmp_path, "C01", None, 1000)
return reader.load([DataQuery(name="C01", calibration="radiance")])["C01"]


@pytest.fixture()
def c01_rad_h5netcdf(tmp_path) -> xr.DataArray:
"""Load c01 radiances through h5netcdf."""
shape = RAD_SHAPE[1000]
rad_data = (np.arange(shape[0] * shape[1]).reshape(shape) + 1.0) * 50.0
rad_data = (rad_data + 1.0) / 0.5
Expand All @@ -172,13 +176,15 @@ def c01_rad_h5netcdf(tmp_path) -> xr.DataArray:

@pytest.fixture()
def c01_counts(tmp_path) -> xr.DataArray:
"""Load c01 counts."""
with _apply_dask_chunk_size():
reader = _create_reader_for_data(tmp_path, "C01", None, 1000)
return reader.load([DataQuery(name="C01", calibration="counts")])["C01"]


@pytest.fixture()
def c07_bt_creator(tmp_path) -> Callable:
"""Create a loader for c07 brightness temperatures."""
def _load_data_array(
clip_negative_radiances: bool = False,
):
Expand Down
3 changes: 3 additions & 0 deletions satpy/tests/reader_tests/test_satpy_cf_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def _create_test_netcdf(filename, resolution=742):

@pytest.fixture(scope="session")
def cf_scene():
"""Create a cf scene."""
tstart = datetime(2019, 4, 1, 12, 0)
tend = datetime(2019, 4, 1, 12, 15)
data_visir = np.array([[1, 2], [3, 4]])
Expand Down Expand Up @@ -214,13 +215,15 @@ def cf_scene():

@pytest.fixture()
def nc_filename(tmp_path):
"""Create an nc filename for viirs m band."""
now = datetime.utcnow()
filename = f"testingcfwriter{now:%Y%j%H%M%S}-viirs-mband-20201007075915-20201007080744.nc"
return str(tmp_path / filename)


@pytest.fixture()
def nc_filename_i(tmp_path):
"""Create an nc filename for viirs i band."""
now = datetime.utcnow()
filename = f"testingcfwriter{now:%Y%j%H%M%S}-viirs-iband-20201007075915-20201007080744.nc"
return str(tmp_path / filename)
Expand Down
1 change: 1 addition & 0 deletions satpy/tests/reader_tests/test_viirs_vgac_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

@pytest.fixture()
def nc_filename(tmp_path):
"""Create an nc test data file and return its filename."""
now = datetime.datetime.utcnow()
filename = f"VGAC_VJ10XMOD_A{now:%Y%j_%H%M}_n004946_K005.nc"
filename_str = str(tmp_path / filename)
Expand Down

0 comments on commit 7591239

Please sign in to comment.