In [1]:
%matplotlib inline

In [2]:
%load_ext autoreload
%autoreload 2

In [3]:
from iuvs import io, plotting
fname = io.l1b_filenames("cruisecal2-mode080-muv", stage=False)
l1b = io.L1BReader(fname[0])
imgop = plotting.L1BImageOperator(l1b)

In [4]:
import plotly.plotly as py

In [168]:
plotly.graph_objs.Histogram?

In [194]:
import plotly.plotly as py

objs = []
images = ['rawfirst', 'rawlast', 'dark1', 'dark2', 
          'rawfirst-dark1','rawfirst-dark2','rawlast-dark1','rawlast-dark2']
for title, img in zip(images, imgop.get_images_from_statements(images)):
    zmin = None
    zmax = None
    if '-' in title:
        zmin = 200
        zmax = 800
    figtitle = "{} | INT_TIME={}".format(title, l1b.img_header['INT_TIME'])
    fig = plotting.make_plotly_multiplot(img, title=figtitle, zmin=zmin, zmax=zmax)
    py.image.save_as(fig, title+'.png', width=1280, height=1024)
    objs.append(py.iplot(fig,
                         width=900,
                         height=700,
                         filename=figtitle,
                         fileopt='overwrite',
                         auto_open=False)
                )

In [195]:
from IPython.display import display

for i,obj in enumerate(objs):
    display(obj)


Now forcing corners to 0

Upper left

Subtracting just mean of upper lift of raws


In [196]:
from iuvs import scaling

In [197]:
import numpy as np

In [198]:
funcs = [scaling.get_ul, scaling.get_ll, scaling.get_ur, scaling.get_lr]
fixed = []
for func in funcs:
    fixed.append(imgop.rawfirst - np.median(func(imgop.rawfirst)))

In [192]:
objs = []
titles = ['UL','LL','UR','LR']
for title, img in zip(titles, fixed):
    figtitle = 
    fig = plotting.make_plotly_multiplot(img, title=title, zmin=200, zmax=800)
    py.image.save_as(fig, title+'.png', width=1280, height=1024)
    objs.append(py.iplot(fig,
                         width=900,
                         height=700,
                         filename=title,
                         fileopt='overwrite',
                         auto_open=False)
                )

In [193]:
for obj in objs:
    display(obj)



In [10]:
raw0 = l1b.detector_raw[0]
dark1 = l1b.detector_dark[1]

def corner_fitting(Scaler):
    corner_light = raw0[:, :50]
    corner_dark = dark1[:, :50]
    scaler = Scaler(corner_dark, corner_light)
    scaler.do_fit()
    return scaler.apply_fit(dark1)

In [11]:
scalers = [scaling.AddScaler, scaling.MultScaler, scaling.PolyScaler]
scaled = []
for scaler in scalers:
    scaled.append(raw0 - corner_fitting(scaler))

In [12]:
objs = []
for title, img in zip(['raw0', 'AddScaler','MultiScaler','PolyScaler'],
                      [raw0]+scaled):
    fig = plotting.make_plotly_multiplot(img, title=title, zmin=200, zmax=800)
    py.image.save_as(fig, title+'.png', width=1280, height=1024)
    objs.append(py.iplot(fig,
                         width=900,
                         height=700,
                         filename=title,
                         fileopt='overwrite',
                         auto_open=False)
                )


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    352             try:  # Python 2.7+, use buffering of HTTP responses
--> 353                 httplib_response = conn.getresponse(buffering=True)
    354             except TypeError:  # Python 2.6 and older

TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-12-e14bc0408b1e> in <module>()
      3                       [raw0]+scaled):
      4     fig = plotting.make_plotly_multiplot(img, title=title, zmin=200, zmax=800)
