@@ -278,11 +278,11 @@ function extract_optimal_iter(dimage, ivarimage, pix_bitmask, trace_params,
278
278
end
279
279
280
280
"""
281
- Given an open HDF.file, `f`, and the telescope, mjd, and a "short" expid , return a dictionary
281
+ Given an open HDF.file, `f`, and the telescope, mjd, and expnum , return a dictionary
282
282
mapping fiber id to fiber type.
283
283
"""
284
- function get_fibTargDict (f, tele, mjd, exposure_id )
285
- exposure_id = short_expid_to_long (mjd, exposure_id )
284
+ function get_fibTargDict (f, tele, mjd, expnum )
285
+ exposure_id = short_expid_to_long (mjd, expnum )
286
286
287
287
# translate confSummary/almanac terminology to AR.jl terminology
288
288
fiber_type_names = Dict (
@@ -304,18 +304,19 @@ function get_fibTargDict(f, tele, mjd, exposure_id)
304
304
# TODO Andrew thinks the fibers with category "" might be serendipitous targets
305
305
306
306
mjdfps2plate = get_fps_plate_divide (tele)
307
- configName, configIdCol, target_type_col = if mjd > mjdfps2plate
307
+ configName, configIdCol, target_type_col = if parse (Int, mjd) > mjdfps2plate
308
308
" fps" , " configid" , " category"
309
309
else
310
310
" plates" , " plateid" , " target_type" # TODO should this be source_type?
311
311
end
312
312
313
- df_exp = DataFrame (read (f[" $(tele) /$(mjd) /exposures" ]))
314
- if ! (exposure_id in df_exp. exposure)
313
+ df_exp = read_almanac_exp_df (f, tele, mjd)
314
+
315
+ if ! (exposure_id in df_exp. exposure_str)
315
316
@warn " Exposure $(exposure_id) not found in $(tele) /$(mjd) /exposures"
316
317
return Dict (1 : 300 .=> " fiberTypeFail" )
317
318
end
318
- exposure_info = df_exp[findfirst (df_exp[! , " exposure " ] .== exposure_id), :]
319
+ exposure_info = df_exp[findfirst (df_exp[! , " exposure_str " ] .== exposure_id), :]
319
320
configid = exposure_info[configIdCol]
320
321
321
322
fibtargDict = if exposure_info. exptype == " OBJECT"
@@ -336,13 +337,22 @@ function get_fibTargDict(f, tele, mjd, exposure_id)
336
337
fiber_types = map (df_fib[! , target_type_col]) do t
337
338
if t in keys (fiber_type_names)
338
339
fiber_type_names[t]
339
-
340
340
else
341
341
# @warn "Unknown fiber type for $(tele)/$(mjd)/fibers/$(configName)/$(configid): $(repr(t))"
342
342
" fiberTypeFail"
343
343
end
344
344
end
345
- Dict (df_fib[! , fiberid_col] .=> fiber_types)
345
+ fibernum_col = df_fib[! , fiberid_col]
346
+ # println(typeof(fibernum_col))
347
+ fibernumvec = if fibernum_col isa AbstractVector{<: Integer }
348
+ fibernum_col
349
+ elseif fibernum_col isa AbstractVector{<: String }
350
+ parse .(Int, fibernum_col)
351
+ else
352
+ @warn " Fiber numbers are neither integers or strings"
353
+ fibernum_col
354
+ end
355
+ Dict (fibernumvec .=> fiber_types)
346
356
catch e
347
357
rethrow (e)
348
358
@warn " Failed to get any fiber type information for $(tele) /$(mjd) /fibers/$(configName) /$(configid) (exposure $(exposure_id) ). Returning fiberTypeFail for all fibers."
@@ -353,7 +363,7 @@ function get_fibTargDict(f, tele, mjd, exposure_id)
353
363
Dict (1 : 300 .=> " cal" )
354
364
end
355
365
356
- if mjd > mjdfps2plate
366
+ if parse (Int, mjd) > mjdfps2plate
357
367
fpifib1, fpifib2 = get_fpi_guide_fiberID (tele)
358
368
fibtargDict[fpifib1] = " fpiguide"
359
369
fibtargDict[fpifib2] = " fpiguide"
@@ -363,15 +373,17 @@ end
363
373
364
374
# hardcoded to use chip c only for now
365
375
# must use dome flats, not quartz flats (need fiber runs to telescope)
366
- function get_fluxing_file (dfalmanac, parent_dir, mjd, tele, expidstr; fluxing_chip = " c" )
367
- expidfull = parse (Int, expidstr)
376
+ # use full exposure_id
377
+ function get_fluxing_file (dfalmanac, parent_dir, tele, mjd, expnum; fluxing_chip = " c" )
378
+ exposure_id = parse (Int, short_expid_to_long (mjd, expnum))
368
379
df_mjd = sort (
369
380
dfalmanac[(dfalmanac. mjd .== parse (Int, mjd)) .& (dfalmanac. observatory .== tele), :],
370
381
:exposure )
371
- expIndex = findfirst (df_mjd. exposure .== expidfull )
382
+ expIndex = findfirst (df_mjd. exposure_int .== exposure_id )
372
383
cartId = df_mjd. cartidInt[expIndex]
373
- expIndex_before = findlast ((df_mjd. imagetyp .== " DomeFlat" ) .& (df_mjd. exposure .< expidfull))
374
- expIndex_after = findfirst ((df_mjd. imagetyp .== " DomeFlat" ) .& (df_mjd. exposure .> expidfull))
384
+ # this needs to have cuts that match those in make_runlist_dome_flats.jl
385
+ expIndex_before = findlast ((df_mjd. imagetyp .== " DomeFlat" ) .& (df_mjd. exposure_int .< exposure_id) .& (df_mjd. nreadInt .> 3 ))
386
+ expIndex_after = findfirst ((df_mjd. imagetyp .== " DomeFlat" ) .& (df_mjd. exposure_int .> exposure_id) .& (df_mjd. nreadInt .> 3 ))
375
387
valid_before = if ! isnothing (expIndex_before)
376
388
all (df_mjd. cartidInt[expIndex_before: expIndex] .== cartId) * 1
377
389
elseif ! isnothing (expIndex_before)
@@ -389,43 +401,43 @@ function get_fluxing_file(dfalmanac, parent_dir, mjd, tele, expidstr; fluxing_ch
389
401
390
402
if valid_before == 1
391
403
return get_fluxing_file_name (
392
- parent_dir, mjd, tele, fluxing_chip, df_mjd. exposure [expIndex_before], cartId)
404
+ parent_dir, tele, mjd, last ( df_mjd. exposure_str [expIndex_before], 4 ), fluxing_chip , cartId)
393
405
elseif valid_after == 1
394
406
return get_fluxing_file_name (
395
- parent_dir, mjd, tele, fluxing_chip, df_mjd. exposure [expIndex_after], cartId)
407
+ parent_dir, tele, mjd, last ( df_mjd. exposure_str [expIndex_after], 4 ), fluxing_chip , cartId)
396
408
# any of the cases below here we could consider using a global file
397
409
elseif valid_before == 2
398
410
return get_fluxing_file_name (
399
- parent_dir, mjd, tele, fluxing_chip, df_mjd. exposure [expIndex_before], cartId)
411
+ parent_dir, tele, mjd, last ( df_mjd. exposure_str [expIndex_before], 4 ), fluxing_chip , cartId)
400
412
elseif valid_after == 2
401
413
return get_fluxing_file_name (
402
- parent_dir, mjd, tele, fluxing_chip, df_mjd. exposure [expIndex_after], cartId)
414
+ parent_dir, tele, mjd, last ( df_mjd. exposure_str [expIndex_after], 4 ), fluxing_chip , cartId)
403
415
else
404
416
return nothing
405
417
end
406
418
end
407
419
408
420
# TODO : switch to meta data dict and then save wavecal flags etc.
409
- function reinterp_spectra (fname; wavecal_type = " wavecal_skyline " )
421
+ function reinterp_spectra (fname; wavecal_type = " waveCalSkyLine " )
410
422
# might need to add in telluric div functionality here?
411
423
412
- sname = split (split (fname, " /" )[end ], " _" )
413
- fnameType, tele, mjd, chip, expid = sname[(end - 5 ): ( end - 1 ) ]
424
+ sname = split (split (split ( fname, " /" )[end ], " .h5 " )[ 1 ], " _" )
425
+ fnameType, tele, mjd, expnum, chip, exptype = sname[(end - 5 ): end ]
414
426
415
427
# could shift this to a preallocation step
416
- outflux = zeros (length (logUniWaveAPOGEE), 300 )
417
- outvar = zeros (length (logUniWaveAPOGEE), 300 )
418
- outmsk = zeros (Int, length (logUniWaveAPOGEE), 300 )
419
- cntvec = zeros (Int, length (logUniWaveAPOGEE), 300 )
428
+ outflux = zeros (length (logUniWaveAPOGEE), N_FIBERS )
429
+ outvar = zeros (length (logUniWaveAPOGEE), N_FIBERS )
430
+ outmsk = zeros (Int, length (logUniWaveAPOGEE), N_FIBERS )
431
+ cntvec = zeros (Int, length (logUniWaveAPOGEE), N_FIBERS )
420
432
421
- pixvec = 1 : (3 * 2048 )
422
- flux_stack = zeros (3 * 2048 , 300 )
423
- ivar_stack = zeros (3 * 2048 , 300 )
424
- mask_stack = zeros (Int, 3 * 2048 , 300 )
425
- wave_stack = zeros (3 * 2048 , 300 )
426
- chipBit_stack = zeros (Int, 3 * 2048 , 300 )
433
+ pixvec = 1 : (N_CHIPS * N_XPIX )
434
+ flux_stack = zeros (N_CHIPS * N_XPIX, N_FIBERS )
435
+ ivar_stack = zeros (N_CHIPS * N_XPIX, N_FIBERS )
436
+ mask_stack = zeros (Int, N_CHIPS * N_XPIX, N_FIBERS )
437
+ wave_stack = zeros (N_CHIPS * N_XPIX, N_FIBERS )
438
+ chipBit_stack = zeros (Int, N_CHIPS * N_XPIX, N_FIBERS )
427
439
428
- ingestBit = zeros (Int, 300 )
440
+ ingestBit = zeros (Int, N_FIBERS )
429
441
430
442
# add a for loop over the exposures (stop thinking about "visits" for now)
431
443
# probably just generate ap1D file names from the alamanc files
@@ -440,10 +452,10 @@ function reinterp_spectra(fname; wavecal_type = "wavecal_skyline")
440
452
chipWaveSoln = f[" chipWaveSoln" ]
441
453
close (f)
442
454
else # this is a terrible global fallback, just so we get something to look at
443
- chipWaveSoln = zeros (2048 , 300 , 3 )
455
+ chipWaveSoln = zeros (N_XPIX, N_FIBERS, N_CHIPS )
444
456
for (chipind, chip) in enumerate ([" a" , " b" , " c" ])
445
457
chipWaveSoln[:, :, chipind] .= rough_linear_wave .(
446
- 1 : 2048 , a = roughwave_dict[tele][chip][1 ], b = roughwave_dict[tele][chip][2 ])
458
+ 1 : N_XPIX , a = roughwave_dict[tele][chip][1 ], b = roughwave_dict[tele][chip][2 ])
447
459
end
448
460
println (" No wavecal found for $(fname) , using fallback" )
449
461
flush (stdout )
@@ -458,11 +470,11 @@ function reinterp_spectra(fname; wavecal_type = "wavecal_skyline")
458
470
mask_1d = f[" mask_1d" ]
459
471
close (f)
460
472
461
- flux_stack[(1 : 2048 ) .+ (3 - chipind) * 2048 , :] .= flux_1d[end : - 1 : 1 , :]
462
- ivar_stack[(1 : 2048 ) .+ (3 - chipind) * 2048 , :] .= ivar_1d[end : - 1 : 1 , :]
463
- mask_stack[(1 : 2048 ) .+ (3 - chipind) * 2048 , :] .= mask_1d[end : - 1 : 1 , :]
464
- wave_stack[(1 : 2048 ) .+ (3 - chipind) * 2048 , :] .= chipWaveSoln[end : - 1 : 1 , :, chipind]
465
- chipBit_stack[(1 : 2048 ) .+ (3 - chipind) * 2048 , :] .+ = 2 ^ (chipind)
473
+ flux_stack[(1 : N_XPIX ) .+ (3 - chipind) * N_XPIX , :] .= flux_1d[end : - 1 : 1 , :]
474
+ ivar_stack[(1 : N_XPIX ) .+ (3 - chipind) * N_XPIX , :] .= ivar_1d[end : - 1 : 1 , :]
475
+ mask_stack[(1 : N_XPIX ) .+ (3 - chipind) * N_XPIX , :] .= mask_1d[end : - 1 : 1 , :]
476
+ wave_stack[(1 : N_XPIX ) .+ (3 - chipind) * N_XPIX , :] .= chipWaveSoln[end : - 1 : 1 , :, chipind]
477
+ chipBit_stack[(1 : N_XPIX ) .+ (3 - chipind) * N_XPIX , :] .+ = 2 ^ (chipind)
466
478
end
467
479
468
480
noBadBits = (mask_stack .& bad_pix_bits .== 0 )
@@ -474,7 +486,7 @@ function reinterp_spectra(fname; wavecal_type = "wavecal_skyline")
474
486
(ivar_stack .> (10 ^- 20 ))
475
487
476
488
# # need to propagate the bit mask
477
- for fiberindx in 1 : 300
489
+ for fiberindx in 1 : N_FIBERS
478
490
good_pix_fiber = good_pix[:, fiberindx]
479
491
flux_fiber = flux_stack[good_pix_fiber, fiberindx]
480
492
ivar_fiber = ivar_stack[good_pix_fiber, fiberindx]
0 commit comments