Repository: sunpy/sunpy

Issue:
Support for saving intermediate data products
Is there a good way to save intermediate SunPy data products? The pickle module does not work properly on some SunPy objects at the moment (e.g. maps, where the header information gets lost).

As an example, I may want to process some data only once (maybe it's time consuming) and generate some products which I then want to work with or manipulate many times, over multiple Python sessions. 



Discussion:
As for pickle on Maps, after the great refactor this may work better.

If you want to process data, then use it later I would say that despite the faff the best way to do it is save a FITS file. Pickle is not a reliable long term method of storage, because if your code changes then your pickles might break.

@Cadair close?
This is probably a good use case for #2366

Resolving patch:
diff --git a/examples/saving_and_loading_data/genericmap_in_asdf.py b/examples/saving_and_loading_data/genericmap_in_asdf.py
new file mode 100644
--- /dev/null
+++ b/examples/saving_and_loading_data/genericmap_in_asdf.py
@@ -0,0 +1,52 @@
+"""
+=======================================
+Saving and loading sunpy Maps with asdf
+=======================================
+
+In this example we are going to look at how we can save and load a
+`~sunpy.map.GenericMap` with `asdf <https://asdf.readthedocs.io/en/latest/>`__.
+
+asdf is a modern file format designed to meet the needs of the astronomy
+community. It has deep integration with Python, SunPy and Astropy as well as
+implementations in other languages. It can be used to store known Python
+objects in a portable, well defined file format. It is primarily useful for
+storing complex Astropy and SunPy objects in a way that can be loaded back into
+the same form as they were saved.
+
+Here, even though we will be working with `~sunpy.map.sources.sdo.AIAMap`
+specifically, the process can be extended to any `~sunpy.map.GenericMap`,
+including ones created using custom FITS files.
+"""
+
+import asdf
+
+import sunpy.data.sample
+import sunpy.map
+
+################################################################################
+# We begin by creating an `~sunpy.map.sources.sdo.AIAMap` object using the
+# sample data.
+aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
+aia_map.peek()
+
+################################################################################
+# We can now save this object to an asdf file to use later. Saving it like this
+# allows us to preserve all of the metadata of the object along with the actual
+# array data. When we load the asdf again, we get an identical
+# `~sunpy.map.sources.sdo.AIAMap` object.
+#
+# asdf files work by saving a dictionary internally, so to save the object we
+# need to put it into a dictionary. This becomes what asdf calls a "tree".
+tree = {'aia_map': aia_map}
+
+################################################################################
+# We can now write the data to an asdf file like so:
+with asdf.AsdfFile(tree) as asdf_file:
+    asdf_file.write_to("sunpy_map.asdf")
+
+################################################################################
+# This asdf file is a portable file and can be safely loaded by anyone with
+# Astropy, SunPy and asdf installed. We can reload it like so:
+with asdf.open("sunpy_map.asdf") as asdf_file:
+    reloaded_aia_map = asdf_file['aia_map']
+    reloaded_aia_map.peek()


Test patch: