Re-projecting from CAR to CEA#

The sunkit_magex.pfss solver takes a cylindrical-equal-area (CEA) projected magnetic field map as input, which is equally spaced in sin(latitude). Some synoptic field maps are equally spaced in latitude, a plate carée (CAR) projection, and need reprojecting.

This example shows how to use the sunkit_magex.pfss.utils.car_to_cea function to reproject a CAR projection to a CEA projection that sunkit_magex.pfss can take as input.

import matplotlib.pyplot as plt

import sunpy.map

from sunkit_magex import pfss

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

adapt_map_car = sunpy.map.Map(pfss.sample_data.get_adapt_map(), hdus=0)
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/checkouts/stable/examples/utils/reproject_car_to_cea.py", line 22, in <module>
    adapt_map_car = sunpy.map.Map(pfss.sample_data.get_adapt_map(), hdus=0)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/manager.py", line 62, in wrapper
    self._download_and_cache_file(name, urls, sha_hash)
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/manager.py", line 92, in _download_and_cache_file
    file_path = self._cache.download(urls, self._namespace)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/cache.py", line 90, in download
    raise e
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/cache.py", line 75, in download
    file_path, file_hash, url = self._download_and_hash(urls, namespace)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/cache.py", line 163, in _download_and_hash
    raise errors[0]
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/site-packages/sunpy/data/data_manager/cache.py", line 154, in _download_and_hash
    path = self._cache_dir / (namespace + get_filename(urlopen(url), url))
                                                       ^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/stable/lib/python3.12/urllib/request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Re-project into a CEA projection.

adapt_map_cea = pfss.utils.car_to_cea(adapt_map_car)

Plot the original map and the reprojected map.

fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(1, 2, 1, projection=adapt_map_car)
ax1 = fig.add_subplot(1, 2, 2, projection=adapt_map_cea)

adapt_map_car.plot(axes=ax)
adapt_map_cea.plot(axes=ax1)

fig.tight_layout()

plt.show()

Total running time of the script: (0 minutes 0.219 seconds)

Gallery generated by Sphinx-Gallery