Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/sunpy/package-template",
"commit": "75f84c4adf1753af67967930c3335bc73bca9bf5",
"commit": "51fb616094a4d7577c8898445aa50effb89afa31",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -16,7 +16,7 @@
"enable_dynamic_dev_versions": "y",
"include_example_code": "n",
"include_cruft_update_github_workflow": "y",
"use_extended_ruff_linting": "n",
"use_extended_ruff_linting": "y",
"_sphinx_theme": "sunpy",
"_parent_project": "",
"_install_requires": "",
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.7.1"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
86 changes: 53 additions & 33 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,77 @@ select = [
"E",
"F",
"W",
#"UP",
#"PT"
"UP",
"BLE",
"A",
"C4",
"INP",
"PIE",
"T20",
"PT",
"RET",
"TID",
"PTH",
"PD",
"PLC",
"PLE",
"FLY",
"NPY",
"PERF",
"RUF",
]
extend-ignore = [
"E712",
"E721",
# pycodestyle (E, W)
# pycodestyle
"E501", # ignore line length will use a formatter instead
# pyupgrade (UP)
"E712", # Avoid equality comparisons to True; use if {cond}: for truth checks
"E721", # type comparison Use is and is not for type comparisons, or isinstance() for isinstance checks
# flake8-pie
"PIE808", # explicit is better than implicit
# upgrades
"UP038", # Use | in isinstance - not compatible with models and is slower
# numpy
"NPY002", # TODO: migrate from np.random.rand to np.random.Generator
# upgrades
"UP038", # Use | in isinstance - not compatible with models and is slower
# pytest (PT)
"PT001", # Always use pytest.fixture()
"PT004", # Fixtures which don't return anything should have leading _
"PT023", # Always use () on pytest decorators
# flake8-pie (PIE)
"PT001", # Always use pytest.fixture()
"PT004", # Fixtures which don't return anything should have leading _
"PT011", # except(ValueRaises) is too broad
"PT012", # except statement is too lengthy
"PT023", # Always use () on pytest decorators
"PT023", # Always use () on pytest decorators
# flake8-pie
"PIE808", # Disallow passing 0 as the first argument to range
# flake8-use-pathlib (PTH)
# flake8-use-pathlib
"PTH123", # open() should be replaced by Path.open()
# Ruff (RUF)
# Ruff
"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
"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.
]
# Part of configuration, not a package.
"setup.py" = ["INP001"]
"conftest.py" = ["INP001"]
"docs/conf.py" = [
"E402" # Module imports not at top of file
"E402" # Module imports not at top of file
]
"docs/*.py" = [
"INP001", # File is part of an implicit namespace package.
"INP001", # Implicit-namespace-package. The examples are not a package.
]
"examples/*.py" = [
"T201", # We need print in our examples
"E501", # Line too long
"INP001", # implicit namespace package
]
"examples/**.py" = [
"ndcube/*.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
]
"__init__.py" = ["E402", "F401", "F403"]
"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"]

[lint.pydocstyle]
convention = "numpy"
11 changes: 6 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import warnings
import datetime
from pathlib import Path

from astropy.utils.exceptions import AstropyDeprecationWarning
from matplotlib import MatplotlibDeprecationWarning
Expand Down Expand Up @@ -58,7 +59,7 @@
]

# Add any paths that contain templates here, relative to this directory.
# templates_path = ["_templates"] # NOQA: ERA001
# templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -116,7 +117,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ["_static"] # NOQA: ERA001
# html_static_path = ["_static"]

# By default, when rendering docstrings for classes, sphinx.ext.autodoc will
# make docs with the class-level docstring and the class-method docstrings,
Expand Down Expand Up @@ -146,11 +147,11 @@
# -- Sphinx Gallery ---------------------------------------------------------

