import pandas as pd
import numpy as np
import plotly.graph_objects as go
import urllib.request
from PIL import Image
# Unknown source of data
dat = pd.read_csv('./Labs/DarkMatter/ngc_134_rc.dat',comment='#',index_col=False,sep='\s+')
V_tot = dat['Vc']
r_arcsec = dat['arcseconds']
name = 'NGC134'
V_r = 1596
H0 = 72
dist = (V_r/H0) # distance to galaxy in Mpc
r = (r_arcsec / 2.062e5) * (dist*1e3) # radius/distance fr center in kpc
V_c = V_tot - V_r
# correct for inclination
a = 7.56
b = 2.16
V_c = V_c / np.sqrt(1-(b/a)**2)
# Usually using an URL with source = "" in the plotly figure works, but it wasn't for these. Instead, use urllib and image to define the images.
urllib.request.urlretrieve('http://depts.washington.edu/astroed/GalaxyRotationCurves/ngc134-cropped.jpg', 'file_name')
img = Image.open('file_name')
# Plotting main points:
fig = go.Figure() #Start graph_objects figure
fig.add_trace(go.Scatter( #Add scatter plot, edit markers or lines
x=r_arcsec,
y=V_c,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.8,
symbol='circle-open',line_width=2),name=''))
# Plotting layout, labels, etc:
fig.update_layout(title={'text': name,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (\")",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey',
'range':[-250,250]},
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey'},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=700,
height=590)
# Option to add finding chart / photo of galaxy, adjust so scaling is correct
fig.add_layout_image(
dict(
source=img,
x=0.5,
y=0.51))
fig.update_layout_images(dict(
xref="paper",
yref="paper",
sizex=1,
sizey=1,
xanchor="center",
yanchor="middle",
opacity=0.8,
layer="below"))
fig.show();
filename = './'+name+'rc.pdf'
# fig.write_html('./'+name+'rc.html')
# This is for reading the DeBlok rotation curve files;
# # @ARTICLE{2002A&A...385..816D,
# author = {{de Blok}, W.~J.~G. and {Bosma}, A.},
# title = "{High-resolution rotation curves of low surface brightness galaxies}",
# journal = {\aap},
# keywords = {GALAXIES: STRUCTURE, GALAXIES: KINEMATICS AND DYNAMICS, GALAXIES: HALOS, Astrophysics},
# year = 2002,
# month = apr,
# volume = {385},
# pages = {816-846},
# doi = {10.1051/0004-6361:20020080},
# archivePrefix = {arXiv},
# eprint = {astro-ph/0201276},
# primaryClass = {astro-ph},
# adsurl = {https://ui.adsabs.harvard.edu/abs/2002A&A...385..816D},
# adsnote = {Provided by the SAO/NASA Astrophysics Data System}
# }
cols=('name','Angular Radius', #in arcsec already
'Physical radius using adopted distance',
'Rotation velocity of gas component',
'Rotation velocity of disk',
'Rotation velocity','Error in rotation velocity')
dat = pd.read_csv('./Labs/DarkMatter/DeBlokRC/procurve.dat',
comment='#',
sep='\s+',
header=None,index_col=False,
names=cols)
data = pd.DataFrame(dat)
names = data.name.unique()
# Example for plotting and artificially mirroring the DeBlok data
name = 'UGC3137'
rvel = data[data.name==name]['Rotation velocity'].values
rang = data[data.name==name]['Angular Radius'].values
rkpc = data[data.name==name]['Physical radius using adopted distance'].values
rangrev = -rang[::-1]
rang_mirrored = np.empty(2*len(rvel))
rang_mirrored[:len(rvel)] = rangrev
rang_mirrored[len(rvel):] = rang
rvelopp = -rvel[::-1]
rvel_mirrored=np.empty(2*len(rvel))
rvel_mirrored[:len(rvel)] = rvelopp
rvel_mirrored[len(rvel):] = rvel
urllib.request.urlretrieve('http://depts.washington.edu/astroed/GalaxyRotationCurves/ugc3137-cropped.jpg', 'file_name')
img = Image.open('file_name')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=rang_mirrored,
y=rvel_mirrored,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.7,
symbol='circle-open',line_width=2),name=''))
fig.update_layout(title={'text': name,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (\")",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey',
'range':[-100,100]}, #change range as needed
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey'},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=700,
height=590)
fig.add_layout_image(
dict(
source=img,
x=0.5,
y=0.5))
fig.update_layout_images(dict(
xref="paper",
yref="paper",
sizex=1,
sizey=1,
# sizex=3.6,
# sizey=3.6,
xanchor="center",
yanchor="middle",
opacity=0.8,
layer="below"))
fig.show();
# fig.write_html('./'+name+'rc.html')
# Example 3:
name = 'NGC3274'
rvel = data[data.name==name]['Rotation velocity'].values
rang = data[data.name==name]['Angular Radius'].values
rkpc = data[data.name==name]['Physical radius using adopted distance'].values
rangrev = -rang[::-1]
rang_mirrored = np.empty(2*len(rvel))
rang_mirrored[:len(rvel)] = rangrev
rang_mirrored[len(rvel):] = rang
rvelopp = -rvel[::-1]
rvel_mirrored=np.empty(2*len(rvel))
rvel_mirrored[:len(rvel)] = rvelopp
rvel_mirrored[len(rvel):] = rvel
urllib.request.urlretrieve('http://depts.washington.edu/astroed/GalaxyRotationCurves/ngc3274-cropped.jpg', 'file_name')
img = Image.open('file_name')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=rang_mirrored,
y=rvel_mirrored,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.7,
symbol='circle-open',line_width=2),name=''))
fig.update_layout(title={'text': name,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (\")",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey',
'range':[-100,100]}, #change range as needed
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey'},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=700,
height=590)
fig.add_layout_image(
dict(
source=img,
x=0.5,
y=0.5))
fig.update_layout_images(dict(
xref="paper",
yref="paper",
sizex=1,
sizey=1,
# sizex=3.6,
# sizey=3.6,
xanchor="center",
yanchor="middle",
opacity=0.8,
layer="below"))
fig.show();
# fig.write_html('./'+name+'rc.html')
# Example 4
name = 'UGC1281'
rvel = data[data.name==name]['Rotation velocity'].values
rang = data[data.name==name]['Angular Radius'].values
rkpc = data[data.name==name]['Physical radius using adopted distance'].values
rangrev = -rang[::-1]
rang_mirrored = np.empty(2*len(rvel))
rang_mirrored[:len(rvel)] = rangrev
rang_mirrored[len(rvel):] = rang
rvelopp = -rvel[::-1]
rvel_mirrored=np.empty(2*len(rvel))
rvel_mirrored[:len(rvel)] = rvelopp
rvel_mirrored[len(rvel):] = rvel
fig = go.Figure()
fig.add_trace(go.Scatter(
x=rang_mirrored,
y=rvel_mirrored,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.7,
symbol='circle-open',line_width=2),name=''))
# Layout:
fig.update_layout(title={'text': name,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (\")",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey',
'range':[-205,205]}, #change range as needed
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey'},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=700,
height=590)
urllib.request.urlretrieve('http://depts.washington.edu/astroed/GalaxyRotationCurves/ugc1281-cropped.jpg', 'file_name')
img = Image.open('file_name')
fig.add_layout_image(
dict(
source=img,
x=0.5,
y=0.515))
fig.update_layout_images(dict(
xref="paper",
yref="paper",
# sizex=3.3,
# sizey=3.3,
sizex=1,
sizey=1,
xanchor="center",
yanchor="middle",
opacity=0.8,
layer="below"))
fig.show();
# fig.write_html('./'+name+'rc.html')
# Example 4
name = 'UGC1281'
rvel = data[data.name==name]['Rotation velocity'].values
rang = data[data.name==name]['Angular Radius'].values
rkpc = data[data.name==name]['Physical radius using adopted distance'].values
rangrev = -rang[::-1]
rang_mirrored = np.empty(2*len(rvel))
rang_mirrored[:len(rvel)] = rangrev
rang_mirrored[len(rvel):] = rang
rvelopp = -rvel[::-1]
rvel_mirrored=np.empty(2*len(rvel))
rvel_mirrored[:len(rvel)] = rvelopp
rvel_mirrored[len(rvel):] = rvel
fig = go.Figure()
fig.add_trace(go.Scatter(
x=rang_mirrored,
y=rvel_mirrored,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.7,
symbol='circle-open',line_width=2),name=''))
# Layout:
fig.update_layout(title={'text': name,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (\")",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey',
'range':[-205,205]}, #change range as needed
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False,
'gridcolor':'lightgrey'},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=700,
height=590)
fig.add_layout_image(
dict(
source='../../Work/cropped-imgs/ugc1281-cropped.jpg',
x=0.5,
y=0.5))
fig.update_layout_images(dict(
xref="paper",
yref="paper",
# sizex=3.3,
# sizey=3.3,
sizex=1,
sizey=1,
xanchor="center",
yanchor="middle",
opacity=0.8,
layer="below"))
fig.show();
# fig.write_html('./'+name+'rc.html')
# To print all rcs from entire list:
for galaxy in names:
rvel = data[data.name==galaxy]['Rotation velocity']
rkpc = data[data.name==galaxy]['Physical radius using adopted distance']
fig = go.Figure()
fig.add_trace(go.Scatter(
x=rkpc,
y=rvel,
mode='markers',
marker=dict(
color='black',
size=5,
opacity=0.7,
symbol='circle-open',line_width=2),name=''))
# Layout:
fig.update_layout(title={'text': galaxy,
'y':0.86,
'x':0.5},
xaxis={'title':"Distance from center (kpc)",
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False},
yaxis={'title':'Rotational Velocity (km/s)',
'linecolor': 'rgba(0, 0, 0, 1)',
'mirror': True,
'zeroline':False},
plot_bgcolor = 'rgba(0, 0, 0, 0)',
showlegend=False,
width=600,
height=600)
# fig.write_html('./'+name+'rc.html')
fig.show();