# -*- coding: utf-8 -*-
"""
Created on Sun Apr 24 23:40:27 2022
"""
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
#############################################################################################################
#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 = 38897 #test discharge for which the notebook will definitely work
shot = shot_no
identifier='E05-W0037_shot_'+str(shot)+'_-450V'
#if identifier=='F10-W0049_shot_'+str(shot)+'_-450V':
# print("hello world")
def get_file(shot, identifier):
#Pick the discharge to analyse
URL = 'http://golem.fjfi.cvut.cz/shots/{shot}/Diagnostics/TimepixDetector/RasPi4-c/{identifier}.t3pa'
url = URL.format(shot=shot, identifier=identifier)
print(url)
try:
file_name_t3pa=url
with urllib.request.urlopen(file_name_t3pa) as ft3pa:
line = ft3pa.readline()
line = line.decode('utf‐8')
ft3pa.close
except HTTPError:
print('File not found at %s. Aborting notebook execution.' % url)
raise StopExecution
return file_name_t3pa
def load_t3pa_file(file_t3pa, hit_map_fig):
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.clf()
#plt.show()
ft3pa.close
print('pocet udalosti: '+str(pocet_udalosti))
#print(len(index))
return #matrix_index, pocet_udalosti
#soubory, ktere ctu:
t3pa=get_file(shot, identifier)
#vytvorene soubory:
#hit_map_hist='F10-W0049_shot_'+str(shot)+'_-450V.txt'
hit_map_fig='icon-fig'
load_t3pa_file(t3pa, hit_map_fig)
http://golem.fjfi.cvut.cz/shots/38897/Diagnostics/TimepixDetector/RasPi4-c/E05-W0037_shot_38897_-450V.t3pa pocet udalosti: 203422
<Figure size 432x288 with 0 Axes>