{ "cells": [ { "cell_type": "markdown", "id": "947185fa", "metadata": {}, "source": [ "# Data preprocessing - Exporting IDyOM output data to other formats\n", "\n", "\n", "py2lispIDyOM provides methods to export certain (or all) properties of the IDyOM outputs of selected (or all) melodies in different formats (`.mat` and `.csv`).\n", "\n", "\n", "This tutorial will cover how to export outputs using py2lispIDyOM, given that you already have the `.dat` file output. For an overview of the py2lispIDyOM functionality, see the [README](../README.md).\n" ] }, { "cell_type": "markdown", "id": "9a96b903", "metadata": {}, "source": [ "\n", "We will continue the sample example as in the [1_running_IDyOM_tutorial.ipynb](1_running_IDyOM_tutorial.ipynb), and extract some IDyOM outputs from that experiment, where the log folder is `experiment_history/21-05-22_17.05.05/`" ] }, { "cell_type": "code", "execution_count": 1, "id": "68bc3de4", "metadata": {}, "outputs": [], "source": [ "# import Export from export module\n", "import py2lispIDyOM as py2lispIDyOM\n", "from py2lispIDyOM.export import Export" ] }, { "cell_type": "markdown", "id": "b317c222", "metadata": {}, "source": [ "## 1. Export outputs to `.mat` formats\n", "\n", "In this section, we will go over how to export the IDyOM outputs of melodies to `.mat` files using the `export2mat()` method." ] }, { "cell_type": "markdown", "id": "2bd66f90", "metadata": {}, "source": [ "### 1.1 Export selected outputs of selected melodies to `.mat`\n", "\n", "In this example, we will export the `melody_name`, `cpitch`, and `information.content` of the two melodies named '\"chord-001\"' and '\"chor-002\"' in the experiment `21-05-22_17.05.05`.\n", "\n", "To check the available `idyom_output_keywords`, please see the [2a_data_preprocessing_extracting tutorial](2a_data_preprocessing_extracting.ipynb)." ] }, { "cell_type": "code", "execution_count": 2, "id": "58455c9a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exported data to experiment_history/21-05-22_17.05.05/outputs_in_mat/\n", "Exported data to experiment_history/21-05-22_17.05.05/outputs_in_mat/\n" ] } ], "source": [ "# define the parameters for the Export object\n", "export_mat = Export(experiment_folder_path='experiment_history/21-05-22_17.05.05/',\n", " idyom_output_keywords=['onset', 'cpitch', 'melody.name'],\n", " melody_names=['\"chor-001\"', '\"chor-002\"'])\n", "\n", "# export to .mat by calling the `export2mat()` method\n", "export_mat.export2mat()" ] }, { "cell_type": "markdown", "id": "228c424d", "metadata": {}, "source": [ "The output files are:\n", "\n", "- chor001_cpitch.mat\n", "- chor001_melody_name.mat\n", "- chor001_onset.mat\n", "- chor002_cpitch.mat\n", "- chor002_melody_name.mat\n", "- chor002_onset.mat\n", "\n", "\n" ] }, { "cell_type": "markdown", "id": "a4e82f47", "metadata": {}, "source": [ "### 1.2 Export selected outputs of all melodies to `.mat`\n", "\n", "To export selected outputs of all melodies, you don't need to specify the `melody_names`. If not specified, the selected properties of all melodies data will be exported, by default.\n", "\n", "Here, we will export `information.content` and `entropy` of all the melodies in the experiment `21-05-22_17.05.05`." ] }, { "cell_type": "code", "execution_count": 3, "id": "e8c30423", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exported data to experiment_history/21-05-22_17.05.05/outputs_in_mat/\n" ] } ], "source": [ "# define the parameters for the Export object\n", "export_mat = Export(experiment_folder_path='experiment_history/21-05-22_17.05.05/',\n", " idyom_output_keywords=['melody.name','information.content', 'entropy'])\n", "\n", "# export to .mat by calling the `export2mat()` method\n", "export_mat.export2mat()" ] }, { "cell_type": "markdown", "id": "0158e870", "metadata": {}, "source": [ "The output files are:\n", "\n", "- entropy.mat\n", "- information_content.mat\n", "- melody_name.mat" ] }, { "cell_type": "markdown", "id": "5ee72c27", "metadata": {}, "source": [ "## 2. Export outputs to `.csv` formats\n", "\n", "In this section, we will go over how to export IDyOM outputs of melodies to `.csv` files using the `export2csv()` method.\n", "\n", "In the current py2lispIDyOM version, `export2csv()` only supports exporting **all** IDyoM outputs of selected or all melodies in the experiment.\n", "\n", "The output will be a `.csv` file containing all IDyOM outputs for each melody." ] }, { "cell_type": "markdown", "id": "c43c85c2", "metadata": {}, "source": [ "### 2.1 Export outputs of selected melodies to `.csv`\n", "\n", "In this example, we will export the IDyOM outputs of the two melodies named '\"chord-005\"' and '\"chor-006\"' in the experiment `21-05-22_17.05.05`.\n", "\n", "To check the available `idyom_output_keywords`, please see the [2a_data_preprocessing_extracting tutorial](2a_data_preprocessing_extracting.ipynb)." ] }, { "cell_type": "code", "execution_count": 4, "id": "e9609bc7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exported data to experiment_history/21-05-22_17.05.05/outputs_in_csv/\n" ] } ], "source": [ "# define the parameters for the Export object\n", "export_mat = Export(experiment_folder_path='experiment_history/21-05-22_17.05.05/',\n", " melody_names=['\"chor-005\"', '\"chor-006\"'])\n", "\n", "# export to .mat by calling the `export2mat()` method\n", "export_mat.export2csv()" ] }, { "cell_type": "markdown", "id": "b351158b", "metadata": {}, "source": [ "The output files are:\n", "\n", "- chor-005.csv\n", "- chor-006.csv" ] }, { "cell_type": "markdown", "id": "245f39d7", "metadata": {}, "source": [ "### 2.2 Export outputs of all melodies to `.csv`\n", "\n", "To export outputs of all melodies, simply leave the `melody_names` argument as empty." ] }, { "cell_type": "code", "execution_count": null, "id": "67520dfd", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.7" } }, "nbformat": 4, "nbformat_minor": 5 }