[PYTHON] How to display multiple images of galaxies in tiles

environment

Google Colab (Python:3.6.9, astroquery:0.4)

Overall flow

--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

code

Save fits file

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()

result

2020-06-06.png

References

[For super beginners] Try implementing principal component analysis (PCA) of images with python.

Recommended Posts

How to display multiple images of galaxies in tiles
[Google Colab] I want to display multiple images side by side in tiles
How to collect images in Python
How to display a specified column of files in Linux (awk)
How to suppress display error in matplotlib
How to handle multiple versions of CUDA in the same environment
How to display multiplication table in python
How to display Hello world in python
How to view images in Django's Admin
How to draw OpenCV images in Pygame
How to change multiple columns of csv in Pandas (Unixtime-> Japan Time)
Understand how to display images on Jupyter (utilization of imshow / matplotlib of OpenCV)
How to keep track of work in Powershell
Summary of how to import files in Python 3
I want to display multiple images with matplotlib.
Summary of how to use MNIST in Python
How to display images continuously with matplotlib Note
How to display videos inline in Google Colab
[Java] How to switch between multiple versions of Java
How to get multiple model objects randomly in Django
How to get the number of digits in Python
How to write string concatenation in multiple lines in Python
How to display DataFrame as a table in Markdown
How to retrieve multiple arrays using slice in python.
Summary of how to share state with multiple functions
How to display the modification date of a file in C language up to nanoseconds
Optimal placement of multiple images
How to develop in Python
How to embed multiple embeds in one message with Discord.py
How to slice a block multiple array from a multiple array in Python
How to define multiple variables in a python for statement
How to develop in a virtual environment of Python [Memo]
How to display a list of installable versions with pyenv
Comparison of how to use higher-order functions in Python 2 and 3
How to increase the number of machine learning dataset images
How to get a list of built-in exceptions in python
Summary of how to write .proto files used in gRPC
How to get an overview of your data in Pandas
How to get a quadratic array of squares in a spiral!
How to display the regional mesh of the official statistics window (eStat) in a web browser
[Super easy! ] How to display the contents of dictionaries and lists including Japanese in Python
How to process camera images with Teams and Zoom Volume of processing in animation style
Pixel manipulation of images in Python
How to handle session in SQLAlchemy
[Rails] How to display Google Map
How to determine the existence of a selenium element in Python
How to implement Java code in the background of RedHat (LinuxONE)
[Image connection] Arrange images in tiles
How to use classes in Theano
How to write soberly in pandas
How to change the color of just the button pressed in Tkinter
How to display formulas in latex when using sympy (> = 1.4) in Google Colaboratory
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
How to update Spyder in Anaconda
How to use SQLite in Python
Summary of how to use pyenv-virtualenv
Waveform display of audio in Python
How to convert 0.5 to 1056964608 in one shot
How to check the memory size of a dictionary in Python
[TensorFlow 2] How to check the contents of Tensor in graph mode
How to reflect CSS in Django