How to plot galaxy visible light data using OpenNGC database in python

What is the Open NGC Catalog?

(OpenNGC) [https://github.com/mattiaverga/OpenNGC] is a database that organizes NGC (New General Catalog) and IC (Index Catalog).

PyOngc in python interface

You can easily get the data using https://github.com/mattiaverga/PyOngc. It can be installed with pip install pyongc on python3 series.

python


import pyongc
name="NGC4051"                                                                                         
DSOobject = pyongc.Dso(name) 
gtype = DSOobject.getType() 
mag = DSOobject.getMagnitudes() 
surf = DSOobject.getSurfaceBrightness() 
hubble = DSOobject.getHubble()                                                                 
# print(gtype,mag,surf,hubble)
# ('Galaxy', (11.08, 12.92, 8.58, 8.06, 7.67), 22.87, 'SABb')

When you install pyongc, command line tools are also installed, and you can see how many stars and galaxies are included with the following command.

python


> ongc stats

PyONGC version: 0.5.1
Database version: 20191019
Total number of objects in database: 13978
Object types statistics:
	Star                         -> 546
	Double star                  -> 246
	Association of stars         -> 62
	Star cluster + Nebula        -> 66
	Dark Nebula                  -> 2
	Duplicated record            -> 636
	Emission Nebula              -> 8
	Galaxy                       -> 10490
	Globular Cluster             -> 205
	Group of galaxies            -> 16
	Galaxy Pair                  -> 212
	Galaxy Triplet               -> 23
	HII Ionized region           -> 83
	Nebula                       -> 93
	Nonexistent object           -> 14
	Nova star                    -> 3
	Open Cluster                 -> 661
	Object of other/unknown type -> 434
	Planetary Nebula             -> 129
	Reflection Nebula            -> 38
	Supernova remnant            -> 11

When analyzing the entire catalog

If you want to analyze the entire catalog, download the original csv file. If wget is installed, you should be able to download it in one shot below.

python


wget https://raw.githubusercontent.com/mattiaverga/OpenNGC/master/NGC.csv .

NGC.csv plot example

Code example

python


import pandas as pd
df = pd.read_table('NGC.csv', header=0,delimiter=";")

import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plt.rcParams['font.family'] = 'serif'
import matplotlib.colors as colors

fig = plt.figure(figsize=(14,7.))
ax = fig.add_subplot(1, 2, 1)

num=len(set(df["Hubble"]))
usercmap = plt.get_cmap('jet')
cNorm  = colors.Normalize(vmin=0, vmax=num)
scalarMap = cm.ScalarMappable(norm=cNorm, cmap=usercmap)

for i, sp in enumerate(set(df["Hubble"])):
    c = scalarMap.to_rgba(i)
    df_species = df[df['Hubble'] == sp]
    ax.scatter(data=df_species, x='B-Mag', y='K-Mag', label=sp, color=c, s=1)

plt.xlabel("B-Mag")
plt.ylabel("K-Mag")
plt.legend(bbox_to_anchor=(0., 1.01, 1., 0.01), loc='lower left',ncol=8, mode="expand", borderaxespad=0.,fontsize=8)

ax = fig.add_subplot(1, 2, 2)


for i, sp in enumerate(set(df["Hubble"])):
    c = scalarMap.to_rgba(i)
    df_species = df[df['Hubble'] == sp]
    ax.scatter(data=df_species, x='B-Mag', y='SurfBr', label=sp, color=c, s=1)

plt.xlabel("B-Mag")
plt.ylabel(r"Surface brigness within 25 mag isophoto (B-band) [mag/arcsec$^2$]")
plt.legend(bbox_to_anchor=(0., 1.01, 1., 0.01), loc='lower left',ncol=8, mode="expand", borderaxespad=0.,fontsize=8)

plt.savefig("ngc_bk_bs.png ")
plt.show()

import seaborn as sns
sns.pairplot(df[df["Type"]=="G"],vars=["B-Mag","V-Mag","K-Mag"])
plt.savefig("ngc_bvk_galaxy.png ")

matplotlib scatter plot diagram

ngc_bk_bs.png

seaborn sns.pairplot diagram

ngc_bvk_galaxy.png

Database description

There is an explanation at https://github.com/mattiaverga/OpenNGC/blob/master/NGC_guide.txt.

How to simplify the Hubble type, remove Nan and then plot

For example, the Hubble type is so numerous that you may want to simplify it. In that case,

python


set(df["Hubble"])

As, check the type of Hubble type. Create a dictionary to convert it and create a new column to record the result of the conversion.

python


htype={'E':"Etype", 'E-S0':"Etype",  'E?':"Etype",  'I':"Etype",  'IAB':"Etype",  'IB':"Etype",  \
'S0':"Etype", 'S0-a':"Etype",  'S?':"Etype",  'SABa':"Stype",   'SABb':"Stype",  'SABc':"Stype",  'SABd':"Stype",  'SABm':"Stype",  'SBa':"Stype", \
'SBab':"Stype", 'SBb':"Stype", 'SBbc':"Stype", 'SBc':"Stype", 'SBcd':"Stype", 'SBd':"Stype", 'SBm':"Stype", 'Sa':"Stype", 'Sab':"Stype", 'Sb':"Stype",  \
'Sbc':"Stype", 'Sc':"Stype", 'Scd':"Stype", 'Sd':"Stype", 'Sm':"Stype", "nan":"Nan"}
df["htype"] = df["Hubble"]
df = df.replace({"htype":htype})

Here, for example, an example of simply dividing into three parts, Etype, Stype, and Nan, is shown. Converting E to E is recursive and can be crazy, so avoid converting to the same character.

How to delete Nan

Since it is a problem if Nan is in the data, extract only the necessary columns and execute dropna for it to delete Nan.

python


    ds = df_species.loc[:,["B-Mag","K-Mag","J-Mag"]] 
    ds = ds.dropna(how='any')

Sample code

python



import pandas as pd
df = pd.read_table('NGC.csv', header=0,delimiter=";")

htype={'E':"Etype", 'E-S0':"Etype",  'E?':"Etype",  'I':"Etype",  'IAB':"Etype",  'IB':"Etype",  \
'S0':"Etype", 'S0-a':"Etype",  'S?':"Etype",  'SABa':"Stype",   'SABb':"Stype",  'SABc':"Stype",  'SABd':"Stype",  'SABm':"Stype",  'SBa':"Stype", \
'SBab':"Stype", 'SBb':"Stype", 'SBbc':"Stype", 'SBc':"Stype", 'SBcd':"Stype", 'SBd':"Stype", 'SBm':"Stype", 'Sa':"Stype", 'Sab':"Stype", 'Sb':"Stype",  \
'Sbc':"Stype", 'Sc':"Stype", 'Scd':"Stype", 'Sd':"Stype", 'Sm':"Stype", "nan":"Nan"}

df["htype"] = df["Hubble"]
df = df.replace({"htype":htype})

import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plt.rcParams['font.family'] = 'serif'
import matplotlib.colors as colors

fig = plt.figure(figsize=(14,7.))

ax = fig.add_subplot(1, 2, 1)
for i, sp in enumerate(set(df["htype"])):
    df_species = df[df['htype'] == sp]
    ds = df_species.loc[:,["B-Mag","K-Mag","J-Mag"]] 
    ds = ds.dropna(how='any')
    bk = ds["B-Mag"] - ds["K-Mag"]
    bj = ds["B-Mag"] - ds["J-Mag"]   
    ax.scatter(bk,bj,label=sp, s=2)
plt.xlabel("B-K")
plt.ylabel("B-J")
plt.legend(bbox_to_anchor=(0., 1.01, 1., 0.01), loc='lower left',borderaxespad=0.,fontsize=8)

ax = fig.add_subplot(1, 2, 2)
for i, sp in enumerate(set(df["htype"])):
    df_species = df[df['htype'] == sp]
    ds = df_species.loc[:,["B-Mag","K-Mag","J-Mag"]] 
    ds = ds.dropna(how='any')
    bj = ds["B-Mag"] - ds["J-Mag"]   
    ax.scatter(ds["B-Mag"],bj,label=sp, s=2)
plt.xlabel("B")
plt.ylabel("B-J")
plt.legend(bbox_to_anchor=(0., 1.01, 1., 0.01), loc='lower left',borderaxespad=0.,fontsize=8)

plt.savefig("ngc_bk_bj.png ")
plt.show()


Generated figure

ngc_bk_bj.png

Recommended Posts

How to plot galaxy visible light data using OpenNGC database in python
How to plot autocorrelation and partial autocorrelation in python
How to plot multiple fits images side by side in galactic coordinates using python
How to exit when using Python in Terminal (Mac)
How to retrieve multiple arrays using slice in python.
How to execute a command using subprocess in Python
How to develop in Python
Data science companion in python, how to specify elements in pandas
How to install python using anaconda
[Python] How to FFT mp3 data
[Python] How to do PCA in Python
How to collect images in Python
How to use SQLite in Python
[Question] How to get data of textarea data in real time using Python web framework bottle
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to handle Japanese in Python
How to update a Tableau packaged workbook data source using Python
How to display legend marks in one with Python 2D plot
[Introduction to Python] How to use class in Python?
How to access environment variables in Python
How to dynamically define variables in Python
[Itertools.permutations] How to put permutations in Python
How to work with BigQuery in Python
Log in to Slack using requests in Python
How to get a stacktrace in python
Get Youtube data in Python using Youtube Data API
How to extract polygon area in Python
How to check opencv version in python
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
How to use "deque" for Python data
How to use regular expressions in Python
How to display Hello world in python
How to use is and == in Python
How to write Ruby to_s in Python
How to generate a new loggroup in CloudWatch using python within Lambda
How to send a visualization image of data created in Python to Typetalk
Convert XML document stored in XML database (BaseX) to CSV format (using Python)
How to get a value from a parameter store in lambda (using python)
How to receive command line arguments in Python
[REAPER] How to play with Reascript in Python
How to generate permutations in Python and C ++
How to embed a variable in a python string
How to take multiple arguments when doing parallel processing using multiprocessing in python
How to implement Discord Slash Command in Python
Summary of how to import files in Python 3
How to simplify restricted polynomial fit in python
How to use Python Image Library in python3 series
How to implement shared memory in Python (mmap.mmap)
[Python] How to name table data and output it in csv (to_csv method)
How to create a JSON file in Python
[Python] How to read data from CIFAR-10 and CIFAR-100
Summary of how to use MNIST in Python
[Introduction to Python] How to handle JSON format data
How to specify TLS version in python requests
How to get article data using Qiita API