biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
87 stars 22 forks source link

ensemble modeling output plot gave inverse values but with accurate projection on map #310

Closed sandeepB055 closed 9 months ago

sandeepB055 commented 1 year ago

i ran ensemble modeling for single species. used plot function from tidyterra in order to visualise the model on my area. the map showed an expected distribution of the sps but the legend of this map showed the exact opposite of expected outcome. it showed zero/absence where there should be presence and the other way around.

## format the data ----
P.karavaali_data <- 
  BIOMOD_FormatingData(
    resp.var = P.karavaali['Phrynoderma.karavaali'],
    resp.xy =P.karavaali[, c('Longitude', 'Latitude')],
    expl.var = bioclim_ZA_sub_stack,
    resp.name = "Phrynoderma.karavaali",
    PA.nb.rep = 1,
    PA.nb.absences = 100,
    PA.strategy = 'random'
  )
beepr::beep(8)

P.karavaali_data
## run the individual models ----
P.karavaali_models <- 
  BIOMOD_Modeling(
    bm.format = P.karavaali_data,
    models = c("GLM", "GBM", "GAM", "CTA", "ANN", "SRE", "FDA", "MARS", "RF", "MAXENT",
               "MAXNET", "XGBOOST"),
    bm.options = NULL,
    nb.rep = 1,
    data.split.perc = 70,
    var.import = 1,
    modeling.id = "demo1"
  )

#ensemble projection of new cropped area using previous single model projection data
P.karavaali_ensemble_models_proj_current <- 
  BIOMOD_EnsembleForecasting(P.karavaali_ensemble_models,
                             bm.proj = P.karavaali_models_proj_current,
                             metric.binary = 'TSS',
                             output.format = ".img",
                             do.stack = FALSE)

plot(P.karavaali_ensemble_models_proj_current) + scale_fill_hypso_c() +
  theme_void()
>>>>> OUTPUT<<<<<

Creating suitable Workdir...

    > Projecting Phrynoderma.karavaali_EMcvByTSS_mergedData_mergedRun_mergedAlgo ...
        Writing projection on hard drive...
    > Projecting Phrynoderma.karavaali_EMcaByTSS_mergedData_mergedRun_mergedAlgo ...
        Writing projection on hard drive...
    > Projecting Phrynoderma.karavaali_EMwmeanByTSS_mergedData_mergedRun_mergedAlgo ...
        Writing projection on hard drive...

! Binary/Filtered transformation automatically deactivated for ensemble models with coefficient of variation or confidence intervals
    > Building TSS binaries / filtered

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Warning messages:
1: Too large for int: nan (GDAL error 1) 
2: Too large for int: nan (GDAL error 1)
> plot(P.karavaali_ensemble_models_proj_current)
Warning message:
Mixed data classes found on layers. Only layers of class <numeric> have been kept (geom_spatraster)
SpatRaster resampled to ncells = 500324
rpatin commented 1 year ago

Hi @sandeepB055, thank you for reporting :pray: Can you share the plot you get ? Can you also share the output of:

Thanks in advance, Best, Rémi

sandeepB055 commented 1 year ago

i used plot("file path of .img file") to obtain the accurate plot for the projections. however when i use the plot function directly plot(P.karavaali_ensemble_models_proj_current) it still gives the inverse projection.

MayaGueguen commented 1 year ago

Hello @sandeepB055,

I'm taking over from Rémi from there. But I'll need a bit more details to understand what is the problem and what is going on. What plot do you get when trying the command ?

plot(P.karavaali_ensemble_models_proj_current)

What is the one you get when you plot directly from the file ?

Maya

sandeepB055 commented 1 year ago

this is the plot i got. this is wrong because the region where it shows "0" presence is actually where we found the species in abundance. while plotting using a file path of the disc image file, im getting the correct distribution map

final<- raster("D:/academics/PhD plans/SDM/P. karavaali/work_dir/Phrynoderma.karavaali/proj_ensemble_current/individual_projections/Phrynoderma.karavaali_EMwmeanByTSS_mergedData_mergedRun_mergedAlgo.img") plot(final)

this gets me the correct plot

given below is the wrong output of plot(P.karavaali_ensemble_models_proj_current)

a14eda04-f706-4c36-b2f0-67b61e51569f

MayaGueguen commented 1 year ago

I'm not sure I can be of much help here... The graphic you show coming from :

plot(P.karavaali_ensemble_models_proj_current)

show probability values, the output of your modeling.

If it does not match your observed data, maybe it is just that your model does not manage to mode your data ?

MayaGueguen commented 11 months ago

I'm sorry that I missed that, but in your code, you seem to load your EMwmean ensemble model, while on your plot, you show the output of EMcv model.

EMcv represents the coefficient of variation of probabilities, and not probabilities. So it is normal that it does not match your observed data. You can check this https://github.com/biomodhub/biomod2/issues/345#issuecomment-1803875396 for more details.

Maya