Skip to content

Commit

Permalink
Merge pull request #25 from VisheshSaluja/Model_Training
Browse files Browse the repository at this point in the history
added code- Prediction File
  • Loading branch information
VisheshSaluja authored Aug 24, 2024
2 parents 7763831 + eb96136 commit 2014a16
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 17 deletions.
106 changes: 89 additions & 17 deletions book/chapters/Predictions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,80 @@
"Finally, we are at the final Chapter where we see the end-product of the model created. As we venture into this critical phase, the model_predict script emerges, guiding the way toward understanding and anticipating the future of snow water equivalent (SWE) through the ExtraTree model. This chapter delves into the intricacies of this script, unraveling the processes that transforms raw, unprocessed data into precise predictions that illuminate the path forward."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"import joblib\n",
"import pandas as pd\n",
"from sklearn.preprocessing import MinMaxScaler, StandardScaler\n",
"import numpy as np\n",
"import os\n",
"import random\n",
"import string\n",
"import shutil\n",
"\n",
"\n",
"def generate_random_string(length):\n",
" # Define the characters that can be used in the random string\n",
" characters = string.ascii_letters + string.digits # You can customize this to include other characters if needed\n",
"\n",
" # Generate a random string of the specified length\n",
" random_string = ''.join(random.choice(characters) for _ in range(length))\n",
"\n",
" return random_string\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"homedir = os.path.expanduser('~')\n",
"work_dir = f\"{homedir}/gridmet_test_run\"\n",
"\n",
"test_start_date = ''\n",
"\n",
"selected_columns = [\n",
" 'swe_value',\n",
" 'SWE',\n",
" 'cumulative_SWE',\n",
"# 'cumulative_relative_humidity_rmin',\n",
"# 'cumulative_air_temperature_tmmx', \n",
"# 'cumulative_air_temperature_tmmn',\n",
"# 'cumulative_relative_humidity_rmax',\n",
"# 'cumulative_potential_evapotranspiration',\n",
"# 'cumulative_wind_speed',\n",
" #'cumulative_fsca',\n",
" 'fsca',\n",
" 'air_temperature_tmmx', \n",
" 'air_temperature_tmmn', \n",
" 'potential_evapotranspiration', \n",
" 'relative_humidity_rmax', \n",
" 'Elevation',\t\n",
" 'Slope',\t\n",
" 'Curvature',\t\n",
" 'Aspect',\t\n",
" 'Eastness',\t\n",
" 'Northness',\n",
"]\n",
"\n",
"\n",
"def month_to_season(month):\n",
" if 3 <= month <= 5:\n",
" return 1\n",
" elif 6 <= month <= 8:\n",
" return 2\n",
" elif 9 <= month <= 11:\n",
" return 3\n",
" else:\n",
" return 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -43,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 35,
"metadata": {
"id": "LkzaZTCtgJ5R"
},
Expand Down Expand Up @@ -71,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 36,
"metadata": {
"id": "wXQ-4JBdgjdG"
},
Expand Down Expand Up @@ -125,7 +199,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 37,
"metadata": {
"id": "d7EsL7aVhltv"
},
Expand Down Expand Up @@ -157,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 38,
"metadata": {
"id": "Uv3nAmw-h3EO"
},
Expand Down Expand Up @@ -202,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -279,7 +353,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 40,
"metadata": {
"id": "aa_il7YriZlE"
},
Expand Down Expand Up @@ -339,6 +413,13 @@
"## 9.5 Results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![SWE MAP](../img/SWE_Map.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -384,7 +465,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 42,
"metadata": {
"id": "qMeBEobUoJcW"
},
Expand Down Expand Up @@ -435,7 +516,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 43,
"metadata": {
"id": "7h9706LXVba2"
},
Expand Down Expand Up @@ -589,15 +670,6 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "JHTfd_L9UkBt"
},
"source": [
"![SWE MAP](../img/SWE_Map.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions book/chapters/ghcnd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@
"# result_df.to_csv(csv_file, index=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Active Stations <br /> \n",
"![](../img/ghcnd/Stations.png)\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
Expand Down
Binary file added book/img/ghcnd/Stations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2014a16

Please sign in to comment.