# belg: A Tool for Calculating Boltzmann Entropy of Landscape Gradients

^{1}

^{2}

^{3}

^{*}

## Abstract

**:**

**belg**as an open source tool for calculating Boltzmann entropy of landscape gradients. The package contains functions to calculate relative and absolute Boltzmann entropy using the hierarchy-based and the aggregation-based methods. It also supports input raster with missing (NA) values, allowing for calculations on real data. In this study, we explain ideas behind implemented methods, describe the core functionality of the software, and present three examples of its use. The examples show the basic functions in this package, how to adjust Boltzmann entropy values for data with missing values, and how to use the

**belg**package in larger workflows. We expect that the

**belg**package will be a useful tool in the discussion of using entropy for a description of landscape patterns and facilitate a thermodynamic understanding of landscape dynamics.

## 1. Introduction

**belg**, for conveniently computing the Boltzmann entropy of a landscape pattern represented using a gradient model, namely, a landscape gradient. The gradient model was focused for two reasons: First, the gradient model could be more universally [37] because it “subsumes the patch-mosaic model as a special case” (McGarigal and Cushman [38], p. 118). Second, software tools for the patch-mosaic model have been developed [35]. It is expected that our package

**belg**, associated with existing tools, will make Boltzmann entropy easy-to-compute with all kinds of landscape patterns, facilitating a thermodynamic understanding of landscape dynamics for sustainable development.

## 2. Methods and Materials

#### 2.1. Boltzmann Entropy for Landscape Gradients

#### 2.1.1. Hierarchy-Based Method for Computing Relative and Absolute Boltzmann Entropies

#### 2.1.2. Aggregation-Based Method for Computing Relative and Absolute Boltzmann Entropies

#### 2.2. Installation of the Belg Package

`install.packages(“belg”)`. The development version is hosted on the GitHub platform at https://github.com/r-spatialecology/belg, and can be installed with

`remotes::install_github(“r-spatialecology/belg”)`. Additionally, this package also has a dedicated website at https://r-spatialecology.github.io/belg/ containing its documentation, installation instructions, and examples of use.

#### 2.3. Core Functionality of the Belg Package

`library(belg)`. This package has one main function

`get_boltzmann()`, which expects input data as the first argument and several additional arguments as the next arguments. Input data can be either a matrix, array, object from the raster package (RasterLayer, RasterStack, RasterBrick), or from the stars package [43,44]. The second argument,

`method`, allows selecting a method of calculation used. It can be either

`“hierarchy”`for the hierarchy-based method [32] or

`“aggregation”`for the aggregation-based method [33]. The third argument,

`na_adjust`, allows for scaling the output value based on the proportion of missing (NA) cells in the input data. Users can also decide on the used logarithm base with the

`base`argument (

`“log”`,

`“log2”`, or

`“log10”`(default)) and if they want to obtain relative or absolute entropy with the

`relative`argument (

`TRUE`or

`FALSE`). The values returned by the

`get_boltzmann()`function are unitless, as the Boltzmann constant ${k}_{b}$ is set to one [28].

## 3. Examples

#### 3.1. Basic Example

library(belg) |

library(raster) |

`land_gradient1`and

`land_gradient2`(Figure 7). Both datasets have 512 rows and columns (262,144 cells in total), where the first one represents a more diverse landscape gradient than the second one.

`get_boltzmann()`function calculates the Boltzmann entropy of landscape gradients. It requires, at least, one argument with input data to work. Other arguments are set by default. This function uses the aggregation-based method (

`method = “aggregation”`), values are scaled based on the proportion of missing values (

`na_adjust = TRUE`), a logarithm of base 10 is used (

`base = “log10”`), and absolute entropy is calculated (

`relative = FALSE`).

get_boltzmann(land_gradient1) |

## [1] 188772.5 |

get_boltzmann(land_gradient2) |

## [1] 121875.2 |

#### 3.2. Example with Missing Values

`data/sample_rasters`folder has eight GeoTIFF files containing digital elevation models for different areas. Each file has 64 rows and columns and a resolution of 90 m.

`dir()`function, and subsequently read to R using the

`lapply()`and

`raster()`functions.

sample_rasters_path = dir(“data/sample_rasters”, pattern = “.tif$”, full.names = TRUE) |

