{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "56c93651",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\functions.py\n"
     ]
    }
   ],
   "source": [
    "from dash import callback, Output, Input, State, html\n",
    "from dash import callback_context\n",
    "import pandas as pd\n",
    "import plotly.graph_objects as go\n",
    "from dash.dependencies import Input, Output\n",
    "import plotly.express as px\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from scipy.interpolate import make_interp_spline\n",
    "import matplotlib.image as mpimg\n",
    "import os \n",
    "import sys\n",
    "# Get the grandparent directory\n",
    "# Add the grandparent directory where the correct functions.py is\n",
    "grandparent_path = os.path.abspath(os.path.join(os.getcwd(), '..'))\n",
    "sys.path.insert(0, grandparent_path)\n",
    "\n",
    "# Now re-import the correct functions.py\n",
    "import importlib\n",
    "import functions\n",
    "importlib.reload(functions)  # Force reload in case it's cached\n",
    "from Thesis_plot.functions import irradiance_analysis\n",
    "\n",
    "print(functions.__file__)  # Should now show ...\\Data\\dash\\functions.py\n",
    "from plotly.subplots import make_subplots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "622fb7d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\functions.py\n"
     ]
    }
   ],
   "source": [
    "print(functions.__file__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f77fdfbe",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:129: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Ceuta = Ceuta.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:130: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Gotland = Gotland.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:131: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Gulf_Gabes = Gulf_Gabes.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:132: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Pantelleria = Pantelleria.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:133: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Zadar = Zadar.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:134: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  avg_hourly_irradiance_Jersey = Jersey.groupby(['Month', 'Day', 'Hour'])['G'].mean().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:136: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Cauta = avg_hourly_irradiance_Ceuta.groupby(['Month', 'Day'])['G'].sum().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:137: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Gotland = avg_hourly_irradiance_Gotland.groupby(['Month', 'Day'])['G'].sum().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:138: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Gulf_Gabes = avg_hourly_irradiance_Gulf_Gabes.groupby(['Month', 'Day'])['G'].sum().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:139: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Pantelleria = avg_hourly_irradiance_Pantelleria.groupby(['Month', 'Day'])['G'].sum().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:140: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Zadar = avg_hourly_irradiance_Zadar.groupby(['Month', 'Day'])['G'].sum().reset_index()\n",
      "c:\\Users\\youss\\Documents\\Tesi\\Data\\dash\\Thesis_plot\\functions.py:141: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
      "  daily_irradiance_Jersey = avg_hourly_irradiance_Jersey.groupby(['Month', 'Day'])['G'].sum().reset_index()\n"
     ]
    }
   ],
   "source": [
    "combined_irradiance = irradiance_analysis()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "86e8d1d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "combined_irradiance.rename(columns={\"Gulf_Gabes\": \"Gulf of Gabes\"}, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "085ca43d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 182812 characters]",
      "text/plain": [
       "<Figure size 1200x600 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.dates as mdates\n",
    "from matplotlib.ticker import MaxNLocator\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "\n",
    "# List of locations (column names)\n",
    "locations = ['Ceuta', 'Gotland', 'Gulf of Gabes', 'Pantelleria', 'Zadar', 'Jersey']\n",
    "\n",
    "# Shaded periods (months where FPV is removed)\n",
    "shaded_periods = {\n",
    "    \"Ceuta\": [1, 2, 3, 4],          # Jan to Apr\n",
    "    \"Jersey\": [11, 12, 1, 2, 3],    # Nov to Mar\n",
    "    \"Zadar\": [11, 12, 1, 2],        # Nov to Feb\n",
    "    \"Gulf of Gabes\": [1, 2, 3, 4]      # Jan to Apr\n",
    "    # Gotland and Pantelleria are always active\n",
    "}\n",
    "\n",
    "# Convert Date column to datetime if not already\n",
    "combined_irradiance['Date'] = pd.to_datetime(combined_irradiance['Date'])\n",
    "combined_irradiance['Month'] = combined_irradiance['Date'].dt.month\n",
    "\n",
    "# Create subplots\n",
    "fig, axes = plt.subplots(2, 3, figsize=(12, 6), sharey='row')\n",
    "axes = axes.flatten()\n",
    "for i, loc in enumerate(locations):\n",
    "    ax = axes[i]\n",
    "    \n",
    "    # Plot irradiance\n",
    "    ax.plot(combined_irradiance['Date'], combined_irradiance[loc], label=loc, linewidth=0.8, color='goldenrod')\n",
    "    \n",
    "    # Shade days belonging to the removal months\n",
    "    if loc in shaded_periods:\n",
    "        for month in shaded_periods[loc]:\n",
    "            dates_to_shade = combined_irradiance[combined_irradiance['Month'] == month]['Date']\n",
    "            for date in dates_to_shade:\n",
    "                ax.axvspan(date, date + pd.Timedelta(days=1), color='grey', alpha=0.1)\n",
    "    \n",
    "    ax.set_title(loc)\n",
    "    ax.set_xlabel(\"Month\")\n",
    "    ax.set_ylabel(r\"$G^{\\text{daily}}_d$ [Wh/m²]\")\n",
    "    ax.grid(True)\n",
    "    \n",
    "    # Format x-axis to show only months\n",
    "    ax.xaxis.set_major_formatter(mdates.DateFormatter('%b'))  # %b for abbreviated month name, %m for month number\n",
    "    ax.xaxis.set_major_locator(mdates.MonthLocator())         # One tick per month\n",
    "    ax.xaxis.set_tick_params(rotation=45)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n"
   ]
  }
 ],
 "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.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
