Skip to content

Commit

Permalink
Merge pull request #113 from spacetelescope/v1.36.0
Browse files Browse the repository at this point in the history
V1.36.0
  • Loading branch information
scfleming authored Feb 13, 2024
2 parents dbf35bd + 748f1de commit d13d62d
Show file tree
Hide file tree
Showing 28 changed files with 691 additions and 68 deletions.
8 changes: 6 additions & 2 deletions History.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Change Log for SPEC_PLOTS
=========================

v1.35.1 - 2023 Aug. 4
v1.36.0 - 2024 Feb. 9
-----------------
* Added basic support HST Hubble Advanced Spectral Products (HASP)

v1.35.1 - 2023 Aug. 4
-----------------
* Added support for flux uncertainties being in FLUX_ERROR column
instead of ERROR column for JWST x1d FITS files.
* Fixed readability of y-axis tick labels by adjusting font size,
angle, and padding.

v1.35.0 - 2023 Jul. 31
v1.35.0 - 2023 Jul. 31
-----------------
* Added required config file for ReadTheDocs.
* Updated package dependencies to newer versions.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
license="MIT",
packages=["spec_plots", "spec_plots.utils", "spec_plots.utils.specutils",
"spec_plots.utils.specutils_cos",
"spec_plots.utils.specutils_hasp",
"spec_plots.utils.specutils_jwst",
"spec_plots.utils.specutils_stis"],
install_requires=["astropy>=5.2.2", "matplotlib>=3.7.1", "numpy>=1.24.3",
Expand Down
8 changes: 6 additions & 2 deletions spec_plots.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Metadata-Version: 2.1
Name: spec-plots
Version: 1.35.1
Name: spec_plots
Version: 1.36.0
Summary: Create preview plots of HST or JWST spectra.
Home-page: https://github.com/spacetelescope/spec_plots
Author: Scott W. Fleming
Author-email: [email protected]
License: MIT
Classifier: Programming Language :: Python :: 3
Requires-Dist: astropy>=5.2.2
Requires-Dist: matplotlib>=3.7.1
Requires-Dist: numpy>=1.24.3
Requires-Dist: future>=0.18.3
4 changes: 4 additions & 0 deletions spec_plots.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec_plots/utils/specutils_cos/get_segment_names.py
spec_plots/utils/specutils_cos/make_fits.py
spec_plots/utils/specutils_cos/plotspec.py
spec_plots/utils/specutils_cos/readspec.py
spec_plots/utils/specutils_hasp/__init__.py
spec_plots/utils/specutils_hasp/haspspectrum.py
spec_plots/utils/specutils_hasp/plotspec.py
spec_plots/utils/specutils_hasp/readspec.py
spec_plots/utils/specutils_jwst/__init__.py
spec_plots/utils/specutils_jwst/jwstspectrum.py
spec_plots/utils/specutils_jwst/plotspec.py
Expand Down
2 changes: 1 addition & 1 deletion spec_plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

from __future__ import absolute_import

__version__ = '1.35.1'
__version__ = '1.36.0'
7 changes: 5 additions & 2 deletions spec_plots/docs/API/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import mock,os,sys
import unittest.mock as mock
import os
import sys

MOCK_MODULES = ['astropy', 'astropy.io', 'matplotlib', 'matplotlib.pyplot', 'matplotlib.ticker', 'matplotlib.collections', 'numpy', 'future', 'future.builtins']
for mod_name in MOCK_MODULES:
Expand All @@ -26,6 +28,7 @@
sys.path.insert(0, os.path.abspath('../../utils/'))
sys.path.insert(0, os.path.abspath('../../utils/specutils/'))
sys.path.insert(0, os.path.abspath('../../utils/specutils_cos/'))
sys.path.insert(0, os.path.abspath('../../utils/specutils_hasp/'))
sys.path.insert(0, os.path.abspath('../../utils/specutils_jwst/'))
sys.path.insert(0, os.path.abspath('../../utils/specutils_stis/'))

Expand Down Expand Up @@ -55,7 +58,7 @@

# General information about the project.
project = u'spec_plots'
copyright = u'2014,2015,2016 Scott W. Fleming'
copyright = u'2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024 Scott W. Fleming'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
2 changes: 1 addition & 1 deletion spec_plots/docs/API/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Documentation for MAST's openSAIL project: spec_plots
Documentation for MAST's spectral preview generator: spec_plots
=====================================================

Contents:
Expand Down
1 change: 1 addition & 0 deletions spec_plots/docs/API/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Utility Modules, Including Instrument-Specific READ and PLOT Modules

utils.specutils
utils.specutils_cos
utils.specutils_hasp
utils.specutils_jwst
utils.specutils_stis
20 changes: 20 additions & 0 deletions spec_plots/docs/API/utils.specutils_hasp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
utils.specutils_hasp package
============================

haspspectrum
---------------------------------------

.. automodule:: utils.specutils_hasp.haspspectrum
:members:
:undoc-members:
:show-inheritance:

plotspec
-----------------------------------

.. autofunction:: utils.specutils_hasp.plotspec

readspec
-----------------------------------

.. autofunction:: utils.specutils_hasp.readspec
2 changes: 1 addition & 1 deletion spec_plots/docs/README_DEVELOPERS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Best Practices for Development Of A New Branch

8.) After doing a final commit of the branch, make sure all Github Issues are closed for that branch, or re-assigned if punting to a later build for that Issue.

