Skip to content

Commit

Permalink
add util.py, with nordic replace and kelvin to celsius function
Browse files Browse the repository at this point in the history
  • Loading branch information
torave committed Mar 30, 2025
1 parent 6b94d68 commit e276f2e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1,022 deletions.
159 changes: 11 additions & 148 deletions notebooks/notebook_current_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data fetch: ok\n"
]
}
],
"outputs": [],
"source": [
"import sys\n",
"import os\n",
Expand All @@ -40,14 +32,13 @@
"# Now we can import the fucntion from the module\n",
"from my_package.fetch_current_data import fetch_current_data\n",
"\n",
"# Import function to replace nordic (æøå)\n",
"from my_package.util import replace_nordic\n",
"\n",
"# User input the city, for the weather\n",
"city_name = input(\"Enter a city in Norway: \")\n",
"\n",
"for letter in city_name:\n",
" if letter in 'æøå':\n",
" city_name = city_name.replace('æ', 'ae')\n",
" city_name = city_name.replace('ø', 'o')\n",
" city_name = city_name.replace('å', 'aa')\n",
"city_name = replace_nordic(city_name)\n",
"\n",
"# Stores the return of the function\n",
"data, folder = fetch_current_data(city_name)"
Expand All @@ -68,17 +59,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data has been written to /Users/toravestlund/Documents/ITBAITBEDR/TDT4114 - Anvendt programmering/anvendt_mappe/data/../data/output_current_data/data_aaa_maura.json\n"
]
}
],
"outputs": [],
"source": [
"# Gets the absolute path to the src folder\n",
"sys.path.append(os.path.abspath(\"../src\"))\n",
Expand All @@ -103,44 +86,9 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'coord': {'lon': 11.0167, 'lat': 60.25},\n",
" 'weather': [{'id': 500,\n",
" 'main': 'Rain',\n",
" 'description': 'light rain',\n",
" 'icon': '10d'}],\n",
" 'base': 'stations',\n",
" 'main': {'temp': 3.14,\n",
" 'temp_min': 2.52,\n",
" 'temp_max': 3.84,\n",
" 'humidity': 93,\n",
" 'sea_level': 1003,\n",
" 'grnd_level': 965},\n",
" 'visibility': 10000,\n",
" 'wind': {'speed': 1.54, 'deg': 70},\n",
" 'rain': {'1h': 0.11},\n",
" 'clouds': {'all': 75},\n",
" 'dt': 1743329160,\n",
" 'sys': {'type': 1,\n",
" 'id': 1624,\n",
" 'country': 'NO',\n",
" 'sunrise': 1743309996,\n",
" 'sunset': 1743357233},\n",
" 'timezone': 7200,\n",
" 'id': 3146270,\n",
" 'name': 'Maura',\n",
" 'cod': 200}"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import json\n",
"\n",
Expand Down Expand Up @@ -175,92 +123,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>name</th>\n",
" <th>main.temp</th>\n",
" <th>main.humidity</th>\n",
" <th>main.sea_level</th>\n",
" <th>main.grnd_level</th>\n",
" <th>wind.speed</th>\n",
" <th>rain.1h</th>\n",
" <th>clouds.all</th>\n",
" <th>sys.country</th>\n",
" <th>sys.sunrise</th>\n",
" <th>sys.sunset</th>\n",
" </tr>\n",
" <tr>\n",
" <th>dt</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2025-03-30 10:06:00</th>\n",
" <td>Maura</td>\n",
" <td>3.14</td>\n",
" <td>93</td>\n",
" <td>1003</td>\n",
" <td>965</td>\n",
" <td>1.54</td>\n",
" <td>0.11</td>\n",
" <td>75</td>\n",
" <td>NO</td>\n",
" <td>2025-03-30 04:46:36</td>\n",
" <td>2025-03-30 17:53:53</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name main.temp main.humidity main.sea_level \\\n",
"dt \n",
"2025-03-30 10:06:00 Maura 3.14 93 1003 \n",
"\n",
" main.grnd_level wind.speed rain.1h clouds.all \\\n",
"dt \n",
"2025-03-30 10:06:00 965 1.54 0.11 75 \n",
"\n",
" sys.country sys.sunrise sys.sunset \n",
"dt \n",
"2025-03-30 10:06:00 NO 2025-03-30 04:46:36 2025-03-30 17:53:53 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
Expand Down
19 changes: 11 additions & 8 deletions notebooks/notebook_one_day_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
" # Prevents from getting data for the current day, or the future\n",
" if dt >= datetime.datetime.now():\n",
" print(\"Failed, cant use future dates\")\n",
" return None\n",
"\n",
" # If \n",
" raise ValueError\n",
"\n",
" # Prints the date chosen\n",
" print(f\"Selected date: {year}-{month:02d}-{day:02d}\")\n",
Expand Down Expand Up @@ -96,18 +98,19 @@
"# Now we can import the fucntion from the module\n",
"from my_package.fetch_data import fetch_data\n",
"\n",
"# Import function to replace nordic (æøå)\n",
"from my_package.util import replace_nordic\n",
"\n",
"# User choose a city they want the weather data from\n",
"city_name = input(\"Enter city name: \")\n",
"\n",
"for letter in city_name:\n",
" if letter in 'æøå':\n",
" city_name = city_name.replace('æ', 'ae')\n",
" city_name = city_name.replace('ø', 'o')\n",
" city_name = city_name.replace('å', 'aa')\n",
"city_name = replace_nordic(city_name)\n",
"\n",
"# Start_date is the first timestamp, end_date is the last\n",
"start_date, end_date = timestamps[0], timestamps[-1]\n",
"\n",
"city_name = replace_nordic(city_name)\n",
"\n",
"# Stores the values in the variables\n",
"weather_data, folder = fetch_data(start_date, end_date, city_name)"
]
Expand Down Expand Up @@ -533,8 +536,8 @@
"ax1.grid(axis = 'x')\n",
"\n",
"# Plot the wind at the second x-axis (the axis below)\n",
"ax3.plot(x_axis, wind_gust, color='tab:purple', label='Wind_gust')\n",
"ax3.plot(x_axis, wind_speed, color='tab:purple', linestyle='dashed', label='Wind_speed')\n",
"ax3.plot(x_axis, wind_gust, color='tab:purple', linestyle='dashed', label='Wind_gust')\n",
"ax3.plot(x_axis, wind_speed, color='tab:purple', label='Wind_speed')\n",
"ax3.set_ylabel('Wind (m/s)')\n",
"\n",
"# Add x_label visible for both x-axis\n",
Expand Down
Loading

0 comments on commit e276f2e

Please sign in to comment.