Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • astron-sdc/escape-wp5/workflows/apertif-vis-example
1 result
Show changes
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<h1>Workflow for plotting and visualizing data from the ESAP shopping basket (WSRT-Apertif)</h1> <h1>Workflow for plotting and visualizing data from the ESAP shopping basket (WSRT-Apertif)</h1>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from astropy.coordinates import SkyCoord from astropy.coordinates import SkyCoord
from hips import WCSGeometry, make_sky_image from hips import WCSGeometry, make_sky_image
from hips import HipsSurveyProperties from hips import HipsSurveyProperties
from ipywidgets import Layout, Box, widgets from ipywidgets import Layout, Box, widgets
from shopping_client import shopping_client from esap_client import ShoppingClient as shopping_client
import pyvo import pyvo
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import astroquery import astroquery
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<h2>Fetching data from the ESAP Shopping basket</h2> <h2>Fetching data from the ESAP Shopping basket</h2>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<hr> <hr>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Instantiate alta connector # Instantiate alta connector
from alta import alta_connector from esap_client.connectors import Alta as alta_connector
#from alta import alta_connector
ac = alta_connector() ac = alta_connector()
# Instantiate ESAP User Profile shopping client, passing alta connector # Instantiate ESAP User Profile shopping client, passing alta connector
shoppingClient = shopping_client(host="https://sdc-dev.astron.nl:443/", connectors=[ac]) shoppingClient = shopping_client(host="https://sdc-dev.astron.nl:443/", connectors=[ac])
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Get data from the shopping basket as a Pandas Dataframe # Get data from the shopping basket as a Pandas Dataframe
basket = shoppingClient.get_basket(convert_to_pandas=True) basket = shoppingClient.get_basket(convert_to_pandas=True)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Store data as a single Pandas Dataframe # Store data as a single Pandas Dataframe
alta_records = list(basket["alta"]["record"]) alta_records = list(basket["alta"]["record"])
df = pd.DataFrame(alta_records) df = pd.DataFrame(alta_records)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Show dataframe # Show dataframe
df df
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Store data as an astropy table # Store data as an astropy table
from astropy.table import Table from astropy.table import Table
astropy_table = Table.from_pandas(df) astropy_table = Table.from_pandas(df)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<hr> <hr>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Visualization (Plotting) # Visualization (Plotting)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Scatter Plot using Matplotlib ## Scatter Plot using Matplotlib
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%matplotlib notebook %matplotlib notebook
from ipywidgets import * from ipywidgets import *
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
x = astropy_table["RA"] x = astropy_table["RA"]
y = astropy_table["dec"] y = astropy_table["dec"]
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(1, 1, 1) ax = fig.add_subplot(1, 1, 1)
line = ax.scatter(x, y) line = ax.scatter(x, y)
plt.xlabel("$ra$", fontsize=20) plt.xlabel("$ra$", fontsize=20)
plt.ylabel("$decl$", fontsize=20) plt.ylabel("$decl$", fontsize=20)
def update(w = 1.0): def update(w = 1.0):
fig.canvas.draw() fig.canvas.draw()
interact(update); interact(update);
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from plotly import __version__ from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from plotly.graph_objs import * from plotly.graph_objs import *
import plotly.graph_objs as go import plotly.graph_objs as go
import numpy as np import numpy as np
init_notebook_mode() # Important init_notebook_mode() # Important
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
## Scatter Plot using Plotly ## Scatter Plot using Plotly
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
N = 100000 N = 100000
trace = go.Scattergl( trace = go.Scattergl(
x = astropy_table["RA"], x = astropy_table["RA"],
y = astropy_table["dec"], y = astropy_table["dec"],
mode = 'markers', mode = 'markers',
marker = dict( marker = dict(
color = '#FFBAD2', color = '#FFBAD2',
line = dict(width = 1) line = dict(width = 1)
) )
) )
data = [trace] data = [trace]
iplot(data, filename='compare_webgl') iplot(data, filename='compare_webgl')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## 3d Plot using Plotly ## 3d Plot using Plotly
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose() x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
trace1 = go.Scatter3d( trace1 = go.Scatter3d(
x=astropy_table["RA"], x=astropy_table["RA"],
y=astropy_table["dec"], y=astropy_table["dec"],
z=astropy_table["fov"], z=astropy_table["fov"],
mode='markers', mode='markers',
marker=dict( marker=dict(
size=12, size=12,
line=dict( line=dict(
color='rgba(217, 217, 217, 0.14)', color='rgba(217, 217, 217, 0.14)',
width=0.5 width=0.5
), ),
opacity=0.8 opacity=0.8
) )
) )
data = [trace1] data = [trace1]
layout = go.Layout( layout = go.Layout(
margin=dict( margin=dict(
l=0, l=0,
r=0, r=0,
b=0, b=0,
t=0 t=0
) )
) )
fig = go.Figure(data=data, layout=layout) fig = go.Figure(data=data, layout=layout)
iplot(fig, filename='simple-3d-scatter') iplot(fig, filename='simple-3d-scatter')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<hr> <hr>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Visualization with Aladin Lite # Visualization with Aladin Lite
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Visualize points in the sky ## Visualize points in the sky
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import ipyaladin as ipyal import ipyaladin as ipyal
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
aladin=ipyal.Aladin(target='14 49 4.874 +52 02 9.05', fov=180) aladin=ipyal.Aladin(target='14 49 4.874 +52 02 9.05', fov=180)
aladin aladin
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
aladin.add_table(astropy_table) aladin.add_table(astropy_table)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Linked Aladin Lite Views ## Linked Aladin Lite Views
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# In the following cells, we create 3 linked views of the sky from different surveys & we plot the data points on each one # In the following cells, we create 3 linked views of the sky from different surveys & we plot the data points on each one
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from ipywidgets import Layout, Box, widgets from ipywidgets import Layout, Box, widgets
a = ipyal.Aladin(layout=Layout(width='33.33%'), target='14 49 4.874 +52 02 9.05', fov=180) a = ipyal.Aladin(layout=Layout(width='33.33%'), target='14 49 4.874 +52 02 9.05', fov=180)
b = ipyal.Aladin(layout=Layout(width='33.33%'), survey='P/DSS2/red') b = ipyal.Aladin(layout=Layout(width='33.33%'), survey='P/DSS2/red')
c = ipyal.Aladin(layout=Layout(width='33.33%'), survey='P/2MASS/color') c = ipyal.Aladin(layout=Layout(width='33.33%'), survey='P/2MASS/color')
# synchronize target between 3 widgets # synchronize target between 3 widgets
widgets.jslink((a, 'target'), (b, 'target')) widgets.jslink((a, 'target'), (b, 'target'))
widgets.jslink((b, 'target'), (c, 'target')) widgets.jslink((b, 'target'), (c, 'target'))
# synchronize FoV (zoom level) between 3 widgets # synchronize FoV (zoom level) between 3 widgets
widgets.jslink((a, 'fov'), (b, 'fov')) widgets.jslink((a, 'fov'), (b, 'fov'))
widgets.jslink((b, 'fov'), (c, 'fov')) widgets.jslink((b, 'fov'), (c, 'fov'))
items = [a, b, c] items = [a, b, c]
box_layout = Layout(display='flex', box_layout = Layout(display='flex',
flex_flow='row', flex_flow='row',
align_items='stretch', align_items='stretch',
border='solid', border='solid',
width='100%') width='100%')
box = Box(children=items, layout=box_layout) box = Box(children=items, layout=box_layout)
box box
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# Add the table to the views # Add the table to the views
a.add_table(astropy_table) a.add_table(astropy_table)
b.add_table(astropy_table) b.add_table(astropy_table)
c.add_table(astropy_table) c.add_table(astropy_table)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Using Aladin Lite to get light curves of objects (using CDS & TAP) ## Using Aladin Lite to get light curves of objects (using CDS & TAP)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
aladin = ipyal.Aladin(layout=Layout(width='70%'), target='M 36', fov=0.3) aladin = ipyal.Aladin(layout=Layout(width='70%'), target='M 36', fov=0.3)
info = widgets.HTML() info = widgets.HTML()
box_layout = Layout(display='flex', box_layout = Layout(display='flex',
flex_flow='row', flex_flow='row',
align_items='stretch', align_items='stretch',
width='100%') width='100%')
box = Box(children=[aladin, info], layout=box_layout) box = Box(children=[aladin, info], layout=box_layout)
box box
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
aladin.add_table(astropy_table) aladin.add_table(astropy_table)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
def process_result(data): def process_result(data):
info.value = '' info.value = ''
ra = data['ra'] ra = data['ra']
dec = data['dec'] dec = data['dec']
radius = min(aladin.fov / 10, 5) radius = min(aladin.fov / 10, 5)
query = """SELECT TOP 1 main_id, ra, dec, DISTANCE(POINT('ICRS', %f, %f), POINT('ICRS', ra, dec)) as d FROM basic query = """SELECT TOP 1 main_id, ra, dec, DISTANCE(POINT('ICRS', %f, %f), POINT('ICRS', ra, dec)) as d FROM basic
WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', %f, %f, %f))=1 WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', %f, %f, %f))=1
ORDER BY d ASC""" % (ra, dec, ra, dec, aladin.fov / 10) ORDER BY d ASC""" % (ra, dec, ra, dec, aladin.fov / 10)
r = requests.get('http://simbad.u-strasbg.fr/simbad/sim-tap/sync', params={'query': query, 'request': 'doQuery', 'lang': 'adql', 'format': 'json', 'phase': 'run'}) r = requests.get('http://simbad.u-strasbg.fr/simbad/sim-tap/sync', params={'query': query, 'request': 'doQuery', 'lang': 'adql', 'format': 'json', 'phase': 'run'})
obj_name = '' obj_name = ''
obj_coo = None obj_coo = None
obj_data = r.json()['data'] obj_data = r.json()['data']
if len(obj_data)==0: if len(obj_data)==0:
return return
obj_name = obj_data[0][0] obj_name = obj_data[0][0]
obj_coo = [obj_data[0][1], obj_data[0][2]] obj_coo = [obj_data[0][1], obj_data[0][2]]
sed_img = '<img src="http://cdsportal.u-strasbg.fr/cgi-bin/PhotVizPreview/plot?ra=%f&dec=%f&radius_arcsec=5&w=200&h=150&point_size=4">' % (obj_coo[0], obj_coo[1]) sed_img = '<img src="http://cdsportal.u-strasbg.fr/cgi-bin/PhotVizPreview/plot?ra=%f&dec=%f&radius_arcsec=5&w=200&h=150&point_size=4">' % (obj_coo[0], obj_coo[1])
info.value = '<h2>%s</h2><br><br>%s' % (obj_name, sed_img) info.value = '<h2>%s</h2><br><br>%s' % (obj_name, sed_img)
aladin.add_listener('click', process_result) aladin.add_listener('click', process_result)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Using Aladin Lite to get metadata on objects (Single object or Selection) ## Using Aladin Lite to get metadata on objects (Single object or Selection)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from ipyaladin import Aladin from ipyaladin import Aladin
from ipywidgets import Layout, Box, widgets from ipywidgets import Layout, Box, widgets
aladin = Aladin(layout=Layout(width='50%'), target='14 44 11.932 +46 15 32.69', fov=180,survey='http://surveys.roe.ac.uk/hips71/LAS/LAS_Y_OUT//properties') aladin = Aladin(layout=Layout(width='50%'), target='14 44 11.932 +46 15 32.69', fov=180,survey='http://surveys.roe.ac.uk/hips71/LAS/LAS_Y_OUT//properties')
button = widgets.Button(description="Select") button = widgets.Button(description="Select")
def on_button_clicked(b): def on_button_clicked(b):
aladin.rectangular_selection() aladin.rectangular_selection()
button.on_click(on_button_clicked) button.on_click(on_button_clicked)
table_info = widgets.HTML(layout=Layout(height='auto', overflow='auto')) table_info = widgets.HTML(layout=Layout(height='auto', overflow='auto'))
box_layout = Layout(display='flex', box_layout = Layout(display='flex',
flex_flow='row', flex_flow='row',
align_items='stretch', align_items='stretch',
width='100%', width='100%',
position='relative', position='relative',
overflow='hidden', overflow='hidden',
height='100vh', height='100vh',
margin='-100px 0 0 0', margin='-100px 0 0 0',
padding='100px 0 0 0 ' padding='100px 0 0 0 '
) )
box = Box(children=[aladin, button, table_info], layout=box_layout) box = Box(children=[aladin, button, table_info], layout=box_layout)
box box
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from astroquery.simbad import Simbad from astroquery.simbad import Simbad
import astropy.units as u import astropy.units as u
aladin.add_table(astropy_table) aladin.add_table(astropy_table)
def process_result(sources): def process_result(sources):
s = '<table border="1">' s = '<table border="1">'
s += '<tr><th>RA</th><th>DEC</th></tr>' s += '<tr><th>RA</th><th>DEC</th></tr>'
for source in sources: for source in sources:
s += '<tr><td>%s</td><td>%s</td></tr>' % ( source['data']['RA'], source['data']['dec']) s += '<tr><td>%s</td><td>%s</td></tr>' % ( source['data']['RA'], source['data']['dec'])
s += '</table>' s += '</table>'
table_info.value = s table_info.value = s
aladin.add_listener('select', process_result) aladin.add_listener('select', process_result)
``` ```
......
...@@ -22,5 +22,5 @@ dependencies: ...@@ -22,5 +22,5 @@ dependencies:
- astroquery - astroquery
- pip: - pip:
- "git+https://git.astron.nl/astron-sdc/esap-userprofile-python-client" - "git+https://git.astron.nl/astron-sdc/esap-userprofile-python-client@8e2e4701ef779cd4a6795e526c86305f8ac98f80"