AAS231 WWT Workshop Notebook (January 2018; Washington, DC)

Please note: these notebooks are preserved for posterity but not kept up-to-date, so you might run into issues with older notebooks.

In [ ]:
from pywwt.jupyter import WWTJupyterWidget
from astropy.coordinates import SkyCoord, concatenate        
from astropy import units as u        
from astropy.table import Table, Column        
import re
wwt = WWTJupyterWidget()
In [ ]:
wwt
In [ ]:
print(type(sorted(wwt._available_layers)))
In [ ]:
# init
layers = {}
spectrum = ['gamma', 'x', 'uv', 'visible', 'ir', 'micro', 'radio', 'other']

# init
for band in spectrum:
    layers[band] = {}

# method
def shorten(string):
    first = string[:re.search(r'[\W]', string).start()].lower()
    
    # just for 2MASS; use num2words to standardize process?
    check = re.search(r'2', first)
    if(check != None):
        first = first[:check.start()] + 'two' + first[check.start()+1:]
        
    return first

# method
def add2dict(diction, full_layer, ind):
    abbr = shorten(full_layer)
    
    # check if abbr exists
    j = 2
    while(abbr in diction[spectrum[ind]]):
        if(str(j-1) in abbr):
            abbr = abbr[:-1]
            
        abbr += str(j)
        j += 1
    
    diction[spectrum[ind]][abbr] = {}
    diction[spectrum[ind]][abbr]['full_name'] = full_layer
    diction[spectrum[ind]][abbr]['thumbnail'] = None
    
# init
for layer in wwt.available_layers:
    ind = 0
    
    if(re.search(r'(?i)gamma',layer) != None):
        add2dict(layers, layer, ind)
        continue #automatically advance to next iteration
    
    ind += 1
    if(re.search(r'(?i)x(-|\s)?ray',layer) != None):
        add2dict(layers, layer, ind)
        continue
        
    ind += 1
    if(re.search(r'(?i)ultra(-|\s)?violet',layer) != None or 
         re.search(r'(?i)[^\d\w]+uv|uv[^\d\w]+',layer) != None):
        add2dict(layers, layer, ind)
        continue
        
    ind += 1
    if(re.search(r'(?i)optical',layer) != None or 
         re.search(r'(?i)visible',layer) != None):
        add2dict(layers, layer, ind)
        continue
    
    ind += 1    
    if(re.search(r'(?i)infrared',layer) != None or 
         re.search(r'(?i)[^\d\w]+ir|ir[^\d\w]+',layer) != None):
        add2dict(layers, layer, ind)
        continue
        
    ind += 1
    if(re.search(r'(?i)microwave',layer) != None or 
         re.search(r'(?i)[^\d\w]+cmb|cmb[^\d\w]+',layer) != None):
        add2dict(layers, layer, ind)
        continue

    ind += 1
    if(re.search(r'(?i)radio',layer) != None):
        add2dict(layers, layer, ind)
        continue

    ind += 1
    add2dict(layers, layer, ind)

layers
In [ ]:
#available_layers = {}
available_layers['visible'] = {'twomass': {'full_name': '2mass survey', 'thumbnail': None},'iras': {'full_name': 'iras', 'thumbnail': None}}
    
class ImageryLayers:
   def __init__(self, layers_dict):
       self._layers = layers_dict

   def __dir__(self):
       return sorted(self._layers.keys())

   def __getattr__(self, name):
       return Bandpass(self._layers[name])

class Bandpass:
   def __init__(self, layers):
       self._layers = layers

   def __dir__(self):
       return sorted(self._layers.keys())

   def __getattr__(self, name):
       return self._layers[name]['full_name']

imagery = ImageryLayers(available_layers)
print(imagery.visible.twomass)
In [ ]:
dice = {}
dice['raw'] = 'cool'
dice['2time'] = 'amen'
dice['lie'] = []
k = 'lie'
dice[k].append('kant')
dice['mine'] = {'from':'Texas', 'to': 'Forever'}
dice['mine'].update({'first':'Biff', 'last': 'Anthony'})
dice['what'] = ['do']#['you'] = 'want'
print(dice)
type(wwt.available_layers)
In [ ]:
print(re.search(r'.*ious\b','laborious'), re.match(r'.*ious\b','laborious'), sep='\n')
print(re.search(r'(?i)optical',wwt.background) != None)
print(re.search(r'(?i)[^\d\w]+uv|uv[^\d\w]+',wwt.background) != None)
fly = '__536_'
print(re.search(r'\d',fly).group(0))
In [ ]:
integers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
string = ' __ !*22more wins'

cut_left = re.search(r'^[_\W]+', string)
if cut_left is not None:
    string = string[cut_left.end():]

cut_right = re.search(r'\W', string)
if cut_right is not None:
    string = string[:cut_right.start()].lower()

digit = re.search(r'^\d', string)
if digit is not None:
    for i, num in enumerate(integers, 0):
        if str(i) == digit.group(0):
            string = string[:digit.start()] + num + string[digit.end():]
            break
        else:
            continue
            
print(string)
In [ ]:
#wwt.add_circle(radius=10*u.arcsec,line_width=3*u.pix,line_color='#008ca8',label='heathen',hover_label=True)
wwt.clear_annotations()
In [ ]:
wwt.center_on_coordinates(SkyCoord.from_name('Megrez'))
In [ ]:
wwt.crosshairs = False
wwt.layer_controls
In [ ]:
'''
# open widget, render at end of each section
wwt = WWTQtWidget(size=(600,400))
'''
# big_dipper.png
bd = concatenate((SkyCoord.from_name('Alkaid'), SkyCoord.from_name('Mizar'),
                  SkyCoord.from_name('Alioth'), SkyCoord.from_name('Megrez'),
                  SkyCoord.from_name('Phecda'), SkyCoord.from_name('Merak'),
                  SkyCoord.from_name('Dubhe')))
