Commit 360a5a28 authored by Unknown's avatar Unknown
Browse files

Doc updates

parent 3e895b38
{
"metadata": {
"language_info": {
"pygments_lexer": "ipython3",
"mimetype": "text/x-python",
"version": "3.5.2",
"nbconvert_exporter": "python",
"file_extension": ".py",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"name": "python"
},
"kernelspec": {
"language": "python",
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"%matplotlib inline"
......@@ -20,10 +40,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"#Import packages\n\n# Ensure that this code works on both python 2 and python 3\nfrom __future__ import division, print_function, absolute_import, unicode_literals\n\n# basic numeric computation:\nimport numpy as np\n\n# The package used for creating and manipulating HDF5 files:\nimport h5py\n\n# Plotting and visualization:\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\n\n# for downloading files:\nimport wget\nimport os\n\n# multivariate analysis:\nfrom sklearn.cluster import KMeans\nfrom sklearn.decomposition import NMF\n\n# finally import pycroscopy:\nimport pycroscopy as px\n\n\"\"\"\n \n\"\"\""
......@@ -38,10 +58,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"data_file_path = 'temp_um.h5'\n# download the data file from Github:\nurl = 'https://raw.githubusercontent.com/pycroscopy/pycroscopy/master/data/BELine_0004.h5'\n_ = wget.download(url, data_file_path, bar=None)\n\nhdf = px.ioHDF5(data_file_path)\nh5_file = hdf.file\n\nprint('Contents of data file:')\nprint('----------------------')\npx.hdf_utils.print_tree(h5_file)\nprint('----------------------')\n\nh5_meas_grp = h5_file['Measurement_000']\n\n# Extracting some basic parameters:\nnum_rows = px.hdf_utils.get_attr(h5_meas_grp,'grid_num_rows')\nnum_cols = px.hdf_utils.get_attr(h5_meas_grp,'grid_num_cols')\n\n# Getting a reference to the main dataset:\nh5_main = h5_meas_grp['Channel_000/Raw_Data']\n\n# Extracting the X axis - vector of frequencies\nh5_spec_vals = px.hdf_utils.getAuxData(h5_main,'Spectroscopic_Values')[-1]\nfreq_vec = np.squeeze(h5_spec_vals.value) * 1E-3\n\nprint('Data currently of shape:', h5_main.shape)\n\nx_label = 'Frequency (kHz)'\ny_label = 'Amplitude (a.u.)'"
......@@ -56,10 +76,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"px.viz.be_viz_utils.jupyter_visualize_be_spectrograms(h5_main)"
......@@ -74,13 +94,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"h5_svd_group = px.doSVD(h5_main, num_comps=256)\n\nh5_u = h5_svd_group['U']\nh5_v = h5_svd_group['V']\nh5_s = h5_svd_group['S']\n\n# Since the two spatial dimensions (x, y) have been collapsed to one, we need to reshape the abundance maps:\nabun_maps = np.reshape(h5_u[:,:25], (num_rows, num_cols, -1))\n\n# Visualize the variance / statistical importance of each component:\npx.plot_utils.plotScree(h5_s, title='Note the exponential drop of variance with number of components')\n\n# Visualize the eigenvectors:\nfirst_evecs = h5_v[:9, :]\n\npx.plot_utils.plot_loops(freq_vec, np.abs(first_evecs), x_label=x_label, y_label=y_label, plots_on_side=3,\n subtitles='Component', title='SVD Eigenvectors (Amplitude)', evenly_spaced=False)\npx.plot_utils.plot_loops(freq_vec, np.angle(first_evecs), x_label=x_label, y_label='Phase (rad)', plots_on_side=3,\n subtitles='Component', title='SVD Eigenvectors (Phase)', evenly_spaced=False)\n\n# Visualize the abundance maps:\npx.plot_utils.plot_map_stack(abun_maps, num_comps=9, heading='SVD Abundance Maps',\n color_bar_mode='single', cmap='inferno')"
"do_svd = px.processing.svd_utils.SVD(h5_main, num_components=256)\nh5_svd_group = do_svd.compute()\n\nh5_u = h5_svd_group['U']\nh5_v = h5_svd_group['V']\nh5_s = h5_svd_group['S']\n\n# Since the two spatial dimensions (x, y) have been collapsed to one, we need to reshape the abundance maps:\nabun_maps = np.reshape(h5_u[:,:25], (num_rows, num_cols, -1))\n\n# Visualize the variance / statistical importance of each component:\npx.plot_utils.plot_scree(h5_s, title='Note the exponential drop of variance with number of components')\n\n# Visualize the eigenvectors:\nfirst_evecs = h5_v[:9, :]\n\npx.plot_utils.plot_loops(freq_vec, np.abs(first_evecs), x_label=x_label, y_label=y_label, plots_on_side=3,\n subtitle_prefix='Component', title='SVD Eigenvectors (Amplitude)', evenly_spaced=False)\npx.plot_utils.plot_loops(freq_vec, np.angle(first_evecs), x_label=x_label, y_label='Phase (rad)', plots_on_side=3,\n subtitle_prefix='Component', title='SVD Eigenvectors (Phase)', evenly_spaced=False)\n\n# Visualize the abundance maps:\npx.plot_utils.plot_map_stack(abun_maps, num_comps=9, heading='SVD Abundance Maps',\n color_bar_mode='single', cmap='inferno')"
]
},
{
......@@ -92,10 +112,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"num_clusters = 4\n\nestimators = px.Cluster(h5_main, 'KMeans', n_clusters=num_clusters)\nh5_kmeans_grp = estimators.do_cluster(h5_main)\nh5_kmeans_labels = h5_kmeans_grp['Labels']\nh5_kmeans_mean_resp = h5_kmeans_grp['Mean_Response']\n\npx.plot_utils.plot_cluster_h5_group(h5_kmeans_grp)"
......@@ -110,10 +130,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"num_comps = 4\n\n# get the non-negative portion of the dataset\ndata_mat = np.abs(h5_main)\n\nmodel = NMF(n_components=num_comps, init='random', random_state=0)\nmodel.fit(data_mat)\n\nfig, axis = plt.subplots(figsize=(5.5, 5))\npx.plot_utils.plot_line_family(axis, freq_vec, model.components_, label_prefix='NMF Component #')\naxis.set_xlabel(x_label, fontsize=12)\naxis.set_ylabel(y_label, fontsize=12)\naxis.set_title('NMF Components', fontsize=14)\naxis.legend(bbox_to_anchor=[1.0, 1.0], fontsize=12)"
......@@ -121,35 +141,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null,
"outputs": [],
"source": [
"# Close and delete the h5_file\nh5_file.close()\nos.remove(data_file_path)"
]
}
],
"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.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
\ No newline at end of file
......@@ -142,7 +142,8 @@ px.viz.be_viz_utils.jupyter_visualize_be_spectrograms(h5_main)
# Furthermore, while it is not discussed in this example, pycroscopy also writes back the results from SVD back to
# the same source h5 file including all relevant links to the source dataset and other ancillary datasets
h5_svd_group = px.doSVD(h5_main, num_comps=256)
do_svd = px.processing.svd_utils.SVD(h5_main, num_components=256)
h5_svd_group = do_svd.compute()
h5_u = h5_svd_group['U']
h5_v = h5_svd_group['V']
......
c88ec8e75de96254d760639ebe99b0bb
\ No newline at end of file
.. _sphx_glr_auto_examples_plot_spectral_unmixing.py:
.. _sphx_glr_auto_examples_data_analysis_plot_spectral_unmixing.py:
=================================================================
......@@ -170,7 +170,7 @@ All the necessary information was present in the H5 file
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_001.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_001.png
:align: center
......@@ -219,7 +219,8 @@ the same source h5 file including all relevant links to the source dataset and o
.. code-block:: python
h5_svd_group = px.doSVD(h5_main, num_comps=256)
do_svd = px.processing.svd_utils.SVD(h5_main, num_components=256)
h5_svd_group = do_svd.compute()
h5_u = h5_svd_group['U']
h5_v = h5_svd_group['V']
......@@ -229,15 +230,15 @@ the same source h5 file including all relevant links to the source dataset and o
abun_maps = np.reshape(h5_u[:,:25], (num_rows, num_cols, -1))
# Visualize the variance / statistical importance of each component:
px.plot_utils.plotScree(h5_s, title='Note the exponential drop of variance with number of components')
px.plot_utils.plot_scree(h5_s, title='Note the exponential drop of variance with number of components')
# Visualize the eigenvectors:
first_evecs = h5_v[:9, :]
px.plot_utils.plot_loops(freq_vec, np.abs(first_evecs), x_label=x_label, y_label=y_label, plots_on_side=3,
subtitles='Component', title='SVD Eigenvectors (Amplitude)', evenly_spaced=False)
subtitle_prefix='Component', title='SVD Eigenvectors (Amplitude)', evenly_spaced=False)
px.plot_utils.plot_loops(freq_vec, np.angle(first_evecs), x_label=x_label, y_label='Phase (rad)', plots_on_side=3,
subtitles='Component', title='SVD Eigenvectors (Phase)', evenly_spaced=False)
subtitle_prefix='Component', title='SVD Eigenvectors (Phase)', evenly_spaced=False)
# Visualize the abundance maps:
px.plot_utils.plot_map_stack(abun_maps, num_comps=9, heading='SVD Abundance Maps',
......@@ -251,22 +252,22 @@ the same source h5 file including all relevant links to the source dataset and o
*
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_002.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_002.png
:scale: 47
*
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_003.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_003.png
:scale: 47
*
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_004.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_004.png
:scale: 47
*
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_005.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_005.png
:scale: 47
......@@ -275,7 +276,7 @@ the same source h5 file including all relevant links to the source dataset and o
Out::
Performing SVD decomposition
SVD took 0.89 seconds. Writing results to file.
SVD took 3.17 seconds. Writing results to file.
2. KMeans Clustering
......@@ -306,7 +307,7 @@ Set the number of clusters below
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_006.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_006.png
:align: center
......@@ -354,7 +355,7 @@ For illustrative purposes, we will only take the amplitude component of the spec
.. image:: /auto_examples/images/sphx_glr_plot_spectral_unmixing_007.png
.. image:: /auto_examples/data_analysis/images/sphx_glr_plot_spectral_unmixing_007.png
:align: center
......@@ -373,7 +374,7 @@ For illustrative purposes, we will only take the amplitude component of the spec
**Total running time of the script:** ( 0 minutes 13.553 seconds)
**Total running time of the script:** ( 0 minutes 32.567 seconds)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment