Ejemplo n.º 1
0
 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())
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
	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)])






# 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[ ]:

# do a radial search of objects:

df = SkyServer.radialSearch(ra=258.25, dec=64.05, radius=0.1, dataRelease=SkyServer_DataRelease)
print(df)


# In[ ]:

#do rectangular search of objects:
    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")