Skip to content

Commit

Permalink
FPS Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Morrison committed Jan 27, 2022
1 parent 9abfcbe commit 7b51a22
Show file tree
Hide file tree
Showing 24 changed files with 274 additions and 143 deletions.
36 changes: 26 additions & 10 deletions bin/plot_sdss_sky
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from matplotlib import pyplot as plt
from astropy.visualization import hist
from astropy.io import fits as pyf
import os
from astropy.table import Table
matplotlib.style.use('default')
import warnings
warnings.filterwarnings("ignore")
Expand All @@ -17,13 +18,14 @@ run2d = os.getenv('RUN2D')
redux = os.getenv('BOSS_SPECTRO_REDUX')

file_c=redux+'/'+run2d+'/fieldlist-'+run2d+'.fits'
hdu_list = pyf.open(file_c)
table_hdu = hdu_list[1]
table_data = table_hdu.data
if os.path.exists(file_c):
hdu_list = pyf.open(file_c)
table_hdu = hdu_list[1]
table_data = table_hdu.data
else: table_data=Table(names=('RACEN','DECCEN', 'PROGRAMNAME'))
RA=table_data.field('RACEN')
DEC=table_data.field('DECCEN')
prog=table_data.field('PROGRAMNAME')

PROG_N=np.zeros(len(prog))
PROG_C=[]
for i in range(0, len(prog)):
Expand All @@ -48,7 +50,9 @@ for i in range(0, len(prog)):
elif 'OFFSET' in prog[i]:
PROG_N[i]=7.0
PROG_C.extend(['black'])

else:
PROG_N[i]=0.0
PROG_C.extend(['saddlebrown'])


PROG_C=np.array(PROG_C)
Expand All @@ -58,6 +62,8 @@ c3=0
c4=0
c5=0
c6=0
c7=0
c0=0

# convert coordinates to degrees
RA *= np.pi / 180
Expand Down Expand Up @@ -92,6 +98,8 @@ for i in range(0, len(RA)):
elif PROG_C[i] == 'green' and c6== 0:
ax.plot(x, y, color=PROG_C[i],label='eFEDS')
c6=1
elif PROG_C[i] == 'black' and c7==0:
ax.plot(x, y, color=PROG_C[i],label='Offset')
else:
ax.plot(x, y, color=PROG_C[i])
plt.legend(loc=1,fontsize=10)
Expand All @@ -106,6 +114,9 @@ c2=0
c3=0
c4=0
c5=0
c6=0
c7=0
c0=0

fig, ax = plt.subplots(figsize=(9.5*1.0,5.5*1.0))
ax = plt.axes(projection='mollweide')
Expand All @@ -131,12 +142,15 @@ for i in range(0, len(RA)):
elif PROG_C[i] == 'orange' and c4== 0:
ax.plot(x, y, color=PROG_C[i],label='AQMES-Wide')
c4=1
elif PROG_C[i] == 'magenta' and c4== 0:
elif PROG_C[i] == 'magenta' and c5== 0:
ax.plot(x, y, color=PROG_C[i],label='AQMES-Bonus')
c5=1
elif PROG_C[i] == 'green' and c5== 0:
elif PROG_C[i] == 'green' and c6== 0:
ax.plot(x, y, color=PROG_C[i],label='eFEDS')
c6=1
elif PROG_C[i] == 'black' and c7== 0:
ax.plot(x, y, color=PROG_C[i],label='eFEDS')
c7=1
else:
ax.plot(x, y, color=PROG_C[i])
plt.legend(loc=1,fontsize=10)
Expand All @@ -147,9 +161,11 @@ plt.savefig(redux+'/'+run2d+'/SDSSV.png',dpi=500)
plt.close()

file_c=redux+'/'+run2d+'/spAll-'+run2d.replace('/','-')+'.fits'
hdu_list = pyf.open(file_c)
table_hdu = hdu_list[1]
table_data = table_hdu.data
if os.path.exists(file_c):
hdu_list = pyf.open(file_c)
table_hdu = hdu_list[1]
table_data = table_hdu.data
else: table_data=Table(names=('PLUG_RA','PLUG_DEC', 'PROGRAMNAME','NSPECOBS'))
RA1=table_data.field('PLUG_RA')
DEC1=table_data.field('PLUG_DEC')
prog1=table_data.field('PROGRAMNAME')
Expand Down
25 changes: 16 additions & 9 deletions bin/run_PyXCSAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def get_fiber(flux, PlugMap, hdr, i):
#meta['objid']=PlugMap['OBJID'][i]
meta['program']=PlugMap['PROGRAM'][i]
meta['objtype']=PlugMap['OBJTYPE'][i]
meta['SOURCETYPE']=PlugMap['SOURCETYPE'][i]

