def compute_glat_glon_distance(table): x, y, z = table['x'].quantity, table['y'].quantity, table['z'].quantity distance, glon, glat = astrometry.galactic(x, y, z) phys_size = table['size_physical'].quantity coordinate = SkyCoord(glon, glat, unit='deg', frame='galactic').transform_to('icrs') ra, dec = coordinate.ra.deg, coordinate.dec.deg r = np.sqrt(table['x'] ** 2 + table['y'] ** 2) constant = 0.000291 / u.arcmin size = phys_size / ((distance.to('pc')) * constant) # Clip size because we have a min / max for allowed size in XML / science tools size = np.clip(size.to('deg').value, 0.01, 100) * u.deg # Add columns to table table['distance'] = Column(distance, unit='kpc', description='Distance observer to source center') table['GLON'] = Column(glon, unit='deg', description='Galactic longitude') table['GLAT'] = Column(glat, unit='deg', description='Galactic latitude') table['RA'] = Column(ra, unit='deg') table['DEC'] = Column(dec, unit='deg') table['size'] = Column(size, unit='deg') table['galactocentric_r'] = Column(r, unit='kpc', description='Galactocentric radius in the xy plan') return table
synt = Table() # In[SNR] q = Table.read(snrsfile, format='ascii') en = q['E[TeV]'][0:40].data # TeV glon, glat, f01, f1 = [], [], [], [] for i in np.arange(int(len(q) / 40)): sed = q['diff_spectrum'][i * 40:(i + 1) * 40] # TeV cm-2 s-1 fl = sed / en**2. # cm-2 s-1 TeV-1 if (sum(fl) != 0): pos = galactic(x=q['POS_Y'][i * 40] * u.kpc, y=-q['POS_X'][i * 40] * u.kpc, z=q['POS_Z'][i * 40] * u.kpc) glon.append(pos[1].value) glat.append(pos[2].value) f01.append(ag.integ(en, fl, emin=0.1, emax=1000.)[0] / crab_01) f1.append(ag.integ(en, fl, emin=1.0, emax=1000.)[0] / crab_1) dic = {'GLON': glon, 'GLAT': glat, 'F01': f01, 'F1': f1} snr = pd.DataFrame(dic) # In[iSNR] isnrs = Table.read(isnrsfile) f01, f1 = [], [] for i in np.arange(len(isnrs)):
def add_observed_parameters(table, obs_pos=None): """Add observable parameters (such as sky position or distance). Input table columns: x, y, z, extension, luminosity Output table columns: distance, glon, glat, flux, angular_extension Position of observer in cartesian coordinates. Center of galaxy as origin, x-axis goes through sun. Parameters ---------- table : `~astropy.table.Table` Input table obs_pos : tuple or None Observation position (X, Y, Z) in Galactocentric coordinates (default: Earth) Returns ------- table : `~astropy.table.Table` Modified input table with columns added """ obs_pos = obs_pos or [astrometry.D_SUN_TO_GALACTIC_CENTER, 0, 0] # Get data x, y, z = table["x"].quantity, table["y"].quantity, table["z"].quantity vx, vy, vz = table["vx"].quantity, table["vy"].quantity, table["vz"].quantity distance, glon, glat = astrometry.galactic(x, y, z, obs_pos=obs_pos) # Compute projected velocity v_glon, v_glat = astrometry.velocity_glon_glat(x, y, z, vx, vy, vz) coordinate = SkyCoord(glon, glat, unit="deg", frame="galactic").transform_to("icrs") ra, dec = coordinate.ra.deg, coordinate.dec.deg # Add columns to table table["distance"] = Column( distance, unit="pc", description="Distance observer to source center" ) table["GLON"] = Column(glon, unit="deg", description="Galactic longitude") table["GLAT"] = Column(glat, unit="deg", description="Galactic latitude") table["VGLON"] = Column( v_glon.to("deg/Myr"), unit="deg/Myr", description="Velocity in Galactic longitude", ) table["VGLAT"] = Column( v_glat.to("deg/Myr"), unit="deg/Myr", description="Velocity in Galactic latitude", ) table["RA"] = Column(ra, unit="deg", description="Right ascension") table["DEC"] = Column(dec, unit="deg", description="Declination") try: luminosity = table["luminosity"] flux = luminosity / (4 * np.pi * distance ** 2) table["flux"] = Column(flux.value, unit=flux.unit, description="Source flux") except KeyError: pass try: extension = table["extension"] angular_extension = np.degrees(np.arctan(extension / distance)) table["angular_extension"] = Column( angular_extension, unit="deg", description="Source angular radius (i.e. half-diameter)", ) except KeyError: pass return table
def test_galactic(): x = Quantity(0, "kpc") y = Quantity(0, "kpc") z = Quantity(0, "kpc") reference = (Quantity(8.5, "kpc"), Quantity(0, "deg"), Quantity(0, "deg")) assert galactic(x, y, z) == reference