def test_fnpickling_many(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle multiple objects from a single file. """ fn = str(tmpdir.join('test3.pickle')) # now try multiples obj3 = 328.3432 obj4 = 'blahblahfoo' fnpickle(obj3, fn) fnpickle(obj4, fn, append=True) res = fnunpickle(fn, number=-1) assert len(res) == 2 assert res[0] == obj3 assert res[1] == obj4 fnpickle(obj4, fn, append=True) res = fnunpickle(fn, number=2) assert len(res) == 2 with pytest.raises(EOFError): fnunpickle(fn, number=5)
def test_fnpickling_many(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle multiple objects from a single file. """ fn = str(tmpdir.join('test3.pickle')) # now try multiples obj3 = 328.3432 obj4 = 'blahblahfoo' fnpickle(obj3, fn) fnpickle(obj4, fn, append=True) res = fnunpickle(fn, number=-1) assert len(res) == 2 assert res[0] == obj3 assert res[1] == obj4 fnpickle(obj4, fn, append=True) res = fnunpickle(fn, number=2) assert len(res) == 2 with pytest.raises(EOFError): fnunpickle(fn, number=5)
def test_fnpickling_simple(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' basic operation by pickling and unpickling a string, using both a filename and a file. """ fn = str(tmpdir.join('test1.pickle')) obj1 = 'astring' fnpickle(obj1, fn) res = fnunpickle(fn, 0) assert obj1 == res # now try with a file-like object instead of a string with open(fn, 'wb') as f: fnpickle(obj1, f) with open(fn, 'rb') as f: res = fnunpickle(f) assert obj1 == res
def test_fnpickling_class(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle custom classes. """ fn = str(tmpdir.join('test2.pickle')) obj1 = 'astring' obj2 = ToBePickled(obj1) fnpickle(obj2, fn) res = fnunpickle(fn) assert res == obj2
def test_fnpickling_class(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle custom classes. """ fn = str(tmpdir.join('test2.pickle')) obj1 = 'astring' obj2 = ToBePickled(obj1) fnpickle(obj2, fn) res = fnunpickle(fn) assert res == obj2
def test_fnpickling_simple(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' basic operation by pickling and unpickling a string, using both a filename and a file. """ fn = str(tmpdir.join('test1.pickle')) obj1 = 'astring' fnpickle(obj1, fn) res = fnunpickle(fn, 0) assert obj1 == res # now try with a file-like object instead of a string with open(fn, 'wb') as f: fnpickle(obj1, f) with open(fn, 'rb') as f: res = fnunpickle(f) assert obj1 == res with catch_warnings(AstropyDeprecationWarning): fnunpickle(fn, 0, True)
def test_fnpickling_protocol(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle pickle files from all protcols. """ import pickle obj1 = 'astring' obj2 = ToBePickled(obj1) for p in range(pickle.HIGHEST_PROTOCOL + 1): fn = str(tmpdir.join('testp{}.pickle'.format(p))) fnpickle(obj2, fn, protocol=p) res = fnunpickle(fn) assert res == obj2
def test_fnpickling_protocol(tmpdir): """ Tests the `fnpickle` and `fnupickle` functions' ability to pickle and unpickle pickle files from all protcols. """ import pickle obj1 = 'astring' obj2 = ToBePickled(obj1) for p in range(pickle.HIGHEST_PROTOCOL + 1): fn = str(tmpdir.join('testp{}.pickle'.format(p))) fnpickle(obj2, fn, protocol=p) res = fnunpickle(fn) assert res == obj2
def main(): filename = "arxiv.pickle" entries = fnunpickle(filename) ii = 0 freqdists = dict() for id, entry in entries.items(): freqdists[id] = nltk.FreqDist(parse_abstract(entry['abstract'])) ii += 1 items = freqdists.items() kl_matrix = np.zeros((len(freqdists.keys()), len(freqdists.keys()))) for ii,(id1,freqdist1) in enumerate(items): for jj,(id2,freqdist2) in enumerate(items): kl_matrix[ii,jj] = kl_divergence(freqdist1, freqdist2) kl_avg = np.zeros_like(kl_matrix) for ii in range(kl_matrix.shape[0]): for jj in range(ii+1): kl_avg[ii,jj] = (kl_matrix[ii,jj] + kl_matrix[jj,ii]) / 2. np.save("arxiv_kl_matrix.npy", kl_avg)
def bkg_read(input_file): """ Read the sky backgound files obtained by bkg_info routine and return the background mask and noise data. """ #set the original directory tempo = time.time() original_path = os.getcwd() save_path = input_file['save_path'] planet = input_file['exoplanet'] #change to save data reduction directory os.chdir(save_path) print 'Reading sky backgound files ...' images = sorted(glob.glob('AB'+planet+'*.fits')) bkg_data = [] bkg_rms = [] for i in range(len(images)): bkg = fnunpickle('./background/'+'bkg_data_'+images[i]+'_.pik') bkg_data.append(bkg.background) bkg_rms.append(bkg.background_rms) use.update_progress((i+1.)/len(images)) os.chdir(original_path) print 'total time = ',abs(time.time()-tempo)/60.,' minutes' return bkg_data, bkg_rms
def sgr(overwrite=False, seed=42): np.random.seed(seed) lm10_cache = os.path.join(project_root, "data", "spitzer_targets", "lm10_cache.pickle") if os.path.exists(lm10_cache) and overwrite: os.remove(lm10_cache) if not os.path.exists(lm10_cache): # select particle data from the LM10 simulation lm10 = particle_table(N=0, expr="(Pcol>-1) & (Pcol<8) & "\ "(abs(Lmflag)==1) & (dist<100)") fnpickle(np.array(lm10), lm10_cache) else: lm10 = Table(fnunpickle(lm10_cache)) # read in the Catalina RR Lyrae data spatial_data = ascii.read(os.path.join(project_root, "data/catalog/Catalina_all_RRLyr.txt")) velocity_data = ascii.read(os.path.join(project_root, "data/catalog/Catalina_vgsr_RRLyr.txt")) catalina = join(spatial_data, velocity_data, join_type='outer', keys="ID") catalina.rename_column("RAdeg", "ra") catalina.rename_column("DEdeg", "dec") catalina.rename_column("dh", "dist") # add Sgr coordinates to the Catalina data catalina = add_sgr_coordinates(catalina) # add Galactocentric distance to the Catalina and LM10 data cat_gc_dist = tbl_to_gc_dist(catalina) lm10_gc_dist = tbl_to_gc_dist(lm10) catalina.add_column(Column(cat_gc_dist, name="gc_dist")) lm10.add_column(Column(lm10_gc_dist, name="gc_dist")) # 1) Select stars < 20 kpc from the orbital plane of Sgr sgr_catalina = catalina[np.fabs(catalina["Z_sgr"]) < 20.] x,y,z = tbl_to_xyz(sgr_catalina) # 2) Stars with D > 15 kpc from the Galactic center sgr_catalina = sgr_catalina[sgr_catalina["gc_dist"] > 15] sgr_catalina_rv = sgr_catalina[~sgr_catalina["Vgsr"].mask] print("{0} CSS RRLs have radial velocities.".format(len(sgr_catalina_rv))) # plot X-Z plane, data and lm10 particles fig,axes = plt.subplots(1,3,figsize=(15,6), sharex=True, sharey=True) x,y,z = tbl_to_xyz(catalina) axes[0].set_title("All RRL", fontsize=20) axes[0].plot(x, z, marker='.', alpha=0.2, linestyle='none') axes[0].set_xlabel("$X_{gc}$ kpc") axes[0].set_ylabel("$Z_{gc}$ kpc") x,y,z = tbl_to_xyz(sgr_catalina) axes[1].set_title(r"RRL $|Z-Z_{sgr}|$ $<$ $20$ kpc", fontsize=20) axes[1].plot(x, z, marker='.', alpha=0.2, linestyle='none') axes[2].plot(lm10["x"], lm10["z"], marker='.', alpha=0.2, linestyle='none') axes[2].set_title("LM10", fontsize=20) axes[2].set_xlim(-60, 40) axes[2].set_ylim(-60, 60) fig.tight_layout() fig.savefig(os.path.join(notes_path, "catalina_all.pdf")) # plot Lambda-dist plane, data and lm10 particles fig,ax = plt.subplots(1,1,figsize=(6,6), subplot_kw=dict(projection="polar")) ax.set_theta_direction(-1) ax.plot(np.radians(lm10["Lambda"]), lm10["dist"], marker='.', alpha=0.2, linestyle='none') ax.plot(np.radians(sgr_catalina["Lambda"]), sgr_catalina["dist"], marker='.', alpha=0.75, linestyle='none', ms=6) fig.tight_layout() fig.savefig(os.path.join(notes_path, "rrl_over_lm10.pdf")) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Select on radial velocities rv_selection_cache = os.path.join(project_root, "data", "spitzer_targets", "rv.pickle") if os.path.exists(rv_selection_cache) and overwrite: os.remove(rv_selection_cache) if not os.path.exists(rv_selection_cache): lmflag_rv_idx = sgr_rv(sgr_catalina_rv, lm10, Nbins=40, sigma_cut=3.) fnpickle(lmflag_rv_idx, rv_selection_cache) else: lmflag_rv_idx = fnunpickle(rv_selection_cache) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Select on distance _selection_cache = os.path.join(project_root, "data", "spitzer_targets", "dist.pickle") if os.path.exists(_selection_cache) and overwrite: os.remove(_selection_cache) if not os.path.exists(_selection_cache): lmflag_dist_idx = sgr_dist(sgr_catalina_rv, lm10, Nbins=40, sigma_cut=3.) fnpickle(lmflag_dist_idx, _selection_cache) else: lmflag_dist_idx = fnunpickle(_selection_cache) ################################################################ # Make X-Z plot fig,ax = plt.subplots(1,1,figsize=(6,6)) x,y,z = tbl_to_xyz(lm10) ax.plot(x, z, marker=',', alpha=0.2, linestyle='none') for lmflag in [1,-1]: ix = lmflag_dist_idx[lmflag] & lmflag_rv_idx[lmflag] x,y,z = tbl_to_xyz(sgr_catalina_rv[ix]) ax.plot(x, z, marker='.', alpha=0.75, linestyle='none', ms=6, label="Lmflag={0}".format(lmflag)) ax.legend(loc='lower right',\ prop={'size':12}) ax.set_title("RV-selected CSS RRLs", fontsize=20) ax.set_xlabel(r"$X_{\rm gc}$ kpc") ax.set_ylabel(r"$Z_{\rm gc}$ kpc") fig.tight_layout() fig.savefig(os.path.join(notes_path, "selected_xz.pdf")) ############################################################## # Finalize two samples: # - 1 with 10 stars in the nearby trailing wrap # - 1 without these stars L = sgr_catalina_rv["Lambda"] B = sgr_catalina_rv["Beta"] D = sgr_catalina_rv["dist"] X,Y = D*np.cos(np.radians(L)),D*np.sin(np.radians(L)) lead_ix = lmflag_dist_idx[1] & lmflag_rv_idx[1] & (np.fabs(B) < 40) trail_ix = lmflag_dist_idx[-1] & lmflag_rv_idx[-1] & (np.fabs(B) < 40) trail_ix[L < 180] &= B[L < 180] > -5 trail_ix = trail_ix & ( ((L > 230) & (L < 315)) | (L < 180) ) #trail_ix &= np.logical_not((L > 50) & (L < 100) & (sgr_catalina_rv["dist"] < 40)) # draw a box around some possible bifurcation members bif_ix = (L > 200) & (L < 230) & (B < 2) & (B > -10) & lead_ix # deselect stars possibly associated with the bifurcation no_bif = (L > 180) & (L < 225) & (B < 20) & (B > 2) no_bif |= (L > 225) & (L < 360) & (B < 17) & (B > 2) no_bif |= ((L <= 180) & (B < 15) & (B > -8) & (L > 50)) lead_ix &= no_bif print(sum(bif_ix), "bifurcation stars") print(sum(lead_ix), "leading arm stars") print(sum(trail_ix), "trailing arm stars ") # select 3 clumps in the leading arm Nclump = 11 ix_lead_clumps = np.zeros_like(lead_ix).astype(bool) for clump in [(215,17), (245,25), (260,40)]: l,d = clump x,y = d*np.cos(np.radians(l)),d*np.sin(np.radians(l)) # find N stars closest to the clump clump_dist = np.sqrt((X-x)**2 + (Y-y)**2) xxx = np.sort(clump_dist[lead_ix])[Nclump] this_ix = lead_ix & (clump_dist <= xxx) print("lead",sum(this_ix)) ix_lead_clumps |= this_ix #select_only(this_ix, 10) ix_lead_clumps &= lead_ix # all southern leading lll = ((L > 45) & (L < 180) & lead_ix) print("southern leading", sum(lll)) ix_lead_clumps |= lll ix_trail_clumps = np.zeros_like(trail_ix).astype(bool) for clump in [(260,19)]: l,d = clump x,y = d*np.cos(np.radians(l)),d*np.sin(np.radians(l)) # find N stars closest to the clump clump_dist = np.sqrt((X-x)**2 + (Y-y)**2) xxx = np.sort(clump_dist[trail_ix])[10] this_ix = trail_ix & (clump_dist <= xxx) #bonus_trail_ix = trail_ix & (clump_dist > xxx) ix_trail_clumps |= this_ix #select_only(this_ix, 10) ix_trail_clumps &= trail_ix # all trailing southern ttt = (L > 45) & (L < 180) & (trail_ix) print("southern trailing", sum(ttt)) ix_trail_clumps |= ttt i1 = integration_time(sgr_catalina_rv[bif_ix]["dist"]) i2 = integration_time(sgr_catalina_rv[ix_lead_clumps]["dist"]) i3 = integration_time(sgr_catalina_rv[ix_trail_clumps]["dist"]) print("final num bifurcation", len(sgr_catalina_rv[bif_ix])) print("final num leading arm", len(sgr_catalina_rv[ix_lead_clumps])) print("final num trailing arm",len(sgr_catalina_rv[ix_trail_clumps])) print("final total", sum(ix_trail_clumps) + sum(ix_lead_clumps) + sum(bif_ix)) print("final total", sum(ix_trail_clumps | ix_lead_clumps | bif_ix)) targets = sgr_catalina_rv[ix_trail_clumps | ix_lead_clumps | bif_ix] bonus_targets = sgr_catalina_rv[(lead_ix | trail_ix) & \ ~(ix_trail_clumps | ix_lead_clumps | bif_ix)] # print() # print("bifurcation", np.sum(i1)) # print("leading",np.sum(i2)) # print("trailing",np.sum(i3)) # print("Total:",np.sum(integration_time(targets["dist"]))) tot_time = 0. for t in targets: Vmag = t["<Vmag>"] if Vmag < 16.6: tot_time += 1.286 elif 16.6 < Vmag < 16.8: tot_time += 1.31 elif 16.8 < Vmag < 17.2: tot_time += 1.83 elif 17.2 < Vmag < 17.8: tot_time += 2.52 elif Vmag > 17.8: tot_time += 4.34 print ("total time: ", tot_time) output_file = "sgr.txt" output = targets.copy() output.rename_column("Eta", "hjd0") output.rename_column("<Vmag>", "VMagAvg") output.keep_columns(["ID", "ra", "dec", "VMagAvg", "Period", "hjd0"]) ascii.write(output, os.path.join(project_root, "data", "spitzer_targets", output_file), Writer=ascii.Basic) output_file = "sgr_bonus.txt" output = bonus_targets.copy() output.rename_column("Eta", "hjd0") output.rename_column("<Vmag>", "VMagAvg") output.keep_columns(["ID", "ra", "dec", "VMagAvg", "Period", "hjd0"]) ascii.write(output, os.path.join(project_root, "data", "spitzer_targets", output_file), Writer=ascii.Basic) # ---------------------------------- # Make Lambda-D plot fig,ax = plt.subplots(1,1,figsize=(6,6), subplot_kw=dict(projection="polar")) ax.set_theta_direction(-1) ax.plot(np.radians(lm10["Lambda"]), lm10["dist"], marker=',', alpha=0.2, linestyle='none') d = sgr_catalina_rv[lead_ix] ax.plot(np.radians(d["Lambda"]), d["dist"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#CA0020", label="leading") d = sgr_catalina_rv[trail_ix] ax.plot(np.radians(d["Lambda"]), d["dist"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#5E3C99", label="trailing") ax.plot(np.radians(targets["Lambda"]), targets["dist"], marker='.', alpha=0.7, linestyle='none', ms=10, c="#31A354", label="targets", mfc='none', mec='k', mew=1.5) ax.legend(loc="lower right") plt.setp(ax.get_legend().get_texts(), fontsize='12') ax.set_ylim(0,65) fig.tight_layout() fig.savefig(os.path.join(notes_path, "xz.pdf")) # --------------------- # Make Lambda-Beta plot fig,ax = plt.subplots(1,1,figsize=(12,5)) ax.plot(lm10["Lambda"], lm10["Beta"], marker=',', alpha=0.2, linestyle='none') dd_bif = sgr_catalina_rv[bif_ix] ax.plot(dd_bif["Lambda"], dd_bif["Beta"], marker='.', alpha=0.75, linestyle='none', ms=6, c="#31A354", label="bifurcation") d = sgr_catalina_rv[lead_ix] ax.plot(d["Lambda"], d["Beta"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#CA0020", label="leading") d = sgr_catalina_rv[trail_ix] ax.plot(d["Lambda"], d["Beta"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#5E3C99", label="trailing") ax.plot(targets["Lambda"], targets["Beta"], marker='.', alpha=0.7, linestyle='none', ms=10, c="#31A354", label="targets", mfc='none', mec='k', mew=1.5) ax.legend(loc="lower right") plt.setp(ax.get_legend().get_texts(), fontsize='12') ax.set_title("RV-selected CSS RRLs", fontsize=20) ax.set_xlabel(r"$\Lambda$ [deg]") ax.set_ylabel(r"$B$ [deg]") ax.set_xlim(360, 0) ax.set_ylim(-45, 45) fig.tight_layout() fig.savefig(os.path.join(notes_path, "LB.pdf"))
exit() datafilename, startcand, endcand = args startcand = int(startcand) endcand = int(endcand) f = fitsio.FITS(datafilename) # Initialize chisq dist minchisq = [] minchisqtype = [] for meta in f[1][startcand:endcand]: pikname = '{0}/{1}.pik'.format(pikdir, meta['snid']) if not os.path.exists(pikname): continue # Candidate results candres = fnunpickle(pikname) # Data for this candidate data = f[2][meta['datastart']:meta['dataend']] mask = data['status'] < 8 data = data[mask] # Trim data based on mask # Loop over models, calculate chisq / dof print "\n",meta['snid'] for name, res in candres.iteritems(): res.chisq = -2. * res.loglmax res.chisqdof = res.chisq / res.ndof print " {} : chisq/dof = {:7.1f}".format(name, res.chisqdof) # Sort modelnames by chisqdof modelnames = sorted(candres.keys(), key=lambda x: candres[x].chisqdof)
def sgr(overwrite=False, seed=42): np.random.seed(seed) lm10_cache = os.path.join(project_root, "data", "spitzer_targets", "lm10_cache.pickle") if os.path.exists(lm10_cache) and overwrite: os.remove(lm10_cache) if not os.path.exists(lm10_cache): # select particle data from the LM10 simulation lm10 = particle_table(N=0, expr="(Pcol>-1) & (Pcol<8) & "\ "(abs(Lmflag)==1) & (dist<100)") fnpickle(np.array(lm10), lm10_cache) else: lm10 = Table(fnunpickle(lm10_cache)) # read in the Catalina RR Lyrae data spatial_data = ascii.read( os.path.join(project_root, "data/catalog/Catalina_all_RRLyr.txt")) velocity_data = ascii.read( os.path.join(project_root, "data/catalog/Catalina_vgsr_RRLyr.txt")) catalina = join(spatial_data, velocity_data, join_type='outer', keys="ID") catalina.rename_column("RAdeg", "ra") catalina.rename_column("DEdeg", "dec") catalina.rename_column("dh", "dist") # add Sgr coordinates to the Catalina data catalina = add_sgr_coordinates(catalina) # add Galactocentric distance to the Catalina and LM10 data cat_gc_dist = tbl_to_gc_dist(catalina) lm10_gc_dist = tbl_to_gc_dist(lm10) catalina.add_column(Column(cat_gc_dist, name="gc_dist")) lm10.add_column(Column(lm10_gc_dist, name="gc_dist")) # 1) Select stars < 20 kpc from the orbital plane of Sgr sgr_catalina = catalina[np.fabs(catalina["Z_sgr"]) < 20.] x, y, z = tbl_to_xyz(sgr_catalina) # 2) Stars with D > 15 kpc from the Galactic center sgr_catalina = sgr_catalina[sgr_catalina["gc_dist"] > 15] sgr_catalina_rv = sgr_catalina[~sgr_catalina["Vgsr"].mask] print("{0} CSS RRLs have radial velocities.".format(len(sgr_catalina_rv))) # plot X-Z plane, data and lm10 particles fig, axes = plt.subplots(1, 3, figsize=(15, 6), sharex=True, sharey=True) x, y, z = tbl_to_xyz(catalina) axes[0].set_title("All RRL", fontsize=20) axes[0].plot(x, z, marker='.', alpha=0.2, linestyle='none') axes[0].set_xlabel("$X_{gc}$ kpc") axes[0].set_ylabel("$Z_{gc}$ kpc") x, y, z = tbl_to_xyz(sgr_catalina) axes[1].set_title(r"RRL $|Z-Z_{sgr}|$ $<$ $20$ kpc", fontsize=20) axes[1].plot(x, z, marker='.', alpha=0.2, linestyle='none') axes[2].plot(lm10["x"], lm10["z"], marker='.', alpha=0.2, linestyle='none') axes[2].set_title("LM10", fontsize=20) axes[2].set_xlim(-60, 40) axes[2].set_ylim(-60, 60) fig.tight_layout() fig.savefig(os.path.join(notes_path, "catalina_all.pdf")) # plot Lambda-dist plane, data and lm10 particles fig, ax = plt.subplots(1, 1, figsize=(6, 6), subplot_kw=dict(projection="polar")) ax.set_theta_direction(-1) ax.plot(np.radians(lm10["Lambda"]), lm10["dist"], marker='.', alpha=0.2, linestyle='none') ax.plot(np.radians(sgr_catalina["Lambda"]), sgr_catalina["dist"], marker='.', alpha=0.75, linestyle='none', ms=6) fig.tight_layout() fig.savefig(os.path.join(notes_path, "rrl_over_lm10.pdf")) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Select on radial velocities rv_selection_cache = os.path.join(project_root, "data", "spitzer_targets", "rv.pickle") if os.path.exists(rv_selection_cache) and overwrite: os.remove(rv_selection_cache) if not os.path.exists(rv_selection_cache): lmflag_rv_idx = sgr_rv(sgr_catalina_rv, lm10, Nbins=40, sigma_cut=3.) fnpickle(lmflag_rv_idx, rv_selection_cache) else: lmflag_rv_idx = fnunpickle(rv_selection_cache) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Select on distance _selection_cache = os.path.join(project_root, "data", "spitzer_targets", "dist.pickle") if os.path.exists(_selection_cache) and overwrite: os.remove(_selection_cache) if not os.path.exists(_selection_cache): lmflag_dist_idx = sgr_dist(sgr_catalina_rv, lm10, Nbins=40, sigma_cut=3.) fnpickle(lmflag_dist_idx, _selection_cache) else: lmflag_dist_idx = fnunpickle(_selection_cache) ################################################################ # Make X-Z plot fig, ax = plt.subplots(1, 1, figsize=(6, 6)) x, y, z = tbl_to_xyz(lm10) ax.plot(x, z, marker=',', alpha=0.2, linestyle='none') for lmflag in [1, -1]: ix = lmflag_dist_idx[lmflag] & lmflag_rv_idx[lmflag] x, y, z = tbl_to_xyz(sgr_catalina_rv[ix]) ax.plot(x, z, marker='.', alpha=0.75, linestyle='none', ms=6, label="Lmflag={0}".format(lmflag)) ax.legend(loc='lower right',\ prop={'size':12}) ax.set_title("RV-selected CSS RRLs", fontsize=20) ax.set_xlabel(r"$X_{\rm gc}$ kpc") ax.set_ylabel(r"$Z_{\rm gc}$ kpc") fig.tight_layout() fig.savefig(os.path.join(notes_path, "selected_xz.pdf")) ############################################################## # Finalize two samples: # - 1 with 10 stars in the nearby trailing wrap # - 1 without these stars L = sgr_catalina_rv["Lambda"] B = sgr_catalina_rv["Beta"] D = sgr_catalina_rv["dist"] X, Y = D * np.cos(np.radians(L)), D * np.sin(np.radians(L)) lead_ix = lmflag_dist_idx[1] & lmflag_rv_idx[1] & (np.fabs(B) < 40) trail_ix = lmflag_dist_idx[-1] & lmflag_rv_idx[-1] & (np.fabs(B) < 40) trail_ix[L < 180] &= B[L < 180] > -5 trail_ix = trail_ix & (((L > 230) & (L < 315)) | (L < 180)) #trail_ix &= np.logical_not((L > 50) & (L < 100) & (sgr_catalina_rv["dist"] < 40)) # draw a box around some possible bifurcation members bif_ix = (L > 200) & (L < 230) & (B < 2) & (B > -10) & lead_ix # deselect stars possibly associated with the bifurcation no_bif = (L > 180) & (L < 225) & (B < 20) & (B > 2) no_bif |= (L > 225) & (L < 360) & (B < 17) & (B > 2) no_bif |= ((L <= 180) & (B < 15) & (B > -8) & (L > 50)) lead_ix &= no_bif print(sum(bif_ix), "bifurcation stars") print(sum(lead_ix), "leading arm stars") print(sum(trail_ix), "trailing arm stars ") # select 3 clumps in the leading arm Nclump = 11 ix_lead_clumps = np.zeros_like(lead_ix).astype(bool) for clump in [(215, 17), (245, 25), (260, 40)]: l, d = clump x, y = d * np.cos(np.radians(l)), d * np.sin(np.radians(l)) # find N stars closest to the clump clump_dist = np.sqrt((X - x)**2 + (Y - y)**2) xxx = np.sort(clump_dist[lead_ix])[Nclump] this_ix = lead_ix & (clump_dist <= xxx) print("lead", sum(this_ix)) ix_lead_clumps |= this_ix #select_only(this_ix, 10) ix_lead_clumps &= lead_ix # all southern leading lll = ((L > 45) & (L < 180) & lead_ix) print("southern leading", sum(lll)) ix_lead_clumps |= lll ix_trail_clumps = np.zeros_like(trail_ix).astype(bool) for clump in [(260, 19)]: l, d = clump x, y = d * np.cos(np.radians(l)), d * np.sin(np.radians(l)) # find N stars closest to the clump clump_dist = np.sqrt((X - x)**2 + (Y - y)**2) xxx = np.sort(clump_dist[trail_ix])[10] this_ix = trail_ix & (clump_dist <= xxx) #bonus_trail_ix = trail_ix & (clump_dist > xxx) ix_trail_clumps |= this_ix #select_only(this_ix, 10) ix_trail_clumps &= trail_ix # all trailing southern ttt = (L > 45) & (L < 180) & (trail_ix) print("southern trailing", sum(ttt)) ix_trail_clumps |= ttt i1 = integration_time(sgr_catalina_rv[bif_ix]["dist"]) i2 = integration_time(sgr_catalina_rv[ix_lead_clumps]["dist"]) i3 = integration_time(sgr_catalina_rv[ix_trail_clumps]["dist"]) print("final num bifurcation", len(sgr_catalina_rv[bif_ix])) print("final num leading arm", len(sgr_catalina_rv[ix_lead_clumps])) print("final num trailing arm", len(sgr_catalina_rv[ix_trail_clumps])) print("final total", sum(ix_trail_clumps) + sum(ix_lead_clumps) + sum(bif_ix)) print("final total", sum(ix_trail_clumps | ix_lead_clumps | bif_ix)) targets = sgr_catalina_rv[ix_trail_clumps | ix_lead_clumps | bif_ix] bonus_targets = sgr_catalina_rv[(lead_ix | trail_ix) & \ ~(ix_trail_clumps | ix_lead_clumps | bif_ix)] # print() # print("bifurcation", np.sum(i1)) # print("leading",np.sum(i2)) # print("trailing",np.sum(i3)) # print("Total:",np.sum(integration_time(targets["dist"]))) tot_time = 0. for t in targets: Vmag = t["<Vmag>"] if Vmag < 16.6: tot_time += 1.286 elif 16.6 < Vmag < 16.8: tot_time += 1.31 elif 16.8 < Vmag < 17.2: tot_time += 1.83 elif 17.2 < Vmag < 17.8: tot_time += 2.52 elif Vmag > 17.8: tot_time += 4.34 print("total time: ", tot_time) output_file = "sgr.txt" output = targets.copy() output.rename_column("Eta", "hjd0") output.rename_column("<Vmag>", "VMagAvg") output.keep_columns(["ID", "ra", "dec", "VMagAvg", "Period", "hjd0"]) ascii.write(output, os.path.join(project_root, "data", "spitzer_targets", output_file), Writer=ascii.Basic) output_file = "sgr_bonus.txt" output = bonus_targets.copy() output.rename_column("Eta", "hjd0") output.rename_column("<Vmag>", "VMagAvg") output.keep_columns(["ID", "ra", "dec", "VMagAvg", "Period", "hjd0"]) ascii.write(output, os.path.join(project_root, "data", "spitzer_targets", output_file), Writer=ascii.Basic) # ---------------------------------- # Make Lambda-D plot fig, ax = plt.subplots(1, 1, figsize=(6, 6), subplot_kw=dict(projection="polar")) ax.set_theta_direction(-1) ax.plot(np.radians(lm10["Lambda"]), lm10["dist"], marker=',', alpha=0.2, linestyle='none') d = sgr_catalina_rv[lead_ix] ax.plot(np.radians(d["Lambda"]), d["dist"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#CA0020", label="leading") d = sgr_catalina_rv[trail_ix] ax.plot(np.radians(d["Lambda"]), d["dist"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#5E3C99", label="trailing") ax.plot(np.radians(targets["Lambda"]), targets["dist"], marker='.', alpha=0.7, linestyle='none', ms=10, c="#31A354", label="targets", mfc='none', mec='k', mew=1.5) ax.legend(loc="lower right") plt.setp(ax.get_legend().get_texts(), fontsize='12') ax.set_ylim(0, 65) fig.tight_layout() fig.savefig(os.path.join(notes_path, "xz.pdf")) # --------------------- # Make Lambda-Beta plot fig, ax = plt.subplots(1, 1, figsize=(12, 5)) ax.plot(lm10["Lambda"], lm10["Beta"], marker=',', alpha=0.2, linestyle='none') dd_bif = sgr_catalina_rv[bif_ix] ax.plot(dd_bif["Lambda"], dd_bif["Beta"], marker='.', alpha=0.75, linestyle='none', ms=6, c="#31A354", label="bifurcation") d = sgr_catalina_rv[lead_ix] ax.plot(d["Lambda"], d["Beta"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#CA0020", label="leading") d = sgr_catalina_rv[trail_ix] ax.plot(d["Lambda"], d["Beta"], marker='.', alpha=0.75, linestyle='none', ms=8, c="#5E3C99", label="trailing") ax.plot(targets["Lambda"], targets["Beta"], marker='.', alpha=0.7, linestyle='none', ms=10, c="#31A354", label="targets", mfc='none', mec='k', mew=1.5) ax.legend(loc="lower right") plt.setp(ax.get_legend().get_texts(), fontsize='12') ax.set_title("RV-selected CSS RRLs", fontsize=20) ax.set_xlabel(r"$\Lambda$ [deg]") ax.set_ylabel(r"$B$ [deg]") ax.set_xlim(360, 0) ax.set_ylim(-45, 45) fig.tight_layout() fig.savefig(os.path.join(notes_path, "LB.pdf"))
def load(fits_file_path): fits_file = fnunpickle(fits_file_path) return fits_file