Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes #67

Merged
merged 17 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ prospect API
.. automodule:: prospect
:members:

.. automodule:: prospect.grid_thumbs
:members:

.. automodule:: prospect.mycoaddcam
:members:

Expand Down Expand Up @@ -38,6 +41,9 @@ prospect API
.. automodule:: prospect.scripts.specview_cmx_targets
:members:

.. automodule:: prospect.scripts.specview_per_expo
:members:

.. automodule:: prospect.scripts.specview_per_night
:members:

Expand All @@ -49,3 +55,21 @@ prospect API

.. automodule:: prospect.utilities
:members:

.. automodule:: prospect.viewer
:members:

.. automodule:: prospect.viewer_cds
:members:

.. automodule:: prospect.viewer_plots
:members:

.. automodule:: prospect.viewer_setup
:members:

.. automodule:: prospect.viewer_widgets
:members:

.. automodule:: prospect.viewer_vi_widgets
:members:
66 changes: 66 additions & 0 deletions py/prospect/grid_thumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""
====================
prospect.grid_thumbs
====================

Grid of thumbnail plots displaying a set of spectra

"""

import numpy as np
import astropy.convolution

import bokeh.plotting as bk
import bokeh.layouts as bl

from .mycoaddcam import coaddcam_prospect

# TODOS:
# - structure: class??
# - improve thumbs with infos, plot quality

def grid_thumbs(spectra, thumb_width, x_range=(3400,10000), thumb_height=None, resamp_factor=15, ncols_grid=5, titles=None) :
'''
Create a bokeh gridplot of thumbnail pictures from spectra
- coadd arms
- smooth+resample to reduce size of embedded CDS, according to resamp_factor
- titles : optional list of titles for each thumb

TODO: Not tested on Spectrum1D objects.
'''

if thumb_height is None : thumb_height = thumb_width//2
if titles is not None : assert len(titles) == spectra.num_spectra()
thumb_wave, thumb_flux, dummy = coaddcam_prospect(spectra)
kernel = astropy.convolution.Gaussian1DKernel(stddev=resamp_factor)

thumb_plots = []
for i_spec in range(spectra.num_spectra()) :
x_vals = (thumb_wave[::resamp_factor])[resamp_factor:-resamp_factor]
# Use astropy convolution : handles NaNs
y_vals = astropy.convolution.convolve(thumb_flux[i_spec,:], kernel)
y_vals = (y_vals[::resamp_factor])[resamp_factor:-resamp_factor]
x_vals = x_vals[~np.isnan(y_vals)] # Needed to avoid 'ValueError: Out of range float values are not JSON compliant'
y_vals = y_vals[~np.isnan(y_vals)]
if len(x_vals)==0 : # All NaN ... this should not happen ...
ymin, ymax = -1, 1
else :
yampl = np.max(y_vals) - np.min(y_vals)
ymin = np.min(y_vals) - 0.1*yampl
ymax = np.max(y_vals) + 0.1*yampl
plot_title = None
if titles is not None : plot_title = titles[i_spec]
mini_plot = bk.figure(plot_width=thumb_width, plot_height=thumb_height, x_range=x_range, y_range=(ymin,ymax), title=plot_title)
if len(x_vals)!=0 : mini_plot.line(x_vals, y_vals, line_color='red')
mini_plot.xaxis.visible = False
mini_plot.yaxis.visible = False
mini_plot.min_border_left = 0
mini_plot.min_border_right = 0
mini_plot.min_border_top = 0
mini_plot.min_border_bottom = 0
thumb_plots.append(mini_plot)

return bl.gridplot(thumb_plots, ncols=ncols_grid, toolbar_location=None, sizing_mode='scale_width')

2 changes: 1 addition & 1 deletion py/prospect/scripts/specview_cmx_coadds.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import desispec.spectra
import desispec.frame

from ..plotframes import plotspectra
from ..viewer import plotspectra
from ..myspecselect import myspecselect
from ..myspecupdate import myspecupdate
from ..utilities import specviewer_selection, match_redrock_zfit_to_spectra, match_zcat_to_spectra
Expand Down
2 changes: 1 addition & 1 deletion py/prospect/scripts/specview_cmx_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import desispec.spectra
import desispec.frame

from ..plotframes import plotspectra
from ..viewer import plotspectra
from ..myspecselect import myspecselect
from ..myspecupdate import myspecupdate
from ..utilities import frames2spectra, specviewer_selection, coadd_targets
Expand Down
2 changes: 1 addition & 1 deletion py/prospect/scripts/specview_cmx_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import desispec.io
from desiutil.log import get_logger

from ..plotframes import plotspectra
from ..viewer import plotspectra
from ..myspecselect import myspecselect
from ..utilities import make_targetdict, load_spectra_zcat_from_targets #, match_zcat_to_spectra

Expand Down
6 changes: 3 additions & 3 deletions py/prospect/scripts/specview_per_night.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import desispec.frame

from ..myspecselect import myspecselect # special (to be edited)
from ..plotframes import plotspectra
from ..viewer import plotspectra
from ..utilities import match_zcat_to_spectra #, match_vi_targets, miniplot_spectrum

def _parse():
Expand Down Expand Up @@ -70,7 +70,7 @@ def main():
the_indices = sort_indices[(i_page-1)*args.nspecperfile:i_page*args.nspecperfile]
thespec = myspecselect(spectra, indices=the_indices)
thezb, kk = match_zcat_to_spectra(zbest,thespec)
model = plotframes.create_model(thespec, thezb)
#model = plotframes.create_model(thespec, thezb)
### No VI results to display by default
# vifile = os.environ['HOME']+"/prospect/vilist_prototype.fits"
# vidata = match_vi_targets(vifile, thespec.fibermap["TARGETID"])
Expand All @@ -80,7 +80,7 @@ def main():
os.makedirs(html_dir)
os.mkdir(html_dir+"/vignettes")

plotframes.plotspectra(thespec, zcatalog=thezb, vidata=None, model=model, title=titlepage, html_dir=html_dir, is_coadded=False)
plotspectra(thespec, zcatalog=thezb, title=titlepage, html_dir=html_dir, is_coadded=False)
# for i_spec in range(thespec.num_spectra()) :
# saveplot = html_dir+"/vignettes/night"+thenight+"_"+file_label+"_"+str(i_page)+"_"+str(i_spec)+".png"
# miniplot_spectrum(thespec, i_spec, model=model, saveplot=saveplot, smoothing = args.vignette_smoothing)
8 changes: 4 additions & 4 deletions py/prospect/scripts/specview_per_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import desispec.frame

from ..myspecselect import myspecselect # special (to be edited)
from ..plotframes import coadd_targets, create_model, plotspectra
from ..utilities import specviewer_selection, match_zcat_to_spectra, match_vi_targets #, miniplot_spectrum
from ..viewer import plotspectra
from ..utilities import coadd_targets, specviewer_selection, match_zcat_to_spectra, match_vi_targets #, miniplot_spectrum


def _parse():
Expand Down Expand Up @@ -108,13 +108,13 @@ def main():
titlepage = "chi2cut-"+str(args.chi2cut[0])+"-"+str(args.chi2cut[1])+"_"+titlepage
if args.mask is not None :
titlepage = args.mask+"_"+titlepage
model = create_model(thespec, thezb)
#model = create_model(thespec, thezb)
html_dir = os.path.join(webdir,"pix"+pixel)
if not os.path.exists(html_dir) :
os.makedirs(html_dir)
os.mkdir(html_dir+"/vignettes")

plotspectra(thespec, zcatalog=zbest, model_from_zcat=True, vidata=None, model=None, title=titlepage, html_dir=html_dir, is_coadded=True, mask_type=args.mask_type)
plotspectra(thespec, zcatalog=zbest, model_from_zcat=True, model=None, title=titlepage, html_dir=html_dir, is_coadded=True, mask_type=args.mask_type)
# for i_spec in range(thespec.num_spectra()) :
# saveplot = html_dir+"/vignettes/pix"+pixel+"_"+str(i_page)+"_"+str(i_spec)+".png"
# miniplot_spectrum(thespec, i_spec, model=model, saveplot=saveplot, smoothing = args.vignette_smoothing)
Expand Down