sample_rasters = lapply(sample_rasters_path, raster) |

`NA`constant is returned. In downscaling, the number and positions of cells with missing values are preserved. More details about calculations for data with missing values are available in the package documentation at https://r-spatialecology.github.io/belg/articles/belg1.html.

be_na = sapply(sample_rasters, get_boltzmann, na_adjust = FALSE) |

be_na |

## [1] 1713.9065 1985.3938 3061.0793 2457.6999 2259.5122 3387.7103 2171.1460 |

## [8] 963.3178 |

be_na_adj = sapply(sample_rasters, get_boltzmann, na_adjust = TRUE) |

be_na_adj |

## [1] 3029.849 3330.128 3061.079 3768.903 2259.512 3387.710 3577.238 1345.754 |

`na_adjust`is set to

`TRUE`, then the initially calculated value of Boltzmann entropy is divided by the proportion (0–1) of cells without missing values. The adjusted values are presented in the bottom row in Figure 8.

#### 3.3. Example of a Larger Workflow

`svn_dem.tif`contains a digital elevation model of 90 m resolution for the whole country of Slovenia (Figure 9).

svn_dem = raster(“data/svn_dem.tif”) |

library(sf) |

`st_make_grid()`function.

svn_grid_geom = st_as_sfc(st_bbox(svn_dem)) |

svn_grid = st_make_grid(svn_grid_geom, cellsize = 5760) |

svn_grid = st_sf(id = seq_along(svn_grid), |

geom = svn_grid) |

`results`.

svn_grid$results = NA |

for (i in seq_len(nrow(svn_grid))){ |

small_raster = crop(svn_dem, svn_grid[i, ]) |

if(!all(is.na(getValues(small_raster)))){ |

svn_grid$results[i] = get_boltzmann(small_raster) |

} |

} |

head(svn_grid) |

## Simple feature collection with 6 features and 2 fields |

## geometry type: POLYGON |

## dimension: XY |

## bbox: xmin: 371601.3 ymin: 31015.3 xmax: 406161.3 ymax: 36775.3 |

## CRS: +proj=tmerc +lat_0=0 +lon_0=15 +k=0.9999 +x_0=500000 +y_0=-5000000 ... |

## id geom results |

## 1 1 POLYGON ((371601.3 31015.3,... NA |

## 2 2 POLYGON ((377361.3 31015.3,... NA |

## 3 3 POLYGON ((383121.3 31015.3,... NA |

## 4 4 POLYGON ((388881.3 31015.3,... 1139.992 |

## 5 5 POLYGON ((394641.3 31015.3,... 2834.936 |

## 6 6 POLYGON ((400401.3 31015.3,... 3120.389 |

## 4. Discussion

**belg**R package for computing Boltzmann entropy of landscape gradients. It implements two computational methods—hierarchy-based and aggregation-based—of Boltzmann entropy using an efficient C++ code. An R interface allows for connecting methods in this package with an abundance of existing R packages for spatial data preparation or visualization. The

**belg**package also expands the implemented methods by allowing calculations for rasters with missing values. We also presented three examples showing different aspects of the Boltzmann entropy calculations. Complete code and data to recreate all of the examples are available at https://github.com/Nowosad/belg-examples.

**belg**package has a few limitations, however, they are mostly also the limitations of the implemented methods. It should be stressed that the absolute Boltzmann entropy calculated using the hierarchy-based method is not thermodynamically consistent [33], meaning that the entropy calculated using this approach does not increase continuously toward a maximum. The relative Boltzmann entropy is thermodynamically consistent, however, it does not allow for comparison between two different landscape gradients [32]. While the later proposed aggregation-based method is thermodynamically consistent, it only works on regular rasters with each dimension equal to k to base 2 [33].

**parallel**and

**future**[36,48], can be used together with

**belg**to calculate Boltzmann entropy of many rasters in parallel, the package does not offer multi-core support for single raster images. Thus, it could be also worth adding parallel processing support for single large rasters. Finally, we look forward to the users’ comments and suggestions on potential changes and improvements in this package.

## Author Contributions

## Funding

## Conflicts of Interest

## References

