Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions notebooks/Project_config.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import os"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **Set Up The Project Paths:** User input required"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Replace the PROJECT_HOME and ERA5LOWRES paths with your actual paths\n",
"ERA5LOWRES = Path(\"/path/to/your/data\") # Replace with the path to your ERA5LOWRES data here. Example: Path(\"/path/to/your/ERA5LOWRES\")\n",
"PROJECT_HOME = None # Replace with the path to your PROJECT_HOME here, or set to None to default to current directory. Example: Path(\"/path/to/your/PROJECT_HOME\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **Path Setting Logic:** Can be ignored by the user"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Ensure PROJECT_HOME is set to a valid Path object\n",
"try:\n",
" if PROJECT_HOME is None:\n",
" PROJECT_HOME = Path.cwd()\n",
" elif not isinstance(PROJECT_HOME, Path):\n",
" raise TypeError(f\"PROJECT_HOME must be a Path object or None. Got: {type(PROJECT_HOME).__name__}\")\n",
"except Exception as e:\n",
" raise ValueError(f\"Error setting PROJECT_HOME: {e}\")\n",
"\n",
"# Validate the PROJECT_HOME path\n",
"try:\n",
" if not PROJECT_HOME.is_dir():\n",
" raise ValueError(f\"The provided PROJECT_HOME path '{PROJECT_HOME}' is not a valid directory. Please update it.\")\n",
"except ValueError as e:\n",
" raise ValueError(f\"Error validating PROJECT_HOME: {e}\")\n",
"\n",
"# Ensure ERA5LOWRES is set to a valid Path object\n",
"try:\n",
" if not isinstance(ERA5LOWRES, Path):\n",
" raise TypeError(f\"ERA5LOWRES must be a Path object. Got: {type(ERA5LOWRES).__name__}\")\n",
"except Exception as e:\n",
" raise ValueError(f\"Error setting ERA5LOWRES: {e}\")\n",
"\n",
"# Validate the ERA5LOWRES path\n",
"try:\n",
" if not ERA5LOWRES.is_dir():\n",
" raise ValueError(f\"The provided ERA5LOWRES path '{ERA5LOWRES}' does not exist or is not a directory. Please update it.\")\n",
"except ValueError as e:\n",
" raise ValueError(f\"Error validating ERA5LOWRES: {e}\")\n",
"\n",
"\n",
"# Set the environment variable if ERA5LOWRES is valid\n",
"if ERA5LOWRES:\n",
" os.environ[\"ERA5LOWRES\"] = str(ERA5LOWRES)\n",
"else:\n",
" print(\"ERA5LOWRES is not set. Please check your configuration.\")\n",
"\n",
"# Define paths in PROJECT_HOME for stats and caching\n",
"default_root_dir = PROJECT_HOME / \"cnn_training\" # Folder to save the trained models and other project outputs\n",
"stats_folder = PROJECT_HOME / \"cnn_training/stats\" # Folder to save estimated mean & standard deviation of fields\n",
"cache_folder = PROJECT_HOME / \"cnn_training/cache\" # Folders used to cache dataset processed by the pipeline\n",
"\n",
"# Ensure that the required directories exist or create them\n",
"stats_folder.mkdir(parents=True, exist_ok=True)\n",
"cache_folder.mkdir(parents=True, exist_ok=True)\n",
"default_root_dir.mkdir(parents=True, exist_ok=True)\n",
"\n",
"# Print paths for debugging\n",
"print(f\"Project Home: {PROJECT_HOME}\")\n",
"print(f\"Stats folder: {stats_folder}\")\n",
"print(f\"Cache folder: {cache_folder}\")\n",
"print(f\"Default root directory: {default_root_dir}\")\n",
"print(f\"ERA5LOWRES: {ERA5LOWRES}\")\n",
"\n",
"# Show contents of the ERA5LOWRES directory\n",
"if ERA5LOWRES:\n",
" print(f\"Contents of ERA5LOWRES:\")\n",
" !ls -l {ERA5LOWRES}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "PET_tutorial",
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading