Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions Jayanta_Banik_AWAKE_GSoC_EvaL.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#importing libraries\n",
"from os import listdir\n",
"import h5py\n",
"\n",
"#defining variables\n",
"input_path = \"C:\\\\Users\\\\scien\\\\Desktop\\\\AWAKE\\\\\" #change to path of where files are stored\n",
"output_path = input_path\n",
"data = [] \n",
"records = []\n",
"\n",
"#reading files\n",
"files_list = listdir(input_path) #reading all available files\n",
"file = h5py.File(input_path+files_list[0], 'r') #reading file\n",
"key_s = list(file.keys())\n",
"for i in key_s:\n",
" data.append(file[i])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CERN Local time - CEST\n",
"2018-11-11 19:48:28 CET+0100\n",
"UTC time\n",
"2018-11-11 18:48:28 UTC+0000\n"
]
}
],
"source": [
"import datetime\n",
"import pytz\n",
"#defining a datetime object \n",
"cern_local = pytz.timezone('Europe/Zurich') \n",
"\n",
"#reading the files atributes of time as first 19 digits\n",
"nano_time = int((files_list[0])[:19])\n",
" \n",
"#assuming the nanoseconds is in UTC timezone converting nanoseconds to seconds and then converting into datetime object and then converting into utc\n",
"utc_dt = pytz.utc.localize(datetime.datetime.utcfromtimestamp(nano_time/pow(10,9))) #converting nanoseconds to seconds\n",
"#converting to cern local time\n",
"loc_dt = utc_dt.astimezone(cern_local)\n",
"print(\"CERN Local time - CEST\")\n",
"print(loc_dt.strftime('%Y-%m-%d %H:%M:%S %Z%z'))\n",
"print(\"UTC time\")\n",
"print(utc_dt.strftime('%Y-%m-%d %H:%M:%S %Z%z'))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#defining a function to explore all nodes of dataset\n",
"def explorer(data):\n",
" try:\n",
" t = list(data.keys())\n",
" for i in range(0,len(t)):\n",
" b = data.get(t[i])\n",
" explorer(b)\n",
" except:\n",
" records.append([str(data.name)])\n",
" #saving size, shape and type of data\n",
" try:\n",
" records[-1].append(str(data.size))\n",
" records[-1].append(str(data.shape))\n",
" records[-1].append(str(data.dtype))\n",
" \n",
" except:\n",
" records[-1].append(str(type(data)))\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#exploring all the groups and datasets\n",
"def data_tree():\n",
" for subfiles in data:\n",
" explorer(subfiles)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import csv\n",
"def wrritter():\n",
" #converting to dataframe\n",
" df = pd.DataFrame(np.array(records))\n",
" #saving into csv\n",
" with open(output_path + 'output_box.csv', 'w') as csvFile:\n",
" writer = csv.writer(csvFile)\n",
" writer.writerows([[\"path\",\"size\",\"shape\",\"type\"]])\n",
" writer.writerows(df[0])\n",
" csvFile.close() "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wrritter()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#reading dataset\n",
"image_1D = list(data[0].__getitem__(\"/AwakeEventData/XMPP-STREAK/StreakImage/streakImageData\"))\n",
"\n",
"img_height = list(data[0].__getitem__(\"/AwakeEventData/XMPP-STREAK/StreakImage/streakImageHeight\"))\n",
"\n",
"img_width = list(data[0].__getitem__(\"/AwakeEventData/XMPP-STREAK/StreakImage/streakImageWidth\"))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#reshape !D into 2D image\n",
"image_2D =np.reshape(image_1D, (img_height[0],img_width[0]))\n",
"#print(image_2D.shape)\n",
"#print(image_2D.ndim)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from scipy.signal import medfilt\n",
"#using filter\n",
"image_ = (medfilt(image_2D))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"#visualising image\n",
"imgplot = plt.imshow(image_)\n",
"#saving image\n",
"plt.imsave(output_path + \"test_2D_image.png\", image_)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading