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 23a1392
Show file tree
Hide file tree
Showing 31 changed files with 222 additions and 343 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,4 @@ package.json
# Repo specific
examples/using_sunkit_magex_pfss/aia_map.fits
docs/sg_execution_times.rst
aia_map.fits
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: 0 additions & 3 deletions examples/finding_data/README.rst

This file was deleted.

65 changes: 0 additions & 65 deletions examples/finding_data/adapt_map_sequence.py

This file was deleted.

File renamed without changes.
41 changes: 13 additions & 28 deletions examples/internals/tracer_performance.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Tracer performance
Tracer Performance
==================
Comparing the performance of Python and Rust tracers.
Checking the performance of the ``streamtracer`` tracer.
"""
import timeit

Expand All @@ -19,72 +19,57 @@
###############################################################################
# Create a dipole map.

def dipole_Br(r, theta):
return 2 * np.sin(theta) / r**3


ntheta = 180
nphi = 360
nr = 50
rss = 2.5

phi = np.linspace(0, 2 * np.pi, nphi)
theta = np.linspace(-np.pi / 2, np.pi / 2, ntheta)
theta, phi = np.meshgrid(theta, phi)

def dipole_Br(r, theta):
return 2 * np.sin(theta) / r**3


br = dipole_Br(1, theta)
br = sunpy.map.Map(br.T, pfss.utils.carr_cea_wcs_header('2010-01-01', br.shape))
pfss_input = pfss.Input(br, nr, rss)
pfss_output = pfss.pfss(pfss_input)
print('Computed PFSS solution')

###############################################################################
# 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 = [[], []]
times = [[] for _ in tracers]

for nseed in nseeds:
print(nseed)
seeds = np.repeat(seed0, nseed, axis=0)
r, lat, lon = pfss.coords.cart2sph(seeds[:, 0], seeds[:, 1], seeds[:, 2])
r = r * astropy.constants.R_sun
lat = (lat - np.pi / 2) * u.rad
lon = lon * u.rad
seeds = astropy.coordinates.SkyCoord(lon, lat, r, frame=pfss_output.coordinate_frame)

for i, tracer in enumerate(tracers):
if nseed > 64 and i == 0:
continue

t = timeit.timeit(lambda: tracer.trace(seeds, pfss_output), number=1)
times[i].append(t)

###############################################################################
# Plot the results.

fig, ax = plt.subplots()
ax.scatter(nseeds[1:len(times[0])], times[0][1:], label='python')
ax.scatter(nseeds[1:], times[1][1:], label='compiled')

pydt = (times[0][4] - times[0][3]) / (nseeds[4] - nseeds[3])
ax.plot([1, 1e5], [pydt, 1e5 * pydt])

fort0 = times[1][1]
fordt = (times[1][-1] - times[1][-2]) / (nseeds[-1] - nseeds[-2])
ax.plot(np.logspace(0, 5, 100), fort0 + fordt * np.logspace(0, 5, 100))
for i, tracer in enumerate(tracers):
ax.scatter(nseeds, times[i], label=tracer.__class__.__name__)
t0 = times[i][1]
dt = (times[i][-1] - times[i][-2]) / (nseeds[-1] - nseeds[-2])
ax.plot(np.logspace(0, 5, 100), t0 + dt * np.logspace(0, 5, 100))

ax.set_xscale('log')
ax.set_yscale('log')

ax.set_xlabel('Number of seeds')
ax.set_ylabel('Seconds')

ax.axvline(180 * 360, color='k', linestyle='--', label='180x360 seed points')

ax.legend()

plt.show()
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

nphi = 360
ns = 180

phi = np.linspace(0, 2 * np.pi, nphi)
s = np.linspace(-1, 1, ns)
s, phi = np.meshgrid(s, phi)
Expand Down Expand Up @@ -59,15 +58,19 @@ def dipole_Br(r, s):
###############################################################################
# Using the Input object, plot the input field.

m = pfss_in.map
in_map = pfss_in.map

fig = plt.figure()
ax = plt.subplot(projection=m)
m.plot()
plt.colorbar()
ax = plt.subplot(projection=in_map)

in_map.plot(axes=ax)

fig.colorbar()
ax.set_title('Input dipole field')

###############################################################################
# Now calculate the PFSS solution.

pfss_out = pfss.pfss(pfss_in)

###############################################################################
Expand All @@ -76,15 +79,15 @@ def dipole_Br(r, s):

ss_br = pfss_out.source_surface_br

# Create the figure and axes
fig = plt.figure()
ax = plt.subplot(projection=ss_br)

# Plot the source surface map
ss_br.plot()
ss_br.plot(axes=ax)

# Plot the polarity inversion line
ax.plot_coord(pfss_out.source_surface_pils[0])
# Plot formatting

plt.colorbar()
ax.set_title('Source surface magnetic field')

Expand All @@ -102,7 +105,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 @@ -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
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
Loading

0 comments on commit 23a1392

Please sign in to comment.