Skip to content

Commit

Permalink
tidy up for release (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil Freij authored May 24, 2022
1 parent 1701c96 commit 68f8de3
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
jobname:
type: string
docker:
- image: circleci/python:3.8
- image: cimg/python:3.9
environment:
TOXENV=<< parameters.jobname >>
steps:
Expand All @@ -55,7 +55,7 @@ jobs:
jobname:
type: string
docker:
- image: circleci/python:3.8
- image: cimg/python:3.9
environment:
TOXENV: << parameters.jobname >>
GIT_SSH_COMMAND: ssh -i ~/.ssh/id_rsa_6464b6a8248237ca368fd4690777d921
Expand Down
45 changes: 25 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
ci:
autofix_prs: false
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/myint/docformatter
rev: v1.4
hooks:
- id: black
- repo: https://github.com/myint/autoflake
- id: docformatter
args: [--in-place, --pre-summary-newline, --make-summary-multi]
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|__init__.py|docs/conf.py)$"
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
args: ['--sp','setup.cfg']
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|docs/conf.py)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
exclude: ".*(.fits|.fts|.fit|.txt)$"
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$"

ci:
autofix_prs: false
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.4.2 (2022-05-24)
==================

Breaking Changes
----------------

- Minimum version of ``sunpy`` required is now 4.0.0

0.4.1 (2022-04-05)
==================

Expand Down
10 changes: 5 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ stages:
apt:
- graphviz
envs:
- macos: py37
- windows: py38
- macos: py38
- windows: py39
- linux: build_docs
posargs: " "
pytest: false
- linux: py39-online
- linux: py37-oldestdeps
- linux: py39-conda
libraries: {}
- linux: py38-oldestdeps

