### Run CLIMADA unit tests for verification Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Execute all CLIMADA unit tests to verify proper installation. Requires advanced setup with access to CLIMADA repository. Tests all modules matching test*.py pattern in climada directory. Validates core functionality. ```bash cd /climada_python mamba activate climada_env python -m unittest discover -s climada -p "test*.py" ``` -------------------------------- ### Install CLIMADA Petals Package Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/install Complete setup process for CLIMADA Petals including repository cloning, environment activation, dependency updates, and package installation. Assumes CLIMADA Core is already installed and climada_env is available. ```shell git clone https://github.com/CLIMADA-project/climada_petals.git cd climada_petals git checkout develop ``` ```shell mamba env update -n climada_env -f requirements/env_climada.yml mamba activate climada_env ``` ```shell python -m pip install -e ./ ``` -------------------------------- ### Clone and checkout CLIMADA repository using Git commands Source: https://climada-python.readthedocs.io/en/latest/development/Guide_CLIMADA_Development This shell command sequence clones the CLIMADA repository from GitHub and switches to a specified branch for development. It demonstrates the initial setup steps required after following the advanced installation instructions. The commands assume Git is installed and the user has network access to GitHub. ```shell git clone https://github.com/CLIMADA-project/climada_python.git cd climada_python git checkout ``` -------------------------------- ### Download and Install Miniforge (macOS/Linux) Source: https://climada-python.readthedocs.io/en/latest/getting-started/install This snippet downloads the Miniforge installer script for macOS and Linux using `curl` and then executes it with `bash`. It sets up the conda environment manager, which is a prerequisite for installing CLIMADA. Users should follow the prompts to accept the license and initialize conda for their shell. ```shell curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh ``` -------------------------------- ### Setup JupyterLab for CLIMADA Development Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/install Installation and activation of JupyterLab within the CLIMADA development environment. Includes environment-specific installation via mamba and proper environment activation before launching JupyterLab interface. ```shell mamba install -n climada_env -c conda-forge jupyterlab ``` ```shell mamba activate climada_env jupyter-lab ``` -------------------------------- ### Setup CLIMADA Development Environment Source: https://climada-python.readthedocs.io/en/latest/development/Guide_Review Commands to fetch the target branch, create a new conda/mamba environment with specific Python version, install dependencies from environment file, and install CLIMADA in editable mode. This setup ensures proper development environment for code review. ```bash git fetch && git checkout mamba create -n # restrict python version here with "python==3.x.*" mamba env update -n -f requirements/env_climada.yml mamba activate pip install -e ./ ``` -------------------------------- ### Activate Spyder Environment and Launch Spyder Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Commands to activate the environment where Spyder is installed and then launch the Spyder IDE. This is part of the process to connect Spyder to a CLIMADA kernel. ```bash mamba activate spyder-env spyder ``` -------------------------------- ### Install CLIMADA Developer Dependencies Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/install Installation of developer dependencies including testing frameworks and pre-commit hooks. The dev extra provides dependencies for running tests and pre-commit actions. Includes pre-commit hook installation for automated code quality checks. ```shell python -m pip install -e "./[dev]" ``` ```shell pre-commit install ``` ```shell mamba install -n climada_env make ``` -------------------------------- ### Switch CLIMADA Git Branches Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/install Commands to fetch, checkout, and pull a specific branch after CLIMADA installation in editable mode. Handles dependency requirements for new branches and provides alternative reinstallation method for non-editable installations. ```shell git fetch git checkout git pull ``` ```shell pip install [-e] ./ ``` -------------------------------- ### Install CLIMADA Developer Dependencies Source: https://climada-python.readthedocs.io/en/latest/guide/install Installs additional dependencies required for CLIMADA development including testing and documentation tools. Requires activated climada_env environment. The 'dev' extra includes pre-commit hooks and test dependencies, while 'doc' extra is for building documentation. ```bash python -m pip install -e "./[dev]" ``` -------------------------------- ### Update CLIMADA using git repository Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Advanced method to update CLIMADA by pulling latest changes from git repository and updating environment. Requires navigating to local CLIMADA repository directory and executing multiple commands sequentially. Updates both code and dependencies. ```bash cd /climada_python git pull ``` ```bash mamba env update -n climada_env -f requirements/env_climada.yml mamba activate climada_env python -m pip install -e ./ ``` -------------------------------- ### Install and Run Pre-commit Hooks for CLIMADA Source: https://climada-python.readthedocs.io/en/latest/_sources/development/Guide_CLIMADA_conventions This snippet shows how to install and run pre-commit hooks, which automate code formatting and checks. It ensures code adheres to project standards before committing. This is crucial for maintaining code consistency across the CLIMADA project. ```shell pre-commit install pre-commit run --all-files ``` -------------------------------- ### Test Configuration Example 1 (JSON) Source: https://climada-python.readthedocs.io/en/latest/development/Guide_Configuration Presents a sample JSON configuration file intended for testing purposes. It overrides default settings and defines paths relative to a 'test_directory', which is set to './climada'. This is suitable for tests run from the installation directory. ```json { "_comment": "this is a climada configuration file meant to supersede the default configuration in climada/conf during test", "test_directory": "./climada", "test_data": "{test_directory}/test/data", "disc_rates": { "test_data": "{test_directory}/entity/disc_rates/test/data" } } ``` -------------------------------- ### Configure VSCode for CLIMADA Pytest Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Instructions to set up the VSCode test explorer to discover and run CLIMADA tests using pytest. This involves selecting pytest as the framework and specifying the directory containing the test files. -------------------------------- ### Install CLIMADA from Source - Git and Conda Source: https://climada-python.readthedocs.io/en/latest/guide/install Installs CLIMADA by cloning the GitHub repository and building from source. This method is suitable for developers or advanced users who need to work with the latest development version or contribute to CLIMADA. It requires Git and involves creating and managing a Conda environment. ```bash apt update apt install git cd git clone https://github.com/CLIMADA-project/climada_python.git cd climada_python git checkout develop mamba create -n climada_env "python=3.11.*" mamba env update -n climada_env -f requirements/env_climada.yml mamba activate climada_env python -m pip install -e ./ python -m unittest climada.engine.test.test_impact ``` -------------------------------- ### Python Set Documentation and Methods Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Shows how to access the documentation for Python's built-in set type using `help(set)` and how to list available methods using `dir(set)`. This is useful for exploring set capabilities. ```python # check set documentation help(set) ``` ```python # check which methods can be applied on set dir(set) ``` -------------------------------- ### Listing and Converting Datasets to DataFrame Source: https://climada-python.readthedocs.io/en/latest/user-guide/climada_util_api_client Provides a practical example of using the CLIMADA API client. It demonstrates initializing the client, fetching a list of 'litpop' datasets for Germany, and then converting this list into a pandas DataFrame for further processing and visualization. ```python from climada.util.api_client import Client client = Client() litpop_datasets = client.list_dataset_infos( data_type="litpop", properties={"country_name": "Germany"}, ) litpop_df = client.into_datasets_df(litpop_datasets) litpop_df ``` -------------------------------- ### Get CLIMADA Environment Python Executable Path Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Python command executed within the `climada_env` to print the absolute path of the Python interpreter. This path is required for configuring IDEs like Spyder to use the correct environment. ```python import sys; print(sys.executable) ``` -------------------------------- ### Basic Hazard Simulation Example (Python) Source: https://climada-python.readthedocs.io/en/latest/_sources/user-guide/climada_engine_CostBenefit A simple example demonstrating how to set up and run a hazard simulation using CLIMADA. This involves defining event data and simulation parameters. ```python from climada.engine import Engine from climada.util.files import read_json # Load event data (e.g., from a JSON file) events = read_json('path/to/your/events.json') # Initialize the CLIMADA engine engine = Engine(events=events) # Run the hazard simulation hazards = engine.run_hazard(imp_type='TropicalCyclone') print(hazards) ``` -------------------------------- ### Install Additional Packages with Pip Source: https://climada-python.readthedocs.io/en/latest/guide/install Install extra Python packages using 'pip' when they are not available through Conda channels. Ensure the 'climada_env' Conda environment is activated before running the pip install command. ```bash mamba activate climada_env python -m pip install ``` -------------------------------- ### Install Pre-commit Hooks Source: https://climada-python.readthedocs.io/en/latest/guide/install Installs and configures pre-commit hooks for automated code quality checks before commits. Requires developer dependencies to be installed first. Hooks are defined in .pre-commit-config.yaml file in the repository. ```bash pre-commit install ``` -------------------------------- ### Python Set Creation and Basic Operations Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Demonstrates how to create Python sets, how they automatically handle duplicate elements, and perform basic membership testing. Sets are unordered collections useful for efficient membership checking and removing duplicates. ```python basket = {"apple", "orange", "apple", "pear", "orange", "banana"} basket # show that duplicates have been removed ``` ```python "orange" in basket # fast membership testing ``` ```python "crabgrass" in basket ``` -------------------------------- ### Install Make via Conda Source: https://climada-python.readthedocs.io/en/latest/guide/install Installs GNU Make utility required for executing test scripts identically to CI pipeline. Pre-installed on macOS and Linux. For Windows systems, installs make into the climada_env environment. ```bash mamba install -n climada_env make ``` -------------------------------- ### Python Function Calls Using Keyword Arguments Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Demonstrates calling a Python function using keyword arguments, allowing arguments to be specified by name regardless of their order. This enhances code readability and flexibility. ```python ask_ok("OK to overwrite the file?", reminder="Come on, only yes or no!") ``` -------------------------------- ### Python Function Calls with Optional Arguments Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Shows different ways to call a Python function with default arguments. Examples include calling with only the mandatory argument, providing an optional argument, and supplying all arguments. ```python # This function can be called in several ways: # giving only the mandatory argument: ask_ok("Do you really want to quit?") ``` ```python # giving one of the optional arguments: ask_ok("OK to overwrite the file?", 2) ``` ```python # or even giving all arguments: ask_ok("OK to overwrite the file?", 2, "Come on, only yes or no!") ``` -------------------------------- ### Install Specific Spyder Kernel Version Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Command to install a specific version of `spyder-kernels` into the `climada_env`. This ensures compatibility by matching the kernel version found in a separate Spyder environment. ```bash mamba install -n climada_env spyder-kernels=X.Y.Z ``` -------------------------------- ### Install additional packages in CLIMADA environment Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Install additional Python packages in CLIMADA conda environment. Prefer conda-forge channel over default channels for updated versions. Fallback to pip installation if package is not available through conda. Maintains environment consistency. ```bash mamba install -n climada_env -c conda-forge ``` ```bash mamba activate climada_env python -m pip install ``` -------------------------------- ### Python: Download UncOutput Example (Cost-Benefit) Source: https://climada-python.readthedocs.io/en/latest/user-guide/climada_engine_unsequa Demonstrates downloading an UncOutput dataset for cost-benefit analysis from the Climada API, similar to the impact analysis example, replacing the dataset name. ```python from climada.util.constants import TEST_UNC_OUTPUT_COSTBEN from climada.util.api_client import Client apiclient = Client() ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_COSTBEN, status="test_dataset") _target_dir, [filename] = apiclient.download_dataset(ds) ``` -------------------------------- ### Install CLIMADA (Simple) - Conda Source: https://climada-python.readthedocs.io/en/latest/guide/install Installs the most recent stable version of CLIMADA using Mamba. This is a straightforward method for users who do not need to modify the source code. It creates a dedicated Conda environment for CLIMADA. ```bash mamba create -n climada_env -c conda-forge climada mamba activate climada_env python -m unittest climada.engine.test.test_impact mamba install -n climada_env -c conda-forge climada-petals ``` -------------------------------- ### Python tuple operations Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Demonstrates tuple creation, indexing, nesting, and immutability in Python. Shows tuple packing and unpacking operations. ```Python t = 12345, 54321, "hello!" t[0] ``` ```Python t ``` ```Python u = t, (1, 2, 3, 4, 5) u ``` ```Python t[0] = 88888 ``` ```Python v = ([1, 2, 3], [3, 2, 1]) v ``` ```Python t = 12345, 54321, "hello!" # tuple packing x, y, z = t # tuple unpacking x, y, z ``` -------------------------------- ### Python: Create and Access Tuples Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/0_intro_python Demonstrates the creation of tuples using comma-separated values and accessing elements by index. Tuples are ordered and immutable sequences. ```python t = 12345, 54321, "hello!" t[0] ``` ```python t ``` -------------------------------- ### Initialize CLIMADA API Client in Python Source: https://climada-python.readthedocs.io/en/latest/user-guide/climada_util_api_client Imports and instantiates the CLIMADA API client to enable data queries. This is the entry point for all interactions with the CLIMADA data API. The Client class provides methods for listing available data types and datasets. ```python from climada.util.api_client import Client client = Client() ``` -------------------------------- ### Install Additional Packages with Mamba Source: https://climada-python.readthedocs.io/en/latest/guide/install Install extra Python packages required by your CLIMADA projects. It's recommended to use Conda Forge for the most up-to-date packages. Use 'pip' only as a fallback if Conda does not provide the package. ```bash mamba install -n climada_env -c conda-forge ``` -------------------------------- ### Module Configuration and Imports - Python Source: https://climada-python.readthedocs.io/en/latest/_modules/climada/util/files_handler Module initialization and configuration setup including import statements for required dependencies (glob, logging, math, urllib, requests, tqdm), configuration import from climada.util.config, and logger setup. Defines module exports via __all__ list for public API specification. ```python """Functions to deal with files.""" __all__ = [ "to_list", "get_file_names", ] import glob import logging import math import urllib from pathlib import Path import requests from tqdm import tqdm from climada.util.config import CONFIG LOGGER = logging.getLogger(__name__) ``` -------------------------------- ### Remove Conda Environment Source: https://climada-python.readthedocs.io/en/latest/guide/install Removes a specified Conda environment. This command is useful for cleaning up environments, especially when transitioning between different installation methods or freeing up disk space. ```bash mamba env remove -n climada_env ``` -------------------------------- ### Remove Climada Environment - Shell Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/install Deactivates and removes the climada_env mamba environment as part of the uninstallation or reset process. Requires mamba package manager to be installed and accessible in the terminal. After execution, repeat the full installation steps to reinstall. ```shell mamba deactivate mamba env remove -n climada_env ``` -------------------------------- ### Python Class Definition and Instantiation Source: https://climada-python.readthedocs.io/en/latest/getting-started/0_intro_python Defines a 'Dog' class with class and instance variables, and demonstrates its instantiation and method usage. It shows how instance variables are unique while class variables are shared. ```python class Dog: kind = "canine" # class variable shared by all instances def __init__(self, name): self.name = name self.tricks = [] def add_trick(self, trick): self.tricks.append(trick) d = Dog("Fido") e = Dog("Buddy") d.add_trick("roll over") e.add_trick("play dead") print(d.tricks) print(e.tricks) print(d.kind) print(e.kind) ``` -------------------------------- ### Switch Git Branch and Update Source: https://climada-python.readthedocs.io/en/latest/guide/install Fetches, checks out, and pulls a specified branch in a Git repository. This is used for switching between different development versions of CLIMADA when installed in editable mode. ```bash git fetch git checkout git pull ``` -------------------------------- ### ImpfTropCyclone Class Methods Source: https://climada-python.readthedocs.io/en/latest/api/climada/climada.entity Provides methods for creating `ImpfTropCyclone` instances from specific data sources or configurations. ```APIDOC ## ImpfTropCyclone Class Methods ### Description Methods for creating `ImpfTropCyclone` instances from specific data sources or configurations. ### Method `from_emanuel_usa` ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **impf_id** (int, optional) - impact function id. Default: 1 - **intensity** (np.array, optional) - intensity array in m/s. Default: 5 m/s step array from 0 to 120m/s - **v_thresh** (float, optional) - first shape parameter, wind speed in m/s below which there is no damage. Default: 25.7(Emanuel 2011) - **v_half** (float, optional) - second shape parameter, wind speed in m/s at which 50% of max. damage is expected. Default: v_threshold + 49 m/s (mean value of Sealy & Strobl 2017) - **scale** (float, optional) - scale parameter, linear scaling of MDD. 0<=scale<=1. Default: 1.0 ### Request Example ```json { "impf_id": 2, "v_thresh": 30, "v_half": 80 } ``` ### Response #### Success Response (200) - **impf** (ImpfTropCyclone) - TC impact function instance based on formula by Emanuel (2011) #### Response Example ```json { "message": "ImpfTropCyclone created using from_emanuel_usa" } ``` ### Raises **ValueError** ### Deprecated `set_emanuel_usa()` is deprecated, use `from_emanuel_usa()` instead. ``` -------------------------------- ### Activate CLIMADA conda environment Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Activate the CLIMADA conda environment to ensure proper package availability. First step in troubleshooting ModuleNotFoundError issues. Required before running CLIMADA commands or installing packages. ```bash mamba activate climada_env ``` -------------------------------- ### Python: Set Operations - Union and Intersection Source: https://climada-python.readthedocs.io/en/latest/_sources/getting-started/0_intro_python Illustrates basic set operations, specifically creating sets from strings to find unique letters and preparing for operations like union and intersection. The example shows the creation of sets `a` and `b`. ```python # Demonstrate set operations on unique letters from two words a = set("abracadabra") b = set("alacazam") a # unique letters in a ``` -------------------------------- ### Python: Download UncOutput Example (Impact) Source: https://climada-python.readthedocs.io/en/latest/user-guide/climada_engine_unsequa This snippet demonstrates downloading an UncOutput dataset for impact analysis from the Climada API. It utilizes the `Client` class to retrieve dataset information and download the HDF5 file, subsequently loading it into an `UncOutput` object. ```python from climada.util.constants import TEST_UNC_OUTPUT_IMPACT from climada.util.api_client import Client apiclient = Client() ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_IMPACT, status="test_dataset") _target_dir, [filename] = apiclient.download_dataset(ds) ``` -------------------------------- ### Python Whitespace Usage Examples Source: https://climada-python.readthedocs.io/en/latest/_sources/development/Guide_PythonDos-n-Donts Demonstrates correct whitespace usage in Python code according to PEP 8 guidelines. Includes examples for function calls, conditional statements, and assignments. ```python spam(ham[1], {eggs: 2}) if x == 4: print x, y; x, y = y, x def complex(real, imag=0.0): ``` -------------------------------- ### Export Spyder Environment for Kernel Version Source: https://climada-python.readthedocs.io/en/latest/getting-started/install Command to export the current Conda environment to a YAML file, specifically to inspect and retrieve the version of `spyder-kernels` installed. This is useful for replicating kernel versions across environments. ```bash mamba env export -n spyder-env | grep spyder-kernels ``` -------------------------------- ### Climada Configuration File Example (JSON) Source: https://climada-python.readthedocs.io/en/latest/_sources/development/Guide_Euler An example JSON structure for the Climada configuration file, specifying the local data system path. Users should replace 'USERNAME' with their actual Euler username and adjust the path as needed. ```json { "local_data": { "system": "/cluster/work/climate/USERNAME/climada/data", ```