ARCCSS-extremes / climpact

Calculate the ET-SCI climate extremes indices
GNU General Public License v3.0
42 stars 29 forks source link

error trying to get 90th percentile values "object cannot be coerced to type 'double'" #95

Closed carolinamarghidan closed 2 years ago

carolinamarghidan commented 2 years ago

Dear @heroldn, @jmccomb , @lisavalexander

I have used climpact to calculate heatwave indices using netcdf data, and would like to extract a file with the 90th percentile values that are used to calculate these per grid cell. However, I get this error (from running the sample script!):

Loading required package: PCICt
Loading required package: lmomco
Loading required package: parallel
Loading required package: ggplot2
Registered S3 methods overwritten by 'ggplot2':
  method         from 
  [.quosures     rlang
  c.quosures     rlang
  print.quosures rlang
# Package SPEI (1.7) loaded [try SPEINews()].
Error in ncdf4::ncvar_put(f, v, dat, start = starts, count = counts) : 
  (list) object cannot be coerced to type 'double'
Calls: create.thresholds.from.file ... nc.put.subset.recursive -> nc.put.subset.recursive -> <Anonymous>
Execution halted

and this is the sample script:

library(climdex.pcic.ncdf)
# list of one to three input files. e.g. c("a.nc","b.nc","c.nc")
input.files=c("./www/sample_data/climpact.sampledata.gridded.1991-2010.nc")

# list of variable names according to above file(s)
vars=c(tmax="tmax", tmin="tmin")

# output file name
output.file="thresholds.1991-2010.nc"

# author data
author.data=list(institution="My University", institution_id="MU")

# reference period
base.range=c(1991,2010)

# number of cores to use (or FALSE)
cores=FALSE

# print messages?
verbose=TRUE

# Directory where Climpact is stored. Use full pathname. Leave as NULL if you are running this script from the Climpact directory (where this script was initially stored).
root.dir=NULL

######################################
# Do not modify without a good reason.

fclimdex.compatible=FALSE

create.thresholds.from.file(input.files,output.file,author.data,variable.name.map=vars,base.range=base.range,parallel=cores,verbose=verbose,fclimdex.compatible=fclimdex.compatible,root.dir=root.dir)`

Any help is much appreciated! Thank you, Carolina

carolinamarghidan commented 2 years ago

solved: I read in another issue that climpact expects the 3 variables; so needed to include precip.

Is it still possible to calculate the thresholds only using tmax and tmin? Do I need to create a dummy variable for precip?

Thank you!

carolinamarghidan commented 2 years ago

I've created a dummy variable and it works!

Bhavesh-2001 commented 1 year ago

Hello @carolinamarghidan I am facing the same error and need to fix it asap. Can you tell me how you created the dummy variable and implemented it. My input file already contains precipitation, tmax and tmin