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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@
"# PyKOALA Data Containers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of contents:\n",
"\n",
"1. [Importing class](#importing-class)\n",
"2. [`HistoryRecord` class](#historyrecord-class)\n",
" - [`HistoryRecord` methods](#historyrecord-methods)\n",
" - [`to_str`](#to_str)\n",
"3. [`DataContainerHistory` class](#datacontainerhistory-class)\n",
" - [`DataContainerHistory` methods](#datacontainerhistory-methods)\n",
" - [`initialise_record`](#initialise_record)\n",
" - [`log_record`](#log_record)\n",
" - [`is_record`](#is_record)\n",
" - [`find_record`](#find_record)\n",
" - [`dump_to_header`](#dump_to_header)\n",
" - [`dump_to_text`](#dump_to_text)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing class"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note: Make sure to run the following cells in order to ensure correct execution.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -16,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -46,9 +80,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Title of history record: Error log\n",
"Comments in history record: ['This is line one.', 'This is line two.']\n"
]
}
],
"source": [
"from pykoala.data_container import HistoryRecord\n",
"\n",
Expand All @@ -57,6 +100,20 @@
"print('Comments in history record: ', hist_record.comments)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### `HistoryRecord` **methods** "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `to_str`"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -66,9 +123,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Error log: This is line one.\\nThis is line two.'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hist_record.to_str()"
]
Expand All @@ -82,9 +150,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is line one.\n",
"This is line two.\n"
]
}
],
"source": [
"for record in hist_record.comments:\n",
" print(record)"
Expand All @@ -106,9 +183,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1: Loaded data\n",
"Step 2: Filtered outliers\n",
"Step 3: Normalized data\n"
]
}
],
"source": [
"from pykoala.data_container import DataContainerHistory\n",
"initial_entries = [\n",
Expand All @@ -128,14 +215,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Functions "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** Make sure to run the following cells in order to ensure correct execution."
"### `DataContainerHistory` **methods** "
]
},
{
Expand All @@ -154,9 +234,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1: Loaded data\n",
"Step 2: Filtered outliers\n",
"Step 3: Normalized data\n"
]
}
],
"source": [
"initial_entries = [\n",
" (\"Step 1\", \"Loaded data\"),\n",
Expand Down Expand Up @@ -193,9 +283,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1: Loaded data\n",
"Step 2: Filtered outliers\n",
"Step 3: Normalized data\n",
"Step 4: Additional data added with log_record method\n"
]
}
],
"source": [
"#We use the same history log as before\n",
"initial_entries = [\n",
Expand Down Expand Up @@ -228,9 +329,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n"
]
}
],
"source": [
"print(history_log.is_record(title='Step 1'))\n",
"print(history_log.is_record(title='Step 42'))"
Expand Down Expand Up @@ -259,9 +369,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of found items: 1\n",
"Step 1: Loaded data\n"
]
}
],
"source": [
"search_results = history_log.find_record(title='Step 1')\n",
"print('Number of found items:', len(search_results))\n",
Expand All @@ -279,9 +398,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of found items: 2\n",
"Step 1: Loaded data\n",
"Step 1: Rinse and repeat\n"
]
}
],
"source": [
"history_log_repeated_titles = DataContainerHistory()\n",
"history_log_repeated_titles.initialise_record(list_of_entries=initial_entries)\n",
Expand Down Expand Up @@ -311,9 +440,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"PYKOALA0= 'Loaded data' / Step 1 \n",
"PYKOALA1= 'Filtered outliers' / Step 2 \n",
"PYKOALA2= 'Normalized data' / Step 3 \n",
"PYKOALA3= 'Additional data added with log_record method' / Step 4 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from astropy.io import fits\n",
"history_log.dump_to_header()\n"
Expand All @@ -335,16 +478,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/mbolivar/pykoala-tutorials/tutorials/0-introduction\n",
"[pykoala] 2024/12/11 10:07|INFO> Writting log into text file\n"
]
}
],
"source": [
"from pathlib import Path\n",
"import os\n",
"\n",
"os.system('pwd')\n",
"path_to_file = './output/history_log.txt'\n",
"history_log.dump_to_text(file=path_to_file)"
"path_output = './output/history_log.txt'\n",
"history_log.dump_to_text(file=path_output)"
]
},
{
Expand Down Expand Up @@ -375,5 +527,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading