{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import floatview\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.cluster import AgglomerativeClustering\n",
    "from sklearn.cluster import DBSCAN\n",
    "from sklearn.datasets import load_iris\n",
    "from sklearn.feature_selection import SelectKBest\n",
    "from sklearn.feature_selection import chi2, f_regression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url=\"data.csv\"\n",
    "tab = pd.read_csv(url, index_col=False)\n",
    "tab = tab[tab.Ex>0]\n",
    "#tab = tab[tab.Ey<50000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gmw = floatview.GlueManagerWidget(tab, modal=True, label=\"nanohubCache\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_clusters = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cluster = AgglomerativeClustering(n_clusters=n_clusters, affinity='euclidean', linkage='ward') \n",
    "df = gmw.gluemanager.data.to_dataframe()\n",
    "diff = (df.columns.difference(['E1', 'E2', 'nu12', 'Ex', 'Ey', 'nu', 'Gxy']))\n",
    "cluster.fit_predict(df.drop(diff, axis=1)) \n",
    "for i in range(n_clusters):\n",
    "  state = np.nonzero(cluster.labels_== i)\n",
    "  gmw.gluemanager.updateSelection(state)\n",
    "  gmw.gluemanager.createSubsetFromSelection(label='cluster'+str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#cluster.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gmw.gluemanager.newView(\"parallels\", ['E1', 'E2', 'nu12', 'G12', 'alpha1', 'alpha2', 'h0', 'Nx', 'Ny', 'Nxy', 'Mx', 'My', 'Mxy', 'Ti', 'Tf', 'Ex', 'Ey', 'nu', 'Gxy', 'alphax', 'alphay', 'alphaxy'], \"Parallel\");\n",
    "gmw.gluemanager.newView(\"parallels\", ['E1', 'E2', 'nu12', 'Ex', 'Ey', 'nu', 'Gxy'], \"Parallel\");\n",
    "gmw.gluemanager.newView(\"histogram\", ['Ex'], \"Ex\");\n",
    "gmw.gluemanager.newView(\"histogram\", ['Ey'], \"Ey\");\n",
    "gmw.gluemanager.newView(\"scatter\", ['Ex', 'Ey'], \"Scatter\");"
   ]
  }
 ],
 "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
