-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Rätz
committed
Dec 23, 2024
1 parent
e831ebf
commit 6868856
Showing
2 changed files
with
184 additions
and
184 deletions.
There are no files selected for viewing
366 changes: 183 additions & 183 deletions
366
docs/jupyter_notebooks/e1_pull_DWD_historical_to_all_output_formats.ipynb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,184 +1,184 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "# AixWeather Tutorial\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "This example is a step-by-step guide to pull historical weather data from the DWD open access database\nand convert it to different output formats.\nThus showing all possible steps on how to use AixWeather.\nTo run the tool for other weather data sources, just change the project class.\nThe rest of the code is streamlined and will remain the same.\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Enable logging, this is just to get more feedback through the terminal\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import logging\n\nlogging.basicConfig(level=\"DEBUG\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Choose the project class according to the desired weather data origin.\nCheck the project_class.py file or the API documentation to see which classes are available.\n[project classes](https://rwth-ebc.github.io/AixWeather//4-joss_paper//docs/code/aixweather.html#module-aixweather.project_class)\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassDWDHistorical\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 0: Initiate the project class which contains or creates all variables and functions.\nFor this, we use the datetime module to specify dates.\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import datetime as dt\n\nproject = ProjectClassDWDHistorical(\n start=dt.datetime(2022, 1, 1),\n end=dt.datetime(2023, 1, 1),\n station=15000,\n # specify whether nan-values should be filled when exporting\n fillna=True,\n # define results path if desired\n abs_result_folder_path=None,\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 1: Import historical weather from the DWD open access database\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.import_data()\nprint(f\"\\nHow the imported data looks like:\\n{project.imported_data.head()}\\n\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 2: Convert this imported data to the core format\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.data_2_core_data()\nprint(f\"\\nHow the core data looks like:\\n{project.core_data.head()}\\n\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "You may optionally also use data quality check utils, like:\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.data_quality_checks import plot_heatmap_missing_values\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Plot data quality\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "plot = plot_heatmap_missing_values(project.core_data)\nplot.show()\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 3: Convert this core data to an output data format of your choice\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.core_2_csv()\nproject.core_2_json()\nproject.core_2_pickle()\nproject.core_2_mos()\nproject.core_2_epw()\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "By the way, if you want to run this with some other weather data source, here are some copy-paste snippets to get you started:\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For DWD Forecast data\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassDWDForecast\n\nproject = ProjectClassDWDForecast(\n station=\"06710\", # Example station: Lausanne\n abs_result_folder_path=None, # Optional: specify result path\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For EPW and TRY we need to import the .epw or .dat file\nThese imports are just to create the path to the file stored in the tests folder\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import os\nfrom aixweather import definitions\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For EPW files\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassEPW\n\nproject = ProjectClassEPW(\n path=os.path.join(\n definitions.ROOT_DIR,\n \"tests/test_files/regular_tests/EPW/test_EPW_Essen_Ladybug/input/DEU_NW_Essen_104100_TRY2035_05_Wint_BBSR.epw\",\n ), # Example: EPW weather file for Essen\n abs_result_folder_path=None,\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For TRY (Test Reference Year) data\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassTRY\n\nproject = ProjectClassTRY(\n path=os.path.join(\n definitions.ROOT_DIR,\n \"tests/test_files/regular_tests/TRY/test_TRY2015/input/TRY2015_507931060546_Jahr.dat\"\n ),\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.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "# AixWeather Tutorial\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "This example is a step-by-step guide to pull historical weather data from the DWD open access database\nand convert it to different output formats.\nThus showing all possible steps on how to use AixWeather.\nTo run the tool for other weather data sources, just change the project class.\nThe rest of the code is streamlined and will remain the same.\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Enable logging, this is just to get more feedback through the terminal\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import logging\n\nlogging.basicConfig(level=\"DEBUG\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Choose the project class according to the desired weather data origin.\nCheck the project_class.py file or the API documentation to see which classes are available.\n[project classes](https://rwth-ebc.github.io/AixWeather//4-joss_paper//docs/code/aixweather.html#module-aixweather.project_class)\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassDWDHistorical\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 0: Initiate the project class which contains or creates all variables and functions.\nFor this, we use the datetime module to specify dates.\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import datetime as dt\n\nproject = ProjectClassDWDHistorical(\n start=dt.datetime(2022, 1, 1),\n end=dt.datetime(2023, 1, 1),\n station=15000,\n # specify whether nan-values should be filled when exporting\n fillna=True,\n # define results path if desired\n abs_result_folder_path=None,\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 1: Import historical weather from the DWD open access database\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.import_data()\nprint(f\"\\nHow the imported data looks like:\\n{project.imported_data.head()}\\n\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 2: Convert this imported data to the core format\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.data_2_core_data()\nprint(f\"\\nHow the core data looks like:\\n{project.core_data.head()}\\n\")\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "You may optionally also use data quality check utils, like:\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.data_quality_checks import plot_heatmap_missing_values\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Plot data quality\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "plot = plot_heatmap_missing_values(project.core_data)\nplot.show()\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "Step 3: Convert this core data to an output data format of your choice\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "project.core_2_csv()\nproject.core_2_json()\nproject.core_2_pickle()\nproject.core_2_mos()\nproject.core_2_epw()\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "By the way, if you want to run this with some other weather data source, here are some copy-paste snippets to get you started:\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For DWD Forecast data\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassDWDForecast\n\nproject = ProjectClassDWDForecast(\n station=\"06710\", # Example station: Lausanne\n abs_result_folder_path=None, # Optional: specify result path\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For EPW and TRY we need to import the .epw or .dat file\nThese imports are just to create the path to the file stored in the tests folder\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "import os\nfrom aixweather import definitions\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For EPW files\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassEPW\n\nproject = ProjectClassEPW(\n path=os.path.join(\n definitions.ROOT_DIR,\n \"tests/test_files/regular_tests/EPW/test_EPW_Essen_Ladybug/input/DEU_NW_Essen_104100_TRY2035_05_Wint_BBSR.epw\",\n ), # Example: EPW weather file for Essen\n abs_result_folder_path=None,\n)\n" | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": "For TRY (Test Reference Year) data\n" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": "from aixweather.project_class import ProjectClassTRY\n\nproject = ProjectClassTRY(\n path=os.path.join(\n definitions.ROOT_DIR,\n \"tests/test_files/regular_tests/TRY/test_TRY2015/input/TRY2015_507931060546_Jahr.dat\"\n ),\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.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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