Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 22 additions & 4 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,37 @@ select = [
"E",
"F",
"W",
#"UP",
#"PT"
"UP",
"PT",
"BLE",
"A",
"C4",
"INP",
"PIE",
"T20",
"RET",
"TID",
"PTH",
"PD",
"PLC",
"PLE",
"FLY",
"NPY",
"PERF",
"RUF",
]
extend-ignore = [
"E712",
"E721",
# pycodestyle (E, W)
"E501", # ignore line length will use a formatter instead
# pyupgrade (UP)
"UP038", # Use | in isinstance - not compatible with models and is slower
# numpy
"NPY002", # TODO: migrate from np.random.rand to np.random.Generator
# pytest (PT)
"PT001", # Always use pytest.fixture()
"PT004", # Fixtures which don't return anything should have leading _
"PT011", # TODO: except(ValueRaises) is too broad
"PT012", # TODO: except statement is too lengthy
"PT023", # Always use () on pytest decorators
# flake8-pie (PIE)
"PIE808", # Disallow passing 0 as the first argument to range
Expand Down
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
17 changes: 15 additions & 2 deletions ndcube/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
======
ndcube
======

A base package for multi-dimensional contiguous and non-contiguous coordinate-aware arrays.
A package for multi-dimensional contiguous and non-contiguous coordinate-aware arrays.

* Homepage: https://github.com/sunpy/ndcube
* Documentation: https://docs.sunpy.org/projects/ndcube/
Expand All @@ -14,4 +15,16 @@
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__",
]
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