Google Colab (Python:3.6.9, astroquery:0.4)
--Save the astronomical catalog (fits file) from skyview --Create and save a galaxy image based on the fits file --Read image data from the directory in order and store it in the ndarray array --Plot
First, get the celestial names and their numbers listed in the catalog specified by Vizier.
from astroquery.vizier import Vizier
v=Vizier(catalog="J/ApJS/80/531/gxfluxes",columns=["Name","logLx","Bmag","dist","type"],row_limit=-1)
data=v.query_constraints()
sname=data[0]["Name"]
namelist=[]
for one in sname:
name=one.strip().split()[0]
name=one.replace("N","NGC").replace("I","IC")
namelist.append(name)
olist=["HRI","DSS"]
In this case, len (namelist) = 448, so we can see that there are 448 celestial bodies. Save the fits files of those objects in order.
def save(p,name,obs): # save file into fits
for onep,oneo in zip(p,obs):
onep.writeto(name+"_"+oneo+".fits",overwrite=True)
from astroquery.skyview import SkyView
path_fits="/content/drive/My Drive/datastore/fits/"
num=int(input("Times of try (for <=448) : "))
filename=[]
for i in range(num):
name=namelist[i]
try:
paths=SkyView.get_images(position=name,survey=olist)
save(paths,path_fits+name,olist)
filename.append(name)
print("Saved {}".format(name))
except:
print("Not found {}".format(name))
Read the fits file from the directory. Since the fits file contains information on 300x300 ndarray arrays, make them into a 1x90000 matrix once. Do the same for other fits files and add the results to the same ndarray.
#One-dimensional image data of fits file in the directory,
#Store image data in each row of data in a two-dimensional array
path_fits=glob.glob("/content/drive/My Drive/datastore/fits/*_DSS.fits")
N=100
#N=len(path_fits)
h=300
w=300
data = np.empty(h*w*N).reshape(N, h*w)
img_data=np.empty(h*w*N)
for i in range(N):
dsshdu=fits.open(path_fits[i])[0]
dsswcs=WCS(dsshdu.header)
dssdata=dsshdu.data
img_data=np.array(dssdata)
data[i] = np.array(dssdata).flatten()
data.shape
The image data flattened earlier is reshaped into a 300 × 300 matrix again. Plot it one by one in the direction of axis = 0.
data_reshaped=data.reshape(N,h,w)
f=plt.figure(figsize=(15,15))
f.subplots_adjust(left=0,right=1,bottom=0,top=1,hspace=0.05,wspace=0.05)
for i in range(N):
ax=f.add_subplot(10, 10, i+1, xticks=[], yticks=[])
ax.imshow(data_reshaped[i], interpolation="bilinear")
plt.show()
[For super beginners] Try implementing principal component analysis (PCA) of images with python.
Recommended Posts