def get_exposure_data(plate, mjd, fibers, args): exps = [] if args.exposure is None: exps.append(('coadd', spectra.load_coadded_spectra(plate, mjd, fibers, not args.no_sky))) else: exp_ids = [0] if args.exposure == -1: exp_ids = range(spectra.get_exposure_count(plate, mjd)) else: exp_ids = [int(args.exposure)] for exp_id in exp_ids: exps.append((exp_id, spectra.load_exposure_spectra(plate, mjd, fibers, exp_id, args.camera, not args.no_sky))) return exps
def main(): per_fiber_flag = False no_plots_flag = False table = None for filename in sys.argv[1:]: if filename not in ["--averages", "--per-fiber", "--no-plots"]: temp_table = Table.read(filename, format="ascii") if table is not None: table = vstack([table, temp_table]) print("Stacking table for {}".format(filename)) else: table = temp_table elif filename == "--per-fiber": per_fiber_flag = True elif filename == "--no-plots": no_plots_flag = True if per_fiber_flag: table = table.group_by(["PLATE", "MJD", "FIBER"]) totals_dtype = [("PLATE", int), ("MJD", int), ("FIBER", int)] else: table = table.group_by(["PLATE", "MJD"]) totals_dtype = [("PLATE", int), ("MJD", int)] if include_obs_metadata: totals_dtype.extend( [("RA", float), ("DEC", float), ("AZ", float), ("ALT", float), ("OBS_START", "S16"), ("OBS_END", "S16")] ) for mwlen in line_markers["Hg"]: totals_dtype.append(("{}_total".format(mwlen), float)) totals_dtype.append(("{}_wlen_target".format(mwlen), float)) totals_dtype.append(("{}_wlen_lower".format(mwlen), float)) totals_dtype.append(("{}_wlen_upper".format(mwlen), float)) totals = np.ndarray((len(table.groups)), dtype=totals_dtype) for i, group in enumerate(table.groups): spectra_data = spectra.load_coadded_spectra( group[0]["PLATE"], group[0]["MJD"], group["FIBER"][:], include_sky=True ) wlen, flux, dflux, count = spectra.get_averages( spectra_data["wlen"], spectra_data["flux"], spectra_data["dflux"] ) np.ma.set_fill_value(wlen, 0) np.ma.set_fill_value(flux, 0) np.ma.set_fill_value(dflux, 0) orig_mask = np.ma.copy(flux.mask) if per_fiber_flag: idstr = "{}-{}-{}".format(group[0]["PLATE"], group[0]["MJD"], group[0]["FIBER"]) else: idstr = "{}-{}-sky".format(group[0]["PLATE"], group[0]["MJD"]) continuum, wo_continuum = smoothing( wlen, flux, orig_mask, idstr=idstr, no_plots=no_plots_flag, keep_chunky=True, block_sizes=block_sizes, no_show=False, ) if "--averages" in sys.argv: total_fluxes = get_total_flux(wlen, wo_continuum, line_markers["Hg"]) work_list = [group[0]["PLATE"], group[0]["MJD"]] if per_fiber_flag: work_list.append(group[0]["FIBER"]) if include_obs_metadata: obs_data = obsmd.get_position_and_time(group[0]["PLATE"], group[0]["MJD"]) start_time = base_date_time + dt.timedelta(seconds=int(obs_data[4])) end_time = base_date_time + dt.timedelta(seconds=int(obs_data[5])) work_list.extend( [ obs_data[0], obs_data[1], obs_data[2], obs_data[3], start_time.strftime("%Y-%m-%d %H:%M"), end_time.strftime("%Y-%m-%d %H:%M"), ] ) for tflux in total_fluxes: work_list.append(tflux["total_flux"]) work_list.append(tflux["wlen_target"]) work_list.append(tflux["wlen_lower_bound"]) work_list.append(tflux["wlen_upper_bound"]) totals[i] = tuple(work_list) totals_table = Table(data=totals) totals_table.write("plate_groups_avg_Hg.csv", format="ascii.csv") save_run_config()