1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
.. _sunpy-how-to-create-a-map:
*************************
Create a `~sunpy.map.Map`
*************************
One of the primary goals of the Map interface is to make it as easy as possible to create a Map.
As such, you can pass many different kinds of inputs to Map.
These are listed below.
File name
=========
If you have a FITS file, this is the easiest and recommended way to create a Map.
This can be either a string or a `~pathlib.Path`.
.. code-block:: python
>>> import pathlib
>>> import sunpy.map
>>> import sunpy.data.sample
>>> my_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE) # doctest: +REMOTE_DATA +IGNORE_WARNINGS
>>> my_map = sunpy.map.Map('file.fits') # doctest: +SKIP
>>> my_map = sunpy.map.Map(pathlib.Path('file.fits')) # doctest: +SKIP
>>> sub_dir = pathlib.Path('local_dir/sub_dir')
>>> my_map = sunpy.map.Map(sub_dir / 'another_file.fits') # doctest: +SKIP
Directory containing FITS files
===============================
If there is more than one FITS file in the directory, this will return a list of Map objects.
.. code-block:: python
>>> my_maps = sunpy.map.Map('local_dir/sub_dir') # doctest: +SKIP
>>> my_maps = sunpy.map.Map(sub_dir) # doctest: +SKIP
Array and `astropy.io.fits.Header`
==================================
If needed, this way can be used to modify the header before passing it to `~sunpy.map.Map`.
.. code-block:: python
>>> import astropy.io.fits
>>> with astropy.io.fits.open(sunpy.data.sample.AIA_171_IMAGE) as hdul: # doctest: +REMOTE_DATA +IGNORE_WARNINGS
... data = hdul[1].data
... header = hdul[1].header
>>> my_map = sunpy.map.Map(data, header) # doctest: +REMOTE_DATA +IGNORE_WARNINGS
These data header pairs can also be passed as a `tuple`,
.. code-block:: python
>>> my_map = sunpy.map.Map((data, header)) # doctest: +REMOTE_DATA
Data array and a `~sunpy.util.metadata.MetaDict` object
=======================================================
This includes any base class of `~sunpy.util.metadata.MetaDict`, including `dict` or `collections.OrderedDict`.
.. code-block:: python
>>> import sunpy.util.metadata
>>> meta = sunpy.util.metadata.MetaDict(header) # doctest: +REMOTE_DATA
>>> my_map = sunpy.map.Map(data, meta) # doctest: +REMOTE_DATA
Data array and an `astropy.wcs.WCS` object
==========================================
.. code-block:: python
>>> import astropy.wcs
>>> wcs = astropy.wcs.WCS(header=header) # doctest: +REMOTE_DATA +IGNORE_WARNINGS
>>> my_map = sunpy.map.Map(data, wcs) # doctest: +REMOTE_DATA
Glob patterns
=============
If the glob pattern matches more than one FITS file, this will return a list of Map objects.
.. code-block:: python
>>> my_map = sunpy.map.Map('eit_*.fits') # doctest: +SKIP
URL
===
.. code-block:: python
>>> sample_data_url = 'http://data.sunpy.org/sunpy/v1/AIA20110607_063302_0171_lowres.fits'
>>> my_map = sunpy.map.Map(sample_data_url) # doctest: +REMOTE_DATA +IGNORE_WARNINGS
Combinations of any of the above
================================
These can either be in a list or as separate arguments.
As with the case of a directory or glob pattern, this will return multiple Map objects.
.. code-block:: python
>>> my_map = sunpy.map.Map(['file1.fits', 'file2.fits', 'file3.fits', 'directory1/']) # doctest: +SKIP
>>> my_map = sunpy.map.Map((data, header), data, meta, 'file1.fits', sample_data_url, 'eit_*.fits') # doctest: +SKIP
|