- Pelorosso, R.; Gobattoni, F.; Leone, A. The Low-Entropy City: A Thermodynamic Approach to Reconnect Urban Systems with Nature. Landsc. Urban Plan.
**2017**, 168, 22–30. [Google Scholar] [CrossRef] - Swati, B.K.; Venkanna, B.V. Basic Thermodynamics; PHI Learning: Delhi, India, 2010. [Google Scholar]
- Boltzmann, L. Weitere Studien über Das Wärmegleichgewicht Unter Gasmolekülen [Further Studies on the Thermal Equilibrium of Gas Molecules]. Sitzungsberichte Akad. Der Wiss.
**1872**, 66, 275–370. [Google Scholar] - Thess, A. The Entropy Principle: Thermodynamics for the Unsatisfied; Springer: Berlin/Heidelberg, Germany, 2011. [Google Scholar]
- Huettner, D.A. Net Energy Analysis: An Economic Assessment. Science
**1976**, 192, 101–104. [Google Scholar] [CrossRef] [PubMed] - Gao, P.C.; Wang, H.Y.; Cushman, S.A.; Cheng, C.X.; Song, C.Q.; Ye, S.J. Sustainable Land-Use Optimization Using NSGA-II: Theoretical and Experimental Comparisons of Improved Algorithms. Landsc. Ecol.
**2020**. [Google Scholar] [CrossRef] - Sawant, S.S.; Manoharan, P. Unsupervised Band Selection Based on Weighted Information Entropy and 3D Discrete Cosine Transform for Hyperspectral Image Classification. Int. J. Remote Sens.
**2020**, 41, 3948–3969. [Google Scholar] [CrossRef] - Fistola, R.; La Rocca, R. The Sustainable City and the Smart City: Measuring Urban Entropy First. WIT Trans. Ecol. Environ.
**2014**, 191, 537–548. [Google Scholar] [CrossRef][Green Version] - Blokh, D.; Stambler, I. The Application of Information Theory for the Research of Aging and Aging-Related Diseases. Prog. Neurobiol.
**2017**, 157, 158–173. [Google Scholar] [CrossRef] - Forman, R.T.T.; Godron, M. Landscape Ecology; John Wiley & Sons: New York, NY, USA, 1986. [Google Scholar]
- Jiang, J.; DeAngelis, D.L.; Smith, T.J.; Teh, S.Y.; Koh, H.L. Spatial Pattern Formation of Coastal Vegetation in Response to External Gradients and Positive Feedbacks Affecting Soil Porewater Salinity: A Model Study. Landsc. Ecol.
**2012**, 27, 109–119. [Google Scholar] [CrossRef] - Naveh, Z. Biocybernetic and Thermodynamic Perspectives of Landscape Functions and Land Use Patterns. Landsc. Ecol.
**1987**, 1, 75–83. [Google Scholar] [CrossRef] - O’Neill, R.V.; Johnson, A.R.; King, A.W. A Hierarchical Framework for the Analysis of Scale. Landsc. Ecol.
**1989**, 3, 193–205. [Google Scholar] [CrossRef] - Wu, J.G.; Loucks, O.L. From Balance of Nature to Hierarchical Patch Dynamics: A Paradigm Shift in Ecology. Q. Rev. Biol.
**1995**, 70, 439–466. [Google Scholar] [CrossRef][Green Version] - Zurlini, G.; Petrosillo, I.; Jones, K.B.; Zaccarelli, N. Highlighting Order and Disorder in Social–Ecological Landscapes to Foster Adaptive Capacity and Sustainability. Landsc. Ecol.
**2013**, 28, 1161–1173. [Google Scholar] [CrossRef] - Cushman, S.A. Thermodynamics in Landscape Ecology: The Importance of Integrating Measurement and Modeling of Landscape Entropy. Landsc. Ecol.
**2015**, 30, 7–10. [Google Scholar] [CrossRef][Green Version] - Bailey, K.D. Entropy Systems Theory. In Parra-Luna; Eolss Publishers/UNESCO: Systems Science and Cybernetics: Oxford, UK, 2009; pp. 149–166. [Google Scholar]
- Vranken, I.; Baudry, J.; Aubinet, M.; Visser, M.; Bogaert, J. A Review on the Use of Entropy in Landscape Ecology: Heterogeneity, Unpredictability, Scale Dependence and Their Links with Thermodynamics. Landsc. Ecol.
**2015**, 30, 51–65. [Google Scholar] [CrossRef][Green Version] - Rocchini, D.; Delucchi, L.; Bacaro, G.; Cavallini, P.; Feilhauer, H.; Foody, G.M.; He, K.S.; Nagendra, H.; Porta, C.; Ricotta, C. Calculating Landscape Diversity with Information-Theory Based Indices: A GRASS GIS Solution. Ecol. Informatics
**2013**, 17, 82–93. [Google Scholar] [CrossRef] - Díaz-Varela, E.; Roces-Díaz, J.V.; Álvarez-Álvarez, P. Detection of Landscape Heterogeneity at Multiple Scales: Use of the Quadratic Entropy Index. Landsc. Urban Plan.
**2016**, 153, 149–159. [Google Scholar] [CrossRef] - Shannon, C.E. A Mathematical Theory of Communication. Bell Syst. Tech. J.
**1948**, 27, 379–423. [Google Scholar] [CrossRef][Green Version] - Shannon, C.E.; Weaver, W. The Mathematical Theory of Communication; The University of Illinois Press: Urbana, IL, USA, 1949. [Google Scholar]
- Nowosad, J.; Stepinski, T.F. Information Theory as a Consistent Framework for Quantification and Classification of Landscape Patterns. Landsc. Ecol.
**2019**, 34, 2091–2101. [Google Scholar] [CrossRef][Green Version] - Lopez-Ruiz, R.; Mancini, H.L.; Calbet, X. A Statistical Measure of Complexity. Phys. Lett. A
**1995**, 209, 321–326. [Google Scholar] [CrossRef][Green Version] - Mohajeri, N.; Gudmundsson, A.; Scartezzini, J.L. Statistical-Thermodynamics Modelling of the Built Environment in Relation to Urban Ecology. Ecol. Model.
**2015**, 307, 32–47. [Google Scholar] [CrossRef] - Sugihakim, R.; Alatas, H. Application of a Boltzmann-Entropy-like Concept in an Agent-Based Multilane Traffic Model. Phys. Lett. A
**2016**, 380, 147–155. [Google Scholar] [CrossRef] - Li, Z.L. Algorithmic Foundation of Multi-Scale Spatial Representation; CRC Press: Boca Raton, FL, USA, 2007. [Google Scholar]
- Cushman, S.A. Calculating the Configurational Entropy of a Landscape Mosaic. Landsc. Ecol.
**2016**, 31, 481–489. [Google Scholar] [CrossRef] - Cushman, S.A. Calculation of Configurational Entropy in Complex Landscapes. Entropy
**2018**, 20, 298. [Google Scholar] [CrossRef][Green Version] - Zhao, Y.; Zhang, X.C. Calculating Spatial Configurational Entropy of a Landscape Mosaic Based on the Wasserstein Metric. Landsc. Ecol.
**2019**, 34, 1849–1858. [Google Scholar] [CrossRef] - Zhang, H.; Wu, Z.W.; Lan, T.; Chen, Y.Y.; Gao, P.C. Calculating the Wasserstein Metric-Based Boltzmann Entropy of a Landscape Mosaic. Entropy
**2020**, 22, 381. [Google Scholar] [CrossRef][Green Version] - Gao, P.C.; Zhang, H.; Li, Z.L. A Hierarchy-Based Solution to Calculate the Configurational Entropy of Landscape Gradients. Landsc. Ecol.
**2017**, 32, 1133–1146. [Google Scholar] [CrossRef] - Gao, P.; Li, Z. Aggregation-Based Method for Computing Absolute Boltzmann Entropy of Landscape Gradient with Full Thermodynamic Consistency. Landsc. Ecol.
**2019**, 34, 1837–1847. [Google Scholar] [CrossRef] - Gao, P.C.; Li, Z.L. Computation of the Boltzmann Entropy of a Landscape: A Review and a Generalization. Landsc. Ecol.
**2019**, 34, 2183–2196. [Google Scholar] [CrossRef] - Zhang, H.; Wu, Z.W. A Head/Tail Breaks-Based Method for Efficiently Estimating the Absolute Boltzmann Entropy of Numerical Raster Data. ISPRS Int. J. Geo-Inf.
**2020**, 9, 103. [Google Scholar] [CrossRef][Green Version] - R Core Team. R: A Language and Environment for Statistical Computing; R Foundation for Statistical Computing: Vienna, Austria, 2020. [Google Scholar]
- Evans, J.S.; Cushman, S.A. Gradient Modeling of Conifer Species Using Random Forests. Landsc. Ecol.
**2009**, 24, 673–683. [Google Scholar] [CrossRef] - McGarigal, K.; Cushman, S.A. The Gradient Concept of Landscape Structure. In Issues and Perspectives in Landscape Ecology; Wiens, J.A., Moss, M.R., Eds.; Cambridge University Press: Cambridge, UK, 2005; pp. 112–119. [Google Scholar]
- Dalarsson, N.; Dalarsson, M.; Golubovic, L. Introductory Statistical Thermodynamics; Academic Press: Amsterdam, The Netherlands, 2011. [Google Scholar]
- Hobbie, R.K.; Roth, B.J. Intermediate Physics for Medicine and Biology; Springer: Berlin/Heidelberg, Germany, 2015. [Google Scholar]
- Serway, R.A.; Jewett, J.W. Physics for Scientists and Engineers with Modern Physics, 8th ed.; Brooks/Cole Publishing Company: Pacific Grove, CA, USA, 2009. [Google Scholar]
- Eddelbuettel, D.; Balamuta, J.J. Extending extitR with extitC++: A Brief Introduction to extitRcpp. PeerJ Prepr.
**2017**, 5, e3188v1. [Google Scholar] [CrossRef] - Hijmans, R.J. Raster: Geographic Data Analysis and Modeling; R Foundation for Statistical Computing: Vienna, Austria, 2020. [Google Scholar]
- Pebesma, E. Stars: Spatiotemporal Arrays, Raster and Vector Data Cubes; R Foundation for Statistical Computing: Vienna, Austria, 2020. [Google Scholar]
- Lovelace, R.; Nowosad, J.; Muenchow, J. Geocomputation with R; CRC Press: Boca Raton, FL, USA, 2019. [Google Scholar]
- Pebesma, E. Simple Features for r: Standardized Support for Spatial Vector Data. R J.
**2018**, 10, 439–446. [Google Scholar] [CrossRef][Green Version] - Tennekes, M. tmap: Thematic Maps in R. J. Stat. Softw.
**2018**, 84, 1–39. [Google Scholar] [CrossRef][Green Version] - Bengtsson, H. Future: Unified Parallel and Distributed Processing in R for Everyone; R Package Version 1.18.0; R Foundation for Statistical Computing: Vienna, Austria, 2020. [Google Scholar]