wwt.center_on_coordinates(SkyCoord.from_name('Megrez'))
       
line = wwt.add_line(bd, width=3 * u.pixel, tag='whoa now', hover_label=True)
#wwt.render('big_dipper.png')
In [ ]:
# big_dipper2.png
line.add_point(SkyCoord.from_name('Megrez'))
line.color = 'salmon'; line.opacity=.3
#wwt.render('big_dipper2.png')
In [ ]:
# polygon.png (1)
wwt.center_on_coordinates(SkyCoord.from_name('eta orion'))

body = concatenate((SkyCoord.from_name('zeta orion'),
                    SkyCoord.from_name('betelgeuse'),
                    SkyCoord.from_name('bellatrix'),
                    SkyCoord.from_name('delta orion')))
club = concatenate((SkyCoord.from_name('xi orionis'),
                    SkyCoord.from_name('chi2 orionis'),
                    SkyCoord.from_name('chi1 orionis'),
                    SkyCoord.from_name('67 orionis')))
head = concatenate((SkyCoord.from_name('betelgeuse'),
                    SkyCoord.from_name('lambda orion'),
                    SkyCoord.from_name('bellatrix')))
bow = concatenate((SkyCoord.from_name('omicron2 orionis'),
                   SkyCoord.from_name('pi2 orionis'),
                   SkyCoord.from_name('pi3 orionis'),
                   SkyCoord.from_name('pi4 orionis'),
                   SkyCoord.from_name('pi5 orionis')))
In [ ]:
# polygon.png (2)
a1 = concatenate((SkyCoord.from_name('betelgeuse'),
                  SkyCoord.from_name('xi orionis')))
a2 = concatenate((SkyCoord.from_name('bellatrix'),
                  SkyCoord.from_name('pi3 orionis')))
l1 = concatenate((SkyCoord.from_name('zeta orionis'),
                  SkyCoord.from_name('kappa orionis')))
l2 = concatenate((SkyCoord.from_name('delta orionis'),
                  SkyCoord.from_name('eta orionis'),
                  SkyCoord.from_name('rigel')))
blt = concatenate((SkyCoord.from_name('zeta orionis'),
                    SkyCoord.from_name('delta orionis')))
string = concatenate((SkyCoord.from_name('omicron2 orionis'),
                      SkyCoord.from_name('pi5 orionis')))
In [ ]:
# polygon.png (3)
orb = wwt.add_polygon(body, fill=True, fill_color='lightslategray', opacity=.4,
                      line_color='lightslategray', line_width=3*u.pixel)
orc = wwt.add_polygon(club, fill=True, fill_color='saddlebrown', opacity=.4,
                      line_color ='saddlebrown', line_width=3 * u.pixel)
orh = wwt.add_polygon(head, fill=True, fill_color='rosybrown', opacity=.4,
                      line_color='lightslategray', line_width=2*u.pixel)
orw = wwt.add_polygon(bow, opacity=.4, 
                      line_width=2*u.pixel, line_color='saddlebrown')

ora1 = wwt.add_line(a1, color='lightslategray')
ora2 = wwt.add_line(a2, color='lightslategray')
orl1 = wwt.add_line(l1, color='lightslategray', width=2*u.pixel)
orl2 = wwt.add_line(l2, color='lightslategray', width=2*u.pixel)
orblt = wwt.add_line(blt, color='azure', width=8*u.pixel)
orstr = wwt.add_line(string, color='azure')

#wwt.render('polygon.png')
In [ ]:
# circles.png
wwt.center_on_coordinates(SkyCoord(190, -55, unit=u.deg))
crc1 = wwt.add_circle(SkyCoord(188, -57, unit=u.deg), radius=10 * u.degree,
                      fill=True, fill_color='#008CA8')
crc2 = wwt.add_circle(radius=10 * u.pixel, opacity=.4,
                      fill=True, fill_color='#C4D600')
#wwt.render('circles.png')
In [ ]:
# stgo_view.png
wwt.constellation_boundaries = True
wwt.constellation_figures = True
wwt.constellation_boundary_color = 'azure'
wwt.constellation_figure_color = '#D3BC8D'
wwt.constellation_selection_color = (1, 0, 1)
wwt.local_horizon_mode = True
wwt.location_latitude = -33.4172 * u.deg
wwt.location_longitude = -70.604 * u.deg
wwt.location_altitude = 300 * u.meter
#wwt.render('stgo_view.png')
In [ ]:
# dust_on_gamma.png
wwt.clear_annotations()
wwt.constellation_boundaries = False
wwt.constellation_figures = False
wwt.local_horizon_mode = False
wwt.crosshairs = False

wwt.center_on_coordinates(SkyCoord(144.545, -68.5, unit=u.deg))
wwt.background = 'Fermi LAT 8-year (gamma)'
wwt.foreground = 'Planck Dust & Gas'
wwt.foreground_opacity = .75
#wwt.render('dust_on_gamma.png')
In [ ]:
#wwt.center_on_coordinates(SkyCoord.from_name('megrez'), fov = 10*u.deg)
wwt.center_on_coordinates(SkyCoord.from_name('eta orion'), fov = 30*u.deg)
In [ ]:
wwt.clear_annotations()
#wwt.crosshairs = False

Credits

This notebook was prepared by O. Justin Otor.