----> 5     py.image.save_as(fig, title+'.png', width=1280, height=1024)
      6     objs.append(py.iplot(fig,
      7                          width=900,

/Users/klay6683/miniconda3/lib/python3.4/site-packages/plotly/plotly/plotly.py in save_as(cls, figure_or_data, filename, format, width, height)
    669             filename += '.'+format
    670 
--> 671         img = cls.get(figure_or_data, format, width, height)
    672 
    673         f = open(filename, 'wb')

/Users/klay6683/miniconda3/lib/python3.4/site-packages/plotly/plotly/plotly.py in get(figure_or_data, format, width, height)
    605         res = requests.post(
    606             url, data=json.dumps(payload, cls=utils.PlotlyJSONEncoder),
--> 607             headers=headers, verify=get_config()['plotly_ssl_verification']
    608         )
    609 

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/api.py in post(url, data, json, **kwargs)
     97     """
     98 
---> 99     return request('post', url, data=data, json=json, **kwargs)
    100 
    101 

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/api.py in request(method, url, **kwargs)
     47 
     48     session = sessions.Session()
---> 49     response = session.request(method=method, url=url, **kwargs)
     50     # By explicitly closing the session, we avoid leaving sockets open which
     51     # can trigger a ResourceWarning in some cases, and look like a memory leak

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    459         }
    460         send_kwargs.update(settings)
--> 461         resp = self.send(prep, **send_kwargs)
    462 
    463         return resp

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/sessions.py in send(self, request, **kwargs)
    571 
    572         # Send the request
--> 573         r = adapter.send(request, **kwargs)
    574 
    575         # Total elapsed time of the request (approximately)

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    368                     decode_content=False,
    369                     retries=self.max_retries,
--> 370                     timeout=timeout
    371                 )
    372 

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, **response_kw)
    516             httplib_response = self._make_request(conn, method, url,
    517                                                   timeout=timeout,
--> 518                                                   body=body, headers=headers)
    519 
    520             # If we're going to release the connection in ``finally:``, then

/Users/klay6683/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, **httplib_request_kw)
    353                 httplib_response = conn.getresponse(buffering=True)
    354             except TypeError:  # Python 2.6 and older
--> 355                 httplib_response = conn.getresponse()
    356         except (SocketTimeout, BaseSSLError, SocketError) as e:
    357             self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

/Users/klay6683/miniconda3/lib/python3.4/http/client.py in getresponse(self)
   1170             response = self.response_class(self.sock, method=self._method)
   1171 
-> 1172         response.begin()
   1173         assert response.will_close != _UNKNOWN
   1174         self.__state = _CS_IDLE

/Users/klay6683/miniconda3/lib/python3.4/http/client.py in begin(self)
    349         # read until we get a non-100 response
    350         while True:
--> 351             version, status, reason = self._read_status()
    352             if status != CONTINUE:
    353                 break

/Users/klay6683/miniconda3/lib/python3.4/http/client.py in _read_status(self)
    311 
    312     def _read_status(self):
--> 313         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    314         if len(line) > _MAXLINE:
    315             raise LineTooLong("status line")

/Users/klay6683/miniconda3/lib/python3.4/socket.py in readinto(self, b)
    369         while True:
    370             try:
--> 371                 return self._sock.recv_into(b)
    372             except timeout:
    373                 self._timeout_occurred = True

/Users/klay6683/miniconda3/lib/python3.4/ssl.py in recv_into(self, buffer, nbytes, flags)
    744                   "non-zero flags not allowed in calls to recv_into() on %s" %
    745                   self.__class__)
--> 746             return self.read(nbytes, buffer)
    747         else:
    748             return socket.recv_into(self, buffer, nbytes, flags)

/Users/klay6683/miniconda3/lib/python3.4/ssl.py in read(self, len, buffer)
    616         try:
    617             if buffer is not None:
--> 618                 v = self._sslobj.read(len, buffer)
    619             else:
    620                 v = self._sslobj.read(len or 1024)

KeyboardInterrupt: 

In [245]:
for o in objs:
    display(o)



In [15]:
from matplotlib.pyplot import subplots,colorbar
import numpy as np

In [22]:
import os

In [30]:
dataid = '_'.join(os.path.basename(l1b.fname).split('_')[3:5])

In [32]:
for title, img in zip(['raw0', 'AddScaler','MultiScaler','PolyScaler'],
                      [raw0]+scaled):
    fig, axes = subplots(2,2, figsize=(14,10))
    axes = axes.flatten()
    p2, p98 = np.percentile(img, (2, 98))
    im = axes[0].imshow(img, vmin=-500, vmax=500, aspect='auto')
    colorbar(im, ax=axes[0])
    axes[1].plot(img[:, 170])
    axes[2].plot(img[30])
    tohist = img[:, :50]
    axes[3].hist(tohist.ravel(), bins=100)
    axes[3].set_title("Mean: {:.1f}, STD: {:.1f}".format(tohist.mean(), tohist.std()), fontsize=16)
    fig.suptitle("{title}, INT_TIME: {itime}, {fname}".format(title=title, 
                                                              itime=l1b.img_header['INT_TIME'],
                                                              fname=dataid),
                 fontsize=19)
    fig.savefig(title+'.png', dpi=150)



In [17]:
pwd


Out[17]:
'/Users/klay6683/Dropbox/src/iuvs/notebooks'

In [18]:
!open .

In [ ]: