Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbferet committed May 13, 2020
2 parents 0507848 + 594e8e5 commit 07a5f04
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 37 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: biodivMapR
Title: biodivMapR: an R package for α- and β-diversity mapping using remotely-sensed images
Version: 1.2.0
Title: biodivMapR: an R package for a- and ß-diversity mapping using remotely-sensed images
Version: 1.2.1
Authors@R: c(person(given = "Jean-Baptiste",
family = "Feret",
email = "jb.feret@teledetection.fr",
Expand Down Expand Up @@ -36,7 +36,7 @@ Imports:
tools,
vegan,
zip
RoxygenNote: 6.1.1
RoxygenNote: 7.1.0
Suggests: knitr,
rmarkdown
VignetteBuilder: knitr
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# biodivMapR v1.2.1

## Changes
- added option to convert the mask file into proper format with raster2BIL

# biodivMapR v1.2.0

## Fixes
Expand Down
14 changes: 9 additions & 5 deletions R/Lib_CheckConvertData.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
# if not, can convert the raster into BIL format expected for diversity mapping
# ==============================================================================

#' converts a raster into BIL format as expected by DivMapping codes
#' converts a raster into BIL format as expected by biodivMapR codes
#'
#' @param Raster_Path character. Full path for the raster to be converted
#' @param Sensor character. Name of the sensor. a .hdr template for the sensor should be provided in extdata/HDR
#' @param Convert_Integer boolean. Should data be converted into integer ?
#' @param Multiplying_Factor numeric. Multiplying factor (eg convert real reflectance values between 0 and 1 into integer between 0 and 10000).
#' @param Output_Dir character. Path to output directory.
#' @param Multiplying_Factor_Last numeric. Multiplying factor for last band.
#' @param Mask boolean is the file a mask file with 0s and 1s only?
#'
#' @return Output_Path path for the image converted into ENVI BIL format
#' @import raster
#' @import tools
#' @export
raster2BIL <- function(Raster_Path, Sensor = "unknown", Output_Dir = FALSE, Convert_Integer = TRUE, Multiplying_Factor = 1, Multiplying_Factor_Last = 1) {
raster2BIL <- function(Raster_Path, Sensor = "unknown", Output_Dir = FALSE, Convert_Integer = TRUE,
Multiplying_Factor = 1, Multiplying_Factor_Last = 1, Mask = FALSE) {

# get directory and file name of original image
Input_File <- basename(Raster_Path)
Expand All @@ -46,15 +48,17 @@ raster2BIL <- function(Raster_Path, Sensor = "unknown", Output_Dir = FALSE, Conv
Last_Band_Name <- Output_Img@data@names[length(Output_Img@data@names)]
Output_Img[[Last_Band_Name]] <- Multiplying_Factor_Last * Output_Img[[Last_Band_Name]]

# convert into integer
if (Convert_Integer == TRUE) {
# convert into integer if requested or if is Mask
if (Convert_Integer == TRUE | Mask == TRUE) {
Output_Img <- round(Output_Img)
}

# write raster
message("writing converted file")
if (Convert_Integer == TRUE) {
if (Convert_Integer == TRUE & Mask == FALSE) {
r <- writeRaster(Output_Img, filename = Output_Path, format = "EHdr", overwrite = TRUE, datatype = "INT2S")
} else if (Convert_Integer == TRUE & Mask == TRUE) {
r <- writeRaster(Output_Img, filename = Output_Path, format = "EHdr", overwrite = TRUE, datatype = "INT1U")
} else {
r <- writeRaster(Output_Img, filename = Output_Path, format = "EHdr", overwrite = TRUE)
}
Expand Down
19 changes: 15 additions & 4 deletions man/map_alpha_div.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions man/map_beta_div.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions man/map_spectral_species.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions man/perform_PCA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions man/perform_radiometric_filtering.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions man/raster2BIL.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/select_PCA_components.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions vignettes/biodivMapR_1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,30 @@ Input_Image_File = raster2BIL(Raster_Path = Path_Raster_File,
Output_Dir = Path_Output_Directory,
Convert_Integer = Convert_Integer,
Multiplying_Factor = Multiplying_Factor,
Multiplying_Factor_Last=Multiplying_Factor_Last)
Multiplying_Factor_Last=Multiplying_Factor_Last,
Mask = FALSE)
```

## Input variables

The following information is expected as input information:
The following information is accepted as input information:

* `Raster_Path`: a string containing the full path for the raster to be converted.
* `Sensor`: a string containing the name of the sensor, which should actually be linked to a template for the corresponding header file.
* `Output_Dir` [optional]: a string defining the path for the output directory where converted file will be stored.
* `Convert_Integer` [optional]: a boolean stating if the raster data should be converted into integer
* `Multiplying_Factor` [optional]: a multiplying factor for the raster data. This is useful when converting real reflectance values between 0 and 1 into integer between 0 and 10000. Set `Multiplying_Factor =10000` in this case.
* `Multiplying_Factor_Last` [optional]: a multiplying factor for last band. This option is useful only if working with dry vegetation acquired with Sentinel-2 images, in order to artifically increase the reflectance of the B12 band (SWIR 2, centered at 2200 nm), so that SWIR 1 band remains below the convex hull defined during Continuum removal. __You do not need to use this option most of the time, unless you want to enhance teh sensitivity to different types of dry vegetation__.
* `Mask` [optional]: a boolean stating if the raster data corresponds to a mask (TRUE) or not (FALSE). If it is a mask, masked pixels should have a value of `0`, and pixels to keep for the analysis should have a value of `1`. raster2BIL converts image information into unsigned 8 bits integer.


Please note that
i) the coordinate system and minimal metadata (spatial resolution, geographic information...) are expected to be provided in the original image or image + header defined in `Raster_Path` if user want them to be included in the final image products.

ii) `Sensor` should refer to the name of a `.hdr` file stored in the installation directory of `biodivMapR`
Please type `system.file(package = "biodivMapR")` in order to get the location of the install directory and create a proper `.hdr` file to be stored in `extdata/HDR/`, containing proper spectral bands __defined in nanometers__ if using optical data and using `perform_radiometric_filtering` and/or `Continuum_Removal = TRUE` in your process. Make sure that the __spectral bands in the binary file are stored with wavelengths following ascending order__.

iii) `Convert_Integer=TRUE` saves 50% space if original image is stored in real values (32bits per value). However, user need to make sure hat their original data are compatible with conversion: if reflectance values are stored as real value between 0 and 1, the final image file will be unusable, unless proper multiplying factor is applied to the full image data (for example `Multiplying_Factor =10000`). Sentinel-2 reflectance data downloaded from ESA hub are stored as integer (16 bits) values between 0 and 10 000 instead of real (32 bits) values between 0 and 1, so integer conversion is unnecessary.
iii) `Convert_Integer=TRUE` saves 50% space if original image is stored in real values (32 bits per value). However, user need to make sure hat their original data are compatible with conversion: if reflectance values are stored as real value between 0 and 1, the final image file will be unusable, unless proper multiplying factor is applied to the full image data (for example `Multiplying_Factor =10000`). Sentinel-2 reflectance data downloaded from ESA hub are stored as integer (16 bits) values between 0 and 10 000 instead of real (32 bits) values between 0 and 1, so integer conversion is unnecessary.

## output variable

Expand Down

0 comments on commit 07a5f04

Please sign in to comment.