In [1]:

    scwid ="066500110010.001" # http://odahub.io/ontology/integral#ScWID
    emin=10.
    emax=900.
    nbins=100

In [2]:

    # Parameters
    scwid = "166500220010.001"

In [3]:

    if emin<0:
        raise Exception("emin can not be <0! got: %lg"%emin)

In [4]:

    from ftplib import FTP
    import astropy.io.fits as fits
    from io import StringIO
    import os
    from nb2workflow.workflows import WorkflowException

    WARNING:root:unable to setup logstash FileNotFoundError(2, 'No such file or directory')

In [5]:

    if len(scwid) != 16:
        raise WorkflowException("bad scwid: "+scwid)

In [6]:

    fn="events.fits"
    os.system("wget ftp://isdcarc.unige.ch/arc/rev_3/scw/"+scwid[:4]+"/"+scwid+"/isgri_events.fits.gz -O "+fn)

    os.system("ls -ltor")

    events=fits.open(fn)[3].data

In [7]:

    fn="spec.png"

    import matplotlib.pyplot as plt
    import numpy as np
    plt.figure()
    h=plt.hist(events['ISGRI_ENERGY'],np.logspace(np.log10(emin),np.log10(emax),nbins),log=True)
    plt.semilogx()
    plt.savefig(fn)

    #Image(fn)

In [8]:

    total_events=len(events['ISGRI_ENERGY'])
    total_events

Out[8]:

    1348841

In [9]:

    #import papermill as pm
    #import base64

    #pm.record("spectrum",dict(filename=fn,content=base64.b64encode(open(fn).read())))

In [ ]:

In [10]:

    spectrum_png = fn # http://odahub.io/ontology/preview/png
    spectrum = h[0].tolist() # http://odahub.io/ontology/preview/png
    total_events

Out[10]:

    1348841

In [11]:

    import papermill as pm
    import scrapbook as sb
    import base64
    import json
    import os

    from nb2workflow.nbadapter import denumpyfy

    try:
        sb.glue("spectrum_png",denumpyfy(spectrum_png))
    except Exception as e:
        print("failed to glue spectrum_png", spectrum_png)
        print("will glue jsonified")
        sb.glue("spectrum_png",json.dumps(denumpyfy(spectrum_png)))

    isinstance(spectrum_png,str) and os.path.exists(spectrum_png) and sb.glue("spectrum_png_content",base64.b64encode(open(spectrum_png,'rb').read()).decode())

    try:
        sb.glue("spectrum",denumpyfy(spectrum))
    except Exception as e:
        print("failed to glue spectrum", spectrum)
        print("will glue jsonified")
        sb.glue("spectrum",json.dumps(denumpyfy(spectrum)))

    isinstance(spectrum,str) and os.path.exists(spectrum) and sb.glue("spectrum_content",base64.b64encode(open(spectrum,'rb').read()).decode())

    try:
        sb.glue("total_events",denumpyfy(total_events))
    except Exception as e:
        print("failed to glue total_events", total_events)
        print("will glue jsonified")
        sb.glue("total_events",json.dumps(denumpyfy(total_events)))

    isinstance(total_events,str) and os.path.exists(total_events) and sb.glue("total_events_content",base64.b64encode(open(total_events,'rb').read()).decode())

Out[11]:

    False