Aim of the function BEE.convert.celsius()

Identifies the unit of a temperature spatraster and convert the pixels values into celsius degrees. If the pixel values are modified, the units metadata of the spatraster is updated to celsius.

Data for this tutorial

A Spatraster imported containning the sea surface temperature in the Gulf of Lion from the 1st of January 2023 to the 31th of Decembre 2025. There are only one variable in the spatraster (sea surface temperature).

### Load the example dataset in R environement :
file_name <- system.file(file.path("extdata", "copernicus_example_data.nc"),
                                   package = "BioExtremeEvent")
copernicus_data <- terra::rast(file_name)

The original dataset is in Kelvin :

terra::units(copernicus_data[[1]]) #first layer only
## [1] "kelvin"

Usage

Argument:

The function takes only one argument, your dataset.

Warnings:

You will receive a warning if :

  • various units are detected for a same layer.
  • different layers have different units.
  • some layers have no unit declared, you will have to declare a unit.
  • the dataset is already in Celsius degrees.
  • if a layer has a unit that is not recognise by the function (see bellow).

Messages:

If your dataset was in Kelvin or Fahrenheit, you will receive a message saying which conversion has been done.

Output

The output is a spatraster with the same properties as yourspatraster but yhe pixel values are in degrees Celsius. Pixels that were NA remain NA.

Example with a dataset in Kelvin

library(BioExtremeEvent)
### Apply function :
copernicus_data_celsius <- BioExtremeEvent::BEE.convert.celsius(copernicus_data)
## Warning in BioExtremeEvent::BEE.convert.celsius(copernicus_data): Your data were in Kelvin and have been converted to Celsius using:
##             former value - 273.15 = new value.
### Values after applying functions : 
head(na.omit(terra::values(x = copernicus_data_celsius[[1]],
                   dataframe=TRUE))) # first pixels are on land so their value is NA
##    analysed_sst_1
## 17       13.83999
## 18       13.76000
## 19       13.76000
## 20       13.79998
## 21       13.92999
## 22       14.05999
### Checking the unit of the spatraster :
 #### Before using BEE.convert.celsius :
 terra::units(copernicus_data[[1]])
## [1] "kelvin"
 #### After using BEE.convert.celsius : 
 terra::units(copernicus_data_celsius[[1]])
## [1] "Celsius"

Example with a dataset already in Celsius

### Apply function :
copernicus_data_celsius <- BioExtremeEvent::BEE.convert.celsius(copernicus_data_celsius)
## [1] "Your dataset is already in celsius, there is no need to use this function."

How to save the output

The output is a spatraster, you can save it using:

terra::writeRaster(copernicus_data_celsius, "your_path/data/copernicus_data_celsius.tiff")