**Figure 1.**Microstates (

**a**–

**p**) of a closed container filled with four gas molecules. These microstates differ in the composition and configuration of molecules.

**Figure 6.**A comparisons between the hierarchical representation (upscaled versions) generated by iterative applying (

**a**) the resampling technique and that by (

**b**) the aggregation technique.

**Figure 7.**Two example landscapes: “land_gradient1” representing a more diverse landscape and “land_gradient2” representing a less diverse landscape.

**Figure 8.**Examples of Boltzmann entropy values not adjusted and adjusted for missing values that were calculated for eight example local landscapes. Example local landscapes are sorted according to their Boltzmann entropy values.

**Figure 10.**Values of Boltzmann entropy in a grid of 5760 by 5760 m calculated for the digital elevation model for Slovenia.

© 2020 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Nowosad, J.; Gao, P.
belg: A Tool for Calculating Boltzmann Entropy of Landscape Gradients. *Entropy* **2020**, *22*, 937.
https://doi.org/10.3390/e22090937

**AMA Style**

Nowosad J, Gao P.
belg: A Tool for Calculating Boltzmann Entropy of Landscape Gradients. *Entropy*. 2020; 22(9):937.
https://doi.org/10.3390/e22090937

**Chicago/Turabian Style**

Nowosad, Jakub, and Peichao Gao.
2020. "belg: A Tool for Calculating Boltzmann Entropy of Landscape Gradients" *Entropy* 22, no. 9: 937.
https://doi.org/10.3390/e22090937