def get_data(): query = "SELECT top 1000 * FROM obsPointing WHERE obs_collection='K2' AND dataproduct_type='image'" df = query_db(CAOM, query) if len(df) == 0: return None df['coords'] = df.apply(lambda x: parse_s_region(x['s_region']), axis=1) # Generate MOC results = [get_polygon_moc(row) for _, row in df.iterrows()] # Union of MOCs if len(results) > 1: moc = MOC.union(*results) else: moc = results return moc
def get_data(sector): query = "SELECT top 1000 * FROM obsPointing WHERE obs_collection='TESS' AND dataproduct_type='image' " \ "AND sequence_number={}".format(sector) df = query_db(CAOM_OPS, query) df['coords'] = df.apply(lambda x: parse_s_region(x['s_region']), axis=1) # Generate MOC start_time = time.time() pool = ThreadPoolExecutor(max_workers=4) results = list(pool.map(get_polygon_moc, [row for _, row in df.iterrows()])) end_time = time.time() print('Total time : {} seconds'.format(end_time - start_time)) # Union of MOCs start_time = time.time() moc = MOC.union(*results) end_time = time.time() print('Total time : {} seconds'.format(end_time - start_time)) return moc
class ASKAPSurvey: ASKAP_ROTATION = 45 * u.deg # may not be an appropriate assumption! # full width (diameter) WIDTH = 2 * 4.1 * u.deg HEIGHT = WIDTH def __init__(self, field_list, max_depth=7): if not os.path.exists(field_list): raise IOError("Cannot find file %s" % field_list) self.fields_df = pd.read_csv(field_list) self.max_depth = max_depth self.region_list = regions.ShapeList() self.moc = MOC() for _, field in self.fields_df.iterrows(): center = SkyCoord(ra=field.RA, dec=field.Dec, unit="hourangle,deg") sep = np.hypot(self.WIDTH, self.HEIGHT) / 2.0 self.region_list.append( regions.RectangleSkyRegion( center, self.WIDTH, self.HEIGHT, self.ASKAP_ROTATION + (field.Rotation * u.deg), )) self.vertices = SkyCoord([ center.directional_offset_by( self.ASKAP_ROTATION + pa + (field.Rotation * u.deg), sep) for pa in [45, 135, 225, 315] * u.deg ]) self.moc = self.moc.union( MOC.from_polygon_skycoord(self.vertices, max_depth=self.max_depth)) def to_moc(self, filename): self.moc.write(filename, overwrite=True) def to_reg(self, filename): regions.write_ds9(self.region_list, filename, coordsys="fk5")
return temp_moc co = 100000 st = 1 en = st + co query = "SELECT objID,ra,dec FROM objectCoords WITH (NOLOCK) WHERE objID between {} AND {}".format( st, en) df = query_db(TIC_CONN, query) # Generate MOC start_time = time.time() pool = ThreadPoolExecutor(max_workers=4) results = list(pool.map(get_catalog_moc, [row for _, row in df.iterrows()])) end_time = time.time() print('Total time : {} seconds'.format(end_time - start_time)) start_time = time.time() # moc = MOC.union(results[0], *results[1:]) moc = MOC.union(*results) end_time = time.time() print('Total time : {} seconds'.format(end_time - start_time)) # Save MOC # hdulist = moc.serialize(format='fits') # hdulist.writeto('TIC_v70_{}.fits'.format(MAX_DEPTH)) moc.write('TIC_v70_{}.fits'.format(MAX_DEPTH), format='fits', overwrite=True) # Read from file moc = MOC.from_fits('TIC_v70_15.fits')
# Generate the figure(s) for t in moc_list: moc, s = t print(s) my_plot(moc, frame=Galactic(), save='figures/tess_S{:04d}.png'.format(int(s))) # fig = plt.figure(111, figsize=(12.5, 10.5)) # # with WCS(fig, # fov=360 * u.deg, # center=SkyCoord(0, 0, unit='deg', frame='galactic'), # coordsys="galactic", # rotation=Angle(0, u.degree), # projection="AIT") as wcs: # ax = fig.add_subplot(1, 1, 1, projection=wcs) # # # Call fill with a matplotlib axe and the `~astropy.wcs.WCS` wcs object. # moc.fill(ax=ax, wcs=wcs, alpha=1, linewidth=1.5, fill=True, color="black") # # moc.border(ax=ax, wcs=wcs, alpha=0.5, color="black") # # plt.tight_layout() # plt.savefig('figures/tess_S{:04d}.png'.format(int(s))) union_moc = MOC.union(*[s[0] for s in moc_list]) my_plot(union_moc, frame=Galactic(), save='caom_TESS_galactic.png')