{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using `pyfwg` for direct morphing with `morph_epw_global` and `morph_epw_europe` (v4 Update)\n", "\n", "This notebook demonstrates the simplest and most direct way to use the `pyfwg` library: the `morph_epw_global` and `morph_epw_europe` functions.\n", "\n", "These functions are designed as one-shot tools that provide full access to all of the Future Weather Generator's parameters without requiring the user to manage the multi-step `MorphingWorkflow` class. It handles parameter validation, temporary file management, and final file placement in a single call.\n", "\n", "**Note:** `pyfwg` now fully supports **FutureWeatherGenerator v4.0.x** (Global) and **v2.0.x** (Europe), which include a new keyword-based CLI, support for string-based parameter options (like `'AVG4P'` for interpolation), and additional output formats (like `'MET'` or `'CSV'`)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Understanding the Parameters\n", "\n", "The `morph_epw_global` and `morph_epw_europe` functions are powerful because these exposes all of the underlying tool's options. Here is a complete reference for all their arguments.\n", "\n", "### Core Parameters\n", "\n", "* `epw_paths` (`Union[str, List[str]]`): **Required.** The path to a single EPW file (as a string) or a list of paths to multiple EPW files.\n", "* `fwg_jar_path` (`str`): **Required.** The absolute or relative path to the Future Weather Generator `.jar` file (e.g., `FutureWeatherGenerator_v4.0.2.jar`).\n", "\n", "### Workflow Control Parameters\n", "\n", "* `output_dir` (`str`, default: `'./morphed_epws'`): The directory where the final morphed files will be saved.\n", "* `delete_temp_files` (`bool`, default: `True`): If `True`, the temporary folders are deleted after processing. Set to `False` for debugging.\n", "* `temp_base_dir` (`str`, default: `'./morphing_temp_results'`): The base directory where temporary folders will be created.\n", "* `fwg_show_tool_output` (`bool`, default: `False`): If `True`, prints the FWG tool's console output in real-time. Highly recommended for monitoring progress.\n", "* `fwg_params` (`Optional[Dict]`, default: `None`): A dictionary for providing a base set of FWG parameters. Any explicit `fwg_` argument will override the values in this dictionary.\n", "\n", "### Future Weather Generator Tool Parameters\n", "\n", "These arguments correspond directly to the options in the FWG command-line tool.\n", "\n", "* `fwg_gcms` (`Optional[List[str]]`, default: `None`): **Only valid for `morph_epw_global`**. A list of GCMs to use. If `None`, the full default list is used to create an ensemble.\n", "* `fwg_rcm_pairs` (`Optional[List[str]]`, default: `None`): **Only valid for `morph_epw_europe`**. List of GCM-RCM pairs to use. If `None`, the tool's default list is used.\n", "* `fwg_create_ensemble` (`bool`, default: `True`): If `True`, creates an ensemble from the selected GCMs.\n", "* `fwg_winter_sd_shift` (`float`, default: `0.0`): Temperature's standard deviation shift for the winter peak month. Range: -2.0 to 2.0.\n", "* `fwg_summer_sd_shift` (`float`, default: `0.0`): Temperature's standard deviation shift for the summer peak month. Range: -2.0 to 2.0.\n", "* `fwg_month_transition_hours` (`int`, default: `72`): Number of hours to smooth the transition between months. Range: 0 to 336.\n", "* `fwg_use_multithreading` (`bool`, default: `True`): If `True`, performs computations in multithread.\n", "* `fwg_interpolation_method_id` (`Union[int, str]`, default: `0`): Selects the grid method. **Legacy options:** `0` (IDW), `1` (AVG4P), `2` (NP). **V4/Europe v2 options:** you can use strings: `'IDW'`, `'BI'`, `'AVG4P'`, `'NP'`.\n", "* `fwg_limit_variables` (`bool`, default: `True`): If `True`, bounds each generated variable to its physical limits.\n", "* `fwg_solar_hour_adjustment` (`Union[int, str]`, default: `1`): Option for solar hour adjustment. **Legacy options:** `0`, `1`, `2`. **V4 options:** `'None'`, `'By_Month'`, `'By_Day'`.\n", "* `fwg_diffuse_irradiation_model` (`Union[int, str]`, default: `1`): Option for diffuse solar irradiation model. **Legacy options:** `0`, `1`, `2`. **V4 options:** `'Ridley_Boland_Lauret_2010'`, `'Engerer_2015'`, `'Paulescu_Blaga_2019'`.\n", "* `fwg_add_uhi` (`bool`, default: `True`): Option to pre-process the Urban Heat Island (UHI) effect.\n", "* `fwg_epw_original_lcz` (`int`, default: `14`): The Local Climate Zone (LCZ) of the original EPW. Range: 1 to 17.\n", "* `fwg_target_uhi_lcz` (`int`, default: `1`): The target LCZ of the generated EPW. Range: 1 to 17.\n", "* `fwg_output_type` (`str`, default: `'EPW'`): **New in V4/Europe v2.** Format of output files: `'EPW'`, `'SPAIN_MET'`, or `'PORTUGAL_CSV'`.\n", "* `fwg_version` (`Optional[str]`, default: `None`): Force a specific CLI version (e.g., `'4'`). If `None`, `pyfwg` auto-detects from the JAR filename." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using `morph_epw_global`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Imports and Setup\n", "\n", "First, we'll import the necessary function and set up our file paths. \n", "\n", "**Important:** You must change the `jar_path` variable to the correct location of your Future Weather Generator `.jar` file. `pyfwg` will automatically detect the version (v3 or v4) and adapt the CLI command accordingly." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-31T07:50:08.442888Z", "start_time": "2025-12-31T07:50:07.762812Z" } }, "source": [ "import os\n", "from pyfwg import get_fwg_parameters_info, morph_epw_global, get_available_lczs, check_lcz_availability, DEFAULT_GLOBAL_GCMS\n", "\n", "# --- Configuration ---\n", "# Define the path to the EPW file to be processed. You can also define a list of paths to process multiple EPW files.\n", "epw_file = 'epws/w_pattern/sevilla_uhi-type-1.epw'\n", "\n", "# !!! IMPORTANT: You MUST change this path to the correct location on your PC !!!\n", "jar_path = r\"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_v4.0.2.jar\"" ], "outputs": [], "execution_count": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exploring FWG Parameters\n", "\n", "Before configuring the workflow, you might want to know which parameters are available and what values they accept. This is especially useful for the new string-based options in V4.\n", "\n", "You can use the `get_fwg_parameters_info` utility to get a detailed list of all parameters." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-31T07:50:09.379340Z", "start_time": "2025-12-31T07:50:09.365348Z" } }, "source": [ "import json\n", "# Get the info and print it nicely\n", "info = get_fwg_parameters_info()\n", "print(json.dumps(info, indent=4))" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"fwg_gcms\": {\n", " \"description\": \"List of Global Climate Models (GCMs) to use for the Global tool.\",\n", " \"allowed_values\": [\n", " \"BCC_CSM2_MR\",\n", " \"CAS_ESM2_0\",\n", " \"CMCC_ESM2\",\n", " \"CNRM_CM6_1\",\n", " \"CNRM_CM6_1_HR\",\n", " \"CNRM_ESM2_1\",\n", " \"CanESM5\",\n", " \"CanESM5_1\",\n", " \"CanESM5_CanOE\",\n", " \"EC_Earth3\",\n", " \"EC_Earth3_Veg\",\n", " \"EC_Earth3_Veg_LR\",\n", " \"FGOALS_g3\",\n", " \"GFDL_ESM4\",\n", " \"GISS_E2_1_G\",\n", " \"GISS_E2_1_H\",\n", " \"GISS_E2_2_G\",\n", " \"IPSL_CM6A_LR\",\n", " \"MIROC6\",\n", " \"MIROC_ES2H\",\n", " \"MIROC_ES2L\",\n", " \"MRI_ESM2_0\",\n", " \"UKESM1_0_LL\"\n", " ],\n", " \"default\": \"All available GCMs\",\n", " \"applies_to\": \"Global\"\n", " },\n", " \"fwg_rcm_pairs\": {\n", " \"description\": \"List of GCM-RCM model pairs to use for the Europe-specific tool.\",\n", " \"allowed_values\": [\n", " \"CNRM_CERFACS_CNRM_CM5_CNRM_ALADIN63\",\n", " \"ICHEC_EC_EARTH_DMI_HIRHAM5\",\n", " \"ICHEC_EC_EARTH_SMHI_RCA4\",\n", " \"MOHC_HadGEM2_ES_DMI_HIRHAM5\",\n", " \"MOHC_HadGEM2_ES_SMHI_RCA4\",\n", " \"MPI_M_MPI_ESM_LR_SMHI_RCA4\",\n", " \"NCC_NorESM1_M_SMHI_RCA4\"\n", " ],\n", " \"default\": \"All available RCM pairs\",\n", " \"applies_to\": \"Europe\"\n", " },\n", " \"fwg_create_ensemble\": {\n", " \"description\": \"Whether to create an ensemble (average) of all selected models.\",\n", " \"allowed_values\": [\n", " true,\n", " false\n", " ],\n", " \"default\": true\n", " },\n", " \"fwg_winter_sd_shift\": {\n", " \"description\": \"Standard deviation shift for winter temperatures.\",\n", " \"range\": [\n", " -2.0,\n", " 2.0\n", " ],\n", " \"default\": 0.0\n", " },\n", " \"fwg_summer_sd_shift\": {\n", " \"description\": \"Standard deviation shift for summer temperatures.\",\n", " \"range\": [\n", " -2.0,\n", " 2.0\n", " ],\n", " \"default\": 0.0\n", " },\n", " \"fwg_month_transition_hours\": {\n", " \"description\": \"Number of hours used for smooth transitions between months.\",\n", " \"range\": [\n", " 0,\n", " 336\n", " ],\n", " \"default\": 72\n", " },\n", " \"fwg_interpolation_method_id\": {\n", " \"description\": \"Method used for spatial interpolation of climate data.\",\n", " \"allowed_values\": {\n", " \"0\": \"IDW\",\n", " \"1\": \"BI\",\n", " \"2\": \"AVG4P\",\n", " \"3\": \"NP\"\n", " },\n", " \"default\": 0\n", " },\n", " \"fwg_solar_hour_adjustment\": {\n", " \"description\": \"Correction method for solar hour based on location.\",\n", " \"allowed_values\": {\n", " \"0\": \"None\",\n", " \"1\": \"By_Month\",\n", " \"2\": \"By_Day\"\n", " },\n", " \"default\": 1\n", " },\n", " \"fwg_diffuse_irradiation_model\": {\n", " \"description\": \"The mathematical model used to calculate diffuse horizontal irradiation.\",\n", " \"allowed_values\": {\n", " \"0\": \"Ridley_Boland_Lauret_2010\",\n", " \"1\": \"Engerer_2015\",\n", " \"2\": \"Paulescu_Blaga_2019\"\n", " },\n", " \"default\": 1\n", " },\n", " \"fwg_output_type\": {\n", " \"description\": \"The format of the generated weather files.\",\n", " \"allowed_values\": [\n", " \"EPW\",\n", " \"SPAIN_MET\",\n", " \"PORTUGAL_CSV\"\n", " ],\n", " \"default\": \"EPW\"\n", " },\n", " \"fwg_add_uhi\": {\n", " \"description\": \"Whether to apply the Urban Heat Island (UHI) effect using LCZs.\",\n", " \"allowed_values\": [\n", " true,\n", " false\n", " ],\n", " \"default\": true\n", " },\n", " \"fwg_epw_original_lcz\": {\n", " \"description\": \"The Local Climate Zone (LCZ) corresponding to the original EPW file location.\",\n", " \"range\": [\n", " 1,\n", " 17\n", " ],\n", " \"default\": 14,\n", " \"note\": \"Commonly 14 for rural/airport locations.\"\n", " },\n", " \"fwg_target_uhi_lcz\": {\n", " \"description\": \"The target Local Climate Zone (LCZ) to which the EPW should be morphed.\",\n", " \"range\": [\n", " 1,\n", " 17\n", " ],\n", " \"default\": 1\n", " },\n", " \"fwg_use_multithreading\": {\n", " \"description\": \"Whether to use multiple CPU cores to speed up calculations.\",\n", " \"allowed_values\": [\n", " true,\n", " false\n", " ],\n", " \"default\": true\n", " },\n", " \"fwg_limit_variables\": {\n", " \"description\": \"Whether to force weather variables to stay within physical limits.\",\n", " \"allowed_values\": [\n", " true,\n", " false\n", " ],\n", " \"default\": true\n", " },\n", " \"fwg_version\": {\n", " \"description\": \"The version of the Future Weather Generator tool to use.\",\n", " \"allowed_values\": [\n", " \"3\",\n", " \"4\",\n", " \"1\",\n", " \"2\"\n", " ],\n", " \"default\": \"Auto-detected from JAR filename\",\n", " \"note\": \"Use 3/4 for Global, 1/2 for Europe.\"\n", " }\n", "}\n" ] } ], "execution_count": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2: Pre-flight Checks (Recommended). Check Available LCZs.\n", "\n", "Before running a long morphing process, it's a good practice to validate your parameters. `pyfwg` provides utility functions to help with this.\n", "\n", "The `fwg_epw_original_lcz` and `fwg_target_uhi_lcz` parameters depend on which Local Climate Zones are available for a specific weather file location. We can find this out using `get_available_lczs`." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:28:23.929914Z", "start_time": "2025-12-30T19:28:04.917341Z" } }, "source": [ "available_zones = get_available_lczs(\n", " epw_paths=epw_file,\n", " fwg_jar_path=jar_path,\n", " # In java_class_path_prefix, use 'futureweathergenerator' for the global scope FWG tool, otherwise 'futureweathergenerator_europe'\n", " java_class_path_prefix='futureweathergenerator',\n", " show_tool_output=False,\n", ")" ], "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:28:04 - INFO - --- Fetching available LCZs for 1 EPW file(s) ---\u001B[0m\n", "\u001B[32m2025-12-30 20:28:04 - INFO - Checking LCZ pair (Original: 0, Target: 0) availability for sevilla_uhi-type-1.epw...\u001B[0m\n", "\u001B[32m2025-12-30 20:28:05 - INFO - --- Applying UHI effect to sevilla_uhi-type-1.epw ---\u001B[0m\n", "\u001B[32m2025-12-30 20:28:05 - INFO - Executing command: java -jar \"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_v4.0.2.jar\" -u -epw=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmpm08u8xr7\\sevilla_uhi-type-1.epw -output_folder=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmpm08u8xr7\\ -uhi=true:0:0 -output_type=EPW\u001B[0m\n", "\u001B[32m2025-12-30 20:28:23 - INFO - Available LCZs for 'sevilla_uhi-type-1.epw': [2, 3, 6, 8, 9, 11, 12, 13, 14, 16]\u001B[0m\n" ] } ], "execution_count": 3 }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:28:24.164189Z", "start_time": "2025-12-30T19:28:24.157166Z" } }, "source": [ "# Print the results in a user-friendly format\n", "for filename, lcz_list in available_zones.items():\n", " print(f\"\\nAvailable LCZs for: {filename}\")\n", " if lcz_list:\n", " print(f\" {lcz_list}\")\n", " else:\n", " print(\" Could not be determined.\")" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Available LCZs for: sevilla_uhi-type-1.epw\n", " [2, 3, 6, 8, 9, 11, 12, 13, 14, 16]\n" ] } ], "execution_count": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3: Run the Morphing Process\n", "\n", "Now, we can call the `morph_epw_global` function. We will override a few of the default parameters to demonstrate how to customize the process. To speed up the process, let's use just one GCM. If you don't know which are these, you can import the list containing the default models:" ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:28:24.195849Z", "start_time": "2025-12-30T19:28:24.182518Z" } }, "source": [ "from pyfwg import get_fwg_parameters_info, DEFAULT_GLOBAL_GCMS\n", "print(DEFAULT_GLOBAL_GCMS)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'GISS_E2_1_H', 'CNRM_CM6_1', 'MIROC6', 'IPSL_CM6A_LR', 'CMCC_ESM2', 'EC_Earth3_Veg', 'EC_Earth3_Veg_LR', 'BCC_CSM2_MR', 'CanESM5_CanOE', 'FGOALS_g3', 'GISS_E2_2_G', 'CanESM5_1', 'GFDL_ESM4', 'CNRM_CM6_1_HR', 'MRI_ESM2_0', 'MIROC_ES2H', 'EC_Earth3', 'MIROC_ES2L', 'CanESM5', 'UKESM1_0_LL', 'GISS_E2_1_G', 'CAS_ESM2_0', 'CNRM_ESM2_1'}\n" ] } ], "execution_count": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "So let's use for instance \"CanESM5\". Note that in **V4**, we can use descriptive strings for parameters like `fwg_interpolation_method_id`." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:00.767667Z", "start_time": "2025-12-30T19:28:24.228116Z" } }, "source": [ "# The validation of parameters is executed automatically inside the function.\n", "created_files_custom = morph_epw_global(\n", " epw_paths=epw_file,\n", " fwg_jar_path=jar_path,\n", " output_dir='./custom_output_global',\n", " fwg_show_tool_output=True, # See the tool's progress in real-time\n", " fwg_gcms=['CanESM5'], # Use only one specific GCM for speed\n", " fwg_interpolation_method_id='AVG4P', # V4 feature: Use string names!\n", " fwg_epw_original_lcz=2, # Use a validated LCZ from the check above\n", " fwg_target_uhi_lcz=3, # Use a validated LCZ from the check above\n", " fwg_version='4' # Explicitly force V4 syntax\n", ")" ], "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:28:24 - INFO - --- Starting Direct Global Morphing Process ---\u001B[0m\n", "\u001B[32m2025-12-30 20:28:24 - INFO - --- Step 2: Configuring and Previewing Morphing Plan ---\u001B[0m\n", "\u001B[32m2025-12-30 20:28:24 - INFO - Validating LCZ availability for sevilla_uhi-type-1.epw...\u001B[0m\n", "\u001B[32m2025-12-30 20:28:24 - INFO - Checking LCZ pair (Original: 2, Target: 3) availability for sevilla_uhi-type-1.epw...\u001B[0m\n", "\u001B[32m2025-12-30 20:28:24 - INFO - --- Applying UHI effect to sevilla_uhi-type-1.epw ---\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "============================================================\n", " MORPHING CONFIGURATION & PREVIEW\n", "============================================================\n", " - FWG JAR Path: D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_v4.0.2.jar\n", " - Final Output Directory: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\n", " - EPWs to be Morphed (1 files):\n", " - sevilla_uhi-type-1.epw\n", "\n", " For input file: sevilla_uhi-type-1.epw\n", " -> Generated 'ssp126_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp126_2050.epw\n", " -> Generated 'ssp245_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp245_2050.epw\n", " -> Generated 'ssp370_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp370_2050.epw\n", " -> Generated 'ssp585_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp585_2050.epw\n", " -> Generated 'ssp126_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp126_2080.epw\n", " -> Generated 'ssp245_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp245_2080.epw\n", " -> Generated 'ssp370_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp370_2080.epw\n", " -> Generated 'ssp585_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ssp585_2080.epw\n", "============================================================\n", "Configuration set. Call execute_morphing() to start the process.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:28:24 - INFO - Executing command: java -jar \"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_v4.0.2.jar\" -u -epw=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmp6c1xil_q\\sevilla_uhi-type-1.epw -output_folder=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmp6c1xil_q\\ -uhi=true:2:3 -output_type=EPW\u001B[0m\n", "\u001B[32m2025-12-30 20:28:40 - INFO - UHI effect applied successfully.\u001B[0m\n", "\u001B[32m2025-12-30 20:28:40 - INFO - LCZ pair (Original: 2, Target: 3) is available.\u001B[0m\n", "\u001B[32m2025-12-30 20:28:40 - INFO - Copied input file to temporary directory: ./morphing_temp_results\\sevilla_uhi-type-1\\sevilla_uhi-type-1.epw\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "-------------------- Executing FWG for sevilla_uhi-type-1.epw --------------------\n", " Full Command (for reference): java -jar \"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_v4.0.2.jar\" -epw=D:\\Python\\pyfwg\\pyfwg\\tutorials\\epws\\w_pattern\\sevilla_uhi-type-1.epw -output_folder=D:\\Python\\pyfwg\\pyfwg\\tutorials\\morphing_temp_results\\sevilla_uhi-type-1\\ -models=CanESM5 -ensemble=true -temp_shift_winter=0.0 -temp_shift_summer=0.0 -smooth_hours=72 -multithread=true -grid_interpolation_method=AVG4P -solar_correction=By_Month -diffuse_method=Engerer_2015 -uhi=true:2:3 -output_type=EPW\n", " --- FWG Real-time Output ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:29:00 - INFO - Direct global morphing complete. 18 files created in D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " --- End of FWG Output ---\n" ] } ], "execution_count": 6 }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:00.798465Z", "start_time": "2025-12-30T19:29:00.790069Z" } }, "source": [ "print(\"\\nSuccessfully created files:\")\n", "for f in created_files_custom:\n", " print(f)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Successfully created files:\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp126_2050.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp126_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp126_2080.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp126_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp245_2050.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp245_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp245_2080.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp245_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp370_2050.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp370_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp370_2080.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp370_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp585_2050.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp585_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp585_2080.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_ssp585_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\ESP_-_SEVILLA_UHI_Target_LCZ-3_Original_LCZ-2_Present-day.epw\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_global\\sevilla_uhi-type-1.epw\n" ] } ], "execution_count": 7 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Expected Output\n", "\n", "When you run the code above with **V4**, you should see:\n", "1. A detailed printout of the **keyword-based command** being executed (e.g., `-epw=... -models=CanESM5`).\n", "2. The real-time console output from the Future Weather Generator tool.\n", "3. A final message listing all the created files in the `./custom_output_global` directory." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's delete the files we just generated." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:00.829735Z", "start_time": "2025-12-30T19:29:00.813145Z" } }, "source": [ "import shutil\n", "if os.path.exists('custom_output_global'):\n", " shutil.rmtree('custom_output_global')" ], "outputs": [], "execution_count": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using `morph_epw_europe`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ">**FYI**: the usage of `morph_epw_europe` is very similar to the global version. The only differences are:\n", "\n", ">* Instead of argument `fwg_gcms`, you need to use `fwg_rcm_pairs`.\n", ">* Instead of variable `DEFAULT_GLOBAL_GCMS`, the available models are in variable `DEFAULT_EUROPE_RCMS`.\n", ">* Future scenarios are RCP instead of SSP.\n", ">* You have to remember using the `jar_path` to the FutureWeatherGenerator_Europe_vx.x.x.jar file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Imports and Setup\n", "\n", "**Important:** Change the `jar_path` variable to the correct location of your European version JAR (v1.x for legacy or v2.x for the update)." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:00.845371Z", "start_time": "2025-12-30T19:29:00.840297Z" } }, "source": [ "from pyfwg import get_fwg_parameters_info, morph_epw_europe\n", "\n", "# !!! IMPORTANT: You MUST change this path to the correct location on your PC !!!\n", "jar_path_europe = r\"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_Europe_v2.0.2.jar\"" ], "outputs": [], "execution_count": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2: Run the Morphing Process\n", "\n", "Now, we can call the `morph_epw_europe` function. In **Europe v2**, we can also specify a different output format like `'MET'`." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:54.395140Z", "start_time": "2025-12-30T19:29:00.855377Z" } }, "source": [ "from pyfwg import get_fwg_parameters_info, DEFAULT_EUROPE_RCMS\n", "\n", "created_files_custom = morph_epw_europe(\n", " epw_paths=epw_file,\n", " fwg_jar_path=jar_path_europe,\n", " output_dir='./custom_output_europe',\n", " fwg_show_tool_output=True,\n", " fwg_rcm_pairs=[list(DEFAULT_EUROPE_RCMS)[0]], # Use the first pair for speed\n", " fwg_interpolation_method_id='NP', # Nearest Point\n", " fwg_epw_original_lcz=2,\n", " fwg_target_uhi_lcz=3,\n", " fwg_output_type='SPAIN_MET' # Output formatted as MET files\n", ")" ], "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:29:00 - INFO - --- Starting Europe-Specific Direct Morphing Process ---\u001B[0m\n", "\u001B[32m2025-12-30 20:29:00 - INFO - --- Step 2: Configuring and Previewing Morphing Plan ---\u001B[0m\n", "\u001B[32m2025-12-30 20:29:00 - INFO - Auto-detected FWG version: 2\u001B[0m\n", "\u001B[32m2025-12-30 20:29:00 - INFO - Validating LCZ availability for sevilla_uhi-type-1.epw...\u001B[0m\n", "\u001B[32m2025-12-30 20:29:00 - INFO - Checking LCZ pair (Original: 2, Target: 3) availability for sevilla_uhi-type-1.epw...\u001B[0m\n", "\u001B[32m2025-12-30 20:29:00 - INFO - --- Applying UHI effect to sevilla_uhi-type-1.epw ---\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "============================================================\n", " MORPHING CONFIGURATION & PREVIEW\n", "============================================================\n", " - FWG JAR Path: D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_Europe_v2.0.2.jar\n", " - Final Output Directory: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\n", " - EPWs to be Morphed (1 files):\n", " - sevilla_uhi-type-1.epw\n", "\n", " For input file: sevilla_uhi-type-1.epw\n", " -> Generated 'rcp26_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp26_2050.epw\n", " -> Generated 'rcp45_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp45_2050.epw\n", " -> Generated 'rcp85_2050.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp85_2050.epw\n", " -> Generated 'rcp26_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp26_2080.epw\n", " -> Generated 'rcp45_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp45_2080.epw\n", " -> Generated 'rcp85_2080.epw' will be moved to: D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\rcp85_2080.epw\n", "============================================================\n", "Configuration set. Call execute_morphing() to start the process.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001B[32m2025-12-30 20:29:00 - INFO - Executing command: java -jar \"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_Europe_v2.0.2.jar\" -u -epw=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmp4znojmmf\\sevilla_uhi-type-1.epw -output_folder=C:\\Users\\sanga\\AppData\\Local\\Temp\\tmp4znojmmf\\ -uhi=true:2:3 -output_type=EPW\u001B[0m\n", "\u001B[32m2025-12-30 20:29:15 - INFO - UHI effect applied successfully.\u001B[0m\n", "\u001B[32m2025-12-30 20:29:15 - INFO - LCZ pair (Original: 2, Target: 3) is available.\u001B[0m\n", "\u001B[32m2025-12-30 20:29:15 - INFO - Copied input file to temporary directory: ./morphing_temp_results_europe\\sevilla_uhi-type-1\\sevilla_uhi-type-1.epw\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "-------------------- Executing FWG for sevilla_uhi-type-1.epw --------------------\n", " Full Command (for reference): java -jar \"D:\\OneDrive - Universidad de Cádiz (uca.es)\\Programas\\FutureWeatherGenerator_Europe_v2.0.2.jar\" -epw=D:\\Python\\pyfwg\\pyfwg\\tutorials\\epws\\w_pattern\\sevilla_uhi-type-1.epw -output_folder=D:\\Python\\pyfwg\\pyfwg\\tutorials\\morphing_temp_results_europe\\sevilla_uhi-type-1\\ -models=MOHC_HadGEM2_ES_DMI_HIRHAM5 -ensemble=true -temp_shift_winter=0.0 -temp_shift_summer=0.0 -smooth_hours=72 -multithread=true -grid_interpolation_method=NP -solar_correction=By_Month -diffuse_method=Engerer_2015 -uhi=true:2:3 -output_type=SPAIN_MET\n", " --- FWG Real-time Output ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001B[33m2025-12-30 20:29:53 - WARNING - PermissionError deleting ./morphing_temp_results_europe\\sevilla_uhi-type-1. Retrying in 0.5s... (Attempt 1/5)\u001B[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " --- End of FWG Output ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001B[33m2025-12-30 20:29:53 - WARNING - PermissionError deleting ./morphing_temp_results_europe\\sevilla_uhi-type-1. Retrying in 0.5s... (Attempt 2/5)\u001B[0m\n", "\u001B[32m2025-12-30 20:29:54 - INFO - Europe morphing complete. 7 files created in D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\u001B[0m\n" ] } ], "execution_count": 10 }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:54.457596Z", "start_time": "2025-12-30T19:29:54.438634Z" } }, "source": [ "print(\"\\nSuccessfully created files:\")\n", "for f in created_files_custom:\n", " print(f)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Successfully created files:\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp26_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp26_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp45_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp45_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp85_2050.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\ESP_-_SEVILLA_Ensemble_UHI_Target_LCZ-3_Original_LCZ-2_rcp85_2080.stat\n", "D:\\Python\\pyfwg\\pyfwg\\tutorials\\custom_output_europe\\sevilla_uhi-type-1.epw\n" ] } ], "execution_count": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's delete the files we just generated." ] }, { "cell_type": "code", "metadata": { "ExecuteTime": { "end_time": "2025-12-30T19:29:54.487409Z", "start_time": "2025-12-30T19:29:54.469610Z" } }, "source": [ "if os.path.exists('custom_output_europe'):\n", " shutil.rmtree('custom_output_europe')" ], "outputs": [], "execution_count": 12 } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }