Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp fix for relative import error #72

Closed
wants to merge 2 commits into from
Closed
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
95 changes: 62 additions & 33 deletions demos/demo_ippm.ipynb

Large diffs are not rendered by default.

239 changes: 109 additions & 130 deletions demos/demo_plotting.ipynb

Large diffs are not rendered by default.

164 changes: 101 additions & 63 deletions demos/demo_save_load.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,42 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "19b809df-7acd-402b-8f05-d44a68910a79",
"metadata": {},
"outputs": [],
"source": [
"# temporary fix for relative import errors. essentially, the notebook is unable to discern that \n",
"# the kymata directory is in the parent directory. It thinks it is in the current one.\n",
"# SOLUTION: update the PATH variable to point to the parent directory, from which it can locate kymata/.\n",
"\n",
"import sys\n",
"sys.path.insert(1, '..')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2023-11-24T15:03:28.701768Z",
"start_time": "2023-11-24T15:03:27.973888Z"
}
},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'numpy'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 6\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtempfile\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m NamedTemporaryFile\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mkymata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdatasets\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msample\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m get_dataset_kymata_mirror_q3_2023, get_dataset_gm_loudness, \\\n\u001b[1;32m 5\u001b[0m get_dataset_d_ins_loudness_tonop_chan1\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mkymata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mentities\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexpression\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ExpressionSet\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mkymata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mio\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmatlab\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m load_matab_expression_files\n",
"File \u001b[0;32m~/Desktop/kymata/kymata-toolbox/demos/../kymata/entities/expression.py:13\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mwarnings\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m warn\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mzipfile\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ZipFile, ZIP_LZMA\n\u001b[0;32m---> 13\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m int_, float_, str_, array, array_equal, ndarray, frombuffer\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtyping\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m NDArray\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msparse\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SparseArray, COO\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'numpy'"
]
}
],
"source": [
"from os import path\n",
"from pathlib import Path\n",
Expand All @@ -24,6 +51,17 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "4df17a3a727b7c02",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-10T20:03:00.508482Z",
"start_time": "2023-11-10T20:02:56.738612Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
Expand All @@ -40,44 +78,38 @@
}
],
"source": [
"## Download sample data. This cell can be ignored if you wish to load your own\n",
"## data from a gridsearch.\n",
"\n",
"# set location of tutorial data\n",
"sample_data_dir = Path(Path(path.abspath(\"\")).parent, \"data\", \"sample-data\")\n",
"\n",
"# First we'll download a sample .nkg file which loads a range of functions,\n",
"# from the Kymata Research Group. nkg files contain both lefthand and\n",
"# righthand data for a set of functions\n",
"\n",
"sample_dataset = KymataMirror2023Q3Dataset(data_root=sample_data_dir, download=True)\n",
"nkg_path = Path(sample_dataset.path, sample_dataset.filenames[0])\n",
"print(nkg_path.name)\n",
"\n",
"# Second we will download two .nkg files which only contain one\n",
"# function each - 'ins_loudness' and 'd_ins_tc1_loudness':\n",
"ins_loudness_only_dataset = TVLInsLoudnessOnlyDataset(data_root=sample_data_dir, download=True)\n",
"ins_loudness_path = Path(ins_loudness_only_dataset.path, ins_loudness_only_dataset.filenames[0])\n",
"\n",
"d_ins_tc1_loudness_only_dataset = TVLDeltaInsTC1LoudnessOnlyDataset(data_root=sample_data_dir, download=True)\n",
"d_ins_tc1_loudness_path = Path(d_ins_tc1_loudness_only_dataset.path, d_ins_tc1_loudness_only_dataset.filenames[0])"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-11-24T15:03:28.707981Z",
"start_time": "2023-11-24T15:03:28.704356Z"
}
},
"id": "1f36e2e91b52522f"
"# Start with sample dataset\n",
"dataset_q3_2023 = get_dataset_kymata_mirror_q3_2023()\n",
"expression_data_kymata_mirror = ExpressionSet.load(from_path_or_file=Path(dataset_q3_2023.path, dataset_q3_2023.filenames[0]))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"# Let's load the KymataMirror2023Q3 .nkg file. This contains around 30 functions.\n",
"expression_data_kymata_mirror = load_expression_set(from_path_or_file=nkg_path)"
"id": "681594ea282bf0f",
"metadata": {
"ExecuteTime": {
"end_time": "2023-11-10T20:03:11.535225Z",
"start_time": "2023-11-10T20:03:00.507022Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading dataset: GMLoudness\n",
"Downloading https://kymata.org/assets_kymata_toolbox_tutorial_data/gridsearch-result-data//GMLoudness_lh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat to /Users/cai/Dox/Work/Kymata lab/Data/kymata_data/GMLoudness/GMLoudness_lh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat\n",
"Downloading https://kymata.org/assets_kymata_toolbox_tutorial_data/gridsearch-result-data//GMLoudness_rh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat to /Users/cai/Dox/Work/Kymata lab/Data/kymata_data/GMLoudness/GMLoudness_rh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat\n",
"Downloading dataset: GMLoudness\n",
"Downloading https://kymata.org/assets_kymata_toolbox_tutorial_data/gridsearch-result-data//GMloudness_tonotop_82dB_d_ins_loudness_tonop_chan1__lh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat to /Users/cai/Dox/Work/Kymata lab/Data/kymata_data/GMLoudness/GMloudness_tonotop_82dB_d_ins_loudness_tonop_chan1__lh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat\n",
"Downloading https://kymata.org/assets_kymata_toolbox_tutorial_data/gridsearch-result-data//GMloudness_tonotop_82dB_d_ins_loudness_tonop_chan1__rh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat to /Users/cai/Dox/Work/Kymata lab/Data/kymata_data/GMLoudness/GMloudness_tonotop_82dB_d_ins_loudness_tonop_chan1__rh_10242verts_-200-800ms_cuttoff1000_5perms_ttestpval.mat\n"
]
}
],
"metadata": {
"collapsed": false,
Expand All @@ -93,23 +125,37 @@
"execution_count": 4,
"outputs": [],
"source": [
"# Let's seperately load the 'ins_loudness' .nkg file, and then load and add the\n",
"# d_ins_tc1_loudness to it using '+='. 'expression_data_new_results' now contains two functions.\n",
"expression_data_new_results = load_expression_set(from_path_or_file=ins_loudness_path)\n",
"expression_data_new_results += load_expression_set(from_path_or_file=d_ins_tc1_loudness_path)"
],
"# Get a second sample dataset\n",
"\n",
"# Create new expression set object for the new results (or you can just add to an existing expressionSet directly using '+=' ).\n",
"dataset_gm_loudness = get_dataset_gm_loudness()\n",
"expression_data_new_results = load_matab_expression_files(\n",
" function_name=\"ins_loudness_2020\",\n",
" lh_file=Path(dataset_gm_loudness.path, dataset_gm_loudness.filenames[0]),\n",
" rh_file=Path(dataset_gm_loudness.path, dataset_gm_loudness.filenames[1]),\n",
")\n",
"dataset_d_ins_loudness_tonop_chan1 = get_dataset_d_ins_loudness_tonop_chan1()\n",
"expression_data_new_results += load_matab_expression_files(\n",
" function_name=\"delta_ins_loudness_tonotop_chan1_2020\",\n",
" lh_file=Path(dataset_d_ins_loudness_tonop_chan1.path, dataset_d_ins_loudness_tonop_chan1.filenames[0]),\n",
" rh_file=Path(dataset_d_ins_loudness_tonop_chan1.path, dataset_d_ins_loudness_tonop_chan1.filenames[1]),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "77c6c3617357edbb",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-11-24T15:03:33.159669Z",
"start_time": "2023-11-24T15:03:32.309852Z"
"end_time": "2023-11-10T20:03:18.279668Z",
"start_time": "2023-11-10T20:03:11.536073Z"
},
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"id": "681594ea282bf0f"
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [
{
"name": "stderr",
Expand All @@ -126,35 +172,27 @@
"\n",
"# Save new expressionSet for use again in the future.\n",
"with NamedTemporaryFile() as tf:\n",
" save_expression_set(expression_data_extended, tf)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-11-24T15:03:44.793458Z",
"start_time": "2023-11-24T15:03:33.162168Z"
}
},
"id": "77c6c3617357edbb"
" expression_data_extended.save(tf)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down