Skip to content

Commit

Permalink
Add scene command module /JTM
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmbeta committed Dec 2, 2021
1 parent c4e3fd2 commit d2e0980
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Thumbs.db
.Spotlight-V100
.Trashes

/paper/
/utils/
/pyplr.egg.info/
/build/
/dist/
Expand Down
2 changes: 1 addition & 1 deletion docs/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/dev_notes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
72 changes: 72 additions & 0 deletions pyplr/stlabscene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 5 11:40:12 2021
@author: jtm545
"""

import requests

from pyplr.stlab import SpectraTuneLab, pulse_protocol, video_file_to_dict


class SpectraTuneLabScene(SpectraTuneLab):
'''Subclass of `stlab.SpectraTuneLab` with support for custom scene
command.
'''

def __init__(self, password, username='admin', identity=1,
lighthub_ip='192.168.7.2'):
'''Initialize class and subclass. See `pyplr.stlab.SpectraTuneLab` for
more info.
Parameters
----------
external : Class, optional
Acquire concurrent measurements with an external spectrometer.
Must be a device class with ``.measurement(...)`` and
``.wavelengths(...)`` methods. See `pyplr.oceanops.OceanOptics`
for an example.
Returns
-------
None.
'''

super().__init__(password, username, identity, lighthub_ip)

def load_video_file_2(self, fname, return_vf_dict=True):
args = [('file', (fname, open(fname, 'rb'), 'application/json'))]
cmd_url = 'http://' + self.info['url'] + ':8181/api/gateway/video/' + \
fname
response = requests.post(
cmd_url, files=args, cookies=self.info['cookiejar'], verify=False)
if 'data' not in response.json():
raise 'Upload file error'
print('video file loaded...')
if return_vf_dict:
return video_file_to_dict(fname)

def preload_video_files():
pass

def scene(self, source1, source2):
data = {
'arg': {
source1: {'spectrum': ['video1.dsf', 0]}, # added zero here for no delay
source2: {'spectrum': ['video2.dsf', 0]} # added zero here for no delay
}
}
cmd_url = 'http://' + self.info['url'] + ':8181/api/gateway/scene'
return requests.post(
cmd_url, json=data, cookies=self.info['cookiejar'], verify=False)

d = SpectraTuneLabScene(password='23acd0c3e4c5c533', identity=1, lighthub_ip='192.168.6.2')
d.load_video_file_2('video1.dsf')
d.load_video_file_2('video2.dsf')
d.get_video_file_metadata('video1.dsf')
d.get_video_file_metadata('video2.dsf')
d.scene(1,2)

0 comments on commit d2e0980

Please sign in to comment.