if 'SOURCETYPE' in hdr:meta['SOURCETYPE']=PlugMap['SOURCETYPE'][i]
elif 'CATEGORY' in hdr:meta['SOURCETYPE']=PlugMap['CATEGORY'][i]
else:meta['SOURCETYPE']=PlugMap['OBJTYPE'][i]

if 'PLATEID' in hdr: meta['FIELDID']=hdr['PLATEID']
elif 'FIELDID' in hdr: meta['FIELDID']=hdr['FIELDID']
else: meta['FIELDID']=np.nan
Expand All @@ -77,9 +79,15 @@ def get_fiber(flux, PlugMap, hdr, i):
meta['sdss_r']=PlugMap['MAG'][i][2]
meta['sdss_i']=PlugMap['MAG'][i][3]
meta['sdss_z']=PlugMap['MAG'][i][4]
meta['gaia_G']=PlugMap['GAIA_G'][i]
meta['BP']=PlugMap['GAIA_BP'][i]
meta['RP']=PlugMap['GAIA_RP'][i]
if 'GAIA_G' in hdr:meta['gaia_G']=PlugMap['GAIA_G'][i]
elif 'GAIA_G_MAG' in hdr:meta['gaia_G']=PlugMap['GAIA_G_MAG'][i]
else: meta['gaia_G']=np.NaN
if 'GAIA_BP' in hdr:meta['BP']=PlugMap['GAIA_BP'][i]
elif 'BP_MAG' in hdr:meta['BP']=PlugMap['BP_MAG'][i]
else: meta['BP']=np.NaN
if 'GAIA_RP' in hdr:meta['RP']=PlugMap['GAIA_RP'][i]
elif 'RP_MAG' in hdr:meta['RP']=PlugMap['RP_MAG'][i]
else: meta['RP']=np.NaN
meta['J']=PlugMap['TWOMASS_MAG'][i][0]
meta['H']=PlugMap['TWOMASS_MAG'][i][1]
meta['K']=PlugMap['TWOMASS_MAG'][i][2]
Expand All @@ -97,8 +105,7 @@ def get_fiber(flux, PlugMap, hdr, i):
default=os.getenv('RUN1D'))
args = parser.parse_args()

platemjd=os.path.basename(args.fitsfile)[8:19]

platemjd='-'.join(os.path.basename(args.fitsfile).split('-')[1:]).split('.')[0]

# Open a file with access mode 'a'
logfile = args.run1d+'/spXCSAO-' + platemjd + '.log'
Expand All @@ -112,7 +119,7 @@ def get_fiber(flux, PlugMap, hdr, i):
splog.write('idlutils version ' + os.popen('idlutils_version').read())
splog.write('Python version ' + python_version())
try:
#splog.write('pyxcsao version ' + pyxcsao.__path__[0].split('/')[-2][:-4])
#splog.write('pyxcsao version ' + pyxcsao.__path__[0].split('/')[-2][:-4])
splog.write('pyxcsao version ' +os.getenv('PYXCSAO_VER'))
c=PyXCSAO(st_lambda=5000,end_lambda=10000)
templates=os.getenv('PYXCSAO_DIR')+'/../grids/phoenix_full1.p'
Expand All @@ -137,5 +144,5 @@ def get_fiber(flux, PlugMap, hdr, i):
test.write(args.run1d+'/spXCSAO-' + platemjd + '.fits',overwrite=True)

splog.write('CPU time to compute RVs = '+ str(datetime.now()-t0))
except: splog.write('WARNING: Python package pyxcsao not installed\n')
except: splog.write('WARNING: Failed run of pyXCSAO\n')
splog.close()
10 changes: 5 additions & 5 deletions pro/fpsconfig/field_to_string.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ function field_to_string, field
for i=0, n_elements(field)-1 do sfield[i] = field_to_string(field[i])
return, sfield
endif

