.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery_tutorials/read_and_plot_spectra.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_gallery_tutorials_read_and_plot_spectra.py: .. _tutorial_read_plot_spec: Read and plot spectra with SpectraContainer =========================================== .. note:: This tutorial is not final. It will be finished once all the core functionalities of `~madcubapy.io.SpectraContainer` are implemented. Introduction to using `madcubapy` to read and plot MADCUBA spectra. We start by importing the necessary libraries for this tutorial. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python from madcubapy.io import SpectraContainer import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 28-41 Reading the spectra file ======================== Spectra are exported from MADCUBA in a single FITS file containing a bintable with each one of the spectra inside. This FITS file is then packaged alongside the :ref:`history file ` inside a *.spec* archive. With the `~madcubapy.io.SpectraContainer` class we can open MADCUBA's **.spec** files alongside their history tables. We can read the **.spec** file with the `SpectraContainer.read() ` method, and the corresponding :ref:`history file ` will be loaded as well if present. .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python spectra_container = SpectraContainer.read( "../examples/data/IRAS16293_position_8_TM2_spectra.spec") .. GENERATED FROM PYTHON SOURCE LINES 46-53 .. note:: Due to how MADCUBA saves some FITS header cards, several `astropy` warnings can pop up when reading spectra. Usually these warnings are incorrectly written units, or units using non-standard conventions. The spectra are stored in the ``bintable`` attribute, which is an Astropy table contaning the data and header information for every spectra. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python # Show the first two spectra inside as an example spectra_container.bintable[0:2] .. raw:: html
Table length=2
PROJIDOBSERVERVERSIONCRPIX1CRPIX2SCANOBS-NUMDATE-OBSTIME-OBSLSTDATEEXPOSUREOBJECTAZIMUTHELEVATIOHISTORYORIGINCTYPE3CRPIX3CRVAL3CDELT3CTYPE1CRVAL1CDELT1CTYPE2CRVAL2CDELT2EQUINOXRADESYSRESTFRQIMAGFREQSPECRESMOLECULETRANSITIONVELDEFVELREFALTRPIXALTRVALZSOURCESTOKESCHANNELSDATAWEIGTHSWAVETELESCOPBMAJBMINBPAFRONTENDBACKENDTSYSTSYSIMAGEOBSMODEQUALITYBUNITAPEREFFBEAMEFFETAFFSANTGAINGAINIMAGRESTWAVHIST-OLDTEMPSCALXAXIS
sssdegdegdegdegdegdegHzHzHzm / sm / sJym or HzdegdegdegKKK / JymHz
bytes32bytes16bytes24int32int32int32int32bytes24float64float64bytes24float32bytes32float32float32bytes32bytes24bytes8float64float64float64bytes8float64float64bytes8float64float64bytes8bytes8float64float64float64bytes16bytes16bytes8int32float64float64float64bytes2int32objectobjectobjectbytes8float32float32float32bytes16bytes16float32float32bytes32int32bytes32float32float32float32float32float32float64bytes32bytes16object
MASSArivilla1226232112018-12-16T13:42:49.72801665751050553.01000.02023-02-17T15:00:39.849Z1.0IRAS_16293-2422180.090.0history file nameMADCUBAFREQ-LSR1.093782290089.0122068.8545532RA---GLS248.094179931279680.0DEC--GLS-24.4752036114647420.02000.0ICRS93900000000.00.0122068.8545532UnknownUnknownVRAD-LSR257958.87635359156872500.08.339171921162217e-06I1918[-0.00553309 -0.00566683 -0.00572642 ... -0.00119151 -0.00168416\n 0.0022412 ][60835.836][-1.]ALMA-0.0005619182-0.00056191820.0PLOT MAD_CUB_member.uid___A001_X100.0100.0MADCUBA1Jy1.01.01.033.8388520.00.00.0TMB[9.37822901e+10 9.37824122e+10 9.37825342e+10 ... 9.40160519e+10\n 9.40161740e+10 9.40162961e+10] Hz
MASSArivilla1226232112018-12-16T13:42:49.72801665751097826.01000.02023-02-17T15:00:39.449Z1.0IRAS_16293-2422180.090.0history file nameMADCUBAFREQ-LSR1.0108880112783.0122069.8044281RA---GLS248.094179931279680.0DEC--GLS-24.4752036114647420.02000.0ICRS108998000000.00.0122069.8044281UnknownUnknownVRAD-LSR257959.28998880460142500.08.339171921162217e-06I1918[-0.00065054 -0.00024617 -0.00393423 ... 0.0009739 -0.0042386\n 0.00021092][37884.938][-1.]ALMA-0.00053032895-0.000530328950.0PLOT MAD_CUB_member.uid___A001_X100.0100.0MADCUBA1Jy1.01.01.028.1945610.00.00.0TMB[1.08880113e+11 1.08880235e+11 1.08880357e+11 ... 1.09113876e+11\n 1.09113999e+11 1.09114121e+11] Hz


.. GENERATED FROM PYTHON SOURCE LINES 58-62 The spectrum data is contained in the ``DATA`` and ``XAXIS`` columns alongside their units if correctly parsed from the header. We can quickly plot a spectrum by accesing these values .. GENERATED FROM PYTHON SOURCE LINES 62-78 .. code-block:: Python index = 6 fig, ax = plt.subplots(1, 1, figsize=(7,5)) x = spectra_container.bintable[index]['XAXIS'] x_unit = spectra_container.bintable[index].table['XAXIS'].unit y = spectra_container.bintable[index]['DATA'] y_unit = spectra_container.bintable[index].table['DATA'].unit ax.plot(x, y, drawstyle='steps-mid') ax.set_xlabel(f"Freq [{x_unit}]") ax.set_ylabel(f"S [{y_unit}]") plt.show() .. image-sg:: /gallery_tutorials/images/sphx_glr_read_and_plot_spectra_001.png :alt: read and plot spectra :srcset: /gallery_tutorials/images/sphx_glr_read_and_plot_spectra_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.084 seconds) .. _sphx_glr_download_gallery_tutorials_read_and_plot_spectra.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: read_and_plot_spectra.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: read_and_plot_spectra.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: read_and_plot_spectra.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_