sphinx_gallery_conf = {
'backreferences_dir': os.path.join('generated', 'modules'),
'backreferences_dir': Path('generated/modules'),
'filename_pattern': '^((?!skip_).)*$',
'examples_dirs': os.path.join('..', 'examples'),
'examples_dirs': Path('../examples'),
'within_subsection_order': "ExampleTitleSortKey",
'gallery_dirs': os.path.join('generated', 'gallery'),
'gallery_dirs': Path('generated/gallery'),
'matplotlib_animations': True,
"default_thumb_file": png_icon,
'abort_on_example_error': False,
Expand Down
2 changes: 1 addition & 1 deletion examples/creating_even_spaced_wavelength_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# `sequence=True` causes a sequence of maps to be returned, one for each image file.
sequence_of_maps = sunpy.map.Map(aia_files, sequence=True)
# Sort the maps in the sequence in order of wavelength.
sequence_of_maps.maps = list(sorted(sequence_of_maps.maps, key=lambda m: m.wavelength))
sequence_of_maps.maps = sorted(sequence_of_maps.maps, key=lambda m: m.wavelength)

#############################################################################
# Using an `astropy.units.Quantity` of the wavelengths of the images, we can construct
Expand Down
11 changes: 10 additions & 1 deletion ndcube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
from .ndcube_sequence import NDCubeSequence, NDCubeSequenceBase
from .version import version as __version__

__all__ = ['NDCube', 'NDCubeSequence', "NDCollection", "ExtraCoords", "GlobalCoords", "ExtraCoordsABC", "GlobalCoordsABC", "NDCubeBase", "NDCubeSequenceBase", "__version__"]
__all__ = ['NDCube',
'NDCubeSequence',
"NDCollection",
"ExtraCoords",
"GlobalCoords",
"ExtraCoordsABC",
"GlobalCoordsABC",
"NDCubeBase",
"NDCubeSequenceBase",
"__version__"]
1 change: 1 addition & 0 deletions ndcube/_dev/scm_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Try to use setuptools_scm to get the current version; this is only used
# in development installations from the git repository.

from pathlib import Path

try:
Expand Down
6 changes: 2 additions & 4 deletions ndcube/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ def ndcube_2d_ln_lt_uncert(wcs_2d_lt_ln):
shape = (10, 12)
data_cube = data_nd(shape)
uncertainty = astropy.nddata.StdDevUncertainty(data_cube * 0.1)
cube = NDCube(data_cube, wcs=wcs_2d_lt_ln, uncertainty=uncertainty)
return cube
return NDCube(data_cube, wcs=wcs_2d_lt_ln, uncertainty=uncertainty)


@pytest.fixture
Expand All @@ -493,8 +492,7 @@ def ndcube_2d_ln_lt_mask_uncert(wcs_2d_lt_ln):
mask[2, 0] = True
mask[3, 3] = True
mask[4:6, :4] = True
cube = NDCube(data_cube, wcs=wcs_2d_lt_ln, uncertainty=uncertainty, mask=mask)
return cube
return NDCube(data_cube, wcs=wcs_2d_lt_ln, uncertainty=uncertainty, mask=mask)


@pytest.fixture
Expand Down
21 changes: 10 additions & 11 deletions ndcube/extra_coords/extra_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def __init__(self, ndcube=None):

# Lookup tables is a list of (pixel_dim, LookupTableCoord) to allow for
# one pixel dimension having more than one lookup coord.
self._lookup_tables = list()
self._dropped_tables = list()
self._lookup_tables = []
self._dropped_tables = []

# We need a reference to the parent NDCube
self._ndcube = ndcube
Expand Down Expand Up @@ -230,8 +230,8 @@ def add(self, name, array_dimension, lookup_table, physical_types=None, **kwargs
self._lookup_tables.append((array_dimension, coord))

# Sort the LUTs so that the mapping and the wcs are ordered in pixel dim order
self._lookup_tables = list(sorted(self._lookup_tables,
key=lambda x: x[0] if isinstance(x[0], Integral) else x[0][0]))
self._lookup_tables = sorted(self._lookup_tables,
key=lambda x: x[0] if isinstance(x[0], Integral) else x[0][0])

@property
def _name_lut_map(self):
Expand All @@ -243,7 +243,7 @@ def _name_lut_map(self):
def keys(self):
# docstring in ABC
if not self.wcs:
return tuple()
return ()

return tuple(self.wcs.world_axis_names) if self.wcs.world_axis_names else None

Expand All @@ -256,7 +256,7 @@ def mapping(self):
# If mapping is not set but lookup_tables is empty then the extra
# coords is empty, so there is no mapping.
if not self._lookup_tables:
return tuple()
return ()

# The mapping is from the array index (position in the list) to the
# pixel dimensions (numbers in the list)
Expand Down Expand Up @@ -292,7 +292,7 @@ def wcs(self):
if not self._lookup_tables:
return None

tcoords = set(lt[1] for lt in self._lookup_tables)
tcoords = {lt[1] for lt in self._lookup_tables}
# created a sorted list of unique items
_tmp = set() # a temporary set
tcoords = [x[1] for x in self._lookup_tables if x[1] not in _tmp and _tmp.add(x[1]) is None]
Expand Down Expand Up @@ -323,8 +323,7 @@ def is_empty(self):
# docstring in ABC
if not self._wcs and not self._lookup_tables:
return True
else:
return False
return False

def _getitem_string(self, item):
"""
Expand Down Expand Up @@ -402,7 +401,7 @@ def __getitem__(self, item):
if self._wcs:
return self._getitem_wcs(item)

elif self._lookup_tables:
if self._lookup_tables:
return self._getitem_lookup_tables(item)

# If we get here this object is empty, so just return an empty extra coords
Expand All @@ -425,7 +424,7 @@ def dropped_world_dimensions(self):

return mtc.dropped_world_dimensions

return dict()
return {}

def resample(self, factor, offset=0, ndcube=None, **kwargs):
"""
Expand Down
Loading