- ${{ if or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.Reason'], 'Manual')) }}:
- stage: CronTests
Expand All @@ -81,6 +79,8 @@ stages:
toxdeps: tox-pypi-filter
envs:
- linux: py310-devdeps
- linux: py39-conda
libraries: {}

# On branches which aren't main, and not Pull Requests, build the wheels but only upload them on tags
- ${{ if and(ne(variables['Build.Reason'], 'PullRequest'), or(ne(variables['Build.SourceBranchName'], 'main'), eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.Reason'], 'Manual'))) }}:
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Configuration file for the Sphinx documentation builder.
isort:skip_file
"""
# flake8: NOQA: E402
Expand Down
4 changes: 1 addition & 3 deletions examples/tracing_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
# The base flux and median flux ratio ``qthresh1`` is 0.0.
# The noise threshold in the image with repect to median flux ``qthresh2`` is 3.0 .
# For the meaning of these parameters please consult the OCCULT2 article.
loops = trace.occult2(
trace_map.data, nsm1=3, rmin=30, lmin=25, nstruc=1000, ngap=0, qthresh1=0.0, qthresh2=3.0
)
loops = trace.occult2(trace_map.data, nsm1=3, rmin=30, lmin=25, nstruc=1000, ngap=0, qthresh1=0.0, qthresh2=3.0)

###############################################################################
# `~sunkit_image.trace.occult2` returns a list, each element of which is a detected loop.
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
requires = [
"extension-helpers",
"oldest-supported-numpy",
"setuptools_scm",
"setuptools",
"setuptools>=56,!=61.0.0",
"setuptools_scm[toml]>=6.2",
"wheel",
]
build-backend = 'setuptools.build_meta'

[tool.black]
line-length = 110
line-length = 120
include = '\.pyi?$'
exclude = '''
(
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering :: Physics

[options]
python_requires = >=3.7
python_requires = >=3.8
packages = find:
include_package_data = True
setup_requires =
setuptools_scm
install_requires =
scikit-image>=0.18.0
sunpy>=3.0.0
sunpy>=4.0.0

[options.extras_require]
tests =
Expand Down
4 changes: 1 addition & 3 deletions sunkit_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class UnsupportedPythonError(Exception):

if sys.version_info < tuple(int(val) for val in __minimum_python_version__.split(".")):
# This has to be .format to keep backwards compatibly.
raise UnsupportedPythonError(
"sunkit_image does not support Python < {}".format(__minimum_python_version__)
)
raise UnsupportedPythonError("sunkit_image does not support Python < {}".format(__minimum_python_version__))

__all__ = []
5 changes: 3 additions & 2 deletions sunkit_image/_dev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This package contains utilities that are only used when developing sunkit_image in a
copy of the source repository.
This package contains utilities that are only used when developing sunkit_image
in a copy of the source repository.
These files are not installed, and should not be assumed to exist at
runtime.
"""
4 changes: 1 addition & 3 deletions sunkit_image/asda.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ def gamma_values(self):
vel = self.gen_vel(index[1], index[0])
# Iterate over the array gamma
for d, (i, j) in enumerate(
product(
np.arange(self.r, self.dshape[0] - self.r, 1), np.arange(self.r, self.dshape[1] - self.r, 1)
)
product(np.arange(self.r, self.dshape[0] - self.r, 1), np.arange(self.r, self.dshape[1] - self.r, 1))
):
self.gamma[i, j, 0], self.gamma[i, j, 1] = calc_gamma(pm, vel[..., d], pnorm, N)
# Transpose back vx & vy
Expand Down
19 changes: 8 additions & 11 deletions sunkit_image/coalignment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module provides routines for the co-alignment of images and
`~sunpy.map.mapsequence.MapSequence` objects through both template
matching and corrections due to solar rotation.
`~sunpy.map.mapsequence.MapSequence` objects through both template matching and
corrections due to solar rotation.
"""
import warnings
from copy import deepcopy
Expand Down Expand Up @@ -101,9 +101,7 @@ def clip_edges(data, yclips: u.pix, xclips: u.pix):
nx = data.shape[1]
# The purpose of the int below is to ensure integer type since by default
# astropy quantities are converted to floats.
return data[
int(yclips[0].value) : ny - int(yclips[1].value), int(xclips[0].value) : nx - int(xclips[1].value)
]
return data[int(yclips[0].value) : ny - int(yclips[1].value), int(xclips[0].value) : nx - int(xclips[1].value)]


@u.quantity_input
Expand Down Expand Up @@ -291,7 +289,8 @@ def parabolic_turning_point(y):

def check_for_nonfinite_entries(layer_image, template_image):
"""
Issue a warning if there is any nonfinite entry in the layer or template images.
Issue a warning if there is any nonfinite entry in the layer or template
images.
Parameters
----------
Expand Down Expand Up @@ -579,8 +578,8 @@ def mapsequence_coalign_by_match_template(

def calculate_solar_rotate_shift(mc, layer_index=0, **kwargs):
"""
Calculate the shift that must be applied to each map contained in a mapsequence
in order to compensate for solar rotation.
Calculate the shift that must be applied to each map contained in a
mapsequence in order to compensate for solar rotation.
The center of the map is used to calculate the position of each mapsequence
layer. Shifts are calculated relative to a specified layer in the mapsequence.
Expand Down Expand Up @@ -627,9 +626,7 @@ def calculate_solar_rotate_shift(mc, layer_index=0, **kwargs):
# Calculate the rotation of the center of the map 'm' at its
# observation time to the observation time of the reference layer
# indicated by "layer_index".
new_coordinate = solar_rotate_coordinate(
m.center, observer=rotate_to_this_layer.observer_coordinate, **kwargs
)
new_coordinate = solar_rotate_coordinate(m.center, observer=rotate_to_this_layer.observer_coordinate, **kwargs)

xshift_arcseconds[i] = new_coordinate.Tx - rotate_to_this_layer.center.Tx
yshift_arcseconds[i] = new_coordinate.Ty - rotate_to_this_layer.center.Ty
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sunkit_image.tests.test_enhance.test_mgn": "ab39d3330a967a6f34fb53043aa820665e87c4a73002381883b9516d2983228d",
"sunkit_image.tests.test_radial.test_fig_nrgf": "a0efb4aa94724bf1b2ff97466decb6edcc1394c704315f5b16dbf458d9c1df84",
"sunkit_image.tests.test_radial.test_fig_fnrgf": "4a653738b96abebac537ebba5aadedce02f3c03dd13cf12de836600c800a650e",
"sunkit_image.tests.test_trace.test_occult2_fig": "c5ff1416cb51dc51ad1705174e5b13f8cb02486dc3c58fd79dc1b80534f6caf5"
}
6 changes: 3 additions & 3 deletions sunkit_image/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def get_hash_library_name():
def figure_test(test_function):
"""
A decorator which marks the test as comparing the hash of the returned
figure to the hash library in the repository.
A `matplotlib.figure.Figure` object should be returned or ``plt.gcf()``
will be called to get the figure object to compare to.
figure to the hash library in the repository. A `matplotlib.figure.Figure`
object should be returned or ``plt.gcf()`` will be called to get the figure
object to compare to.
Examples
--------
Expand Down
8 changes: 2 additions & 6 deletions sunkit_image/tests/test_asda.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ def test_asda_artificial():
with pytest.raises(ValueError, match="Keyword 'factor' must be an integer"):
lo = asda.Lamb_Oseen(vmax=vmax, rmax=rmax, ratio_vradial=ratio, factor=1.2, r=1)

with pytest.warns(
UserWarning, match="One of the input parameters is missing," + "setting both to 'None'"
):
with pytest.warns(UserWarning, match="One of the input parameters is missing," + "setting both to 'None'"):
lo = asda.Lamb_Oseen(vmax=vmax, rmax=rmax, gamma=0.5, ratio_vradial=ratio, factor=1)

lo = asda.Lamb_Oseen(vmax=vmax, rmax=rmax, ratio_vradial=ratio, factor=1)
# Generate vx and vy
with pytest.warns(
UserWarning, match="One of the input parameters is missing, setting " + " both to 'None'"
):
with pytest.warns(UserWarning, match="One of the input parameters is missing, setting " + " both to 'None'"):
vx, vy = lo.get_vxvy(x_range=[-100, 100, 200], y_range=[-100, 100, 200], x=np.meshgrid)

vx, vy = lo.get_vxvy(x_range=[-100, 100, 200], y_range=[-100, 100, 200])
Expand Down
42 changes: 11 additions & 31 deletions sunkit_image/tests/test_coalignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,12 @@ def test_check_for_nonfinite_entries():
a[i] = non_number
b = a.reshape(3, 3)

with pytest.warns(
SunpyUserWarning, match="The layer image has nonfinite entries."
) as warning_list:
with pytest.warns(SunpyUserWarning, match="The layer image has nonfinite entries.") as warning_list:
check_for_nonfinite_entries(b, np.ones((3, 3)))

assert len(warning_list) == 1

with pytest.warns(
SunpyUserWarning, match="The template image has nonfinite entries."
) as warning_list:
with pytest.warns(SunpyUserWarning, match="The template image has nonfinite entries.") as warning_list:
check_for_nonfinite_entries(np.ones((3, 3)), b)

assert len(warning_list) == 1
Expand Down Expand Up @@ -162,9 +158,7 @@ def test_find_best_match_location(aia171_test_map_layer, aia171_test_template, a

result = match_template_to_layer(aia171_test_map_layer, aia171_test_template)
match_location = u.Quantity(find_best_match_location(result))
assert_allclose(
match_location.value, np.array(result.shape) / 2.0 - 0.5 + aia171_test_shift, rtol=1e-3, atol=0
)
assert_allclose(match_location.value, np.array(result.shape) / 2.0 - 0.5 + aia171_test_shift, rtol=1e-3, atol=0)


def test_lower_clip(aia171_test_clipping):
Expand Down Expand Up @@ -214,10 +208,8 @@ def aia171_test_mc_pixel_displacements():
@pytest.fixture
def aia171_mc_arcsec_displacements(aia171_test_mc_pixel_displacements, aia171_test_map):
return {
"x": np.asarray([0.0, aia171_test_mc_pixel_displacements[1] * aia171_test_map.scale[0].value])
* u.arcsec,
"y": np.asarray([0.0, aia171_test_mc_pixel_displacements[0] * aia171_test_map.scale[1].value])
* u.arcsec,
"x": np.asarray([0.0, aia171_test_mc_pixel_displacements[1] * aia171_test_map.scale[0].value]) * u.arcsec,
"y": np.asarray([0.0, aia171_test_mc_pixel_displacements[0] * aia171_test_map.scale[1].value]) * u.arcsec,
}


Expand Down Expand Up @@ -381,9 +373,7 @@ def test_apply_shifts(aia171_test_map):

# Test that keywords are correctly passed
# Test for an individual keyword
test_mc = apply_shifts(
mc, astropy_displacements["y"], astropy_displacements["x"], clip=False, cval=np.nan
)
test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False, cval=np.nan)
assert np.all(np.logical_not(np.isfinite(test_mc[1].data[:, -1])))

# Test for a combination of keywords, and that changing the interpolation
Expand All @@ -397,9 +387,7 @@ def test_apply_shifts(aia171_test_map):

@pytest.fixture
def aia171_test_submap(aia171_test_map):
return aia171_test_map.submap(
SkyCoord(((0, 0), (400, 500)) * u.arcsec, frame=aia171_test_map.coordinate_frame)
)
return aia171_test_map.submap(SkyCoord(((0, 0), (400, 500)) * u.arcsec, frame=aia171_test_map.coordinate_frame))


@pytest.fixture
Expand Down Expand Up @@ -430,23 +418,15 @@ def test_calculate_solar_rotate_shift(
):
# Test that the default works
test_output = calculate_solar_rotate_shift(aia171_test_mapsequence)
assert_allclose(
test_output["x"].to("arcsec").value, known_displacements_layer_index0["x"], rtol=5e-2, atol=1e-5
)
assert_allclose(
test_output["y"].to("arcsec").value, known_displacements_layer_index0["y"], rtol=5e-2, atol=1e-5
)
assert_allclose(test_output["x"].to("arcsec").value, known_displacements_layer_index0["x"], rtol=5e-2, atol=1e-5)
assert_allclose(test_output["y"].to("arcsec").value, known_displacements_layer_index0["y"], rtol=5e-2, atol=1e-5)

# Test that the rotation relative to a nonzero layer_index works
test_output = calculate_solar_rotate_shift(aia171_test_mapsequence, layer_index=1)
print(test_output["x"].to("arcsec").value)
print(test_output["y"].to("arcsec").value)
assert_allclose(
test_output["x"].to("arcsec").value, known_displacements_layer_index1["x"], rtol=5e-2, atol=1e-5
)
assert_allclose(
test_output["y"].to("arcsec").value, known_displacements_layer_index1["y"], rtol=5e-2, atol=1e-5
)
assert_allclose(test_output["x"].to("arcsec").value, known_displacements_layer_index1["x"], rtol=5e-2, atol=1e-5)
assert_allclose(test_output["y"].to("arcsec").value, known_displacements_layer_index1["y"], rtol=5e-2, atol=1e-5)


def test_mapsequence_solar_derotate(aia171_test_mapsequence, aia171_test_submap):
Expand Down
Loading

0 comments on commit 68f8de3

Please sign in to comment.