Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson authored Jul 26, 2023
1 parent 1b1cdb6 commit 7eebcc5
Showing 1 changed file with 55 additions and 24 deletions.
79 changes: 55 additions & 24 deletions docs/nb/import_sleap_h5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
"cells": [
{
"cell_type": "markdown",
"id": "15d9a8e9",
"id": "b9ca18fc",
"metadata": {},
"source": [
"#### Import SLEAP H5 files \n",
"\n"
"#### Import SLEAP H5 files "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d05d067c",
"cell_type": "markdown",
"id": "aa326dda",
"metadata": {},
"outputs": [],
"source": [
"Importing a directory of .SLP files into a SimBA project. The .SLP files has been created by joining several .SLP files.\n",
"\n",
Expand All @@ -25,21 +22,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "e92fbb4d",
"execution_count": 3,
"id": "0980ef83",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from simba.mixins.config_reader import ConfigReader\n",
"from simba.utils.read_write import find_files_of_filetypes_in_directory, write_df\n",
"from simba.utils.data import slp_to_df_convert"
"from simba.utils.data import slp_to_df_convert\n",
"from simba.utils.read_write import get_fn_ext\n",
"from simba.data_processors.interpolation_smoothing import Smooth, Interpolate"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8113369",
"execution_count": 4,
"id": "df59619d",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,8 +49,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e74729b",
"execution_count": 5,
"id": "fbfd1b2f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -62,8 +61,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "be4b0bf9",
"execution_count": 8,
"id": "f122c47a",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -74,7 +73,7 @@
},
{
"cell_type": "markdown",
"id": "caeb8999",
"id": "3f6333cc",
"metadata": {},
"source": [
"FOR EVERY H5 FILE FOUND IN THE DATA_DIR, WE (i) CONVERT IT TO A DATAFRAME AND APPEND THE HEADERS AS DEFINED IN THE SIMBA PROJECT, AND (ii) SAVE THE DATAFRAME IN THE SIMBA PROJECT `project_folder/csv/input_csv` directory.\n",
Expand All @@ -84,10 +83,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "2709383d",
"execution_count": 9,
"id": "97eb4f62",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Importing LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 50597 Dam_Nose_1 body-parts for animal Dam in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 1653 Dam_Head_1 body-parts for animal Dam in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 298 Dam_Body_1 body-parts for animal Dam in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 34014 Dam_Tail_1 body-parts for animal Dam in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 251 Nest_First_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 8 Nest_Second_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 139 Nest_Third_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 177 Nest_Fourth_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 1551 Nest_Fifth_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 1056 Nest_Sixth_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Interpolating 23041 Nest_Sevent_corner_2 body-parts for animal Nest in video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n",
"Video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c interpolated (elapsed time 5.4641) ...\n",
"SIMBA COMPLETE: 1 data file(s) interpolated) (elapsed time: 5.47s) \tcomplete\n",
"Video LBNL4b_LBN_P05_3_2022-01-17_19-48-06c smoothed (Savitzky Golay: 200ms) (elapsed time 4.3516)...\n",
"SIMBA COMPLETE: 1 data file(s) smoothened (elapsed time: 4.3593s) \tcomplete\n",
"Complete: LBNL4b_LBN_P05_3_2022-01-17_19-48-06c...\n"
]
}
],
"source": [
"for file_path in data_files:\n",
" _, video_name, _ = get_fn_ext(filepath=file_path)\n",
Expand All @@ -96,14 +119,14 @@
" save_path = os.path.join(config.input_csv_dir, f'{video_name}.csv')\n",
" write_df(df=df, file_type='csv', save_path=save_path, multi_idx_header=True)\n",
"\n",
" #Run interpolation if `interpolation_method` is not None\n",
" #Run interpolation if `interpolation_method` is not \"None\"\n",
" if interpolation_method != 'None':\n",
" Interpolate(input_path=save_path,\n",
" config_path=CONFIG_PATH,\n",
" method=interpolation_method,\n",
" initial_import_multi_index=True)\n",
"\n",
" # Run smoothing if `smoothing_method['Method']` is not None\n",
" # Run smoothing if `smoothing_method['Method']` is not \"None\"\n",
" if smoothing_method['Method'] != 'None':\n",
" Smooth(config_path=CONFIG_PATH,\n",
" input_path=save_path,\n",
Expand All @@ -113,13 +136,21 @@
"\n",
" print(f'Complete: {video_name}...')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5fcfeb1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "simba_dev",
"display_name": "Python [conda env:.conda-simba_dev]",
"language": "python",
"name": "simba_dev"
"name": "conda-env-.conda-simba_dev-py"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 7eebcc5

Please sign in to comment.