Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
rev: "v0.6.9"
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--unsafe-fixes"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
Expand Down
89 changes: 54 additions & 35 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
target-version = "py310"
line-length = 110
exclude = [
".git,",
"__pycache__",
"build",
"ndcube/version.py",
# Allow unused variables when underscore-prefixed.
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py312"
line-length = 120
extend-exclude=[
"__pycache__",
"build",
"tools/**",
]

[lint]
select = [
"E",
"F",
"W",
#"UP",
#"PT"
]
extend-ignore = [
"E712",
"E721",
# pycodestyle (E, W)
"E501", # LineTooLong # TODO! fix
# pytest (PT)
"PT001", # Always use pytest.fixture()
"PT004", # Fixtures which don't return anything should have leading _
"PT007", # Parametrize should be lists of tuples # TODO! fix
"PT011", # Too broad exception assert # TODO! fix
"PT023", # Always use () on pytest decorators
lint.select = [
"ALL",
]
lint.ignore = [
"ANN",
]
lint.extend-ignore = [
"ANN", # All annotation
"COM812", # May cause conflicts when used with the formatter
"CPY001", # Missing copyright notice at top of file
"D200", # One-line docstring should fit on one line
"D205", # 1 blank line required between summary line and description
"D400", # First line should end with a period
"D401", # First line should be in imperative mood
"D404", # First word of the docstring should not be "This"
"E501", # Line too long
"FIX002", # Line contains TODO, consider resolving the issue
"TD003", # Missing issue link on the line following this TODO
"TD002", # Missing author in TODO
"ISC001", # May cause conflicts when used with the formatter
"PLC0415", # `import` should be at the top-level of a file"
"PLR2004", # Magic value used in comparison
"S101", # Use of `assert` detected
]

[lint.per-file-ignores]
# Part of configuration, not a package.
"setup.py" = ["INP001"]
"conftest.py" = ["INP001"]
"examples/*.py" = [
"B018", # Not print but display
"D400", # First line should end with a period, question mark, or exclamation point
"ERA001", # Commented out code
"INP001", # Implicit namespace package
"T201", # Use print
]
"docs/conf.py" = [
"E402" # Module imports not at top of file
"INP001", # conf.py is part of an implicit namespace package
]
"docs/*.py" = [
"INP001", # Implicit-namespace-package. The examples are not a package.
"test_*.py" = [
"D", # All docs
"SLF001", # Access private memeber
]
"__init__.py" = [
"D104", # Missing docstring in public package
]
"conftest.py" = [
"D100", # Missing docstring in public module
"D103", # Missing docstring in public function
]
"__init__.py" = ["E402", "F401", "F403"]
"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"]

[lint.pydocstyle]
convention = "numpy"

[format]
docstring-code-format = true
indent-style = "space"
quote-style = "double"
88 changes: 44 additions & 44 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#
# Configuration file for the Sphinx documentation builder.
import datetime
import os
import warnings
import datetime

from astropy.utils.exceptions import AstropyDeprecationWarning
from matplotlib import MatplotlibDeprecationWarning
from packaging.version import Version

# -- Read the Docs Specific Configuration ------------------------------------
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if on_rtd:
os.environ['HIDE_PARFIVE_PROGESS'] = 'True'
os.environ["HIDE_PARFIVE_PROGESS"] = "True"

# -- Project information -----------------------------------------------------

Expand All @@ -31,29 +31,29 @@

project = "ndcube"
author = "The SunPy Community"
copyright = f'{datetime.datetime.now().year}, {author}' # noqa: A001
copyright = f"{datetime.datetime.now().year}, {author}" # noqa: A001

warnings.filterwarnings("error", category=MatplotlibDeprecationWarning)
warnings.filterwarnings("error", category=AstropyDeprecationWarning)

# -- General configuration ---------------------------------------------------

extensions = [
'matplotlib.sphinxext.plot_directive',
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.doctest',
'sphinx.ext.mathjax',
'sphinx_automodapi.automodapi',
'sphinx_automodapi.smart_resolver',
'ndcube.utils.sphinx.code_context',
'sphinx_changelog',
'sphinx_gallery.gen_gallery',
"matplotlib.sphinxext.plot_directive",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.inheritance_diagram",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.doctest",
"sphinx.ext.mathjax",
"sphinx_automodapi.automodapi",
"sphinx_automodapi.smart_resolver",
"ndcube.utils.sphinx.code_context",
"sphinx_changelog",
"sphinx_gallery.gen_gallery",
"sphinxext.opengraph",
]

Expand All @@ -78,17 +78,17 @@
# -- Options for intersphinx extension ---------------------------------------

intersphinx_mapping = {
'python': ('https://docs.python.org/3/',
(None, 'http://data.astropy.org/intersphinx/python3.inv')),
'numpy': ('https://docs.scipy.org/doc/numpy/',
(None, 'http://data.astropy.org/intersphinx/numpy.inv')),
'matplotlib': ('https://matplotlib.org/',
(None, 'http://data.astropy.org/intersphinx/matplotlib.inv')),
'astropy': ('http://docs.astropy.org/en/stable/', None),
'sunpy': ('https://docs.sunpy.org/en/stable/', None),
'mpl_animators': ('https://docs.sunpy.org/projects/mpl-animators/en/stable/', None),
'gwcs': ('https://gwcs.readthedocs.io/en/stable/', None),
'reproject': ("https://reproject.readthedocs.io/en/stable/", None)
"python": ("https://docs.python.org/3/",
(None, "http://data.astropy.org/intersphinx/python3.inv")),
"numpy": ("https://docs.scipy.org/doc/numpy/",
(None, "http://data.astropy.org/intersphinx/numpy.inv")),
"matplotlib": ("https://matplotlib.org/",
(None, "http://data.astropy.org/intersphinx/matplotlib.inv")),
"astropy": ("http://docs.astropy.org/en/stable/", None),
"sunpy": ("https://docs.sunpy.org/en/stable/", None),
"mpl_animators": ("https://docs.sunpy.org/projects/mpl-animators/en/stable/", None),
"gwcs": ("https://gwcs.readthedocs.io/en/stable/", None),
"reproject": ("https://reproject.readthedocs.io/en/stable/", None),
}

# -- Options for HTML output -------------------------------------------------
Expand All @@ -97,9 +97,9 @@
# a list of builtin themes.
html_theme = "sunpy"

html_logo = png_icon = 'logo/ndcube.png'
html_logo = png_icon = "logo/ndcube.png"

html_favicon = 'logo/favicon.png'
html_favicon = "logo/favicon.png"

# Render inheritance diagrams in SVG
graphviz_output_format = "svg"
Expand Down Expand Up @@ -136,7 +136,7 @@
nitpicky = True
# This is not used. See docs/nitpick-exceptions file for the actual listing.
nitpick_ignore = []
for line in open('nitpick-exceptions'):
for line in open("nitpick-exceptions"):
if line.strip() == "" or line.startswith("#"):
continue
dtype, target = line.split(None, 1)
Expand All @@ -146,18 +146,18 @@
# -- Sphinx Gallery ---------------------------------------------------------

sphinx_gallery_conf = {
'backreferences_dir': os.path.join('generated', 'modules'),
'filename_pattern': '^((?!skip_).)*$',
'examples_dirs': os.path.join('..', 'examples'),
'within_subsection_order': "ExampleTitleSortKey",
'gallery_dirs': os.path.join('generated', 'gallery'),
'matplotlib_animations': True,
"backreferences_dir": os.path.join("generated", "modules"),
"filename_pattern": "^((?!skip_).)*$",
"examples_dirs": os.path.join("..", "examples"),
"within_subsection_order": "ExampleTitleSortKey",
"gallery_dirs": os.path.join("generated", "gallery"),
"matplotlib_animations": True,
"default_thumb_file": png_icon,
'abort_on_example_error': False,
'plot_gallery': 'True',
'remove_config_comments': True,
'doc_module': ('ndcube'),
'only_warn_on_example_error': True,
"abort_on_example_error": False,
"plot_gallery": "True",
"remove_config_comments": True,
"doc_module": ("ndcube"),
"only_warn_on_example_error": True,
}

# -- Sphinxext Opengraph ----------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions examples/creating_a_gwcs_from_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
# We aim to create coordinates that are focused around time and energies using astropy quantities.

energy = np.arange(10) * u.keV
time = Time('2020-01-01 00:00:00') + np.arange(9)*u.s
time = Time("2020-01-01 00:00:00") + np.arange(9)*u.s

##############################################################################
# Then, we need to turn these into lookup tables using
# `~ndcube.extra_coords.table_coord.QuantityTableCoordinate` and
# `~ndcube.extra_coords.table_coord.TimeTableCoordinate` to create table coordinates.

energy_coord = QuantityTableCoordinate(energy, names='energy', physical_types='em.energy')
energy_coord = QuantityTableCoordinate(energy, names="energy", physical_types="em.energy")
print(energy_coord)

time_coord = TimeTableCoordinate(time, names='time', physical_types='time')
time_coord = TimeTableCoordinate(time, names="time", physical_types="time")
print(time_coord)

##############################################################################
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -55,6 +55,6 @@

my_cube = NDCube(sequence_of_maps.as_array(), wcs=cube_wcs)
# Produce an interactive plot of the spectral-image stack.
my_cube.plot(plot_axes=['y', 'x', None])
my_cube.plot(plot_axes=["y", "x", None])

plt.show()
2 changes: 1 addition & 1 deletion examples/creating_ndcube_from_fitsfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# `~ndcube.NDCube` from data stored in a FITS file.
# Here we are using an example file from ``astropy``.

image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
image_file = get_pkg_data_filename("tutorials/FITS-images/HorseHead.fits")

###########################################################################
# Lets extract the image data and the header information from the FITS file.
Expand Down
10 changes: 5 additions & 5 deletions examples/dev/example_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
plt.figure()
plt.imshow(z)
plt.colorbar()
plt.xlabel('$x$')
plt.ylabel('$y$')
plt.xlabel("$x$")
plt.ylabel("$y$")

###########################################################################
# Again it is possible to continue the discussion with a new Python string. This
# time to introduce the next code block generates 2 separate figures.

plt.figure()
plt.imshow(z, cmap=plt.cm.get_cmap('hot'))
plt.imshow(z, cmap=plt.cm.get_cmap("hot"))
plt.figure()
plt.imshow(z, cmap=plt.cm.get_cmap('Spectral'), interpolation='none')
plt.imshow(z, cmap=plt.cm.get_cmap("Spectral"), interpolation="none")

##########################################################################
# There's some subtle differences between rendered html rendered comment
Expand All @@ -70,7 +70,7 @@ def dummy():
############################################################################
# Output of the script is captured:

print('Some output from Python')
print("Some output from Python")

############################################################################
# Finally, I'll call ``show`` at the end just so someone running the Python
Expand Down
6 changes: 3 additions & 3 deletions examples/slicing_ndcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
data = np.random.rand(5, 45, 45)
# Define the WCS
wcs = astropy.wcs.WCS(naxis=3)
wcs.wcs.ctype = 'HPLT-TAN', 'HPLN-TAN', "WAVE"
wcs.wcs.cunit = 'arcsec', 'arcsec', 'Angstrom'
wcs.wcs.ctype = "HPLT-TAN", "HPLN-TAN", "WAVE"
wcs.wcs.cunit = "arcsec", "arcsec", "Angstrom"
wcs.wcs.cdelt = 10, 10, 0.2
wcs.wcs.crpix = 2, 2, 0
wcs.wcs.crval = 1, 1, 10
wcs.wcs.cname = 'HPC lat', 'HPC lon', 'wavelength'
wcs.wcs.cname = "HPC lat", "HPC lon", "wavelength"
# Instantiate the `~ndcube.NDCube`
example_cube = NDCube(data, wcs=wcs)

Expand Down
2 changes: 1 addition & 1 deletion ndcube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
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__"]
5 changes: 3 additions & 2 deletions ndcube/_dev/scm_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
try:
from setuptools_scm import get_version

version = get_version(root=os.path.join('..', '..'), relative_to=__file__)
version = get_version(root=os.path.join("..", ".."), relative_to=__file__)
except ImportError:
raise
except Exception as e:
raise ValueError('setuptools_scm can not determine version.') from e
msg = "setuptools_scm can not determine version."
raise ValueError(msg) from e
Loading