Skip to content
Snippets Groups Projects
Commit e629575d authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-235: add jupyter notebook for testing

parent 0240a667
No related branches found
No related tags found
1 merge request!108Resolve L2SS-235 "Archive pcc attribute"
%% Cell type:code id:b2af67ec tags:
``` python
import sys, time
import numpy as np
sys.path.append('/hosthome/tango/devices')
from toolkit.archiver import Archiver,Retriever
from toolkit.archiver_base import *
from matplotlib import pyplot as plt
```
%% Cell type:code id:c873d747 tags:
``` python
device_name = 'LTS/PCC/1'
attr_name = 'rcu_temperature_r'
attr_fq_name = str(device_name+'/'+attr_name).lower()
archiver = Archiver()
d=DeviceProxy(device_name)
# Need to increase the default timeout (3s) or device could raise error on initialising,
# when checking the list of archived attributes
print("timeout %s" % str(d.get_timeout_millis()))
timeout = 10000
print("new_timeout %s" % timeout)
d.set_timeout_millis(timeout)
state = str(d.state())
print(state)
```
%% Output
timeout 3000
new_timeout 10000
OFF
%% Cell type:code id:684cf0a7 tags:
``` python
# OPTIONAL
# Archiving starts at device initializations with polling-period = 1s, but period can be explicitly set
# Archiving strategies are ['ALWAYS','RUN','SHUTDOWN','SERVICE']
archiver.remove_attribute_from_archiver(device_name,attr_name)
time.sleep(3)
archiver.add_attribute_to_archiver(attribute=attr_fq_name,polling_period=1000,event_period=10000,strategy='RUN')
```
%% Cell type:code id:249271c1 tags:
``` python
if state == "OFF":
d.initialise()
time.sleep(1)
state = str(d.state())
if state == "STANDBY":
d.on()
state = str(d.state())
if state == "ON":
print("Device is now in ON state")
```
%% Output
Device is now in ON state
%% Cell type:code id:81acaa95 tags:
``` python
attr_list = d.get_attribute_list()
#for a in attr_list:
#print(a)
print(len(attr_list))
#List of archived attributes - it should be 1 for now -
arch_attr_list = archiver.es.AttributeList
print(len(arch_attr_list))
print(arch_attr_list)
```
%% Output
35
1
('tango://databaseds:10000/lts/pcc/1/rcu_temperature_r',)
%% Cell type:code id:9fd8415d tags:
``` python
# OPTIONAL: stop archiving switching off device or explicitly stopping
d.off()
#archiver.stop_archiving_attribute(device_name,attr_name)
```
%% Cell type:code id:88307600 tags:
``` python
retriever = Retriever()
retriever.get_all_archived_attributes()
```
%% Output
[<Attribute(fullname='tango://databaseds:10000/lts/pcc/1/rcu_temperature_r',data_type ='39',ttl='0',facility ='tango://databaseds:10000',domain ='lts',family ='pcc',member ='1',name ='rcu_temperature_r')>]
%% Cell type:code id:c5a7e5e2 tags:
``` python
# Print database type of the attribute
print(retriever.get_attribute_datatype(attr_fq_name))
```
%% Output
array_devdouble_ro
%% Cell type:code id:07fcc423 tags:
``` python
# Retrieve records in the last n hours (works even with decimals)
records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.1)
# Convert DB Array records into Python lists
data = build_array_from_record(records,records[0].dim_x_r)
# Extract only the value from the array
array_values = get_values_from_record(data)
#records
#data
#array_values
```
%% Cell type:code id:3aad4160 tags:
``` python
# Extract and process timestamps for plotting purposes
def get_timestamps(data,strformat):
timestamps = []
for i in range(len(data)):
timestamps.append(data[i][0].recv_time.strftime(strformat))
return timestamps
timestamps = get_timestamps(data,"%Y-%m-%d %X")
```
%% Cell type:code id:929132fd tags:
``` python
# Plot of array values
heatmap = np.array(array_values,dtype=np.float)
fig = plt.figure()
plt.rcParams['figure.figsize'] = [32, 32]
#plt.rcParams['figure.dpi'] = 128
ax = fig.add_subplot(111)
im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm')
ax.set_xlabel('Array index')
ax.set_ylabel('Timestamp')
ax.set_yticks(range(0,len(timestamps)))
ax.set_yticklabels(timestamps,fontsize=4)
#ax.set_yticks(range(0,len(timestamps),10))
ax.set_title('Archived data for '+ attr_fq_name)
cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal')
plt.show()
```
%% Output
%% Cell type:code id:8e0ef798 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment