diff --git a/.editorconfig b/.editorconfig index 00ec98a..6a0a2a2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,6 +13,6 @@ trim_trailing_whitespace = true indent_style = space indent_size = 4 -[*.yml] +[*.{yaml,yml,toml}] indent_style = space indent_size = 2 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 38db7b3..0000000 --- a/.flake8 +++ /dev/null @@ -1,27 +0,0 @@ -[flake8] -ignore = - # missing-whitespace-around-operator - E225 - # missing-whitespace-around-arithmetic-operator - E226 - # line-too-long - E501 - # unused-import - F401 - # undefined-local-with-import-star - F403 - # redefined-while-unused - F811 - # Line break occurred before a binary operator - W503, - # Line break occurred after a binary operator - W504 -max-line-length = 110 -exclude = - .git - __pycache__ - docs/conf.py - build - radiospectra/__init__.py -rst-directives = - plot diff --git a/.isort.cfg b/.isort.cfg index 3db949c..409b636 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -10,7 +10,7 @@ known_sunpy = sunpy known_first_party = radiospectra length_sort = false length_sort_sections = stdlib -line_length = 110 +line_length = 120 multi_line_output = 3 no_lines_before = LOCALFOLDER sections = STDLIB, THIRDPARTY, ASTROPY, SUNPY, FIRSTPARTY, LOCALFOLDER diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ca8855..a16957e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,13 @@ repos: # This should be before any formatting hooks like isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.14.14" + rev: "v0.15.2" hooks: - - id: ruff + - id: ruff-check args: ["--fix"] + - id: ruff-format - repo: https://github.com/PyCQA/isort - rev: 7.0.0 + rev: 8.0.0 hooks: - id: isort exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|radiospectra/extern)$" diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 4f38fb2..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 2 -build: - os: ubuntu-20.04 - tools: - python: "3.12" - apt_packages: - - graphviz - -sphinx: - builder: html - configuration: docs/conf.py - fail_on_warning: false - -python: - install: - - method: pip - extra_requirements: - - all - - docs - path: . diff --git a/docs/conf.py b/docs/conf.py index 0b7c6ef..44427a1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -36,7 +36,7 @@ elif _version.is_devrelease: version = release = f"{_version.base_version}.dev{_version.dev}" is_development = _version.is_devrelease -is_release = not(_version.is_prerelease or _version.is_devrelease) +is_release = not (_version.is_prerelease or _version.is_devrelease) project = "radiospectra" author = "The SunPy Community" diff --git a/pyproject.toml b/pyproject.toml index f446710..c0e80f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,27 +59,6 @@ exclude = ["radiospectra._dev*"] [tool.setuptools_scm] version_file = "radiospectra/_version.py" -[tool.black] -line-length = 120 -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs - | \.git - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - | docs - | .history - )/ -) -''' - [tool.gilesbot] [tool.gilesbot.pull_requests] enabled = true diff --git a/radiospectra/__init__.py b/radiospectra/__init__.py index d4ced70..43efbbb 100644 --- a/radiospectra/__init__.py +++ b/radiospectra/__init__.py @@ -1,4 +1,3 @@ - from .version import version as __version__ __all__ = ["__version__"] diff --git a/radiospectra/_dev/scm_version.py b/radiospectra/_dev/scm_version.py index 988debf..d0c4c1f 100644 --- a/radiospectra/_dev/scm_version.py +++ b/radiospectra/_dev/scm_version.py @@ -5,8 +5,8 @@ try: from setuptools_scm import get_version - version = get_version(root=Path('../..'), relative_to=__file__) + version = get_version(root=Path("../.."), relative_to=__file__) except ImportError: raise except Exception as e: - raise ValueError('setuptools_scm can not determine version.') from e + raise ValueError("setuptools_scm can not determine version.") from e diff --git a/radiospectra/net/sources/eovsa.py b/radiospectra/net/sources/eovsa.py index 87fcc68..bc38b68 100644 --- a/radiospectra/net/sources/eovsa.py +++ b/radiospectra/net/sources/eovsa.py @@ -26,10 +26,14 @@ class EOVSAClient(GenericClient): """ + from sunpy import __version__ + if __version__ >= "6.1.0": - pattern = ("https://ovsa.njit.edu/fits/synoptic/{{year:4d}}/{{month:2d}}/{{day:2d}}/" - "EOVSA_{{PolType:5l}}_{{year:4d}}{{month:2d}}{{day:2d}}.fts") + pattern = ( + "https://ovsa.njit.edu/fits/synoptic/{{year:4d}}/{{month:2d}}/{{day:2d}}/" + "EOVSA_{{PolType:5l}}_{{year:4d}}{{month:2d}}{{day:2d}}.fts" + ) else: baseurl = "https://ovsa.njit.edu/fits/synoptic/%Y/%m/%d/EOVSA_.*_%Y%m%d.fts" pattern = "{}/synoptic/{year:4d}/{month:2d}/{day:2d}/EOVSA_{PolType:5l}_{year:4d}{month:2d}{day:2d}.fts" diff --git a/radiospectra/net/sources/tests/test_ilofar.py b/radiospectra/net/sources/tests/test_ilofar.py index ecae79d..4b14b72 100644 --- a/radiospectra/net/sources/tests/test_ilofar.py +++ b/radiospectra/net/sources/tests/test_ilofar.py @@ -61,7 +61,7 @@ def test_ilofar_client_polarisation(mock_urlopen, client, html_responses): assert query_x[0]["Source"] == "ILOFAR" assert query_x[0]["Provider"] == "ILOFAR" assert query_x[0]["Start Time"].iso == "2018-06-01 10:00:41.000" - assert query_x[0]["Polarisation"] =='X' + assert query_x[0]["Polarisation"] == "X" @mock.patch("sunpy.net.scraper.urlopen") diff --git a/radiospectra/net/sources/tests/test_psp_client.py b/radiospectra/net/sources/tests/test_psp_client.py index 493d40e..e8dfe96 100644 --- a/radiospectra/net/sources/tests/test_psp_client.py +++ b/radiospectra/net/sources/tests/test_psp_client.py @@ -91,8 +91,8 @@ def test_search_with_wavelength(mock_urlopen, client, http_responces): @pytest.mark.remote_data def test_get_url_for_time_range(client): - url_start = "https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/rfs_lfr/2019/" "psp_fld_l2_rfs_lfr_20191001_v03.cdf" - url_end = "https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/rfs_hfr/2019/" "psp_fld_l2_rfs_hfr_20191015_v03.cdf" + url_start = "https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/rfs_lfr/2019/psp_fld_l2_rfs_lfr_20191001_v03.cdf" + url_end = "https://spdf.gsfc.nasa.gov/pub/data/psp/fields/l2/rfs_hfr/2019/psp_fld_l2_rfs_hfr_20191015_v03.cdf" tr = a.Time("2019/10/01", "2019/10/15") res = client.search(tr) urls = [i["url"] for i in res] diff --git a/radiospectra/spectrogram/sources/tests/test_solo_rpw.py b/radiospectra/spectrogram/sources/tests/test_solo_rpw.py index 5858def..a041830 100644 --- a/radiospectra/spectrogram/sources/tests/test_solo_rpw.py +++ b/radiospectra/spectrogram/sources/tests/test_solo_rpw.py @@ -17,7 +17,7 @@ def test_solo_rpw_tnr(parse_path_moc): start_time = Time("2024-03-23 00:00:00.000") end_time = Time("2024-03-24 00:00:00.000") - + # fmt: off meta = { "cdf_meta": { "Project": "SOLO>Solar Orbiter", @@ -51,7 +51,7 @@ def test_solo_rpw_tnr(parse_path_moc): 634525, 662618, 691955, 722590, 754582, 787990, 822878, 859310, 897355, 937084, 978572]) * u.Hz, } - + # fmt: on array = np.zeros((128, 7322)) parse_path_moc.return_value = [(array, meta)] @@ -74,6 +74,7 @@ def test_solo_rpw_hfr(parse_path_moc): start_time = Time("2024-03-23 00:00:00.000") end_time = Time("2024-03-24 00:00:00.000") + # fmt: off meta = { "cdf_meta": { "Project": "SOLO>Solar Orbiter", @@ -100,7 +101,7 @@ def test_solo_rpw_hfr(parse_path_moc): 13375000, 13725000, 14375000, 14925000, 15275000, 15625000, 16075000, 16325000]) * u.Hz, } - + # fmt: on array = np.zeros((50, 16499)) parse_path_moc.return_value = [(array, meta)] diff --git a/radiospectra/spectrogram/spectrogram_factory.py b/radiospectra/spectrogram/spectrogram_factory.py index f3d8b0b..b233878 100644 --- a/radiospectra/spectrogram/spectrogram_factory.py +++ b/radiospectra/spectrogram/spectrogram_factory.py @@ -441,24 +441,21 @@ def _read_cdf(file): "freqs": freqs, } return data, meta - elif ("SOLO" in cdf_globals.get("Project", "")[0]): + elif "SOLO" in cdf_globals.get("Project", "")[0]: data_type = cdf_globals.get("Data_type", [""])[0] data_descriptor = cdf_globals.get("Descriptor", "")[0] - if ("RPW-HFR-SURV" not in data_descriptor - and "RPW-TNR-SURV-FLUX" not in data_descriptor): - raise ValueError( - f"Currently radiospectra supports Level 2 HFR survey data " - "and Level 3 HFR, TNR survey data the file " - f'{file.name} is {cdf_globals.get("Logical_source_description", [""])[0]}' - ) - if("L3" in data_type): + if "RPW-HFR-SURV" not in data_descriptor and "RPW-TNR-SURV-FLUX" not in data_descriptor: + raise ValueError( + f"Currently radiospectra supports Level 2 HFR survey data " + "and Level 3 HFR, TNR survey data the file " + f"{file.name} is {cdf_globals.get('Logical_source_description', [''])[0]}" + ) + if "L3" in data_type: epoch = cdf.varget("Epoch") times = Time("J2000.0") + epoch * u.ns - freqs = cdf.varget("FREQUENCY") << u.Unit( - cdf.varattsget("FREQUENCY")["UNITS"] - ) + freqs = cdf.varget("FREQUENCY") << u.Unit(cdf.varattsget("FREQUENCY")["UNITS"]) data = cdf.varget("PSD_SFU") - data = np.squeeze(data).T << sfu + data = np.squeeze(data).T << sfu detector = cdf_globals.get("Instrument", [""])[0].split(">")[0] meta = { "cdf_globals": cdf_globals, diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..d85cae4 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,79 @@ +target-version = "py312" +line-length = 120 +exclude = [ + ".git,", + "__pycache__", + "build", + "radiospectra/version.py", +] + +[lint] +select = [ + "E", + "F", + "W", + "UP", + "PT", + "BLE", + "A", + "C4", + "INP", + "PIE", + "T20", + "RET", + "TID", + "PTH", + "PD", + "PLC", + "PLE", + "FLY", + "NPY", + "PERF", + "RUF", +] +extend-ignore = [ + # pycodestyle (E, W) + "E501", # ignore line length will use a formatter instead + # pytest (PT) + "PT001", # Always use pytest.fixture() + "PT023", # Always use () on pytest decorators + # flake8-pie (PIE) + "PIE808", # Disallow passing 0 as the first argument to range + # flake8-use-pathlib (PTH) + "PTH123", # open() should be replaced by Path.open() + # Ruff (RUF) + "RUF003", # Ignore ambiguous quote marks, doesn't allow ' in comments + "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + "RUF013", # PEP 484 prohibits implicit `Optional` + "RUF015", # Prefer `next(iter(...))` over single element slice +] + +[lint.per-file-ignores] +"setup.py" = [ + "INP001", # File is part of an implicit namespace package. +] +"conftest.py" = [ + "INP001", # File is part of an implicit namespace package. +] +"docs/conf.py" = [ + "E402" # Module imports not at top of file +] +"docs/*.py" = [ + "INP001", # File is part of an implicit namespace package. +] +"examples/**.py" = [ + "T201", # allow use of print in examples + "INP001", # File is part of an implicit namespace package. +] +"__init__.py" = [ + "E402", # Module level import not at top of cell + "F401", # Unused import + "F403", # from {name} import * used; unable to detect undefined names + "F405", # {name} may be undefined, or defined from star imports +] +"test_*.py" = [ + "E402", # Module level import not at top of cell +] + +[lint.pydocstyle] +convention = "numpy"