{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d19a1c0c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "import geopandas as gpd\n",
    "\n",
    "from fracability import Entities\n",
    "from fracability.operations.Geometry import center_object, tidy_intersections\n",
    "from fracability.operations.Cleaners import connect_dots\n",
    "from fracability.operations.Topology import nodes_conn\n",
    "from fracability.operations.Statistics import NetworkFitter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0cd98e0e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "n_path = 'fracability/datasets/Fracture_network.shp'\n",
    "b_path = 'fracability/datasets/Interpretation_boundary_laghettoSalza.shp'\n",
    "\n",
    "\n",
    "fracs = gpd.read_file(n_path)\n",
    "\n",
    "bound_gpd = gpd.read_file(b_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d54d74f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fractures = Entities.Fractures(fracs)\n",
    "\n",
    "boundaries = Entities.Boundary(bound_gpd)\n",
    "\n",
    "# clean_dup_points(fractures)\n",
    "\n",
    "fracture_net = Entities.FractureNetwork()\n",
    "\n",
    "fracture_net.add_fractures(fractures)\n",
    "\n",
    "fracture_net.add_boundaries(boundaries)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7b01eb9c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "center_object(fracture_net)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "68d67940",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculating intersections -\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-\\|/-"
     ]
    }
   ],
   "source": [
    "tidy_intersections(fracture_net)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d7b692d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "connect_dots(fracture_net)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a309b4ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "nodes_conn(fracture_net)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "69204144",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/gabriele/.local/lib/python3.10/site-packages/pyvista/jupyter/notebook.py:58: UserWarning: Failed to use notebook backend: \n",
      "\n",
      "No module named 'trame'\n",
      "\n",
      "Falling back to a static output.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 67608 characters]",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=1024x768>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fracture_net.vtk_object.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a7f85bc0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fitter = NetworkFitter(fracture_net)\n",
    "fitter.fit('Fit_Lognormal_2P')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "bf8062d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 35864 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fitter.plot_kde()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "261d7f27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 81744 characters]",
      "text/plain": [
       "<Figure size 900x700 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fitter.summary_plot(x_max=20)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b2815054",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30168 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r"
     ]
    }
   ],
   "source": [
    "fitter.plot_function('PDF', x_max=25)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88e21d01",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bed7b641",
   "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