if field lt 10000 then $
return, strtrim(string(field,f='(i5.5)'),2) $
else $
return, strtrim(field,2)
return, strtrim(string(field,f='(i6.6)'),2)
;if field lt 10000 then $
; return, strtrim(string(field,f='(i6.6)'),2) $
;else $
; return, strtrim(field,2)

end
2 changes: 1 addition & 1 deletion pro/rm/rm_combine_script.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if keyword_set(legacy) then begin
;fieldstr = strmid(planfile,11,4)
fieldstr = strsplit(repstr(repstr(planfile,'spPlancomb',''),'.par', ''),'-',/extract)
endif else begin
fieldstr = strmid(planfile,11,5)
fieldstr = (strsplit(repstr(repstr(planfile,'spPlancomb',''),'.par', ''),'-',/extract))[0]
endelse

if not keyword_set(finaldir) then finaldir = '';'recalib/' ; 'recalib/test20/'
Expand Down
5 changes: 3 additions & 2 deletions pro/rm/rm_spcoadd_v5.pro
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,8 @@ pro rm_spcoadd_v5, spframes, outputname, $
;----------
; Remove header cards that were specific to this first exposure
; (where we got the header).
sxaddpar, bighdr, 'FIELDID', strmid(outputname,8,5)
sxaddpar, bighdr, 'FIELDID', (strsplit(outputname,'-',/EXTRACT))[1]
;sxaddpar, bighdr, 'FIELDID', strmid(outputname,8,5)
ncoeff = sxpar(bighdr, 'NWORDER')
for i=2, ncoeff-1 do sxdelpar, bighdr, 'COEFF'+strtrim(string(i),2)

Expand Down Expand Up @@ -1474,7 +1475,7 @@ pro rm_spcoadd_v5, spframes, outputname, $
;coaddname = repstr(repstr(outputname,'spField','spSpec'),'.fits', $
; '-'+string(itarget,format='(i3.3)')+'.fits')
coaddname = repstr(repstr(outputname,'spField','spSpec'),'.fits', $
'-'+targid_tar+'.fits')
'-'+strtrim(targid_tar,2)+'.fits')
fulloutname_coadd = djs_filepath(coaddname, root_dir=coadddir)
; HDU # 0 header
mwrfits, junk_d, fulloutname_coadd, bighdr, /create
Expand Down
4 changes: 2 additions & 2 deletions pro/rm/rm_spcombine_v5.pro
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ pro rm_spcombine_v5, planfile, docams=docams, adderr=adderr, xdisplay=xdisplay,
if (NOT keyword_set(thismjd)) then $
thismjd = max(allseq.mjd)
if keyword_set(legacy) or keyword_set(plates) then begin
fieldmjd = string(yanny_par(hdr,'plateid'),format='(i5.5)') $
fieldmjd = field_to_string(yanny_par(hdr,'plateid')) $
+ '-' + string(thismjd,format='(i5.5)')
endif else begin
fieldmjd = string(yanny_par(hdr,'fieldid'),format='(i5.5)') $
fieldmjd = field_to_string(yanny_par(hdr,'fieldid')) $
+ '-' + string(thismjd,format='(i5.5)')
endelse
for i=0, n_elements(allseq.mjd)-1 do begin
Expand Down
7 changes: 4 additions & 3 deletions pro/rm/spreduce1d_empca.pro
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ CPU, TPOOL_NTHREADS = 1

;----------
; Determine names of output files

platemjd = strmid(fileandpath(platefile), 8, 11)
platemjd=(strsplit(repstr(platefile,".fits",""), '-',/extract))[1:2]
platemjd=strjoin(platemjd, '-')
;platemjd = strmid(fileandpath(platefile), 8, 11)
if platemjd eq '15013-59165' or platemjd eq '15014-59165' then begin
chop_data = [3600., 9000.]
splog, 'Setting wavelength coverage as:'+string(chop_data[0])+' to '+string(chop_data[1])+' for plate-mjd '+platemjd
Expand Down Expand Up @@ -946,7 +947,7 @@ endif
endif

plottitle = string(zans[0].field, zans[0].mjd, $
format='("Flux-Calibration Errors Field=", i4, " MJD=", i5)')
format='("Flux-Calibration Errors Field=", i4 ," MJD=", i5)')
qaplot_fcalibvec, objloglam, objflux, objivar, synflux, plugmap, zans, $
plottitle=plottitle

