{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Instrumentación computacional inteligente\n", "## Estudio de datos de estaciones meteorológicas\n", "\n", "### Fernando Ayats Llamas\n", "### 2023-04-11" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "hide-cell" ] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `c:\\Users\\ayats\\Documents\\ici-parsing`\n" ] }, { "data": { "application/vnd.webio.node+json": { "children": [], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": {}, "type": "node" }, "text/html": [ "
\n", "

The WebIO Jupyter extension was not detected. See the\n", "\n", " WebIO Jupyter integration documentation\n", "\n", "for more information.\n", "

\n" ], "text/plain": [ "WebIO._IJuliaInit()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "using Pkg\n", "Pkg.activate(@__DIR__);\n", "Pkg.instantiate()\n", "\n", "using StatsPlots\n", "using CSV, DataFrames\n", "\n", "import Dates: DateTime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
120×2 DataFrame
95 rows omitted
Rowvaluets
Float64DateTime
15.42021-01-01T01:00:00
24.22021-01-01T02:00:00
34.12021-01-01T03:00:00
44.12021-01-01T04:00:00
53.82021-01-01T05:00:00
63.32021-01-01T06:00:00
72.72021-01-01T07:00:00
82.92021-01-01T08:00:00
93.62021-01-01T09:00:00
104.22021-01-01T10:00:00
114.82021-01-01T11:00:00
125.52021-01-01T12:00:00
136.52021-01-01T13:00:00
1097.32021-01-05T13:00:00
1106.62021-01-05T14:00:00
1116.92021-01-05T15:00:00
1126.12021-01-05T16:00:00
1135.62021-01-05T17:00:00
1145.12021-01-05T18:00:00
1154.72021-01-05T19:00:00
1163.92021-01-05T20:00:00
1172.92021-01-05T21:00:00
1181.52021-01-05T22:00:00
1192.32021-01-05T23:00:00
1202.32021-01-06T00:00:00
" ], "text/latex": [ "\\begin{tabular}{r|cc}\n", "\t& value & ts\\\\\n", "\t\\hline\n", "\t& Float64 & DateTime\\\\\n", "\t\\hline\n", "\t1 & 5.4 & 2021-01-01T01:00:00 \\\\\n", "\t2 & 4.2 & 2021-01-01T02:00:00 \\\\\n", "\t3 & 4.1 & 2021-01-01T03:00:00 \\\\\n", "\t4 & 4.1 & 2021-01-01T04:00:00 \\\\\n", "\t5 & 3.8 & 2021-01-01T05:00:00 \\\\\n", "\t6 & 3.3 & 2021-01-01T06:00:00 \\\\\n", "\t7 & 2.7 & 2021-01-01T07:00:00 \\\\\n", "\t8 & 2.9 & 2021-01-01T08:00:00 \\\\\n", "\t9 & 3.6 & 2021-01-01T09:00:00 \\\\\n", "\t10 & 4.2 & 2021-01-01T10:00:00 \\\\\n", "\t11 & 4.8 & 2021-01-01T11:00:00 \\\\\n", "\t12 & 5.5 & 2021-01-01T12:00:00 \\\\\n", "\t13 & 6.5 & 2021-01-01T13:00:00 \\\\\n", "\t14 & 6.4 & 2021-01-01T14:00:00 \\\\\n", "\t15 & 4.3 & 2021-01-01T15:00:00 \\\\\n", "\t16 & 3.4 & 2021-01-01T16:00:00 \\\\\n", "\t17 & 3.5 & 2021-01-01T17:00:00 \\\\\n", "\t18 & 3.6 & 2021-01-01T18:00:00 \\\\\n", "\t19 & 3.6 & 2021-01-01T19:00:00 \\\\\n", "\t20 & 3.7 & 2021-01-01T20:00:00 \\\\\n", "\t21 & 3.7 & 2021-01-01T21:00:00 \\\\\n", "\t22 & 3.6 & 2021-01-01T22:00:00 \\\\\n", "\t23 & 3.5 & 2021-01-01T23:00:00 \\\\\n", "\t24 & 3.0 & 2021-01-02T00:00:00 \\\\\n", "\t25 & 2.4 & 2021-01-02T01:00:00 \\\\\n", "\t26 & 2.0 & 2021-01-02T02:00:00 \\\\\n", "\t27 & 1.6 & 2021-01-02T03:00:00 \\\\\n", "\t28 & 1.0 & 2021-01-02T04:00:00 \\\\\n", "\t29 & 0.4 & 2021-01-02T05:00:00 \\\\\n", "\t30 & 1.0 & 2021-01-02T06:00:00 \\\\\n", "\t$\\dots$ & $\\dots$ & $\\dots$ \\\\\n", "\\end{tabular}\n" ], "text/plain": [ "\u001b[1m120×2 DataFrame\u001b[0m\n", "\u001b[1m Row \u001b[0m│\u001b[1m value \u001b[0m\u001b[1m ts \u001b[0m\n", " │\u001b[90m Float64 \u001b[0m\u001b[90m DateTime \u001b[0m\n", "─────┼──────────────────────────────\n", " 1 │ 5.4 2021-01-01T01:00:00\n", " 2 │ 4.2 2021-01-01T02:00:00\n", " 3 │ 4.1 2021-01-01T03:00:00\n", " 4 │ 4.1 2021-01-01T04:00:00\n", " 5 │ 3.8 2021-01-01T05:00:00\n", " 6 │ 3.3 2021-01-01T06:00:00\n", " 7 │ 2.7 2021-01-01T07:00:00\n", " 8 │ 2.9 2021-01-01T08:00:00\n", " 9 │ 3.6 2021-01-01T09:00:00\n", " 10 │ 4.2 2021-01-01T10:00:00\n", " 11 │ 4.8 2021-01-01T11:00:00\n", " ⋮ │ ⋮ ⋮\n", " 111 │ 6.9 2021-01-05T15:00:00\n", " 112 │ 6.1 2021-01-05T16:00:00\n", " 113 │ 5.6 2021-01-05T17:00:00\n", " 114 │ 5.1 2021-01-05T18:00:00\n", " 115 │ 4.7 2021-01-05T19:00:00\n", " 116 │ 3.9 2021-01-05T20:00:00\n", " 117 │ 2.9 2021-01-05T21:00:00\n", " 118 │ 1.5 2021-01-05T22:00:00\n", " 119 │ 2.3 2021-01-05T23:00:00\n", " 120 │ 2.3 2021-01-06T00:00:00\n", "\u001b[36m 99 rows omitted\u001b[0m" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = CSV.File(\n", " open(\"data/Grazalema_AEMET_2021-2022.csv\");\n", " normalizenames=true,\n", " select=[:ts, :value],\n", " types=Dict(:ts => DateTime),\n", " dateformat=\"yyyy-mm-dd HH:MM:SS.s\"\n", ") |> DataFrame\n", "\n", "data = data[1:24*5, :]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorbar": { "len": 0.914342738407699, "title": "", "x": 0.9934383202099737, "y": 0.5329861111111112 }, "legendgroup": "Measured", "line": { "color": "rgba(0, 154, 250, 1.000)", "dash": "solid", "shape": "linear", "width": 1 }, "marker": { "color": "rgba(0, 154, 250, 1.000)", "line": { "color": "rgba(0, 0, 0, 1.000)", "width": 1 }, "size": 4, "symbol": "circle" }, "mode": "lines+markers", "name": "Measured", "showlegend": true, "type": "scatter", "x": [ 63745146000000, 63745149600000, 63745153200000, 63745156800000, 63745160400000, 63745164000000, 63745167600000, 63745171200000, 63745174800000, 63745178400000, 63745182000000, 63745185600000, 63745189200000, 63745192800000, 63745196400000, 63745200000000, 63745203600000, 63745207200000, 63745210800000, 63745214400000, 63745218000000, 63745221600000, 63745225200000, 63745228800000, 63745232400000, 63745236000000, 63745239600000, 63745243200000, 63745246800000, 63745250400000, 63745254000000, 63745257600000, 63745261200000, 63745264800000, 63745268400000, 63745272000000, 63745275600000, 63745279200000, 63745282800000, 63745286400000, 63745290000000, 63745293600000, 63745297200000, 63745300800000, 63745304400000, 63745308000000, 63745311600000, 63745315200000, 63745318800000, 63745322400000, 63745326000000, 63745329600000, 63745333200000, 63745336800000, 63745340400000, 63745344000000, 63745347600000, 63745351200000, 63745354800000, 63745358400000, 63745362000000, 63745365600000, 63745369200000, 63745372800000, 63745376400000, 63745380000000, 63745383600000, 63745387200000, 63745390800000, 63745394400000, 63745398000000, 63745401600000, 63745405200000, 63745408800000, 63745412400000, 63745416000000, 63745419600000, 63745423200000, 63745426800000, 63745430400000, 63745434000000, 63745437600000, 63745441200000, 63745444800000, 63745448400000, 63745452000000, 63745455600000, 63745459200000, 63745462800000, 63745466400000, 63745470000000, 63745473600000, 63745477200000, 63745480800000, 63745484400000, 63745488000000, 63745491600000, 63745495200000, 63745498800000, 63745502400000, 63745506000000, 63745509600000, 63745513200000, 63745516800000, 63745520400000, 63745524000000, 63745527600000, 63745531200000, 63745534800000, 63745538400000, 63745542000000, 63745545600000, 63745549200000, 63745552800000, 63745556400000, 63745560000000, 63745563600000, 63745567200000, 63745570800000, 63745574400000 ], "xaxis": "x", "y": [ 5.4, 4.2, 4.1, 4.1, 3.8, 3.3, 2.7, 2.9, 3.6, 4.2, 4.8, 5.5, 6.5, 6.4, 4.3, 3.4, 3.5, 3.6, 3.6, 3.7, 3.7, 3.6, 3.5, 3, 2.4, 2, 1.6, 1, 0.4, 1, 1, 1.4, 2.7, 4.4, 5.3, 6.1, 6.2, 6.3, 4.7, 3.4, 2.3, 2, 1.7, 2.3, 2.5, 1.4, 1.1, 1.3, 0.7, -0.9, -1.1, -1.9, -1.5, 0.3, 0.4, 1.2, 3.5, 4.4, 5, 5.8, 6, 6.7, 4.5, 3.2, 2.3, 1.2, 1, 0.7, 0.3, 0.6, 0.8, 0.5, 1.2, 1.3, 1.4, 1.9, 1, 1.9, 2, 1.9, 4, 4.1, 5.8, 6.1, 5.9, 5.4, 4.6, 4.2, 3.5, 1.4, 0.9, 1.5, 1.2, 2, 3, 2.7, 2.3, 2.6, 2.7, 3, 3.1, 2.8, 1.6, 1.1, 3.4, 5.6, 6.6, 7.6, 7.3, 6.6, 6.9, 6.1, 5.6, 5.1, 4.7, 3.9, 2.9, 1.5, 2.3, 2.3 ], "yaxis": "y" } ], "layout": { "annotations": [], "height": 400, "legend": { "bgcolor": "rgba(255, 255, 255, 1.000)", "bordercolor": "rgba(0, 0, 0, 1.000)", "borderwidth": 1, "font": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 11 }, "title": { "font": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 15 }, "text": "" }, "tracegroupgap": 0, "traceorder": "normal", "x": 1, "xanchor": "auto", "y": 1, "yanchor": "auto" }, "margin": { "b": 20, "l": 0, "r": 0, "t": 20 }, "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "showlegend": true, "width": 600, "xaxis": { "anchor": "y", "domain": [ 0.061654272382618835, 0.9934383202099737 ], "gridcolor": "rgba(0, 0, 0, 0.100)", "gridwidth": 0.5, "linecolor": "rgba(0, 0, 0, 1.000)", "mirror": false, "range": [ 63745133148000, 63745587252000 ], "showgrid": true, "showline": true, "showticklabels": true, "tickangle": 0, "tickcolor": "rgb(0, 0, 0)", "tickfont": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 11 }, "tickmode": "array", "ticks": "inside", "ticktext": [ "2021-01-01", "2021-01-02", "2021-01-03", "2021-01-04", "2021-01-05", "2021-01-06" ], "tickvals": [ 63745142400000, 63745228800000, 63745315200000, 63745401600000, 63745488000000, 63745574400000 ], "title": "Date", "titlefont": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 15 }, "type": "-", "visible": true, "zeroline": false, "zerolinecolor": "rgba(0, 0, 0, 1.000)" }, "yaxis": { "anchor": "x", "domain": [ 0.07581474190726165, 0.9901574803149606 ], "gridcolor": "rgba(0, 0, 0, 0.100)", "gridwidth": 0.5, "linecolor": "rgba(0, 0, 0, 1.000)", "mirror": false, "range": [ -5, 15 ], "showgrid": true, "showline": true, "showticklabels": true, "tickangle": 0, "tickcolor": "rgb(0, 0, 0)", "tickfont": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 11 }, "tickmode": "array", "ticks": "inside", "ticktext": [ "-5", "0", "5", "10", "15" ], "tickvals": [ -5, 0, 5, 10, 15 ], "title": "Temperature", "titlefont": { "color": "rgba(0, 0, 0, 1.000)", "family": "sans-serif", "size": 15 }, "type": "-", "visible": true, "zeroline": false, "zerolinecolor": "rgba(0, 0, 0, 1.000)" } } }, "text/html": [ "
\n", " \n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@df data plot(:ts, :value, \n", " label=\"Measured\", \n", " marker=:circle,\n", " markersize=2,\n", ")\n", "\n", "macro plot_common()\n", " return quote\n", " (-5, 15) |> ylims!\n", " \"Date\" |> xlabel!\n", " \"Temperature\" |> ylabel!\n", " end\n", "end\n", "\n", "@plot_common()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# import SingularSpectrumAnalysis as SSA\n", "\n", "# data_trend, data_season = SSA.analyze(\n", "# data[:, :value],\n", "# 20,\n", "# ) \n", "\n", "\n", "# plot(data[:, :ts], data_trend, lab=\"Trend\")\n", "# plot!(data[:, :ts], data_season, lab=\"Seasonality\")\n", "# @lims()" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.8.5", "language": "julia", "name": "julia-1.8" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }