# -*- coding: utf-8 -*-
"""
Created on Sun Apr 24 23:40:27 2022
@author: Stepan
"""
import numpy as np
#import pandas as pd
import matplotlib.pyplot as plt
from urllib.error import HTTPError # recognise the error stemming from missing data
#import urllib
import urllib.request
#from urllib.request import urlopen
import time
import seaborn as sns #; sns.set_theme()
#import plotly.graph_objects as go
import collections # OrderedDict is one Python's high-performance containers
######################################################################
#Define an exception which will be raised if the data is missing and stop the notebook execution
class StopExecution(Exception):
def _render_traceback_(self):
pass
shot_no = 39034
#shot_no = 38897 #test discharge for which the notebook will definitely work
shot = shot_no
#identifier='E05-W0037_shot_'+str(shot)+'_-450V'
detectors= 'E05-W0037 F10-W0049 H03-W0051' #
det_list = detectors.split(' ')
#print(len(det_list))
#print(det_list)
detector=det_list
#print(detector)
#def get_file(shot, identifier):
def get_file(shot, detector):
#det_list = detectors.split(' ')
#print(len(detector))
#print(detector)
pom=0 #pomocna promenna pro rozhodnuti,zda ukoncit script
pom1=0
pom2=0
for i in range(0,len(det_list)):
#pom = 0
identifier=str(det_list[i])+'_shot_'+str(shot)+'_-450V'
print(identifier)
URL = 'http://golem.fjfi.cvut.cz/shots/{shot}/Diagnostics/TimepixDetector/RasPi4-c/{identifier}.t3pa'
url = URL.format(shot=shot, identifier=identifier)
print(url)
det =det_list[i]
try:
file_name_t3pa=url
with urllib.request.urlopen(file_name_t3pa) as ft3pa:
line = ft3pa.readline()
line = line.decode('utf‐8')
pom=pom+1
print(pom)
if pom>0:
break
ft3pa.close
#break
except HTTPError:
if pom==0:
try:
if (i==(len(detector)-1)) and pom>0:
print('chyba\n')#StopExecution
pom1=1
break
if (i<(len(detector)-1)) and pom>0:
print('chyba\n')#StopExecution
#print(len(detector))
continue
if (i<(len(detector)-1)) and pom==0:
print('chyba\n')#StopExecution
#print(len(detector))
continue
if (i==(len(detector)-1)) and pom==0:
pass
except:
raise StopExecution
raise StopExecution
print(pom)
return file_name_t3pa, det
def load_t3pa_file(file_t3pa, hit_map_fig, det):
matrix_index=[]
RowNo=[]
ClmNo=[]
pocet_udalosti = 0
#RowNo=[]
#ClmNo=[]
count = []
for i in range(0,256):
pom = [] # pomocne pole
for j in range(0,256):
pom.append(0)
count.append(pom)
with urllib.request.urlopen(file_t3pa) as ft3pa:
line = ft3pa.readline()
line = line.decode('utf‐8')
while True:
line = ft3pa.readline()
line = line.decode('utf‐8')
word=line.strip().split('\t') #v t3pa souboru je oddelovac \t
#print(word)
#poc=0
if line == '':
break
pocet_udalosti = pocet_udalosti + 1
RowNo.append(int(int(word[1]))//int(256))
ClmNo.append(int(int(word[1]))%int(256))
x=(int(int(word[1]))//int(256))
y=(int(int(word[1]))%int(256))
count[x][y]=count[x][y]+1
plt.hist2d(RowNo,ClmNo,bins=(256,256),cmap='Blues')
cb=plt.colorbar()
cb.set_label('Counts in bin')
#plt.show()
plt.savefig(hit_map_fig, dpi = 1000)
plt.savefig(det, dpi = 1000)
plt.clf()
#plt.show()
ft3pa.close
print('pocet udalosti: '+str(pocet_udalosti))
#print(len(index))
return #matrix_index, pocet_udalosti
#soubory, ktere ctu:
t3pa, DetName =get_file(shot, detector)
#vytvorene soubory:
#hit_map_hist='F10-W0049_shot_'+str(shot)+'_-450V.txt'
hit_map_fig='icon-fig'
#hit_map_fig='RasPi4-c.png'
load_t3pa_file(t3pa, hit_map_fig, DetName)
E05-W0037_shot_39034_-450V http://golem.fjfi.cvut.cz/shots/39034/Diagnostics/TimepixDetector/RasPi4-c/E05-W0037_shot_39034_-450V.t3pa 1 pocet udalosti: 100705
<Figure size 432x288 with 0 Axes>