Expand Down
25 changes: 21 additions & 4 deletions pro/spec1d/conflist.pro
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ pro conflist, plist=plist, create=create, $
'data' , ' ', $
'plots' , ' ', $
'fieldquality' , ' ', $
'platesn2' , 0.0, $
'fieldsn2' , 0.0, $
'deredsn2' , 0.0, $
'qsurvey' , 0L, $
'mjdlist' , ' ', $
Expand Down Expand Up @@ -998,8 +998,13 @@ pro conflist, plist=plist, create=create, $
hdr=hdrcomb,/anonymous))[0].mjd
;if jdtemp ge 59309 and run2d ne 'master' then begin
;if jdtemp ge 59309 then begin
plate_temp = (yanny_readone(combparfile[ifile], 'SPEXP', $
hdr=hdrcomb,/anonymous))[0].plateid
if keyword_set(plates) then begin
plate_temp = (yanny_readone(combparfile[ifile], 'SPEXP', $
hdr=hdrcomb,/anonymous))[0].plateid
endif else begin
plate_temp = (yanny_readone(combparfile[ifile], 'SPEXP', $
hdr=hdrcomb,/anonymous))[0].fieldid
endelse
epoch_temp = (yanny_readone(combparfile[ifile], 'SPEXP', $
hdr=hdrcomb,/anonymous))[0].epoch_combine
plist[ifile].mapname=strtrim(string(plate_temp),2)+'-'+strtrim(string(epoch_temp),2)
Expand Down Expand Up @@ -1224,7 +1229,19 @@ pro conflist, plist=plist, create=create, $
plist[ifile].epoch = cinfo.epoch
plist[ifile].chunkhtml='<a href="https://platedesign.sdss.org/runs/'+cinfo.chunk+'/'+cinfo.chunk+'.html">'+cinfo.chunk+'</a>'
endif else begin
splog, 'Empty or missing platePlans.par file'
if keyword_set(plates) or keyword_set(legacy) then begin
splog, 'Empty or missing platePlans.par file'
endif else begin
splog, 'Empty or missing configPlans.par file'
fibermap='fibermap-'+strtrim(yanny_par(hdrp,'fieldid'),2)+'.fits'
fibermap=djs_filepath(fibermap, root_dir=topdir + '/' + run2d, subdir=field_to_string(yanny_par(hdrp,'fieldid')))
if FILE_TEST(fibermap) then begin
plughead=headfits(fibermap,EXTEN=1)
plist[ifile].racen = sxpar(plughead,'RACEN')
plist[ifile].deccen = sxpar(plughead,'DECCEN')
;if strtrim(sxpar(plughead,'OBS'),2) EQ 'APO'
endif else splog, 'Empty or missing fibermap: '+fibermap
endelse
endelse

;----------
Expand Down
18 changes: 11 additions & 7 deletions pro/spec1d/fieldmerge.pro
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pro fieldmerge1, field=field, mjd=mjd, except_tags1=except_tags1, $
endif else begin
outroot = ['spAll','spAllLine']
if (keyword_set(field) and keyword_set(mjd)) then begin
outroot='spectra/full/'+strtrim(string(field),2)+'/'+strtrim(string(mjd),2)+'/'+outroot+'-'+strtrim(string(field),2)+'-'+strtrim(string(mjd),2)
outroot='spectra/full/'+field_to_string(field)+'/'+strtrim(string(mjd),2)+'/'+outroot+'-'+field_to_string(field)+'-'+strtrim(string(mjd),2)
endif else begin
if (keyword_set(run2d)) then outroot = outroot + '-' + repstr(run2d,'/','-')
endelse
Expand Down Expand Up @@ -315,10 +315,11 @@ pro fieldmerge1, field=field, mjd=mjd, except_tags1=except_tags1, $
for ifile=0L, nfile-1 do begin
print, 'Reading ZANS file ',ifile+1, ' of ', nfile
if keyword_set(legacy) or keyword_set(plates) then begin
field_plate=plist[ifile].field
field_plate=field_to_string(plist[ifile].field)
endif else begin
field_plate=plist[ifile].field
field_plate=field_to_string(plist[ifile].field)
endelse

readspec, field_plate, mjd=plist[ifile].mjd, $
run2d=strtrim(plist[ifile].run2d), run1d=strtrim(plist[ifile].run1d), $
zans=zans, objhdr=objhdr, $ ;; zmanual=zmanual,
Expand Down Expand Up @@ -475,9 +476,12 @@ pro fieldmerge1, field=field, mjd=mjd, except_tags1=except_tags1, $
; Get PRIMTARGET+SECTARGET with those values from
; the plug-map structure in spfield file.
; HJIM decoment the next three lines for the final version
outdat[indx].primtarget = plugmap.primtarget
outdat[indx].sectarget = plugmap.sectarget
outdat[indx].lambda_eff = plugmap.lambda_eff
if (tag_exist(plugmap,'primtarget')) then $
outdat[indx].primtarget = plugmap.primtarget
if (tag_exist(plugmap,'sectarget')) then $
outdat[indx].sectarget = plugmap.sectarget
if (tag_exist(plugmap,'lambda_eff')) then $
outdat[indx].lambda_eff = plugmap.lambda_eff
if (tag_exist(plugmap,'zoffset')) then $
outdat[indx].zoffset = plugmap.zoffset
if (tag_exist(plugmap,'xfocal')) then $
Expand Down Expand Up @@ -636,7 +640,7 @@ pro fieldmerge1, field=field, mjd=mjd, except_tags1=except_tags1, $
'-' + string(plugmap[fid].catalogid,format='(i11.11)')+'.fits'
endfor
endif else begin
if not keyword_keyword_set(legacy) then begin
if not keyword_set(legacy) then begin
for fid = 0L, n_elements(zans)-1 do begin
healpix_dir_t[fid]=mwm_root + $
strtrim(string(healp[fid].healpixgrp),2) + '/' + $
Expand Down
19 changes: 12 additions & 7 deletions pro/spec1d/plate_spec_image.pro
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ for i=0L, n_elements(zans)-1L do begin
if keyword_set(legacy) then begin
pmjdf= pmjd+'-'+string(f='(i4.4)', fiber)
endif else begin
catalogid=plug[i].catalogid
if catalogid eq 0 then begin
pmjdf= pmjd+'-'+string(f='(i11.11)', fiber)
endif else begin
if plug[i].program.contains('offset', /FOLD_CASE ) then begin
pmjdf= pmjd+'-'+strtrim(string(catalogid),1)
if keyword_set(plates) then begin
catalogid=plug[i].catalogid
if catalogid eq 0 then begin
pmjdf= pmjd+'-'+string(f='(i11.11)', fiber)
endif else begin
pmjdf= pmjd+'-'+string(f='(i11.11)', catalogid)
if plug[i].program.contains('offset', /FOLD_CASE ) then begin
pmjdf= pmjd+'-'+strtrim(string(catalogid),1)
endif else begin
pmjdf= pmjd+'-'+string(f='(i11.11)', catalogid)
endelse
endelse
endif else begin
catalogid=plug[i].catalogid
pmjdf=pmjd+'-'+strtrim(string(catalogid),2)
endelse
endelse
stamp='http://skyserver.sdss.org/dr16/SkyServerWS/ImgCutout/getjpeg?TaskName=Skyserver.Chart.Image&ra='+strtrim(string(f='(f40.5)', ra),2)+'&dec='+strtrim(string(f='(f40.5)', dec),2)+'&scale=0.1&width=512&height=512&opt=G&query=&Grid=on'
Expand Down
3 changes: 2 additions & 1 deletion pro/spec1d/readspec.pro
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ pro readspec1, plate, rownums, mjd=mjd, flux=flux, flerr=flerr, invvar=invvar, $
align=align, silent=silent, qread=qread, sdss=sdss, unsigned=unsigned, $
legacy=legacy, plates=plates

platestr = field_to_string(plate)
;platestr = plate_to_string(plate)
platestr = string(plate, format='(i5.5)')
; platestr = string(plate, format='(i5.5)')
if (NOT keyword_set(mjd)) then mjdstr = '*' $
else mjdstr = string(mjd,format='(i5.5)')
if (keyword_set(path)) then begin
Expand Down
Loading

0 comments on commit 7b51a22

Please sign in to comment.