9.) After regression testing is finished and all Issues assigned to this branch are closed or moved to a future build, initiate a pull request and merge into master.
9.) After regression testing is finished and all Issues assigned to this branch are closed or moved to a future build, initiate a pull request and merge into main.

10.) To upload to PyPI with twine: twine upload dist/*, with the -u and -p options.

Expand Down
68 changes: 62 additions & 6 deletions spec_plots/make_hst_spec_previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from __future__ import absolute_import
from __future__ import print_function
import argparse
from os import path
from builtins import str
from os import path
import sys
#--------------------
# External Imports
#--------------------
Expand All @@ -27,7 +28,7 @@
#--------------------
# Package Imports
#--------------------
from spec_plots.utils import specutils, specutils_cos, specutils_stis
from spec_plots.utils import specutils, specutils_cos, specutils_stis, specutils_hasp
from spec_plots import __version__

FLUX_SCALE_FACTOR_DEFAULT = 10.
Expand All @@ -43,7 +44,7 @@

#--------------------

class HSTSpecPrevError(Exception, object):
class HSTSpecPrevError(Exception):
"""
This class defines a generic Exception to use for errors raised in
MAKE_HST_SPEC_PREVIEWS. It simply prints the given string when raising the
Expand Down Expand Up @@ -99,7 +100,8 @@ def check_input_options(args):

def get_instrument_name(input_file):
"""
Retrieves the instrument name from a FITS file primary header.
Determines whether the input file is for HASP (Hubbble Advanced
Spectral Product).
:param input_file: Name of input FITS file.
Expand All @@ -124,11 +126,28 @@ def get_instrument_name(input_file):
except KeyError:
print("*** MAKE_HST_SPEC_PREVIEWS ERROR: INSTRUME keyword not"
" found in this file's primary header: " + input_file)
exit(1)
sys.exit()
return this_instrument.strip().upper()

#--------------------

def is_hasp_product(input_file):
"""
Retrieves the instrument name from a FITS file primary header.
:param input_file: Name of input FITS file.
:type input_file: str
:returns: bool -- Returns True if the filename ends in _cspec.fits.
"""

if input_file.endswith("_cspec.fits"):
return True
return False

#--------------------

def make_hst_spec_previews(input_file, flux_scale_factor=
FLUX_SCALE_FACTOR_DEFAULT, fluxerr_scale_factor=
FLUXERR_SCALE_FACTOR_DEFAULT, n_consecutive=
Expand Down Expand Up @@ -227,13 +246,50 @@ def make_hst_spec_previews(input_file, flux_scale_factor=
if ofile is not None:
if ofile[-4:] == '.png':
print(" Output file: " + ofile)
print(" Output file: " + ofile.strip('\.png') +
print(" Output file: " + ofile.split('.png')[0] +
'_thumb.png')
else:
print(" Output file: " + ofile)
else:
print(" Plotting to screen.")

# Handle previews for HASP products.
if is_hasp_product(input_file):
if verbose:
print("HASP product")
# Get wavelengths, fluxes, flux uncertainties.
hasp_spectrum = specutils_hasp.readspec(input_file)

# Make "large-size" plot.
for out_type, out_file in zip(output_type, output_files):
if out_type != 'fits':
# Make "large-size" plot
hasp_plot_metrics = specutils.calc_plot_metrics("hasp",
hasp_spectrum.wavelengths,
hasp_spectrum.fluxes,
hasp_spectrum.fluxerrs,
hasp_spectrum.dqs,
1, flux_scale_factor, fluxerr_scale_factor)
specutils_hasp.plotspec(hasp_spectrum,
out_type, out_file,
flux_scale_factor, fluxerr_scale_factor,
hasp_plot_metrics,
dpi_val=dpi_val, output_size=1024,
debug=debug, full_ylabels=full_ylabels,
optimize=optimize)

# Make "thumbnail-size" plot, if requested. Notice that in this
# case we always plot just the first association, by passing only
# `stitched_spectra[0]`.
if not debug:
specutils_hasp.plotspec(hasp_spectrum,
out_type, out_file,
flux_scale_factor, fluxerr_scale_factor,
hasp_plot_metrics,
dpi_val=dpi_val,
output_size=128, optimize=optimize)
return

# Read in the FITS file to determine which instrument it comes from.
# Print the name of the instrument found in the header if verbose is turned
# on.
Expand Down
9 changes: 5 additions & 4 deletions spec_plots/make_jwst_spec_previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from __future__ import absolute_import
from __future__ import print_function
import argparse
from os import path
from builtins import str
from os import path
import sys
#--------------------
# External Imports
#--------------------
Expand All @@ -43,7 +44,7 @@

#--------------------

class JWSTSpecPrevError(Exception, object):
class JWSTSpecPrevError(Exception):
"""
This class defines a generic Exception to use for errors raised in
MAKE_JWST_SPEC_PREVIEWS. It simply prints the given string when raising the
Expand Down Expand Up @@ -124,7 +125,7 @@ def get_instrument_name(input_file):
except KeyError:
print("*** MAKE_JWST_SPEC_PREVIEWS ERROR: INSTRUME keyword not"
" found in this file's primary header: " + input_file)
exit(1)
sys.exit()
return this_instrument.strip().upper()

#--------------------
Expand Down Expand Up @@ -228,7 +229,7 @@ def make_jwst_spec_previews(input_file, flux_scale_factor=
if ofile is not None:
if ofile[-4:] == '.png':
print(" Output file: " + ofile)
print(" Output file: " + ofile.strip('\.png') +
print(" Output file: " + ofile.split('.png')[0] +
'_thumb.png')
else:
print(" Output file: " + ofile)
Expand Down
1 change: 0 additions & 1 deletion spec_plots/utils/specutils/calc_plot_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,3 @@ def calc_plot_metrics(instrument, wls, fls, flerrs, dqs, n_consecutive,
optimal_xaxis_range, "avoid_regions":avoid_regions,
"y_axis_range":y_axis_range, "line_collection":linecoll}
#--------------------

5 changes: 4 additions & 1 deletion spec_plots/utils/specutils/edge_trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def _set_plot_xrange_test(instrument, flux_values, flux_err_values, median_flux,
# Return array of boolean values for the edge_trim test.
if numpy.isfinite(median_flux):
bool_results = [((instrument == "cos" and x != 0. and check_fluxes) or
(instrument == "hasp" and x != 0. and check_fluxes) or
(instrument == "stis" and x != 0. and check_fluxes) or
(instrument == "miri" and x != 0. and check_fluxes) or
(not check_fluxes))
Expand All @@ -132,6 +133,8 @@ def _set_plot_xrange_test(instrument, flux_values, flux_err_values, median_flux,
is_bad_dq(instrument, z) and check_dqs) or
(instrument == "cos" and not
is_bad_dq(instrument, z) and check_dqs) or
(instrument == "hasp" and not
is_bad_dq(instrument, z) and check_dqs) or
(instrument == "miri" and not
is_bad_dq(instrument, z) and check_dqs) or
(not check_dqs))
Expand Down Expand Up @@ -217,7 +220,7 @@ def edge_trim(instrument, fluxes, fluxerrs, dqs, n_consecutive, median_flux,

# First run the xrange test on the first and last 100 elements (for
# speed). If no good indices are found within those ranges, then and only
# then will we run it on the entire array. """
# then will we run it on the entire array.
where_good_fluxes_nodq = numpy.where(numpy.asarray(_set_plot_xrange_test(
instrument, numpy.concatenate((fluxes[0:edge_size],
fluxes[-1*edge_size:])),
Expand Down
23 changes: 12 additions & 11 deletions spec_plots/utils/specutils/is_bad_dq.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ def is_bad_dq(instrument, dqs):
if instrument == "cos":
if isinstance(dqs, numpy.ndarray):
return numpy.asarray([x < 1 for x in dqs])
else:
return dqs < 1
return dqs < 1

elif instrument == "stis":
if instrument == "hasp":
if isinstance(dqs, numpy.ndarray):
return numpy.asarray([x != 0 and x != 16 for x in dqs])
else:
return dqs != 0 and dqs != 16
return numpy.asarray([x < 1 for x in dqs])
return dqs < 1

if instrument == "stis":
if isinstance(dqs, numpy.ndarray):
return numpy.asarray([x not in (0, 16) for x in dqs])
return dqs not in (0, 16)

elif instrument in ["miri", "nirspec", "niriss"]:
if instrument in ["miri", "nirspec", "niriss"]:
if isinstance(dqs, numpy.ndarray):
return numpy.asarray([x < 1 for x in dqs])
else:
return dqs < 1
return dqs < 1

else:
return numpy.asarray([])
return numpy.asarray([])
#--------------------
10 changes: 4 additions & 6 deletions spec_plots/utils/specutils/set_plot_yrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ def set_plot_yrange(wavelengths, fluxes, avoid_regions=None, wl_range=None):
if min_flux != max_flux:
if min_flux - ybuffer > 0.:
return [min_flux-ybuffer, max_flux+ybuffer]
else:
# We don't want the y-axis range to be TOO far negative, so limit
# it to be close to the lowest data point. """
return [1.1*min_flux, max_flux+ybuffer]
else:
return [min_flux-1., max_flux+1.]
# We don't want the y-axis range to be TOO far negative, so limit
# it to be close to the lowest data point.
return [1.1*min_flux, max_flux+ybuffer]
return [min_flux-1., max_flux+1.]
#--------------------
Loading

0 comments on commit d13d62d

Please sign in to comment.