.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/Basic_Plots/plot_geometrical_models_on_empty_map.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_Basic_Plots_plot_geometrical_models_on_empty_map.py: Plot geometrical models on empty Map ------------------------------------ This example shows how to plot an ellipsoid on a blank map. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Import Required Modules .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np import sunpy.map from astropy.coordinates import SkyCoord from IPython.display import display from sunpy.coordinates import frames from PyThea.data.sample_data import json_fitting_file_sample_data from PyThea.geometrical_models import ellipsoid from PyThea.utils import model_fittings .. GENERATED FROM PYTHON SOURCE LINES 23-25 Create a blank map using with an array of zeros and construct a header to pass to Map. This is based on the `SunPy's example `_ .. GENERATED FROM PYTHON SOURCE LINES 25-43 .. code-block:: Python def create_blank_map(obstime): data = np.full((10, 10), np.nan) # Define a reference coordinate and create a header using sunpy.map.make_fitswcs_header skycoord = SkyCoord(0*u.arcsec, 0*u.arcsec, obstime=obstime, observer='earth', frame=frames.Helioprojective) # Scale set to the following for solar limb to be in the field of view header = sunpy.map.make_fitswcs_header(data, skycoord, scale=[220, 220]*u.arcsec/u.pixel) # Use sunpy.map.Map to create the blank map blank_map = sunpy.map.Map(data, header) return blank_map .. GENERATED FROM PYTHON SOURCE LINES 44-49 User defined ellipsoid ^^^^^^^^^^^^^^^^^^^^^^ In this part of the example we construct an ellipsoid model using ``ellipsoid`` class from PyThea's geometrical_models. .. GENERATED FROM PYTHON SOURCE LINES 51-52 First create an ellipsoid providing an observation time, the ellipsoid center coordinates, and the geomertical parameters. .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: Python obstime = '2021-10-28' center = SkyCoord(90*u.degree, 0*u.degree, 1*u.R_sun, obstime=obstime, observer='earth', frame=frames.HeliographicStonyhurst) model_shock = ellipsoid(center, 1*u.R_sun, 1*u.R_sun, 1*u.R_sun, 0 * u.degree) .. GENERATED FROM PYTHON SOURCE LINES 59-61 Create a blank map with WCS defined by a helioprojective frame as observed from Earth at the observation time. We use this map to overplot the ellipsoid. .. GENERATED FROM PYTHON SOURCE LINES 61-64 .. code-block:: Python blank_map = create_blank_map(obstime) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Create a figure and plot the map and the ellipsoid. .. GENERATED FROM PYTHON SOURCE LINES 66-78 .. code-block:: Python fig = plt.figure() ax = fig.add_subplot(projection=blank_map) blank_map.plot(axes=ax) blank_map.draw_limb(axes=ax, color='k') blank_map.draw_grid(axes=ax, color='k') model_shock.plot(ax, mode='Full') ax.set_title('Plotting ellipsoid on a map') plt.show() .. image-sg:: /_examples/Basic_Plots/images/sphx_glr_plot_geometrical_models_on_empty_map_001.png :alt: Plotting ellipsoid on a map :srcset: /_examples/Basic_Plots/images/sphx_glr_plot_geometrical_models_on_empty_map_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 79-83 Ellipsoid from fitting file ^^^^^^^^^^^^^^^^^^^^^^^^^^^ In this part we will construct an ellipsoid model using the parameters from a fitting file. .. GENERATED FROM PYTHON SOURCE LINES 85-87 Import a sample JSON fitting file using ``json_fitting_file_sample_data.fetch()`` method. This sample data contains a series of fitted ellipsoids for a selected event. Then use the ``model_fittings.load_from_json(json_fitting_file)`` to load the model parameters. .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. code-block:: Python json_fitting_file = json_fitting_file_sample_data.fetch('FLX1p0D20211028T153500MEllipsoid.json') model_fittings_class = model_fittings.load_from_json(json_fitting_file) .. GENERATED FROM PYTHON SOURCE LINES 92-93 Select one of the fittings and display the parameters of the geometrical model. .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: Python model_parameters = model_fittings_class.parameters.iloc[0] display(model_parameters) .. rst-class:: sphx-glr-script-out .. code-block:: none hgln 3.62 hglt -25.07 crln 274.118677 crlt -25.07 rcenter 2.208355 radaxis 2.051645 orthoaxis1 2.2494 orthoaxis2 2.615581 tilt 0.0 height 4.26 kappa 0.69 epsilon -0.41 alpha 0.86 imager LC2 fits_file Name: 2021-10-28 15:48:18.842000, dtype: object .. GENERATED FROM PYTHON SOURCE LINES 98-99 Create the ellipsoid using the observation time, the ellipsoid center coordinates, and the geomertical parameters from the fitting. .. GENERATED FROM PYTHON SOURCE LINES 99-114 .. code-block:: Python obstime = model_parameters.name center = SkyCoord(model_parameters['hgln']*u.degree, model_parameters['hglt']*u.degree, model_parameters['rcenter']*u.R_sun, obstime=obstime, observer='earth', frame=frames.HeliographicStonyhurst) model_shock = ellipsoid(center, model_parameters['radaxis']*u.R_sun, model_parameters['orthoaxis1']*u.R_sun, model_parameters['orthoaxis2']*u.R_sun, model_parameters['tilt']*u.degree) .. GENERATED FROM PYTHON SOURCE LINES 115-116 Create a figure and plot the map and the ellipsoid. .. GENERATED FROM PYTHON SOURCE LINES 116-127 .. code-block:: Python fig = plt.figure() ax = fig.add_subplot(projection=blank_map) blank_map.plot(axes=ax) blank_map.draw_limb(axes=ax, color='k') blank_map.draw_grid(axes=ax, color='k') model_shock.plot(ax, mode='Full') ax.set_title('Plotting ellipsoid on a map') plt.show() .. image-sg:: /_examples/Basic_Plots/images/sphx_glr_plot_geometrical_models_on_empty_map_002.png :alt: Plotting ellipsoid on a map :srcset: /_examples/Basic_Plots/images/sphx_glr_plot_geometrical_models_on_empty_map_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.536 seconds) .. _sphx_glr_download__examples_Basic_Plots_plot_geometrical_models_on_empty_map.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_geometrical_models_on_empty_map.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_geometrical_models_on_empty_map.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_geometrical_models_on_empty_map.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_