metno / esd

An R-package designed for climate and weather data analysis, empirical-statistical downscaling, and visualisation.
88 stars 30 forks source link

Regrid & NA values #263

Open CaptainMiao123 opened 2 years ago

CaptainMiao123 commented 2 years ago

It all goes well using the newest version 1.10.3 of esd R package untill I regrid the NC file to some specific stations. It bothered me a lot since for a specific station location the regrid function of some NC file returns NA while others not.

       And my regrid code is like:

       gcm.can <- retrieve(file='pr_day_CanESM5_historical_r19i1p1f1_gn_18500101-20141231.nc',param="pr",
                  lon=c(89,105),lat=c(24,36),plot=TRUE)
       y<-regrid(gcm.can,is=list(lon=104.32,lat=28.49))

       gcm.bcc <- retrieve(file='pr_day_BCC-CSM2-MR_historical_r1i1p1f1_gn_19500101-19741231.nc',param="pr",
                  lon=c(89,105),lat=c(24,36),plot=TRUE)
       y<-regrid(gcm.bcc,is=list(lon=104.32,lat=28.49))

       There are other stations that found NA from other NC files. And I am not sure if my code usage is correct. Could you help me with this? 
abdelkaderm commented 2 years ago

Hi, your command lines are correct and it is hard to answer your question on why some of your files return NA values for the coordinates you specified. The only explanation is that your netCDF files may be stored differently or may be corrupted. One way to investigate this is to use a loop with the function summary.ncdf4 which will return the summary of the NC files content such as dimensions, variable names and check some of the attributes whether they exist or not.

brasmus commented 2 years ago

I think the reason why you get NA values is because you retrieved a region too small and with a boundary too close to the coordinate that you wanted to interpolate. The GCM data is fairly coarse and you need valid data on all four grid points around it. If you try lon=c(100,110),lat=c(24,36), I think you may get better results.

CaptainMiao123 commented 2 years ago

I just tried to station the retrieved NC data first and then regrid it, and got every station-scaled value surprisingly! I think my experience may be useful for future users so I share my results here and remain open to further discuss!