def test_one(plate, mjd, all_fibers, args): exps = [] if args.exposure is None: if args.cc: exps.append(('coadd', load_coadded_spectra(plate, mjd, all_fibers[all_fibers <= 500], not args.no_sky), load_coadded_spectra(plate, mjd, all_fibers[all_fibers > 500], not args.no_sky) )) else: exps.append(('coadd', load_coadded_spectra(plate, mjd, all_fibers, not args.no_sky))) else: exp_ids = [0] if args.exposure == -1: remote_path = finder.get_spec_path(plate, mjd, all_fibers[0], lite=False) local_path = mirror.get(remote_path) specfile = SpecFile(local_path) exp_ids = range(specfile.num_exposures/2) else: exp_ids = [int(args.exposure)] for exp_id in exp_ids: exps.append((exp_id, load_exposure_spectra(plate, mjd, all_fibers, exp_id, args.camera, not args.no_sky))) if(args.plot): for exp_wrap in exps: exp = exp_wrap[1] wlen_cat_wavg, flux_cat_wavg, dflux_cat_wavg, flux_cnt = get_averages(exp[0], exp[1], exp[2]) averages = {"wlen": wlen_cat_wavg, "flux" : flux_cat_wavg, "dflux": dflux_cat_wavg, "count": flux_cnt} wlen_cat_wvar, flux_cat_wvar, dflux_cat_wvar = get_var(exp[0], exp[1], exp[2], args) variances = {"wlen": wlen_cat_wvar, "flux" : flux_cat_wvar, "dflux": dflux_cat_wvar} wlen_cat_wstd, flux_cat_wstd, dflux_cat_wstd = get_std(exp[0], exp[1], exp[2], args) stds = {"wlen": wlen_cat_wstd, "flux" : flux_cat_wstd, "dflux": dflux_cat_wstd} # l_cor, r_cor, d_cor = get_diff_cc(exp[0], None) r_wlen_cat_wavg, r_flux_cat_wavg, r_dflux_cat_wavg, r_flux_cnt = get_averages(exp_wrap[2][0], exp_wrap[2][1], exp_wrap[2][2]) conv = get_diff_convolve(flux_cat_wavg, r_flux_cat_wavg) print(conv.shape) plot_it(averages, variances, stds, conv, args) return exps
def main(): parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--file', type=str, help = 'Input filename', required=True) args = parser.parse_args() table = Table.read(args.file, format='ascii') plates = {} for row in table: if row['PLATE'] in plates: if row['MJD'] in plates[row['PLATE']]: plates[row['PLATE']][row['MJD']].append(row['FIBER']) else: plates[row['PLATE']][row['MJD']] = [row['FIBER']] else: plates[row['PLATE']] = {row['MJD'] : [row['FIBER']]} for plate,mjd_dict in plates.items(): for mjd,fibers_list in mjd_dict.items(): try: all_fibers = np.array(fibers_list) all_sky_spectra = clrp.load_coadded_spectra(plate, mjd, all_fibers, include_sky=True) fibers_left = all_fibers[all_fibers < 501] left_sky_spectra = clrp.load_coadded_spectra(plate, mjd, fibers_left, include_sky=True) fibers_right = all_fibers[all_fibers > 500] right_sky_spectra = clrp.load_coadded_spectra(plate, mjd, fibers_right, include_sky=True) kde = KernelDensity() pca = PCA(n_components=4) print(all_sky_spectra[1][:, floor:cutoff].shape) # pca.fit(left_sky_spectra[1][:, 0:cutoff]) pca.fit(all_sky_spectra[1][:, floor:cutoff]) # kde.fit(np.transpose(all_sky_spectra[1][:, floor:cutoff])) plot_components(pca) # plot_kde(kde) except Exception as e: print(e) traceback.print_exc() print("Failed to load {}-{}; moving on.".format(plate, mjd)) print("")