Skip to content

Commit

Permalink
chore(examples): Automatic commit of example files in Markdown and Ju…
Browse files Browse the repository at this point in the history
…pyter Notebook format.
  • Loading branch information
[email protected] authored and [email protected] committed Jan 6, 2025
1 parent 5694707 commit 7fc29a9
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 184 deletions.
371 changes: 188 additions & 183 deletions docs/jupyter_notebooks/e1_pull_DWD_historical_to_all_output_formats.ipynb
Original file line number Diff line number Diff line change
@@ -1,184 +1,189 @@
{
"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, e.g. from your local drive. The\nReadme provides information on where you can download your own EPW and TRY files. For this\nexample, we use the test files provided in the tests folder (be sure to have the full\nrepository downloaded to have access to these files).\nIf you use your own files, you can specify the path to the file in the `path` argument.\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "These 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ project = ProjectClassDWDForecast(
)
```

For EPW and TRY we need to import the .epw or .dat file
For EPW and TRY we need to import the .epw or .dat file, e.g. from your local drive. The
Readme provides information on where you can download your own EPW and TRY files. For this
example, we use the test files provided in the tests folder (be sure to have the full
repository downloaded to have access to these files).
If you use your own files, you can specify the path to the file in the `path` argument.

These imports are just to create the path to the file stored in the tests folder

```python
Expand Down

0 comments on commit 7fc29a9

Please sign in to comment.