Skip to content
Snippets Groups Projects
Commit 646e0c93 authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

Merge pull request #34 in ASAPO/asapo from python_api to develop

* commit '6a1ec0f5':
  add test with jupyter notebook
  add python test
  added __version__ to python module
parents c2b2323c 6a1ec0f5
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
%matplotlib inline
```
%% Cell type:code id: tags:
``` python
import asapo_worker
import h5py
import numpy as np
import matplotlib.pyplot as plt
import tempfile
import cbf
import time
from IPython import display
broker, err = asapo_worker.create_server_broker("psana002:8400", "/tmp", "asapo_test2","yzgAcLmijSLWIm8dBiGNCbc0i42u5HSm-zR6FRqo__Y=", 1000000)
```
%% Cell type:code id: tags:
``` python
last_id = 0
try:
while True:
data, meta, err = broker.get_last(meta_only=False)
id = meta['_id']
if id == last_id:
time.sleep(1)
continue
tmpfile = tempfile.NamedTemporaryFile()
tmpfile.write(data)
content = cbf.read(tmpfile.name)
numpy_array_with_data = content.data
header_metadata = content.metadata
plt.imshow(numpy_array_with_data, cmap='gnuplot', vmax=500)
# display.display(plt.gcf())
display.clear_output(wait=True)
plt.show()
print (meta)
last_id = id
except KeyboardInterrupt:
pass
```
%% Output
{'_id': 198, 'size': 6247362, 'name': 'data/file_lin/test_dir/sample_1_00001.cbf'}
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
ssh -l root asap3-tst01 scp max-wgs:/beegfs/desy/group/it/ReferenceData/MX/Pilatus/sample_1_0000$1.cbf /run/user/data/file_lin/test_dir/
import asapo_worker
import h5py
import numpy as np
import matplotlib.pyplot as plt
#d1 = np.random.random(size = (20))
#f = h5py.File("mytestfile1.hdf5", "w")
#dset = f.create_dataset("mydataset", data = d1)
#f.close()
broker, err = asapo_worker.create_server_broker("psana002:8400", "/tmp", "asapo_test2","yzgAcLmijSLWIm8dBiGNCbc0i42u5HSm-zR6FRqo__Y=", 1000000)
last_id = 0
while True:
data, meta, err = broker.get_last(meta_only=False)
id = meta['_id']
if id == last_id:
continue
fid = h5py.h5f.open_file_image(data)
f = h5py.File(fid)
data1 = np.array(f['mydataset'])
print(data1)
plt.plot(data1)
plt.ylabel('some numbers')
plt.show()
last_id = id
f.close()
#alternative - but tobytes creates an additional copy - not nice.
#import tables
#h5file1 = tables.open_file("in-memory-sample.h5", driver="H5FD_CORE",
# driver_core_image=data.tobytes(),
# driver_core_backing_store=0)
#data2 = h5file1.root.mydataset.read()
......@@ -76,3 +76,6 @@ cdef class PyDataBrokerFactory:
def create_server_broker(server_name,source_path,beamtime_id,token,timeout):
factory = PyDataBrokerFactory()
return factory.create_server_broker(_bytes(server_name),_bytes(source_path),_bytes(beamtime_id),_bytes(token),timeout)
__version__ = "@ASAPO_VERSION_PYTHON@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment