1

I have multiple .nc which are also in .tif files that I would like to use to calculate the probability based on a statistical model. I have 5 files (V1.nc, V2.nc, V3.nc, V4.nc, V5.nc), and a statistical model being: y = 1 / (1 + exp(-(Intercept + V1 * 1.87 + V2 * 1.53 + V3 * (-4.18) + V4 * 3.58 + V5 * 9.13))).

I normally use Qgis, RStudio and Ubuntu, and I do not care which of these programs to use.

Is there a way for me to use those files to calculate the overall y?

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Thomas
  • 441
  • 3
  • 16
  • See documentation on the QGIS raster calculator. https://docs.qgis.org/3.16/en/docs/user_manual/working_with_raster/raster_analysis.html The only issue is there is no exponential function - replace with 2.71828 ^ ( ... ) – Robert Davy Apr 06 '21 at 22:31

1 Answers1

2

You can try to cat the files into one using

cdo cat V?.nc combined.nc 

and then make a new variable using the expression command

intercept=2.3123 # or whatever the value is 
cdo expr,'y=1 / (1 + exp(-(${intercept} + V1 * 1.87 + V2 * 1.53 - 4.18*V3 + V4 * 3.58 + V5 * 9.13)))' combined.nc newvar.nc

I'm assuming the variable in V1.nc is called "V1" etc, if not substitute the name accordingly.

EDIT: According to the comment each file uses the same variable name. So either the variable should be renamed in each file using NCO prior to the above, or one could combine the original files using separate cdo functions as follows:

cdo -pow,-1 -addc,1 -exp -mulc,-1 -addc,$intercept -add -mulc,1.87 V1.nc -add -mulc,1.53 V2.nc -add -mulc,-4.18 V4.nc -add -mulc,3.58 V4.nc -mulc,9.13 V5.nc mynewvariable.nc 

I've used piping to get it on one line and avoid intermediate files, check my equation carefully but I hope it doesn't contain mistakes. With piping it helps to read from right to left.

The variable in the file mynewvariable.nc will also be called Band1; you might want to change the metadata appropriately using nco, always a good habit to have even if the files are only for your own use...

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Hi @Adrian, Thanks for your response. The variables in the five `nc files` are actually all called Band1, should that be changed prior to the `cat` call? Is that also why I get as if the variables are five different timestamps when I use the `cat`? Thank you again. – Thomas Apr 06 '21 at 22:24
  • yes that would cause some confusion... either rename the variables or build up the answer with separate cdo functions... I'll edit my answer – ClimateUnboxed Apr 07 '21 at 07:31
  • Of course Adrian, thanks. I will try it out right now, and then I'll return, thanks! – Thomas Apr 07 '21 at 07:43
  • There was something I learned from Robert Wilson recently, I'm trying to remember, I think it was also to use -L if you get a core error when piping, it forces sequential I/O access. Just in case it dies while trying to pipe. – ClimateUnboxed Apr 07 '21 at 07:48
  • 1
    Thanks, it seems to work nicely. Beautiful - thanks! – Thomas Apr 07 '21 at 08:43