Skip to content

Commit

Permalink
Drop a bunch of stuff now we use sunpy
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Jul 24, 2024
1 parent ef37fbe commit d28706f
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 236 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1.0.0 (2024-05-31)
==================

This is the first release and aims to keep the API the same from `pfsspy` to
`sunkit_magex`. The main difference is that you will need to replace the
import like so:

.. code-block:: python
# Before
import pfsspy
from pfsspy import tracing
# After
from sunkit_magex import pfss as pfsspy
from sunkit_magex.pfss import tracing
The main changes from the previous release of `pfsspy` are as follows:

* The ``GongSynopticMap`` class has moved into `sunpy`, note that the new
class in ``sunpy`` is slightly different in that it does not modify the
header.
1 change: 1 addition & 0 deletions changelog/63.breaking.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made streamtracer a hard dependency of sunkit-magex.
4 changes: 4 additions & 0 deletions changelog/63.breaking.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Removed the following pfss utils:

- pfss.utils.fix_hmi_meta
- pfss.utils.load_adapt
1 change: 1 addition & 0 deletions changelog/63.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased the minimum required version of ``sunpy`` to v6.0.0.
34 changes: 34 additions & 0 deletions changelog/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
=========
Changelog
=========

.. note::

This README was adapted from the pytest changelog readme under the terms of the MIT licence.

This directory contains "news fragments" which are short files that contain a small **ReST**-formatted text that will be added to the next ``CHANGELOG``.

The ``CHANGELOG`` will be read by users, so this description should be aimed at SunPy users instead of describing internal changes which are only relevant to the developers.

Make sure to use full sentences with correct case and punctuation, for example::

Add support for Helioprojective coordinates in `sunpy.coordinates.frames`.

Please try to use Sphinx intersphinx using backticks.

Each file should be named like ``<PULL REQUEST>.<TYPE>[.<COUNTER>].rst``, where ``<PULL REQUEST>`` is a pull request number, ``COUNTER`` is an optional number if a PR needs multiple entries with the same type and ``<TYPE>`` is one of:

* ``breaking``: A change which requires users to change code and is not backwards compatible. (Not to be used for removal of deprecated features.)
* ``feature``: New user facing features and any new behavior.
* ``bugfix``: Fixes a reported bug.
* ``doc``: Documentation addition or improvement, like rewording an entire session or adding missing docs.
* ``deprecation``: Feature deprecation
* ``removal``: Feature removal.
* ``trivial``: A change which has no user facing effect or is tiny change.

So for example: ``123.feature.rst``, ``456.bugfix.rst``.

If you are unsure what pull request type to use, don't hesitate to ask in your PR.

Note that the ``towncrier`` tool will automatically reflow your text, so it will work best if you stick to a single paragraph, but multiple sentences and links are OK and encouraged.
You can install ``towncrier`` and then run ``towncrier --draft`` if you want to get a preview of how your change will look in the final release notes.
26 changes: 4 additions & 22 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,7 @@
Full Changelog
**************

1.0.0 (2024-05-31)
==================

This is the first release and aims to keep the API the same from `pfsspy` to
`sunkit_magex`. The main difference is that you will need to replace the
import like so:

.. code-block:: python
# Before
import pfsspy
from pfsspy import tracing
# After
from sunkit_magex import pfss as pfsspy
from sunkit_magex.pfss import tracing
The main changes from the previous release of `pfsspy` are as follows:

* The ``GongSynopticMap`` class has moved into `sunpy`, note that the new
class in ``sunpy`` is slightly different in that it does not modify the
header.
.. changelog::
:towncrier: ../
:towncrier-skip-if-empty:
:changelog_file: ../CHANGELOG.rst
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"sphinx_automodapi.automodapi",
"sphinx_automodapi.smart_resolver",
'sphinx_gallery.gen_gallery',
'sphinx_changelog',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Alternatively ``sunkit-magex`` can be installed from PyPI using:
pip install sunkit-magex
This will install sunkit_magex and all of its dependencies.
In addition to the core dependencies, there are optional dependencies (numba, streamtracer) that can improve code performance.
In addition to the core dependencies, there are optional dependencies (numba) that can improve code performance.
These can be installed with

.. code:: shell
Expand Down
5 changes: 2 additions & 3 deletions docs/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ To enable this simply `install numba`_ and use `sunkit_magex.pfss` as normal.
Streamline tracing
==================

