5  Data Processing

LogoClim integrates WorldClim data into NetLogo models through a multi-step conversion process that can introduce minor discrepancies between the original data and the values used in the model. We recommend verifying data accuracy by running the Near-Equality Tests notebook before proceeding with your analysis.

To convert the downloaded GeoTIFF files to Esri ASCII grid format, we developed the worldclim_to_ascii() function, also part of the orbis R package (Vartanian, 2026). Just like worldclim_download(), it is pretty straightforward to use. Here is a overview of its main parameters:

worldclim_to_ascii(
  file,
  shape = NULL
  box = NULL
)

worldclim_to_ascii allow you not only convert the GeoTIFF files to Esri ASCII format, but also crop the data to a specific region of interest. This is done using the shape or box parameters.

The first parameter, shape, expects a spatial object that defines the area to crop. The second parameter, box, allows you to specify a bounding box using numeric coordinates. You can use one or the other, but not both at the same time. If neither is provided, the function will convert the entire dataset without cropping.

5.1 Shapes

To obtain shapes of countries and their administrative boundaries, we recommend using the geodata R package (Hijmans et al., 2024), which provides access to shapes from the GADM database (Hijmans, n.d.). You can install in R with:

install.packages("geodata")

And load it with:

library(geodata)

With geodata loaded, use the gadm() function to download country shapes. This function identifies countries using the ISO 3166-1 alpha-3 standard and supports multiple resolutions, from country boundaries (level 0) to administrative subdivisions (levels 1, 2, and 3).

For example, if you want to crop WorldClim data to the boundaries of Brazil, you could use the following code:

country_shape <- gadm("BRA", level = 0)

This code will download the shape of Brazil and store it in the country_shape variable, which can then be passed to the shape parameter of the worldclim_to_ascii function for cropping.

Code
library(leaflet)
library(sf)

leaflet() |>
  addProviderTiles(providers$Esri.WorldStreetMap) |>
  fitBounds(
    lng1 = country_shape |>
      st_bbox() |>
      magrittr::extract("xmin") |>
      unname(),
    lat1 = country_shape |>
      st_bbox() |>
      magrittr::extract("ymin") |>
      unname(),
    lng2 = country_shape |>
      st_bbox() |>
      magrittr::extract("xmax") |>
      unname(),
    lat2 = country_shape |>
      st_bbox() |>
      magrittr::extract("ymax") |>
      unname()
  ) |>
  addPolygons(
    data = country_shape,
    fillColor = "transparent",
    color = "blue",
    weight = 2,
    opacity = 1
  )

5.2 Boxes

Alternatively, you can specify a bounding box using the box parameter. This parameter expects a numeric vector with four values: c(xmin, ymin, xmax, ymax), where xmin and xmax are the minimum and maximum longitudes, and ymin and ymax are the minimum and maximum latitudes of the area you want to crop.

For example, if you want to crop the entire European region, you could use the following code:

box <- c(-24.534, 34.625, 50.601, 71.181)
Code
library(leaflet)
library(sf)

leaflet() |>
  addProviderTiles(providers$Esri.WorldStreetMap) |>
  addRectangles(
    lng1 = box[1],
    lat1 = box[2],
    lng2 = box[3],
    lat2 = box[4],
    fillColor = "transparent",
    color = "blue",
    weight = 2,
    opacity = 1
  )

Use the bbox finder tool to easily obtain the coordinates for your area of interest.

5.3 Conversion

With the files downloaded and the shape or box defined, you can proceed to convert the data using the worldclim_to_ascii function. This function will take care of the conversion and cropping (if specified) in one step.

For example, to work with average maximum temperature from the Historical Climate Data series at 10-minute resolution for Brazil, you could use the following code:

files <- worldclim_download(
  series = "hcd",
  resolution = "10m",
  variable = "tmax",
  dir = "path/to/your/data/directory"
)
#> ✔ Scraping WorldClim website [688ms]
#> ℹ Total download size (compressed): 35.7M.
#> ✔ Calculating file sizes [614ms]
#> ✔ Creating LICENSE and README files [291ms]
#> ℹ Downloading 1 file to /path/to/your/data/directory/historical-climate-data
#> ✔ Downloading files [37.3s]
#> ✔ Unzipping files [14ms]
country_shape <- gadm("BRA", level = 0)
files |> worldclim_to_ascii(shape = country_shape)
#> Converting data ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s

The function default values already takes care of possible distortions caused by geographic projection or rotating issues (e.g., shapes that cross the International Date Line). It also removes abnormal outliers from the data.

After processing the data, you’re ready to use LogoClim. Just open the model and point at your data directory using the model interface.

For more details on available conversion parameters, refer to the worldclim_to_ascii documentation.