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

Allow deployment of prospect without DESI software stack #50

Merged
merged 4 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
577 changes: 577 additions & 0 deletions doc/nb/Prospect_spectrum_service.ipynb

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions doc/nb/Prospect_specutils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"sys.path.insert(0, os.path.join(os.environ['HOME'], 'Documents', 'Code', 'git', 'desihub', 'prospect', 'py'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"import numpy as np\n",
"from astropy.table import Table\n",
"from specutils import Spectrum1D, SpectrumCollection, SpectrumList\n",
Expand Down Expand Up @@ -66,6 +77,7 @@
"metadata": {},
"outputs": [],
"source": [
"os.environ['SPECTRO_REDUX'] = os.path.join(os.environ['HOME'], 'Documents', 'Data', 'sdss', 'dr16', 'sdss', 'spectro', 'redux')\n",
"run2d = '26'\n",
"plate = '2955'\n",
"mjd = '54562'\n",
Expand Down Expand Up @@ -191,9 +203,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "DESI prospect",
"display_name": "Python 3",
"language": "python",
"name": "desi-prospect"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -205,7 +217,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
26 changes: 15 additions & 11 deletions py/prospect/myspecselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# to include expid-based selection + indices-based selection
# changes : fct name+args ; self=>thespec ; expid/indices-based selection + final selection

import desispec.spectra
_desispec_imported = True
try:
import desispec.spectra
except ImportError:
_desispec_imported = False

def myspecselect(thespec, nights=None, bands=None, targets=None, fibers=None, expids=None, indices=None, invert=False, remove_scores=False, clean_fiberstatus=False, output_indices=False):
"""
Expand All @@ -15,21 +19,21 @@ def myspecselect(thespec, nights=None, bands=None, targets=None, fibers=None, ex
bands (list): optional list of bands to select.
targets (list): optional list of target IDs to select.
fibers (list): list/array of fiber indices to select.
ADDED=> expids (list): list/array of individual exposures to select.
ADDED =>indices (list) : list of raw (arbitrary) indices in the Spectra object to select.
ADDED=> expids (list): list/array of individual exposures to select.
ADDED =>indices (list) : list of raw (arbitrary) indices in the Spectra object to select.
invert (bool): after combining all criteria, invert selection.
remove_scores (bool): probably tmp trick, TODO
output_indices (bool): if True, also returns indices of kept spectra
Returns (Spectra):
a new Spectra object containing the selected data.
"""

keep_fiberstatus = None
if clean_fiberstatus == False :
keep_fiberstatus = [ True for x in range(thespec.num_spectra()) ]
else :
keep_fiberstatus = [ (x==0) for x in thespec.fibermap["FIBERSTATUS"] ]

keep_bands = None
if bands is None:
keep_bands = thespec.bands
Expand All @@ -47,7 +51,7 @@ def myspecselect(thespec, nights=None, bands=None, targets=None, fibers=None, ex
if sum(keep_nights) == 0:
print("myspecselect: no valid nights were selected.")
return None

keep_targets = None
if targets is None:
keep_targets = [ True for x in range(thespec.num_spectra()) ]
Expand All @@ -56,7 +60,7 @@ def myspecselect(thespec, nights=None, bands=None, targets=None, fibers=None, ex
if sum(keep_targets) == 0:
print("myspecselect: no valid targets were selected.")
return None

keep_fibers = None
if fibers is None:
keep_fibers = [ True for x in range(thespec.num_spectra()) ]
Expand Down Expand Up @@ -122,13 +126,13 @@ def myspecselect(thespec, nights=None, bands=None, targets=None, fibers=None, ex
keep_scores = None
if not remove_scores :
if thespec.scores is not None : keep_scores = thespec.scores[keep]
ret = desispec.spectra.Spectra(keep_bands, keep_wave, keep_flux, keep_ivar,
mask=keep_mask, resolution_data=keep_res,

ret = desispec.spectra.Spectra(keep_bands, keep_wave, keep_flux, keep_ivar,
mask=keep_mask, resolution_data=keep_res,
weaverba137 marked this conversation as resolved.
Show resolved Hide resolved
fibermap=thespec.fibermap[keep], meta=thespec.meta, extra=keep_extra,
single=thespec._single, scores=keep_scores)

if output_indices :
return (ret, keep)

return ret
21 changes: 15 additions & 6 deletions py/prospect/myspecupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
# Reason : EXPID is not available in coadd spectra

import numpy as np
import desispec.spectra
from desiutil.io import encode_table
from desispec.maskbits import specmask
from desispec.resolution import Resolution
_desiutil_imported = True
try:
from desiutil.io import encode_table
except ImportError:
_desiutil_imported = False

_desispec_imported = True
try:
import desispec.spectra
from desispec.maskbits import specmask
from desispec.resolution import Resolution
except ImportError:
_desispec_imported = False
weaverba137 marked this conversation as resolved.
Show resolved Hide resolved

def myspecupdate(spectra_in, other) :

Expand Down Expand Up @@ -91,7 +100,7 @@ def myspecupdate(spectra_in, other) :
or ("FIBER" not in spectra_in.fibermap.keys())
or ("FIBER" not in other.fibermap.keys()) ) :
check_exists = False
if check_exists :
if check_exists :
for r in range(nother):
expid = other.fibermap[r]["EXPID"]
fiber = other.fibermap[r]["FIBER"]
Expand All @@ -106,7 +115,7 @@ def myspecupdate(spectra_in, other) :
indx_exists = np.where(exists == 1)[0]
indx_new = np.where(exists == 0)[0]

# Make new data arrays of the correct size to hold both the old and
# Make new data arrays of the correct size to hold both the old and
# new data

nupdate = len(indx_exists)
Expand Down