[R] find number of consecutive days in NC files by R

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Mon Aug 10 05:23:00 CEST 2020


Hi Ahmet,
An easy way is this:

library(ncdf4)
soilm<-nc_open("soilw.0-10cm.gauss.1949.nc")
soil_moist<-ncvar_get(soilm)
smdim<-dim(soil_moist)
# identify NA grid cells
sm_NA_count<-matrix(NA,nrow=smdim[1],ncol=smdim[2])
for(i in 1:smdim[1]) {
 for(j in 1:smdim[2]) {
  sm_NA_count[i,j]<-sum(!is.na(soil_moist[i,j,]))
 }
}

The resulting matrix contains the counts of valid (not NA) values in
each 365 day series in the array. It looks to me as though there are
5914 complete series and the rest are all NA. This does not tell you
why some files (the third dimension) are all NA. Probably the best
guess is that the soil moisture content is not measurable for some
reason. Here is the explanation from NOAA:

Missing Data:

There is no missing data though the ocean has 0's. There is a file
with the percent of the grid that is land. Another file has simply 1
and 0's for land/ocean. Grids where the percent of land is zero are
"missing".

You can get a feel for the geographic coverage like this (white cells
are not NA):

library(maps)
library(plotrix)
color2D.matplot(t(sm_NA_count))

Jim

On Mon, Aug 10, 2020 at 4:09 AM ahmet varlı <varli61 using windowslive.com> wrote:
>
> Hi Jim,
>
>
>
> Could you help me to remove NA values which are water values ?
>
>
>
>
>
> Kimden: Jim Lemon
> Gönderilme: 7 Ağustos 2020 Cuma 22:53
> Kime: ahmet varlı
> Konu: Re: [R] find number of consecutive days in NC files by R
>
>
>
> There are 17848 grid cells in the file I downloaded for 1949. Many of
> them only contain NA values, probably because they are from a
> geographic grid that is covered by water. In the code there is a
> section that prints out a list of the grid cells that contain minimum
> values less than 0.3. Since I don't know which grid cell you are
> using, I had to find one that would produce interpretable results for
> the problem you are trying to solve.
>
> Jim
>
> On Fri, Aug 7, 2020 at 11:03 PM ahmet varlı <varli61 using windowslive.com> wrote:
> >
> > I am greatfull for your helps and ı just want to ask why did you use cell 159,66
> >
>
>



More information about the R-help mailing list