`sunkit_magex.pfss` has two streamline tracers: a pure python `sunkit_magex.pfss.tracing.PythonTracer` and a complied tracer `sunkit_magex.pfss.tracing.FortranTracer`.
The compiled version is significantly faster, using the `streamtracer`_ package.
`sunkit_magex.pfss` uses a complied tracer `sunkit_magex.pfss.tracing.PerformanceTracer` using the `streamtracer`_ package.

.. _numba: https://numba.pydata.org
.. _install numba: http://numba.pydata.org/numba-doc/latest/user/installing.html
.. _streamtracer: https://github.com/sunpy/streamtracer
.. _streamtracer: https://docs.sunpy.org/projects/streamtracer/en/stable/
3 changes: 1 addition & 2 deletions examples/internals/tracer_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def dipole_Br(r, theta):
# Trace some field lines.

seed0 = np.atleast_2d(np.array([1, 1, 0]))
tracers = [pfss.tracing.PythonTracer(),
pfss.tracing.FortranTracer()]
tracers = [pfss.tracing.PerformanceTracer()]
nseeds = 2**np.arange(14)
times = [[], []]

Expand Down
2 changes: 1 addition & 1 deletion examples/testing/plot_error_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
dthetas = []
print(f'Tracing {step_size}...')
# Trace
tracer = pfss.tracing.FortranTracer(step_size=step_size)
tracer = pfss.tracing.PerformanceTracer(step_size=step_size)
flines = tracer.trace(seeds, pfss_out)
# Set a mask of open field lines
mask = flines.connectivities.astype(bool).reshape(theta.shape)
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/tracer_step_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
for step_size in step_sizes:
print(f'Tracing {step_size}...')
# Trace
tracer = tracing.FortranTracer(step_size=step_size)
tracer = tracing.PerformanceTracer(step_size=step_size)
flines = tracer.trace(seeds, pfss_out)
# Set a mask of open field lines
mask = flines.connectivities.astype(bool).reshape(theta.shape)
Expand Down
2 changes: 1 addition & 1 deletion examples/using_sunkit_magex_pfss/plot_aia_overplotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
###############################################################################
# Trace field lines from the footpoints defined above.

tracer = tracing.FortranTracer()
tracer = tracing.PerformanceTracer()
flines = tracer.trace(seeds, pfss_out)

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/using_sunkit_magex_pfss/plot_dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def dipole_Br(r, s):
lat = np.linspace(-np.pi / 2, np.pi / 2, 33) * u.rad
seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)

tracer = pfss.tracing.FortranTracer()
tracer = pfss.tracing.PerformanceTracer()
field_lines = tracer.trace(seeds, pfss_out)

for field_line in field_lines:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Now take a seed point, and trace a magnetic field line through the PFSS
# solution from this point

tracer = pfss.tracing.FortranTracer()
tracer = pfss.tracing.PerformanceTracer()
r = 1.2 * const.R_sun
lat = 70 * u.deg
lon = 0 * u.deg
Expand Down
2 changes: 1 addition & 1 deletion examples/using_sunkit_magex_pfss/plot_gong.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_axes_lims(ax):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

tracer = pfss.tracing.FortranTracer()
tracer = pfss.tracing.PerformanceTracer()
r = 1.2 * const.R_sun
lat = np.linspace(-np.pi / 2, np.pi / 2, 8, endpoint=False)
lon = np.linspace(0, 2 * np.pi, 8, endpoint=False)
Expand Down
2 changes: 1 addition & 1 deletion examples/using_sunkit_magex_pfss/plot_open_closed_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# Trace the field lines.

print('Tracing field lines...')
tracer = pfss.tracing.FortranTracer(max_steps=2000)
tracer = pfss.tracing.PerformanceTracer(max_steps=2000)
field_lines = tracer.trace(seeds, pfss_out)
print('Finished tracing field lines')

