This notebook shows how to connect to a data2dome JSON feed.
In this example we query the ESO images feed and search for recent images in fulldome format. We then construct an html table with thumbnail images so that we can select which ones we want. Finally we import the selected image into DigitalSky and crete a button to load it nd turn it on and off.
Mark SubbaRao, April 25th, 2017
import pandas as pd
from IPython.display import Image, HTML
from datetime import date, timedelta
import requests
from PIL import Image as Im
import os
# D2D Feed
ESOimages = 'http://www.eso.org/public/images/d2d/'
howRecent = 200 # in days
pd.set_option('max_colwidth',5000) # so we will return the full description without truncation
numReturn=20 # maximum number of results to return
desiredResolution = 4096
This code block downloads the pagenated json feed and parses it selecting only the images in fulldome format until numReturn objects are found.
page = ESOimages+'?after='+(date.today()-timedelta(days=howRecent)).strftime('%Y%m%d')+'0000' #the 0000 is the time component of the date
nImg = 0
nPage=0
feedImages=[]
while (page!='' and nImg < numReturn):
print(page)
df=pd.read_json(page)
# The Next parameter may or may not exist
try:
page=df.Next[0]
except:
page=''
nPage=nPage+1
for feedImage in df.Collections:
if (feedImage['Assets'][0]['Resources'][0]['ProjectionType']=='Fulldome'and nImg < numReturn):
feedImages.append(feedImage)
nImg=nImg+1
print(str(nPage) + ' pages parsed ' + str(nImg) + ' fulldome images found')
http://www.eso.org/public/images/d2d/?after=201610100000 1 pages parsed 1 fulldome images found http://www.eso.org/public/images/d2d/?after=201610100000&page=2 2 pages parsed 5 fulldome images found http://www.eso.org/public/images/d2d/?after=201610100000&page=3 3 pages parsed 11 fulldome images found http://www.eso.org/public/images/d2d/?after=201610100000&page=4 4 pages parsed 13 fulldome images found
titleList=[]
descriptionList=[]
thumbnailList=[]
pubdateList=[]
for pic in feedImages:
titleList.append(pic['Title'])
descriptionList.append(pic['Description'].replace("\r\n",''))
pubdateList.append(pic['PublicationDate'])
for resource in pic['Assets'][0]['Resources']:
if (resource['ResourceType']=='Thumbnail'):
thumbnailList.append('<img src="'+resource['URL']+'"/>')
df3 = pd.DataFrame({'title':titleList,'description':descriptionList,'thumbnail':thumbnailList,'pubdate':pubdateList},columns=['title','thumbnail','description','pubdate'])
HTML(df3.to_html(escape=False))
title | thumbnail | description | pubdate | |
---|---|---|---|---|
0 | Fulldome selfie | Beneath the grand arc of the Milky Way, ESO Photo Ambassador Petr Horálek is just a small speck in an enormous Universe. Horálek is standing amongst the antennas of the Atacama Large Millimeter/submillimeter Array (ALMA), which studies some of the coldest objects in the Universe. |
2017-02-24T13:58:20Z | |
1 | Paranal bow — fisheye | The four huge Unit Telescopes (UTs) at ESO's Paranal Observatory in Chile are among the most advanced in the world. The perfect backdrop is provided by a view on the galaxy in which we live — the Milky Way. Links |
2017-01-18T14:10:33Z | |
2 | Milky Way between UTs — fisheye | The Milky Way tucks in nicely between the two Unit Telescope (UT) behemoths that make up part of ESO's Very Large Telescope in Chile. As can be seen from the brilliant Milky Way, the skies here are crystal-clear, a result of the lack of light pollution and high altitude. Links |
2017-01-18T10:50:51Z | |
3 | Dawn at La Silla — fisheye | The rising Sun brings an end to observations at ESO's La Silla Observatory in the Atacama desert of Chile. La Silla was ESO's first observatory in Chile, the telescopes there taking their first light from the Universe in the late 1960s. Links |
2017-01-18T10:45:26Z | |
4 | Razor-sharp Paranal | New webcams installed at ESO's facilities in Chile provide unparalleled levels of detail of the world's most productive astronomical observatories. Here, the Very Large Telescope is imaged in 4K definition, beneath the cloudless Atacama sky. Such images could be used in the ESO Supernova Planetarium & Visitor Centre in Garching, Germany. |
2016-11-30T14:24:39.419215Z | |
5 | That much closer | With light pollution and cloud cover rarely issues at ESO's Paranal Observatory, the Universe can seem closer than ever. Here, one of ESO's Photo Ambassadors, Petr Horálek, gets a better view on the Very Large Telescope, nearer the heavens. Images like this were gathered on the Fulldome Expedition, an endeavour to produce visuals for the ESO Supernova Planetarium & Visitor Centre in Garching, Munich. |
2016-11-28T12:20:48.677643Z | |
6 | ALMA gegenschein — fisheye | On the Chajnantor plateau in Chile, home of the Atacama Large Millimetre/submillimetre Array (ALMA), the sky is so dark that the famous and extremely difficult to observe gegenschein (or "countershine") is sometimes visible. This is a faint brightening of the night sky in the region of the ecliptic directly opposite the Sun, caused by reflection of sunlight by interplanetary dust in the Solar System. Links |
2016-11-24T13:48:26Z | |
7 | Nightfall Residencia — fisheye | An oasis in an otherwise barren desert, the Paranal Residencia provides accommodation for the scientists, engineers and technicians who work at ESO's Very Large Telescope in Chile. It's not everywhere in the world where you can get a view like this from your bedroom window. Links |
2016-11-23T13:22:29.707760Z | |
8 | Four units | The four large Unit Telescopes (UTs) make up the bulk of ESO's Very Large Telescope, located at Paranal Observatory in the Chilean desert. This fisheye photograph shows the UTs in action. Such an image could be shown in planetariums worldwide, such as in the ESO Supernova Planetarium & Visitor Centre in Munich, Germany. |
2016-11-16T14:08:27.352267Z | |
9 | Milky Way slice | The wide arch of the Milky Way cuts through the centre of this fisheye photograph of ESO's Paranal Observatory, which is home to the Very Large Telescope. One of the facility's Auxiliary Telescopes is wide-eyed and taking in light from the Universe's phenomena. Such an image could be shown in planetariums worldwide, such as in the ESO Supernova Planetarium & Visitor Centre in Munich, Germany. |
2016-11-16T14:07:52.641158Z | |
10 | Looking out | Four behemoths make up the Unit Telescopes (UTs) of ESO's Very Large Telescope, located at Paranal Observatory in the Chilean desert. This fisheye photograph shows the UTs open and busy observing. Such an image could be shown in planetariums worldwide, such as in the ESO Supernova Planetarium & Visitor Centre in Munich, Germany. |
2016-11-16T13:49:43.292116Z | |
11 | La Silla under the arch | This fisheye projection shows the ESO 3.6-metre telescope at La Silla Observatory in Chile, beneath the glowing arch of the Milky Way. Links |
2016-10-21T11:53:55Z | |
12 | Antennas towards the Milky Way | A mind-boggling fisheye projection of some of the 66 antennas which make up ESO's Atacama Large Millimetre Array (ALMA) in Chile. Each individual telescope can be moved to very precise locations in order to observe the Universe in the best possible clarity. |
2016-10-11T09:53:23.318994Z |
The next code block contains a function to acquire the desired image and create a DigitalSky button. Given a name and the number of the image, it will:
DSShowsPath = r'C:\DigitalSky\Shows'
DSImageDirectory = 'D2Dcontent'
DSButtonDirectory = r'C:\DigitalSky\Buttons\D2D'
def addImageDS(imageNum,buttonNum,imageName):
imURL=''
imSize=0
imDict = feedImages[imageNum]
imDir = os.path.join(DSShowsPath,DSImageDirectory)
# Select image asset, download image, resize if necessary, and save in SHOWS directory
for resource in imDict['Assets'][0]['Resources']:
if ((resource['Dimensions'][0]>=imSize and imSize < desiredResolution) or (resource['Dimensions'][0]<=imSize and imSize > desiredResolution and resource['Dimensions'][0] > desiredResolution)):
imSize = resource['Dimensions'][0]
imURL = resource['URL']
print('downloading '+imURL)
im = Im.open(requests.get(imURL, stream=True).raw)
if (imSize > desiredResolution):
im = im.resize((desiredResolution,desiredResolution))
print('resizing image from '+str(imSize)+' to '+str(desiredResolution))
imSize=desiredResolution
imageNameExt=imageName+'.jpg'
im.save(os.path.join(imDir,imageNameExt))
# Create a Button for this image
scriptText=''';----------------------------------------------------------------------
; Script number = F'''+str(buttonNum)+'''
; Title = "'''+imageName+'''"
; Color = "255,255,0"
; Created on : '''+date.today().strftime('%Y-%m-%d')+'''
; Modified : '''+date.today().strftime('%Y-%m-%d')+'''
; Version : 2.3
; Created by : '''+imDict["Credit"]+'''
; Keywords :
; Description : '''+imDict["Title"]+'''
;----------------------------------------------------------------------
;
+0.1 Text Add "'''+imageName+'''" "Showpath\\'''+os.path.join(DSImageDirectory,imageNameExt)+'''" '''+str(imSize)+''' '''+str(imSize)+''' 0 90 0 0 1 0
+2 Text Locate "'''+imageName+'''" 0 0 90 0 180 180
Text View "'''+imageName+'''" 3 100 100 100 100
ButtonText "Remove '''+imageName+'''"
STOP
Text View "'''+imageName+'''" 2 0 0 0 0
+2 Text "Remove '''+imageName+'''"'''
print('writing button file')
buttonFileName='F'+str(buttonNum)+'.sct'
writeFile = open(os.path.join(DSButtonDirectory,buttonFileName),'w')
writeFile.write(scriptText)
writeFile.close()
print('Done :)')
Here is an example of how to call the addImageDS function
addImageDS(3,19,'VLT') #Pass image number, button number, object nam3
downloading https://cdn.eso.org/images/large/2016-04-13-la-silla-mw-dawn-eq-fd-cc.jpg resizing image from 17494 to 4096 writing button file Done :)
C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (306040036 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning)
Here is an example of how to create a buttonset with all of the images from the query
for i in range(len(feedImages)):
ni=i+1 # convert from 0 to 1 index
addImageDS(i,ni,'VLT'+str(ni))
downloading https://cdn.eso.org/images/large/2016-04-09-alma-fd-selfie-horalek-fd-cc.jpg resizing image from 16083 to 4096 writing button file
C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (258646806 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning) C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (325062870 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning)
Done :) downloading https://cdn.eso.org/images/large/2016-04-06-fd-paranal-among-vlts1-fd-cc.jpg resizing image from 18030 to 4096 writing button file Done :) downloading https://cdn.eso.org/images/large/2016-04-06-mw-among-vlts-fulldome-fd-cc.jpg resizing image from 16410 to 4096 writing button file
C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (269288100 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning) C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (306040036 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning)
Done :) downloading https://cdn.eso.org/images/large/2016-04-13-la-silla-mw-dawn-eq-fd-cc.jpg resizing image from 17494 to 4096 writing button file Done :) downloading https://cdn.eso.org/images/large/preset-99.jpg resizing image from 4373 to 4096 writing button file Done :) downloading https://cdn.eso.org/images/large/beletsky-paranal-30-cc.jpg writing button file Done :) downloading https://cdn.eso.org/images/large/2016-04-08-alma-gegenshein-fd-cc.jpg resizing image from 20368 to 4096 writing button file
C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (414875792 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning) C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (277722225 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning)
Done :) downloading https://cdn.eso.org/images/large/2016-04-06-night-residencia-outside-fd-cc.jpg resizing image from 16665 to 4096 writing button file Done :) downloading https://cdn.eso.org/images/large/beletsky-paranal-28-cc.jpg writing button file Done :) downloading https://cdn.eso.org/images/large/beletsky-paranal-25-cc.jpg writing button file Done :) downloading https://cdn.eso.org/images/large/beletsky-paranal-27-cc.jpg writing button file Done :) downloading https://cdn.eso.org/images/large/nik9850p2-cc.jpg resizing image from 11923 to 4096 writing button file
C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (142157929 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning) C:\Anaconda3\lib\site-packages\PIL\Image.py:2224: DecompressionBombWarning: Image size (335146249 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. DecompressionBombWarning)
Done :) downloading https://cdn.eso.org/images/large/2016-04-10-alma-fd-mw-center-cc.jpg resizing image from 18307 to 4096 writing button file Done :)