From 7de229db7f3abce246fe222cda8fbabd19fd66f0 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Fri, 30 Aug 2024 09:58:36 +0200 Subject: [PATCH] Sort imports with ruff --- .pre-commit-config.yaml | 10 +++++----- doc/source/conf.py | 1 - pygac/__init__.py | 1 + pygac/configuration.py | 1 + pygac/correct_tsm_issue.py | 5 +++-- pygac/gac_io.py | 2 +- pygac/gac_pod.py | 2 +- pygac/gac_reader.py | 2 -- pygac/klm_reader.py | 1 + pygac/lac_pod.py | 2 +- pygac/lac_reader.py | 2 -- pygac/pygac_geotiepoints.py | 1 - pygac/reader.py | 2 +- pygac/runner.py | 3 +-- pygac/tests/test_angles.py | 3 +-- pygac/tests/test_io.py | 7 +++---- pygac/tests/test_pod.py | 10 ++++------ pygac/tests/test_reader.py | 11 ++++++----- pygac/tests/test_slerp.py | 4 +++- pygac/tests/test_tsm.py | 3 ++- pygac/tests/test_utils.py | 2 +- pygac/utils.py | 7 +++---- 22 files changed, 39 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index efc390eb..ec1d934a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,12 +2,12 @@ exclude: '^$' fail_fast: false repos: - #- repo: https://github.com/astral-sh/ruff-pre-commit + - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - #rev: 'v0.3.2' - #hooks: - #- id: ruff - #args: [--fix] + rev: 'v0.6.2' + hooks: + - id: ruff + args: [--fix] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: diff --git a/doc/source/conf.py b/doc/source/conf.py index 388725e1..d658487a 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,7 +11,6 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/pygac/__init__.py b/pygac/__init__.py index 8c97fc85..d9567fb8 100644 --- a/pygac/__init__.py +++ b/pygac/__init__.py @@ -30,6 +30,7 @@ "install').") import logging + from pygac.configuration import get_config, read_config_file # noqa from pygac.runner import get_reader_class, process_file # noqa diff --git a/pygac/configuration.py b/pygac/configuration.py index 9ca301e2..9a6e804e 100644 --- a/pygac/configuration.py +++ b/pygac/configuration.py @@ -27,6 +27,7 @@ import logging import os import sys + try: import configparser except ImportError: diff --git a/pygac/correct_tsm_issue.py b/pygac/correct_tsm_issue.py index f940125f..7ca3b905 100644 --- a/pygac/correct_tsm_issue.py +++ b/pygac/correct_tsm_issue.py @@ -23,10 +23,11 @@ an orbit contain corrupt data. This module identifies affected pixels and flags them with fill values.""" -import numpy as np -import bottleneck as bn import datetime +import bottleneck as bn +import numpy as np + TSM_AFFECTED_INTERVALS_POD = { 3: [(datetime.datetime(2001, 10, 19, 4, 50), datetime.datetime(2001, 10, 19, 13, 38)), (datetime.datetime(2001, 10, 19, 16, 58), diff --git a/pygac/gac_io.py b/pygac/gac_io.py index 8b08b2d5..79cc2625 100644 --- a/pygac/gac_io.py +++ b/pygac/gac_io.py @@ -33,7 +33,7 @@ import h5py import numpy as np -from pygac.utils import slice_channel, strip_invalid_lat, check_user_scanlines +from pygac.utils import check_user_scanlines, slice_channel, strip_invalid_lat LOG = logging.getLogger(__name__) diff --git a/pygac/gac_pod.py b/pygac/gac_pod.py index 380014cd..bc814163 100644 --- a/pygac/gac_pod.py +++ b/pygac/gac_pod.py @@ -30,8 +30,8 @@ import numpy as np -from pygac.pod_reader import PODReader, main_pod from pygac.gac_reader import GACReader +from pygac.pod_reader import PODReader, main_pod LOG = logging.getLogger(__name__) diff --git a/pygac/gac_reader.py b/pygac/gac_reader.py index daa82e12..711dd6e0 100644 --- a/pygac/gac_reader.py +++ b/pygac/gac_reader.py @@ -31,8 +31,6 @@ import pygac.pygac_geotiepoints as gtp from pygac.pygac_geotiepoints import GAC_LONLAT_SAMPLE_POINTS from pygac.reader import Reader, ReaderError -import pygac.pygac_geotiepoints as gtp - LOG = logging.getLogger(__name__) diff --git a/pygac/klm_reader.py b/pygac/klm_reader.py index 0b1c3553..78e48774 100644 --- a/pygac/klm_reader.py +++ b/pygac/klm_reader.py @@ -36,6 +36,7 @@ import datetime import logging + try: from enum import IntFlag except ImportError: diff --git a/pygac/lac_pod.py b/pygac/lac_pod.py index 3ecffbf0..8d84dd9c 100644 --- a/pygac/lac_pod.py +++ b/pygac/lac_pod.py @@ -28,8 +28,8 @@ import numpy as np -from pygac.pod_reader import PODReader, main_pod from pygac.lac_reader import LACReader +from pygac.pod_reader import PODReader, main_pod LOG = logging.getLogger(__name__) diff --git a/pygac/lac_reader.py b/pygac/lac_reader.py index 5229d30b..ac633829 100644 --- a/pygac/lac_reader.py +++ b/pygac/lac_reader.py @@ -29,8 +29,6 @@ import pygac.pygac_geotiepoints as gtp from pygac.pygac_geotiepoints import LAC_LONLAT_SAMPLE_POINTS from pygac.reader import Reader, ReaderError -import pygac.pygac_geotiepoints as gtp - LOG = logging.getLogger(__name__) diff --git a/pygac/pygac_geotiepoints.py b/pygac/pygac_geotiepoints.py index 18d35cc0..ed41c609 100644 --- a/pygac/pygac_geotiepoints.py +++ b/pygac/pygac_geotiepoints.py @@ -25,7 +25,6 @@ import geotiepoints as gtp - import numpy as np GAC_LONLAT_SAMPLE_POINTS = np.arange(4, 405, 8) diff --git a/pygac/reader.py b/pygac/reader.py index b4a4bf9b..9e844e8b 100644 --- a/pygac/reader.py +++ b/pygac/reader.py @@ -36,10 +36,10 @@ import numpy as np import pyorbital +import xarray as xr from packaging.version import Version from pyorbital import astronomy from pyorbital.orbital import Orbital -import xarray as xr from pygac import gac_io from pygac.utils import calculate_sun_earth_distance_correction, centered_modulus, get_absolute_azimuth_angle_diff diff --git a/pygac/runner.py b/pygac/runner.py index 7fd72140..877dfd10 100644 --- a/pygac/runner.py +++ b/pygac/runner.py @@ -31,13 +31,12 @@ class for a given file. import logging import os +from pygac.configuration import get_config from pygac.gac_klm import GACKLMReader from pygac.gac_pod import GACPODReader from pygac.lac_klm import LACKLMReader from pygac.lac_pod import LACPODReader from pygac.utils import file_opener -from pygac.configuration import get_config - LOG = logging.getLogger(__name__) diff --git a/pygac/tests/test_angles.py b/pygac/tests/test_angles.py index 97b5e6be..e3be986d 100644 --- a/pygac/tests/test_angles.py +++ b/pygac/tests/test_angles.py @@ -28,8 +28,7 @@ import numpy as np -from pygac.utils import (get_absolute_azimuth_angle_diff, - centered_modulus) +from pygac.utils import centered_modulus, get_absolute_azimuth_angle_diff class TestAngles(unittest.TestCase): diff --git a/pygac/tests/test_io.py b/pygac/tests/test_io.py index df3a4cb7..1cedd798 100644 --- a/pygac/tests/test_io.py +++ b/pygac/tests/test_io.py @@ -20,12 +20,11 @@ """Test the I/O.""" import unittest -try: - import mock -except ImportError: - from unittest import mock +from unittest import mock + import numpy as np import numpy.testing + import pygac.gac_io as gac_io import pygac.utils as utils diff --git a/pygac/tests/test_pod.py b/pygac/tests/test_pod.py index 2b60ba88..0c344772 100644 --- a/pygac/tests/test_pod.py +++ b/pygac/tests/test_pod.py @@ -21,19 +21,17 @@ """Test module for the pod reading.""" import datetime as dt +import sys import unittest +from unittest import mock + import numpy as np import numpy.testing -import sys -try: - from unittest import mock -except ImportError: - import mock from pygac.clock_offsets_converter import txt as clock_offsets_txt -from pygac.reader import ReaderError, NoTLEData from pygac.gac_pod import GACPODReader from pygac.lac_pod import LACPODReader +from pygac.reader import NoTLEData, ReaderError from pygac.tests.utils import CalledWithArray diff --git a/pygac/tests/test_reader.py b/pygac/tests/test_reader.py index 0c0ea92a..35cd0d4f 100644 --- a/pygac/tests/test_reader.py +++ b/pygac/tests/test_reader.py @@ -500,11 +500,12 @@ def test_get_sat_angles_without_tle(self, get_tle_lines): [71.7390608, 71.78108857, 70.01126173, 69.99449392, 69.97770882, 69.9609375, 69.9442054, 69.92751555, 69.91086544, 61.67769951, 61.52802445]]) - self.reader._times_as_np_datetime64 = np.array([numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 15, 469000)), - numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 15, 969000)), - numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 16, 469000)), - numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 16, 969000)), - numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 17, 469000))]) + self.reader._times_as_np_datetime64 = np.array( + [numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 15, 469000)), + numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 15, 969000)), + numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 16, 469000)), + numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 16, 969000)), + numpy.datetime64(datetime.datetime(1980, 1, 3, 11, 47, 17, 469000))]) expected_sat_azi_0 = np.array([283.09872924, 283.12775589, 283.13951497, 283.14786413, 283.19638805]) expected_sat_azi_201 = np.array([272.85051989, 273.79847634, 272.04794616, 273.01363377, 274.00055397]) expected_sat_azi_408 = np.array([39.77021472, 39.71516966, 39.68104134, 39.60503726, 39.5403431]) diff --git a/pygac/tests/test_slerp.py b/pygac/tests/test_slerp.py index f2256310..f48201fd 100644 --- a/pygac/tests/test_slerp.py +++ b/pygac/tests/test_slerp.py @@ -25,9 +25,11 @@ import unittest -from pygac.slerp import slerp + import numpy as np +from pygac.slerp import slerp + class TestSlerp(unittest.TestCase): diff --git a/pygac/tests/test_tsm.py b/pygac/tests/test_tsm.py index 5a21d103..45d3fe84 100644 --- a/pygac/tests/test_tsm.py +++ b/pygac/tests/test_tsm.py @@ -21,11 +21,12 @@ """Test TSM module.""" import unittest -import pygac.correct_tsm_issue as tsm import numpy as np import numpy.testing +import pygac.correct_tsm_issue as tsm + class TSMTest(unittest.TestCase): """Test TSM module.""" diff --git a/pygac/tests/test_utils.py b/pygac/tests/test_utils.py index 3361ca12..17aca216 100644 --- a/pygac/tests/test_utils.py +++ b/pygac/tests/test_utils.py @@ -31,7 +31,7 @@ import numpy as np -from pygac.utils import file_opener, calculate_sun_earth_distance_correction +from pygac.utils import calculate_sun_earth_distance_correction, file_opener class TestUtils(unittest.TestCase): diff --git a/pygac/utils.py b/pygac/utils.py index 76a7fd9e..c283b57e 100644 --- a/pygac/utils.py +++ b/pygac/utils.py @@ -22,7 +22,6 @@ import gzip import io import logging - from contextlib import contextmanager, nullcontext import numpy as np @@ -199,9 +198,9 @@ def _slice(ch, start_line, end_line, update=None): ch_slc = ch[start_line:end_line + 1, :].copy() if update: - updated = [_update_scanline(l, start_line, end_line) - if l is not None else None - for l in update] + updated = [_update_scanline(line, start_line, end_line) + if line is not None else None + for line in update] return ch_slc, updated return ch_slc