HiClimR
Hierarchical Climate Regionalization
Install / Use
/learn @hsbadr/HiClimRREADME
HiClimR
HiClimR: Hierarchical Climate Regionalization
Table of Contents
Introduction
HiClimR is a tool for Hierarchical Climate Regionalization applicable to any correlation-based clustering. Climate regionalization is the process of dividing an area into smaller regions that are homogeneous with respect to a specified climatic metric. Several features are added to facilitate the applications of climate regionalization (or spatiotemporal analysis in general) and to implement a cluster validation function with an objective tree cutting to find an optimal number of clusters for a user-specified confidence level. These include options for preprocessing and postprocessing as well as efficient code execution for large datasets and options for splitting big data and computing only the upper-triangular half of the correlation/dissimilarity matrix to overcome memory limitations. Hybrid hierarchical clustering reconstructs the upper part of the tree above a cut to get the best of the available methods. Multivariate clustering (MVC) provides options for filtering all variables before preprocessing, detrending and standardization of each variable, and applying weights for the preprocessed variables.
Features
HiClimR adds several features and a new clustering method (called, regional linkage) to hierarchical clustering in R (hclust function in stats library) including:
- data regridding
- coarsening spatial resolution
- geographic masking
- by continents
- by regions
- by countries
- contiguity-constrained clustering
- data filtering by thresholds
- mean threshold
- variance threshold
- data preprocessing
- detrending
- standardization
- PCA
- faster correlation function
- splitting big data matrix
- computing upper-triangular matrix
- using optimized
BLASlibrary on 64-Bit machinesATLASOpenBLASIntel MKL
- different clustering methods
regionallinkage or minimum inter-regional correlationward's minimum variance or error sum of squares methodsinglelinkage or nearest neighbor methodcompletelinkage or diameteraveragelinkage, group average, or UPGMA methodmcquitty's or WPGMA methodmedian, Gower's or WPGMC methodcentroidor UPGMC method
- hybrid hierarchical clustering
- the upper part of the tree is reconstructed above a cut
- the lower part of the tree uses user-selected method
- the upper part of the tree uses
regionallinkage method
- multivariate clustering (MVC)
- filtering all variables before preprocessing
- detrending and standardization of each variable
- applying weight for the preprocessed variables
- cluster validation
- summary statistics based on raw data or the data reconstructed by PCA
- objective tree cut using minimum significant correlation between region means
- visualization of regionalization results
- exporting region map and mean timeseries into NetCDF-4
The regional linkage method is explained in the context of a spatiotemporal problem, in which N spatial elements (e.g., weather stations) are divided into k regions, given that each element has a time series of length M. It is based on inter-regional correlation distance between the temporal means of different regions (or elements at the first merging step). It modifies the update formulae of average linkage method by incorporating the standard deviation of the merged region timeseries, which is a function of the correlation between the individual regions, and their standard deviations before merging. It is equal to the average of their standard deviations if and only if the correlation between the two merged regions is 100%. In this special case, the regional linkage method is reduced to the classic average linkage clustering method.
Implementation
Badr et al. (2015) describes the regionalization algorithms, features, and data processing tools included in the package and presents a demonstration application in which the package is used to regionalize Africa on the basis of interannual precipitation variability. The figure below shows a detailed flowchart for the package. Cyan blocks represent helper functions, green is input data or parameters, yellow indicates agglomeration Fortran code, and purple shows graphics options. For multivariate clustering (MVC), the input data is a list of matrices (one matrix for each variable with the same number of rows to be clustered; the number of columns may vary per variable). The blue dashed boxes involve a loop for all variables to apply mean and/or variance thresholds, detrending, and/or standardization per variable before weighing the preprocessed variables and binding them by columns in one matrix for clustering. x is the input N x M data matrix, xc is the coarsened N0 x M data matrix where N0 ≤ N (N0 = N only if lonStep = 1 and latStep = 1), xm is the masked and filtered N1 x M1 data matrix where N1 ≤ N0 (N1 = N0 only if the number of masked stations/points is zero) and M1 ≤ M (M1 = M only if no columns are removed due to missing values), and x1 is the reconstructed N1 x M1 data matrix if PCA is performed.
HiClimR is applicable to any correlation-based clustering.
Installation
There are many ways to install an R package from precompiled binaries or source code. For more details, you may search for how to install an R package, but here are the most convenient ways to install HiClimR:
From CRAN
This is the easiest way to install an R package on Windows, Mac, or Linux. You just fire up an R shell and type:
install.packages("HiClimR")
In theory the package should just install, however, you may be asked to select your local mirror (i.e. which server should you use to download the package). If you are using R-GUI or R-Studio, you can find a menu for package installation where you can just search for HiClimR and install it.
From GitHub
This is intended for developers and requires a development environment (compilers, libraries, ... etc) to install the latest development release of HiClimR. On Linux and Mac, you can download the source code and use R CMD INSTALL to install it. In a convenient way, you may use pak as follows:
- Install
pakfrom CRAN:
install.packages("pak")
-
Make sure you have a working development environment:
- Windows: Install
Rtools. - Mac: Install Xcode from the Mac App Store.
- Linux: Install a compiler and various development libraries (details vary across different flavors of Linux).
- Windows: Install
-
Install
HiClimRfrom GitHub source:
pak::pkg_install("hsbadr/HiClimR")
Source
The source code repository can be found on GitHub at hsbadr/HiClimR.
License
HiClimR is licensed under GPL v3. The code is modified by Hamada S. Badr from src/library/stats/R/hclust.R part of R package Copyright © 1995-2021 The R Core Team.
- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
