def test_SkyServer_objectSearch(self): #object search object = SkyServer.objectSearch(ra=258.25, dec=64.05, dataRelease=SkyServer_DataRelease) self.maxDiff = None self.assertEqual(SkyServer_ObjectSearchResultObjID, object[0]["Rows"][0]["id"])
def test_SkyServer_radialSearch(self): # radial search df = SkyServer.radialSearch(ra=258.25, dec=64.05, radius=0.1, dataRelease=SkyServer_DataRelease) self.maxDiff = None self.assertEqual(SkyServer_RadialSearchResultCSV, df.to_csv(index=False, float_format="%.6f"))
def test_SkyServer_rectangularSearch(self): #rectangular search df = SkyServer.rectangularSearch(min_ra=258.3, max_ra=258.31, min_dec=64, max_dec=64.01, dataRelease=SkyServer_DataRelease) self.maxDiff = None self.assertEqual(SkyServer_RectangularSearchResultCSV, df.to_csv(index=False, float_format="%.6f"))
def test_SkyServer_getJpegImgCutout(self): #image cutout img = SkyServer.getJpegImgCutout( ra=197.614455642896, dec=18.438168853724, width=512, height=512, scale=0.4, dataRelease=SkyServer_DataRelease, opt="OG", query= "SELECT TOP 100 p.objID, p.ra, p.dec, p.r FROM fGetObjFromRectEq(197.6,18.4,197.7,18.5) n, PhotoPrimary p WHERE n.objID=p.objID" ) im = skimage.io.imread("./TestGalaxy.jpeg") self.assertEqual(img.tobytes(), im.tobytes())
def get_images(df, width=424, height=424, scale=.02): """Get images for objects present in pandas dataframe. Downloads JPEG images of objects from SDSS to disk storage, naming images according to their :attr:`specobjid`. Filepaths are additionally stored in the dataframe, such that the dataframe can be used with :class:`keras.preprocessing.image.ImageDataGenerator` """ catalog_path = os.path.join(ARGS.DATA, ARGS.CATALOG + '.h5') df = df.assign(imgpath=None) with tqdm(total=len(df.index), unit='object') as pbar: for index, obj in df.iterrows(): # allows for restarting incomplete downloads by # checking for all entries if the path already exists # XXX: tqdm includes better ways to approach this if obj['imgpath'] is not None: pbar.update(1) continue img = None img = SkyServer.getJpegImgCutout(ra=obj['ra'], dec=obj['dec'], width=width, height=height, scale=(scale * obj['petroR90_r']), dataRelease='DR15') if img is not None: imgpath = os.path.join(ARGS.IMG, '{0}.jpeg'.format(obj['specobjid'])) Image.fromarray(img).save(imgpath) df.at[index, 'imgpath'] = imgpath df.to_hdf(catalog_path, key=ARGS.CATALOG, append=False, mode='w') pbar.update(1) return df.dropna(axis=0, subset=['imgpath'], inplace=True)
def get_catalog(): """Downloads GZ2 object catalog. Retrieve a dataframe of the objects present in the GalaxyZoo2 catalog, as well as weighted fraction task answers for each object. """ sql = 'SELECT gz2.specobjid, gz2.ra, gz2.dec, dr7.petroR90_r, ' \ 'gz2.t01_smooth_or_features_a01_smooth_weighted_fraction' \ ' AS t01a01, ' \ 'gz2.t01_smooth_or_features_a02_features_or_disk_weighted_fraction' \ ' AS t01a02, ' \ 'gz2.t01_smooth_or_features_a03_star_or_artifact_weighted_fraction' \ ' AS t01a03, ' \ 'gz2.t02_edgeon_a04_yes_weighted_fraction' \ ' AS t02a04, ' \ 'gz2.t02_edgeon_a05_no_weighted_fraction' \ ' AS t02a05, ' \ 'gz2.t03_bar_a06_bar_weighted_fraction' \ ' AS t03a06, ' \ 'gz2.t03_bar_a07_no_bar_weighted_fraction' \ ' AS t03a07, ' \ 'gz2.t04_spiral_a08_spiral_weighted_fraction' \ ' AS t04a08, ' \ 'gz2.t04_spiral_a09_no_spiral_weighted_fraction' \ ' AS t04a09, ' \ 'gz2.t05_bulge_prominence_a10_no_bulge_weighted_fraction' \ ' AS t05a10, ' \ 'gz2.t05_bulge_prominence_a11_just_noticeable_weighted_fraction' \ ' AS t05a11, ' \ 'gz2.t05_bulge_prominence_a12_obvious_weighted_fraction' \ ' AS t05a12, ' \ 'gz2.t05_bulge_prominence_a13_dominant_weighted_fraction' \ ' AS t05a13, ' \ 'gz2.t06_odd_a14_yes_weighted_fraction' \ ' AS t06a14, ' \ 'gz2.t06_odd_a15_no_weighted_fraction' \ ' AS t06a15, ' \ 'gz2.t07_rounded_a16_completely_round_weighted_fraction' \ ' AS t07a16, ' \ 'gz2.t07_rounded_a17_in_between_weighted_fraction' \ ' AS t07a17, ' \ 'gz2.t07_rounded_a18_cigar_shaped_weighted_fraction' \ ' AS t07a18, ' \ 'gz2.t08_odd_feature_a19_ring_weighted_fraction' \ ' AS t08a19, ' \ 'gz2.t08_odd_feature_a20_lens_or_arc_weighted_fraction' \ ' AS t08a20, ' \ 'gz2.t08_odd_feature_a21_disturbed_weighted_fraction' \ ' AS t08a21, ' \ 'gz2.t08_odd_feature_a22_irregular_weighted_fraction' \ ' AS t08a22, ' \ 'gz2.t08_odd_feature_a23_other_weighted_fraction' \ ' AS t08a23, ' \ 'gz2.t08_odd_feature_a24_merger_weighted_fraction' \ ' AS t08a24, ' \ 'gz2.t08_odd_feature_a38_dust_lane_weighted_fraction' \ ' AS t08a38, ' \ 'gz2.t09_bulge_shape_a25_rounded_weighted_fraction' \ ' AS t09a25, ' \ 'gz2.t09_bulge_shape_a26_boxy_weighted_fraction' \ ' AS t09a26, ' \ 'gz2.t09_bulge_shape_a27_no_bulge_weighted_fraction' \ ' AS t09a27, ' \ 'gz2.t10_arms_winding_a28_tight_weighted_fraction' \ ' AS t10a28, ' \ 'gz2.t10_arms_winding_a29_medium_weighted_fraction' \ ' AS t10a29, ' \ 'gz2.t10_arms_winding_a30_loose_weighted_fraction' \ ' AS t10a30, ' \ 'gz2.t11_arms_number_a31_1_weighted_fraction' \ ' AS t11a31, ' \ 'gz2.t11_arms_number_a32_2_weighted_fraction' \ ' AS t11a32, ' \ 'gz2.t11_arms_number_a33_3_weighted_fraction' \ ' AS t11a33, ' \ 'gz2.t11_arms_number_a34_4_weighted_fraction' \ ' AS t11a34, ' \ 'gz2.t11_arms_number_a36_more_than_4_weighted_fraction' \ ' AS t11a36, ' \ 'gz2.t11_arms_number_a37_cant_tell_weighted_fraction' \ ' AS t11a37 ' \ 'FROM zoo2MainSpecz as gz2 JOIN SpecDR7 AS dr7 ' \ 'ON gz2.dr7objid=dr7.dr7objid' return SkyServer.sqlSearch(sql=sql, dataRelease='DR15')
def test_SkyServer_sqlSearch(self): #sql search df = SkyServer.sqlSearch(sql=SkyServer_TestQuery, dataRelease=SkyServer_DataRelease) self.assertEqual(SkyServer_QueryResultCSV, df.to_csv(index=False))
#help(SkyServer) # In[ ]: #defining sql query and SDSS data relelease: SkyServer_TestQuery = "select top 1 specobjid, ra, dec from specobj order by specobjid" SkyServer_DataRelease = "DR13" # In[ ]: #Exectute sql query df = SkyServer.sqlSearch(sql=SkyServer_TestQuery, dataRelease=SkyServer_DataRelease) print(df) # In[ ]: #get an image cutout img = SkyServer.getJpegImgCutout(ra=197.614455642896, dec=18.438168853724, width=2, height=2, scale=0.4, dataRelease=SkyServer_DataRelease,opt="OG", query="SELECT TOP 100 p.objID, p.ra, p.dec, p.r FROM fGetObjFromRectEq(197.6,18.4,197.7,18.5) n, PhotoPrimary p WHERE n.objID=p.objID") plt.imshow(img) # In[ ]:
imgName = str(galaxies.iloc[x][0]) + ".jpeg" maxValue = 0 shapeIndex = ellipticIndex for y in xrange(ellipticIndex,combinedIndex + 1): if galaxies.iloc[x][y] > maxValue: maxValue = galaxies.iloc[x][y] shapeIndex = y hd2 = galaxies.iloc[x][1] + " " + galaxies.iloc[x][2] # Obtain decimal representation ra1, dec1 = pyasl.coordsSexaToDeg(hd2) img = SkyServer.getJpegImgCutout(ra=ra1, dec=dec1, width=512, height=512, scale=0.1, dataRelease="DR13",opt="I", query="SELECT TOP 1 g.objID, g.ra, g.dec, g.r FROM fGetObjFromRectEq(ra1-0.5,dec1-0.5,ra1+0.5,dec1+0.5) n, Galaxy g WHERE n.objID=g.objID") im = Image.fromarray(img) im.save(imgName) with open('shapes.csv', 'a') as f: writer = csv.writer(f) writer.writerow([str(galaxies.iloc[x][0]), str(shapeIndex)])
csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for x in range(0, num_lines): row = next(csv_reader) if line_count == 0: line_count += 1 else: ra_sx, dec_sx = row[1], row[2] c = SkyCoord(ra_sx, dec_sx, unit=u.degree) print(f'object {row[0]}', c) line_count += 1 img = SkyServer.getJpegImgCutout(ra=c.ra.deg, dec=c.dec.deg, width=IMG_WIDTH, height=IMG_HEIGHT, scale=0.1, dataRelease='DR13') Image.fromarray(img).save(f"skyserver_fits/{row[0]}.png") r, g, b = img[:, :, 0], img[:, :, 1], img[:, :, 2] red = fits.PrimaryHDU(data=r) red.writeto(f"skyserver_fits/{row[0]}r.fits") green = fits.PrimaryHDU(data=g) green.writeto(f"skyserver_fits/{row[0]}g.fits") blue = fits.PrimaryHDU(data=b) blue.writeto(f"skyserver_fits/{row[0]}b.fits")