Expand Down
5 changes: 3 additions & 2 deletions examples/utils/plot_car_reproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"""
import matplotlib.pyplot as plt

import sunpy.map

from sunkit_magex import pfss

###############################################################################
# Load a sample ADAPT map, which has a CAR projection.

adapt_maps = pfss.utils.load_adapt(pfss.sample_data.get_adapt_map())
adapt_map_car = adapt_maps[0]
adapt_map_car = sunpy.map.Map(pfss.sample_data.get_adapt_map(), hdus=0)

###############################################################################
# Re-project into a CEA projection.
Expand Down
56 changes: 50 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ dynamic = ["version"]

[project.optional-dependencies]
tests = [
"sunkit-magex[all]",
"pytest",
"pytest-doctestplus",
"pytest-cov",
"pytest-xdist",
"pytest-arraydiff",
"parfive",
"reproject",
"sympy",
]
docs = [
"sphinx",
"sphinx-automodapi",
"sunkit-magex[all]",
"pillow",
"reproject",
"sphinx-automodapi",
"sphinx-changelog",
"sphinx-gallery",
"sunpy[net,map]",
"sympy",
"sphinx",
"sunpy-sphinx-theme",
]
performance = [
Expand All @@ -60,7 +60,7 @@ dev = ["sunkit-magex[all,tests,docs]"]
Homepage = "https://sunpy.org"
Download = "https://pypi.org/project/sunkit-magex/"
"Source Code" = "https://github.com/sunpy/sunkit-magex/"
Documentation = "https://docs.sunpy.org/"
Documentation = "https://docs.sunpy.org/projects/sunkit-magex/en/stable/"
Changelog = "https://docs.sunpy.org/en/stable/whatsnew/changelog.html"
"Issue Tracker" = "https://github.com/sunpy/sunkit-magex/issues"

Expand All @@ -73,3 +73,47 @@ exclude = ["sunkit_magex._dev*"]

[tool.setuptools_scm]
write_to = "sunkit_magex/_version.py"

# TODO: This should be in towncrier.toml but Giles currently only works looks in
# pyproject.toml we should move this back when it's fixed.
[tool.towncrier]
package = "sunkit_magex"
filename = "CHANGELOG.rst"
directory = "changelog/"
issue_format = "`#{issue} <https://github.com/sunkit_magex/sunkit_magex/pull/{issue}>`__"
title_format = "{version} ({project_date})"

[[tool.towncrier.type]]
directory = "breaking"
name = "Breaking Changes"
showcontent = true

[[tool.towncrier.type]]
directory = "deprecation"
name = "Deprecations"
showcontent = true

[[tool.towncrier.type]]
directory = "removal"
name = "Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "feature"
name = "New Features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bug Fixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "trivial"
name = "Internal Changes"
showcontent = true
7 changes: 4 additions & 3 deletions sunkit_magex/pfss/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from sunpy.map import Map

import sunkit_magex.pfss
from sunkit_magex.pfss import utils
from sunkit_magex.tests.helpers import get_dummy_map_from_header, get_fitsfile_from_header


Expand Down Expand Up @@ -65,10 +64,12 @@ def adapt_test_file(tmp_path):
package="sunkit_magex.pfss.tests.data"
)


@pytest.fixture
def adapt_map(adapt_test_file):
return utils.load_adapt(adapt_test_file)
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
return Map(adapt_test_file, hdus=0)


@pytest.fixture
Expand Down
22 changes: 11 additions & 11 deletions sunkit_magex/pfss/tests/test_pfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def test_bunit(gong_map):


def test_expansion_factor(dipole_result):
inp, out = dipole_result
_, out = dipole_result
out_frame = out.coordinate_frame

tracer = tracing.PythonTracer()
tracer = tracing.PerformanceTracer()
seed = coord.SkyCoord(0 * u.deg, 80 * u.deg, 1.1 * R_sun, frame=out_frame)
field_line = tracer.trace(seed, out)[0]
assert field_line.expansion_factor > 1
Expand All @@ -80,10 +80,10 @@ def test_expansion_factor(dipole_result):


def test_field_line_polarity(dipole_result):
input, out = dipole_result
_, out = dipole_result
out_frame = out.coordinate_frame

tracer = tracing.PythonTracer()
tracer = tracing.PerformanceTracer()
seed = coord.SkyCoord(0 * u.deg, 90*u.deg, 1.01 * R_sun, frame=out_frame)
field_line = tracer.trace(seed, out)
assert field_line[0].polarity == 1
Expand All @@ -99,10 +99,10 @@ def test_field_line_polarity(dipole_result):


def test_footpoints(dipole_result):
input, out = dipole_result
_, out = dipole_result
out_frame = out.coordinate_frame

tracer = tracing.PythonTracer(atol=1e-8, rtol=1e-8)
tracer = tracing.PerformanceTracer()

def check_radius(coord, r):
coord.representation_type = 'spherical'
Expand All @@ -128,12 +128,12 @@ def check_open_fline(fline):

def test_shape(zero_map):
# Test output map shapes
input, out = zero_map
nr = input.grid.nr
nphi = input.grid.nphi
ns = input.grid.ns
_input, out = zero_map
nr = _input.grid.nr
nphi = _input.grid.nphi
ns = _input.grid.ns

out = sunkit_magex.pfss.pfss(input)
out = sunkit_magex.pfss.pfss(_input)
alr, als, alp = out._al
for comp in (alr, als, alp):
assert np.all(comp == 0)
Expand Down
Loading

0 comments on commit d28706f

Please sign in to comment.