Ejemplo n.º 1
0
 def queue(self, line=None, display=None):
     cmd = shlex.split(line) or [
         '/opt/slurm/bin/squeue',
         '-u',
         getpass.getuser(),
         '-O',
         'JobArrayID:80,JobID:80,name:80,state:80,ReasonList:80,MINCPUS:80,tres-per-job:80,MinMemory:80,SubmitTime:80,TimeUsed:80,TimeLeft:80',
     ]
     display = display or IPython.display.display(
         {'text/plain': 'getting data..'}, raw=True, display_id=True)
     p = subprocess.run(cmd, capture_output=True, timeout=5)
     if not p.returncode:
         output = p.stdout.decode('ascii').split("\n")
         rows = [f'<th>{"</th><th>".join(output[0].split())}</th>'] + [
             f'<td>{"</td><td>".join(line.split())}</td>'
             for line in output[1:-1]
         ]
         html = "<table><tr>" + '</tr>\n<tr>'.join(rows) + '</tr><table>'
         display.update(
             {
                 'text/html':
                 html +
                 f'<i>Last Updated at {time.asctime(time.localtime())}</i>'
             },
             raw=True)
         time.sleep(1)
     else:
         return p.returncode
def show_frame(frame):
    global display
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    f = BytesIO()
    PIL.Image.fromarray(frame).save(f, 'jpeg')
    img = IPython.display.Image(data=f.getvalue())
    display.update(img)
Ejemplo n.º 3
0
def _finalize_logging_displays(display=True, **kwargs):
    import pyccc.ui
    global _current_tabs

    if not _current_tabs: return

    for display in _current_tabs.children:
        if isinstance(display, pyccc.ui.JobStatusDisplay):
            display.update()
def _finalize_logging_displays(display=True, **kwargs):
    import pyccc.ui
    global _current_tabs

    if not _current_tabs: return

    for display in _current_tabs.children:
        if isinstance(display, pyccc.ui.JobStatusDisplay):
            display.update()
def show_picture(img):
    global display, current_display_id
    # setup display
    display = IPython.display.display('', display_id=current_display_id)
    current_display_id += 1
    # display image
    f = BytesIO()
    PIL.Image.fromarray(img).save(f, 'jpeg')
    display_image = IPython.display.Image(data=f.getvalue())
    display.update(display_image)
Ejemplo n.º 6
0
def display_notebook(host, port, display):
    """Display Aim instance in an ipython context output frame.
    """
    import IPython.display
    shell = """
          <iframe id="aim" width="100%" height="800" frameborder="0" src={}:{}{}>
          </iframe>
        """.format(host, port, '/notebook/')

    # @TODO write passing proxy logic

    iframe = IPython.display.HTML(shell)
    display.update(iframe)
Ejemplo n.º 7
0
 def play_and_display(cls, agent, steps_per_render=10, steps_per_control=1):
     """Render a game in IPython, as updating HTML."""
     game = cls()
     display = IPython.display.display(game, display_id=True)
     control = agent(game.state)
     while True:
         for _ in range(steps_per_render):
             outcome = game.step(control)
             if outcome:
                 return outcome
             if game.elapsed_steps % steps_per_control == 0:
                 control = agent(game.state)
         display.update(game)
         time.sleep(game.timestep * steps_per_render)
 def show_masked_video():
     global cap, released
     if not released:
         cap.release()
         released = True
     cap = cv2.VideoCapture(video_port)
     resize_cap(cap, resize_width, resize_height)
     released = False
     start = time.time()
     while time.time() - start < limit:
         frame = None
         try:
             frame = cap.read()[1]
         except:
             print(
                 'Video feed is in use. Please run again or restart kernel.'
             )
         if frame is None:
             print(
                 'Video feed is in use. Please run again or restart kernel.'
             )
             break
         else:
             try:
                 hsv_min = (h.value[0], s.value[0], v.value[0])
                 hsv_max = (h.value[1], s.value[1], v.value[1])
                 frame = cv2.flip(frame, 1)
                 frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                 img_hsv = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV)
                 mask = cv2.inRange(img_hsv, hsv_min, hsv_max)
                 img_masked = cv2.bitwise_and(frame, frame, mask=mask)
                 f = BytesIO()
                 PIL.Image.fromarray(img_masked).save(f, 'jpeg')
                 img_jpeg = IPython.display.Image(data=f.getvalue())
                 display.update(img_jpeg)
                 time.sleep(1.0 / fps)
             except Exception as e:
                 print(e)
                 break
     cap.release()
     released = True
     print('END OF HSV SELECT')
Ejemplo n.º 9
0
def display_colab(port, display):
    """Display Aim instance in a Colab output frame.
       It need go through the proxy
    """
    import IPython.display

    shell = """
        (async () => {{
            const url = new URL('/notebook/', await google.colab.kernel.proxyPort({port}, {{'cache': true}}));
            const iframe = document.createElement('iframe');
            iframe.src = url;
            iframe.setAttribute('width', '100%');
            iframe.setAttribute('height', '800');
            iframe.setAttribute('frameborder', 0);
            document.body.appendChild(iframe);
        }})();
    """.format(port=port)

    script = IPython.display.Javascript(shell)

    if display:
        display.update(script)
    else:
        IPython.display.display(script)
Ejemplo n.º 10
0
def hsv_select_live(limit = 10, fps = 4):
    global current_display_id
    display = IPython.display.display('', display_id=current_display_id)
    current_display_id += 1
    
    # Create sliders
    h = widgets.IntRangeSlider(value=[0, 179], min=0, max=179, description='Hue:', continuous_update=True, layout=widgets.Layout(width='100%'))
    s = widgets.IntRangeSlider(value=[0, 255], min=0, max=255, description='Saturation:', continuous_update=True, layout=widgets.Layout(width='100%'))
    v = widgets.IntRangeSlider(value=[0, 255], min=0, max=255, description='Value:', continuous_update=True, layout=widgets.Layout(width='100%'))
    display.update(h)
    display.update(s)
    display.update(v)
    
    # Live masked video for the thread
    def show_masked_video():
        global cap, released
        if not released:
            cap.release()
            released = True
        cap = cv2.VideoCapture(video_port)
        resize_cap(cap, resize_width, resize_height)
        released = False
        start = time.time()
        while time.time() - start < limit:
            frame = None
            try:
                frame = cap.read()[1]
            except:
                print('Video feed is in use. Please run again or restart kernel.')
            if frame is None:
                print('Video feed is in use. Please run again or restart kernel.')
                break
            else:
                try:
                    hsv_min = (h.value[0], s.value[0], v.value[0])
                    hsv_max = (h.value[1], s.value[1], v.value[1])
                    frame = cv2.flip(frame, 1)
                    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                    img_hsv = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV)
                    mask = cv2.inRange(img_hsv, hsv_min, hsv_max)
                    img_masked = cv2.bitwise_and(frame, frame, mask = mask)
                    f = BytesIO()
                    PIL.Image.fromarray(img_masked).save(f, 'jpeg')
                    img_jpeg = IPython.display.Image(data=f.getvalue())
                    display.update(img_jpeg)
                    time.sleep(1.0 / fps)
                except Exception as e:
                    print(e)
                    break
        cap.release()
        released = True
        print('END OF HSV SELECT')
    
    # Open video on new thread (needed for slider update)
    hsv_thread = threading.Thread(target=show_masked_video)
    hsv_thread.start()
Ejemplo n.º 11
0
 def imshow(self, frame, display):
     display.update(frame)
     s = f"""{int(1/(t2-t1))} FPS"""
     d2.update( IPython.display.HTML(s) )