From 5574d9cc077adef570c39f431a4a9aacc45d405c Mon Sep 17 00:00:00 2001 From: profxj Date: Mon, 13 Feb 2023 12:45:19 -0800 Subject: [PATCH 1/4] docs and docs --- doc/coadd1d.rst | 9 ++++-- doc/out_onespec.rst | 52 +++++++++++++++++++++++++++++++++++ pypeit/core/telluric.py | 37 ++++++++++++------------- pypeit/scripts/show_1dspec.py | 3 +- pypeit/specobjs.py | 4 +++ 5 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 doc/out_onespec.rst diff --git a/doc/coadd1d.rst b/doc/coadd1d.rst index f91c69d1b1..7ff04ea909 100644 --- a/doc/coadd1d.rst +++ b/doc/coadd1d.rst @@ -284,16 +284,19 @@ be provided directly using the ``coadd1dfile`` parameter in the is ``coadd1d___.fits`` or ``coadd1d___-.fits``, if the coadd included more than one day's worth of data. The default location of the file -will be along side the first spec1d file. Currently ``instrument_name`` is +will be along side the first spec1d file. +Currently ``instrument_name`` is taken from the ``camera`` attribute of the relevant :class:`~pypeit.spectrographs.spectrograph.Spectrograph` class. The format of the 1D coadd file follows follows the general -class :class:`~pypeit.onespec.OneSpec`, such that its file extensions are: +class :class:`~pypeit.onespec.OneSpec`, such +that its file extensions are: .. include:: include/datamodel_onespec.rst -You view the spectrum using the ``lt_xspec`` script, which loads the data +You view the spectrum using the ``lt_xspec`` script +(``pypeit_show_1dspec`` will not work), which loads the data and launches a GUI from the `linetools`_ package. e.g.: .. code-block:: console diff --git a/doc/out_onespec.rst b/doc/out_onespec.rst new file mode 100644 index 0000000000..b0a8fae775 --- /dev/null +++ b/doc/out_onespec.rst @@ -0,0 +1,52 @@ + +.. include:: include/links.rst + +.. _onespec: + +======= +OneSpec +======= + +Overview +======== + +Generally, the ultimate PypeIt spectrum output is a single +spectrum per source, fully calibrated and (as desired) +with a :doc:`telluric` performed. + +The standard way to generate this file is +with the :ref:`_pypeit_coadd_1dspec` script. + +The naming of this file is user-generated, +i.e. it can be anything you wish. + +The header of the primary extension includes the +`core_meta` of PypeIt, e.g. RA, DEC, MJD, and +configuration parmaeters of the instrument. + +Inspection +========== + +You view the spectrum using the ``lt_xspec`` script +(``pypeit_show_1dspec`` will not work), which loads the data +and launches a GUI from the `linetools`_ package. e.g.: + +.. code-block:: console + + lt_xspec J1217p3905_coadd.fits + + +Current Data Model +================== + +Internally, the spectrum for a single object is held by the +:class:`~pypeit.onespec.OneSpec` class. + +Here is its datamodel, which +is written as an `astropy.io.fits.BinTableHDU`_ in the +first HDU of the file. + +.. include:: include/datamodel_onespec.rst + +All wavelengths are in vacuum and flux units +depend on whether :doc:`Fluxing` was performed. diff --git a/pypeit/core/telluric.py b/pypeit/core/telluric.py index 531bd68244..437b335fa3 100644 --- a/pypeit/core/telluric.py +++ b/pypeit/core/telluric.py @@ -627,12 +627,25 @@ def general_spec_reader(specfile, ret_flam=False): The 6th is a :obj:`dict` of metadata. And the 7th is an `astropy.io.fits.Header`_ object with the primary header from the input file. """ - # Place holder routine that provides a generic spectrum reader bonus = {} - try: #TODO JFH Please fix this try except issue. Can we determine datatype from file header? - # Read in the standard spec1d file produced by Pypeit - #sobjs, head = load.load_specobjs(specfile) + # Figure out which flavor input file + hdul = fits.open(specfile) + if 'DMODCLS' in hdul[1].header and hdul[1].header['DMODCLS'] == 'OneSpec': + # Load + spec = onespec.OneSpec.from_file(specfile) + # Unpack + wave = spec.wave + # wavelength grid evaluated at the bin centers, uniformly-spaced in lambda or log10-lambda/velocity. + # see core.wavecal.wvutils.py for more info. + # variable defaults to None if datamodel for this is also None (which is the case for spec1d file). + wave_grid_mid = spec.wave_grid_mid + counts = spec.flux + counts_ivar = spec.ivar + counts_gpm = spec.mask.astype(bool) + spect_dict = spec.spect_meta + head = spec.head0 + else: sobjs = specobjs.SpecObjs.from_fitsfile(specfile, chk_version=False) if np.sum(sobjs.OPT_WAVE) is None: raise ValueError("This is an ugly hack until the DataContainer bug is fixed") @@ -656,22 +669,6 @@ def general_spec_reader(specfile, ret_flam=False): spectrograph = load_spectrograph('shane_kast_blue') spect_dict = spectrograph.parse_spec_header(head) head['PYP_SPEC'] = spectrograph.name - except: - #TODO Make it so that we can type a file based on the DataContainer file header - msgs.warn('Ignore the error message above. This is a hack for now until DataContainer is tightened up') - # Load - spec = onespec.OneSpec.from_file(specfile) - # Unpack - wave = spec.wave - # wavelength grid evaluated at the bin centers, uniformly-spaced in lambda or log10-lambda/velocity. - # see core.wavecal.wvutils.py for more info. - # variable defaults to None if datamodel for this is also None (which is the case for spec1d file). - wave_grid_mid = spec.wave_grid_mid - counts = spec.flux - counts_ivar = spec.ivar - counts_gpm = spec.mask.astype(bool) - spect_dict = spec.spect_meta - head = spec.head0 # Build this meta_spec = dict(bonus=bonus) diff --git a/pypeit/scripts/show_1dspec.py b/pypeit/scripts/show_1dspec.py index 2bc4ea98dd..6775499f9d 100644 --- a/pypeit/scripts/show_1dspec.py +++ b/pypeit/scripts/show_1dspec.py @@ -40,7 +40,8 @@ def main(args): from pypeit import specobjs from pypeit import msgs - sobjs = specobjs.SpecObjs.from_fitsfile(args.file, chk_version=False) + sobjs = specobjs.SpecObjs.from_fitsfile(args.file, + chk_version=False) # List only? if args.list: diff --git a/pypeit/specobjs.py b/pypeit/specobjs.py index 6093fb710d..dd6e1c1471 100644 --- a/pypeit/specobjs.py +++ b/pypeit/specobjs.py @@ -79,6 +79,10 @@ def from_fitsfile(cls, fits_file, det=None, chk_version=True): slf.header = hdul[0].header # Keep track of HDUList for closing later + # Catch common error of trying to read a OneSpec file + if 'DMODCLS' in hdul[1].header and hdul[1].header['DMODCLS'] == 'OneSpec': + msgs.error('This is a OneSpec file. You are treating it like a SpecObjs file.') + detector_hdus = {} # Loop for Detectors first as we need to add these to the objects for hdu in hdul[1:]: From c6e0a75bd5a68b47b5f92587449cd97af86e8913 Mon Sep 17 00:00:00 2001 From: profxj Date: Mon, 13 Feb 2023 13:53:05 -0800 Subject: [PATCH 2/4] turn on 3.10 and turn down from 3.11 --- CHANGES.rst | 2 ++ doc/installing.rst | 2 +- setup.cfg | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 05f804a830..f330993343 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -31,6 +31,8 @@ - Parse Keck/NIRES dither patterns, similar to MOSFIRE - Introduce BitMaskArray class to ease use of bitmasks - Fixed memory hogging by matplotlib when using version >= 3.6.1 +- New docs on OneSpec +- Modify install notes to allow 3.10 1.11.0 (21 Oct 2022) -------------------- diff --git a/doc/installing.rst b/doc/installing.rst index e8c56ee62f..bb4a90498a 100644 --- a/doc/installing.rst +++ b/doc/installing.rst @@ -18,7 +18,7 @@ Installation .. warning:: - Python 3.10 is not yet supported. + Python 3.11 is not yet supported. Below, we provide detailed instructions for installing PypeIt. For troubleshooting, please consult the PypeIt :ref:`community` and/or `submit diff --git a/setup.cfg b/setup.cfg index fc55361f02..762e1ee0f4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,8 +17,8 @@ classifiers = Natural Language :: English Operating System :: OS Independent Programming Language :: Python - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 Topic :: Documentation :: Sphinx Topic :: Scientific/Engineering :: Astronomy Topic :: Software Development :: Libraries :: Python Modules @@ -28,7 +28,7 @@ classifiers = zip_safe = False use_2to3=False packages = find: -python_requires = >=3.8,<3.12 +python_requires = >=3.8,<3.11 setup_requires = setuptools_scm include_package_data = True install_requires = From b4a6ff8f43d91eeca3bc30269eebfe1b6746933e Mon Sep 17 00:00:00 2001 From: Ryan Cooke Date: Tue, 14 Feb 2023 12:37:49 +0000 Subject: [PATCH 3/4] typo --- doc/coadd1d.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/coadd1d.rst b/doc/coadd1d.rst index 7ff04ea909..fcd3747564 100644 --- a/doc/coadd1d.rst +++ b/doc/coadd1d.rst @@ -289,7 +289,7 @@ Currently ``instrument_name`` is taken from the ``camera`` attribute of the relevant :class:`~pypeit.spectrographs.spectrograph.Spectrograph` class. -The format of the 1D coadd file follows follows the general +The format of the 1D coadd file follows the general class :class:`~pypeit.onespec.OneSpec`, such that its file extensions are: From f1351cc40c77d7eec3e8b37d7d2e92623fa70797 Mon Sep 17 00:00:00 2001 From: Ryan Cooke Date: Tue, 14 Feb 2023 12:41:00 +0000 Subject: [PATCH 4/4] typo --- doc/out_onespec.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/out_onespec.rst b/doc/out_onespec.rst index b0a8fae775..c79f0877ff 100644 --- a/doc/out_onespec.rst +++ b/doc/out_onespec.rst @@ -22,7 +22,7 @@ i.e. it can be anything you wish. The header of the primary extension includes the `core_meta` of PypeIt, e.g. RA, DEC, MJD, and -configuration parmaeters of the instrument. +configuration parameters of the instrument. Inspection ==========