.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/suvi/thematic_map_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_suvi_thematic_map_example.py: Thematic Map Example ==================== .. GENERATED FROM PYTHON SOURCE LINES 8-10 # Purpose: Example fits and plot commands for the SUVI thematic map product .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python # Import modules import os import requests from astropy.io import fits import matplotlib import matplotlib.pyplot as plt from datetime import datetime .. GENERATED FROM PYTHON SOURCE LINES 22-35 .. code-block:: Python # Access thematic map file dir = './' file = 'dr_suvi-l2-thmap_g16_s20210416T212000Z_e20210416T212400Z_v1-0-2.fits' # Download the file if it does not exist locally if not os.path.exists(os.path.join(dir, file)): with open(os.path.join(dir, file), "wb") as f: url_path = 'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/' \ 'suvi-l2-thmap/2021/04/16/' r = requests.get(url_path + file) f.write(r.content) .. GENERATED FROM PYTHON SOURCE LINES 36-37 Open file and read data .. GENERATED FROM PYTHON SOURCE LINES 39-48 .. code-block:: Python with fits.open(os.path.join(dir, file)) as hdul: thmap_data = hdul[0].data if 'DATE-OBS' in hdul[0].header.keys(): thmap_date_str = hdul[0].header['DATE-OBS'] thmap_date = datetime.strptime(thmap_date_str, "%Y-%m-%dT%H:%M:%S.%f") else: start_string = file.split("_")[3][1:-1] thmap_date = datetime.strptime(start_string, "%Y%m%dT%H%M%S") .. GENERATED FROM PYTHON SOURCE LINES 49-50 Plot thematic map .. GENERATED FROM PYTHON SOURCE LINES 52-88 .. code-block:: Python # Function to plot thematic map def plot_thematic_map(thmap_data, thmap_date, save=False, save_folder='./'): fig = plt.figure(figsize=(15,15)) plt.axis('off') SOLAR_CLASSES = [('unlabeled', 0), ('outer_space', 1), ('bright_region', 3), ('filament', 4), ('prominence', 5), ('coronal_hole', 6), ('quiet_sun', 7), ('limb', 8), ('flare', 9)] SOLAR_CLASS_NAME = {number: theme for theme, number in SOLAR_CLASSES} SOLAR_COLORS = {"unlabeled": "white", "outer_space": "black", "bright_region": "#F0E442", "filament": "#D55E00", "prominence": "#E69F00", "coronal_hole": "#009E73", "quiet_sun": "#0072B2", "limb": "#56B4E9", "flare": "#CC79A7"} colortable = [SOLAR_COLORS[SOLAR_CLASS_NAME[i]] if i in SOLAR_CLASS_NAME else 'white' for i in range(max(list(SOLAR_CLASS_NAME.keys())) + 1)] cmap = matplotlib.colors.ListedColormap(colortable) plt.imshow(thmap_data, origin='lower', cmap=cmap, vmin=-1, vmax=len(colortable), interpolation='none') plt.axis('off') plt.margins(0, 0) plt.title(thmap_date.strftime("%Y/%m/%d %H:%M"), fontsize=40) fig.tight_layout() if save: fig.savefig(save_folder + 'thematic_map' + thmap_date.strftime("%Y%m%dT%H%M%S") + '.png', bbox_inches='tight') .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: Python # Plot the thematic map without saving plot_thematic_map(thmap_data, thmap_date) .. image-sg:: /examples/suvi/images/sphx_glr_thematic_map_example_001.png :alt: 2021/04/16 21:20 :srcset: /examples/suvi/images/sphx_glr_thematic_map_example_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 95-102 .. code-block:: Python # Plot and save the thematic map save_folder = './' plot_thematic_map(thmap_data, thmap_date, save=True, save_folder=save_folder) .. image-sg:: /examples/suvi/images/sphx_glr_thematic_map_example_002.png :alt: 2021/04/16 21:20 :srcset: /examples/suvi/images/sphx_glr_thematic_map_example_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.376 seconds) .. _sphx_glr_download_examples_suvi_thematic_map_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: thematic_map_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: thematic_map_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: thematic_map_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_