Created
March 20, 2024 16:58
-
-
Save aliaksei135/972d45673eb8b801cafe45a72f866fec to your computer and use it in GitHub Desktop.
Rough calculation of proportion of VMC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Requirement already satisfied: meteostat in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (1.6.7)\n", | |
"Requirement already satisfied: pandas>=1.1 in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from meteostat) (2.2.1)\n", | |
"Requirement already satisfied: pytz in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from meteostat) (2024.1)\n", | |
"Requirement already satisfied: numpy in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from meteostat) (1.26.4)\n", | |
"Requirement already satisfied: python-dateutil>=2.8.2 in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from pandas>=1.1->meteostat) (2.8.2)\n", | |
"Requirement already satisfied: tzdata>=2022.7 in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from pandas>=1.1->meteostat) (2024.1)\n", | |
"Requirement already satisfied: six>=1.5 in /home/aliaksei/PycharmProjects/URE/venv/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas>=1.1->meteostat) (1.16.0)\n" | |
] | |
} | |
], | |
"source": [ | |
"!pip install meteostat\n", | |
"\n", | |
"import meteostat as ms\n", | |
"from datetime import datetime,timedelta" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"Warning: Cannot load hourly/2017/03866.csv.gz from https://bulk.meteostat.net/v2/\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: Support for nested sequences for 'parse_dates' in pd.read_csv is deprecated. Combine the desired columns with pd.to_datetime after parsing instead.\n", | |
"FutureWarning: 'H' is deprecated and will be removed in a future version, please use 'h' instead.\n" | |
] | |
} | |
], | |
"source": [ | |
"START = datetime(2017, 1, 1)\n", | |
"END = datetime(2023, 12, 31)\n", | |
"LOC = ms.Point(50.777934, -1.086725, 100) # Portsmouth, UK\n", | |
"\n", | |
"data = ms.Hourly(LOC, START, END)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"df = data.fetch()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Hours between 2017-01-01 00:00:00 and 2023-12-31 00:00:00: 61320\n" | |
] | |
} | |
], | |
"source": [ | |
"print(f'Hours between {START} and {END}: {(END-START).days * 24}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"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>temp</th>\n", | |
" <th>dwpt</th>\n", | |
" <th>rhum</th>\n", | |
" <th>prcp</th>\n", | |
" <th>snow</th>\n", | |
" <th>wdir</th>\n", | |
" <th>wspd</th>\n", | |
" <th>wpgt</th>\n", | |
" <th>pres</th>\n", | |
" <th>tsun</th>\n", | |
" <th>coco</th>\n", | |
" <th>hour</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>time</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", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>2017-01-01 13:00:00</th>\n", | |
" <td>8.5</td>\n", | |
" <td>6.5</td>\n", | |
" <td>87.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>230.0</td>\n", | |
" <td>7.6</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1014.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>8.0</td>\n", | |
" <td>13</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2017-01-01 15:00:00</th>\n", | |
" <td>7.5</td>\n", | |
" <td>6.4</td>\n", | |
" <td>93.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>20.0</td>\n", | |
" <td>5.4</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1016.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>7.0</td>\n", | |
" <td>15</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2017-01-01 16:00:00</th>\n", | |
" <td>3.5</td>\n", | |
" <td>2.5</td>\n", | |
" <td>93.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>10.0</td>\n", | |
" <td>20.5</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1017.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>7.0</td>\n", | |
" <td>16</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2017-01-01 17:00:00</th>\n", | |
" <td>2.5</td>\n", | |
" <td>1.5</td>\n", | |
" <td>93.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>20.0</td>\n", | |
" <td>18.4</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1018.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>7.0</td>\n", | |
" <td>17</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2017-01-01 18:00:00</th>\n", | |
" <td>1.5</td>\n", | |
" <td>0.5</td>\n", | |
" <td>93.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>20.0</td>\n", | |
" <td>18.4</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1019.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>7.0</td>\n", | |
" <td>18</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2023-12-30 15:00:00</th>\n", | |
" <td>11.5</td>\n", | |
" <td>9.6</td>\n", | |
" <td>88.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>180.0</td>\n", | |
" <td>24.1</td>\n", | |
" <td>46.3</td>\n", | |
" <td>1001.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>4.0</td>\n", | |
" <td>15</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2023-12-30 16:00:00</th>\n", | |
" <td>11.5</td>\n", | |
" <td>9.6</td>\n", | |
" <td>88.0</td>\n", | |
" <td>0.1</td>\n", | |
" <td>NaN</td>\n", | |
" <td>180.0</td>\n", | |
" <td>24.1</td>\n", | |
" <td>46.3</td>\n", | |
" <td>1000.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>7.0</td>\n", | |
" <td>16</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2023-12-30 17:00:00</th>\n", | |
" <td>11.5</td>\n", | |
" <td>9.6</td>\n", | |
" <td>88.0</td>\n", | |
" <td>0.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>180.0</td>\n", | |
" <td>27.7</td>\n", | |
" <td>46.3</td>\n", | |
" <td>998.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>8.0</td>\n", | |
" <td>17</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2023-12-30 18:00:00</th>\n", | |
" <td>11.5</td>\n", | |
" <td>9.6</td>\n", | |
" <td>88.0</td>\n", | |
" <td>0.1</td>\n", | |
" <td>NaN</td>\n", | |
" <td>170.0</td>\n", | |
" <td>22.3</td>\n", | |
" <td>46.3</td>\n", | |
" <td>997.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>8.0</td>\n", | |
" <td>18</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2023-12-30 19:00:00</th>\n", | |
" <td>11.5</td>\n", | |
" <td>9.6</td>\n", | |
" <td>88.0</td>\n", | |
" <td>0.2</td>\n", | |
" <td>NaN</td>\n", | |
" <td>160.0</td>\n", | |
" <td>24.1</td>\n", | |
" <td>48.2</td>\n", | |
" <td>995.0</td>\n", | |
" <td>NaN</td>\n", | |
" <td>8.0</td>\n", | |
" <td>19</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>27119 rows × 12 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" temp dwpt rhum prcp snow wdir wspd wpgt pres \\\n", | |
"time \n", | |
"2017-01-01 13:00:00 8.5 6.5 87.0 NaN NaN 230.0 7.6 NaN 1014.0 \n", | |
"2017-01-01 15:00:00 7.5 6.4 93.0 NaN NaN 20.0 5.4 NaN 1016.0 \n", | |
"2017-01-01 16:00:00 3.5 2.5 93.0 NaN NaN 10.0 20.5 NaN 1017.0 \n", | |
"2017-01-01 17:00:00 2.5 1.5 93.0 NaN NaN 20.0 18.4 NaN 1018.0 \n", | |
"2017-01-01 18:00:00 1.5 0.5 93.0 NaN NaN 20.0 18.4 NaN 1019.0 \n", | |
"... ... ... ... ... ... ... ... ... ... \n", | |
"2023-12-30 15:00:00 11.5 9.6 88.0 0.0 NaN 180.0 24.1 46.3 1001.0 \n", | |
"2023-12-30 16:00:00 11.5 9.6 88.0 0.1 NaN 180.0 24.1 46.3 1000.0 \n", | |
"2023-12-30 17:00:00 11.5 9.6 88.0 0.0 NaN 180.0 27.7 46.3 998.0 \n", | |
"2023-12-30 18:00:00 11.5 9.6 88.0 0.1 NaN 170.0 22.3 46.3 997.0 \n", | |
"2023-12-30 19:00:00 11.5 9.6 88.0 0.2 NaN 160.0 24.1 48.2 995.0 \n", | |
"\n", | |
" tsun coco hour \n", | |
"time \n", | |
"2017-01-01 13:00:00 NaN 8.0 13 \n", | |
"2017-01-01 15:00:00 NaN 7.0 15 \n", | |
"2017-01-01 16:00:00 NaN 7.0 16 \n", | |
"2017-01-01 17:00:00 NaN 7.0 17 \n", | |
"2017-01-01 18:00:00 NaN 7.0 18 \n", | |
"... ... ... ... \n", | |
"2023-12-30 15:00:00 NaN 4.0 15 \n", | |
"2023-12-30 16:00:00 NaN 7.0 16 \n", | |
"2023-12-30 17:00:00 NaN 8.0 17 \n", | |
"2023-12-30 18:00:00 NaN 8.0 18 \n", | |
"2023-12-30 19:00:00 NaN 8.0 19 \n", | |
"\n", | |
"[27119 rows x 12 columns]" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clean_df = df.dropna(subset=['coco'])\n", | |
"clean_df = clean_df.assign(hour=clean_df.index.hour)\n", | |
"clean_df = clean_df[(clean_df['hour'] > 6) & (clean_df['hour'] < 20)]\n", | |
"clean_df" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Hours with VMC: 20305\n", | |
"Hours with IMC: 6814\n", | |
"Percentage of VMC: 74.87370478262473%\n" | |
] | |
} | |
], | |
"source": [ | |
"# Some very generous assumptions\n", | |
"VMC_CODES = [\n", | |
" 1,\n", | |
" 2,\n", | |
" 3,\n", | |
" 7,\n", | |
" 14,\n", | |
"] # https://dev.meteostat.net/formats.html#weather-condition-codes\n", | |
"\n", | |
"vmc = clean_df[clean_df['coco'].isin(VMC_CODES)].shape[0]\n", | |
"print(f'Hours with VMC: {vmc}')\n", | |
"print(f'Hours with IMC: {clean_df.shape[0] - vmc}')\n", | |
"print(f'Percentage of VMC: {vmc / clean_df.shape[0] * 100}%')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "venv", | |
"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.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment