knitr::opts_chunk$set(collapse = TRUE, comment = "#>", message=FALSE)

Overview

This vignette shows how the climate forcing data for a climate stress test can be prepared with weathergenr.

Running weather generator from python

in progress

Prerequisites: \ 1. Install latest version of R via https://mirror.lyrahosting.com/CRAN/ \ 2. Create a new python environment with packages rpy2, r-base, r-essentials, pandas, numpy2 \

First set the PATH variables correctly ```{python, py1, eval = FALSE} import os os.environ['PATH'] = 'C:/Program Files/R/R-4.1.2/bin/x64' + os.pathsep + os.environ.get('PATH', '') os.environ['PYTHONHOME'] = 'C:/Users/taner/Anaconda3/envs/wegentest' os.environ['PYTHONPATH'] = 'C:/Users/taner/Anaconda3/envs/wegentest/Lib/site-packages'

Location of R executable

os.environ['R_HOME'] = 'C:/Program Files/R/R-4.1.2'

Location of R packages installed

os.environ['R_USER'] = 'C:/Users/taner/Anaconda3/envs/wegentest/Lib/site-packages/rpy2'

Check if variables are correctly defined for rpy2
```{python, py2, eval = FALSE}

import rpy2.situation
for row in rpy2.situation.iter_info():
    print(row)
#Import necessary packages
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr

# This is needed for conversion between R and Python syntax
d = {'package.dependencies': 'package_dot_dependencies',
     'package_dependencies': 'package_uscore_dependencies'}

# Load core packages
base = importr('base')
utils = importr('utils')
utils.chooseCRANmirror(ind=1) # select the first mirror in the list
devtools = utils.install_packages('devtools')
devtools = importr('devtools', robject_translations = d)

# Install weathergenr from Github master branch
weathergenr = devtools.install_github("tanerumit/weathergenr")
weathergenr = importr('weathergenr', robject_translations = d)

Run test code ```{python, py3, eval = FALSE}

Load netcdf file

ncfile = base.system_file("extdata", "ntoum_era5_data.nc", package = "weathergenr") ncdata = weathergenr.readNetcdf(ncfile)

Set path to store weather generator results

output_path = "C:/testrun/" variables = base.c("precip", "temp", "temp_min", "temp_max") realization_num = 3

stochastic_weather = weathergenr.generateWeatherSeries( weather_data = ncdata[0], weather_grid = ncdata[1], weather_date = ncdata[2], variable_names = variables, output_path = output_path, month_start = 1, realization_num = realization_num, warm_variable = "precip", warm_signif_level = 0.90, warm_sample_num = 5000, knn_sample_num = 100, evaluate_model = False, evaluate_grid_num = 20, mc_wet_threshold = 0.2, mc_extreme_quantile = 0.8, seed = 100) ```



Deltares/weathergenr documentation built on July 25, 2024, 6:15 p.m.