Download obsid browse image


In [1]:
from pyrise import products
from pyrise.products import PRODUCT_ID
from pyrise.downloads import download_browse_product

In [5]:
obsid = 'PSP_003092_0985_RED'

In [8]:
from urllib.request import urlretrieve

In [10]:
"""Download a browse product from HiRISE website.

By default, store it in current path.

Parameters
----------
obsid : str
    HiRISE observation ID
kind : {'RED','COLOR'}, optional
    String indicating the kind of required browse product. Default: 'RED'
annotated : bool, optional
    Switch to control if the annotated version is required. Default: True
saveroot : str, pathlib.Path, optional
    Path in where the browse product is being stored. Default: '.'
overwrite : bool, optional
    Boolean switch to control if an existing path should be overwritten. Default: False
"""
kind='RED'
pid = PRODUCT_ID(f"{obsid}_{kind}")
url = pid.browse_url
print("URL:", url)
savepath = 'test.jpg'
print("Downloading\n", url, '\nto\n', savepath)
try:
    urlretrieve(url, str(savepath))
except HTTPError as e:
    print(e)


Out[10]:
"Download a browse product from HiRISE website.\n\nBy default, store it in current path.\n\nParameters\n----------\nobsid : str\n    HiRISE observation ID\nkind : {'RED','COLOR'}, optional\n    String indicating the kind of required browse product. Default: 'RED'\nannotated : bool, optional\n    Switch to control if the annotated version is required. Default: True\nsaveroot : str, pathlib.Path, optional\n    Path in where the browse product is being stored. Default: '.'\noverwrite : bool, optional\n    Boolean switch to control if an existing path should be overwritten. Default: False\n"
URL: https://hirise-pds.lpl.arizona.edu/PDS/EXTRAS/RDR/PSP/ORB_003000_003099/PSP_003092_0985/PSP_003092_0985_RED.browse.jpg
Downloading
 https://hirise-pds.lpl.arizona.edu/PDS/EXTRAS/RDR/PSP/ORB_003000_003099/PSP_003092_0985/PSP_003092_0985_RED.browse.jpg 
to
 test.jpg
Out[10]:
('test.jpg', <http.client.HTTPMessage at 0x112407940>)

In [11]:
!open test.jpg

In [68]:
download_browse_product(obsid, annotated=False)


Path exists and 'overwrite' switch is False:
Out[68]:
PosixPath('PSP_003092_0985_RED.browse.jpg')

In [70]:
!open {_}

Download list of obsid browse images


In [71]:
def download_browse_list(obsids, **kwargs):
    """Download browse products for a list of obsids.
    
    Parameters
    ----------
    obsids : iterable
        Container with HiRISE observation ID strings
        
    Example
    -------
    download_browse_list(['PSP_003092_0985', 'ESP_020146_0950'])
    """
    for obsid in obsids:
        download_browse_product(obsid, **kwargs)

In [76]:
download_browse_list(['PSP_003092_0985', 'ESP_020146_0950'], kind='COLOR')


Downloading
 https://hirise-pds.lpl.arizona.edu/PDS/EXTRAS/RDR/PSP/ORB_003000_003099/PSP_003092_0985/PSP_003092_0985_COLOR.abrowse.jpg 
to
 PSP_003092_0985_COLOR.abrowse.jpg
Downloading
 https://hirise-pds.lpl.arizona.edu/PDS/EXTRAS/RDR/ESP/ORB_020100_020199/ESP_020146_0950/ESP_020146_0950_COLOR.abrowse.jpg 
to
 ESP_020146_0950_COLOR.abrowse.jpg

Create presentation from browse images


In [169]:
from pptx import Presentation
from scipy.misc import imread

def create_browse_presentation(obsids, **kwargs):
    prs = Presentation()

    pic_left  = int(prs.slide_width * 0.0)
    pic_top   = int(prs.slide_height * 0.0)
    
    blank_slide_layout = prs.slide_layouts[6]

    for obsid in obsids[0:]:
        imgpath = str(download_browse_product(obsid, **kwargs))
        slide = prs.slides.add_slide(blank_slide_layout)
        img = imread(imgpath)
        ratio = img.shape[0] / img.shape[1]
        if ratio < 1:
            pic_width = int(prs.slide_width)
            pic_height = int(pic_width * img.shape[0] / img.shape[1])
        else:
            pic_height = int(prs.slide_height)
            pic_width = int(pic_height / ratio)
        pic = slide.shapes.add_picture(imgpath, pic_left, pic_top, pic_width, pic_height)

    prs.save('obsid_browse_images.pptx')

In [170]:
obsids = ['PSP_003092_0985', 'ESP_020146_0950']

In [171]:
create_browse_presentation(obsids)


Path exists and 'overwrite' switch is False: PSP_003092_0985_RED.abrowse.jpg
Path exists and 'overwrite' switch is False: ESP_020146_0950_RED.abrowse.jpg

In [ ]: