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

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Fri Sep 4 01:49:23 CEST 2020


Hi Ahmet,
I really can't work out what your problem is. I don't have access to
the data you are using and so cannot inspect "a" to see what might be
in it.

Jim

On Wed, Sep 2, 2020 at 8:54 AM ahmet varlı <varli61 using windowslive.com> wrote:
>
> Hi jim,
>
>
>
> I have a new question. I have 71 years raster data from 1949 to 2019 and ı am trying to convert these 71 yeears raster an array to calculate a liner regration.
>
>
>
>
>
> library(raster)
>
> r<-raster("C:/Teaching/MSCprojects/2020/Ahmet/soilm/max_consecutive_days/max_consecutive_days_1949.tif")
>
> a<-array(NA,dim=c(dim(r)[1:2],70))
>
> i <- 1
>
> for (year in 1949:2019) {
>
>   fi<-paste0("C:/Teaching/MSCprojects/2020/Ahmet/soilm/max_consecutive_days_",year,".tif")
>
>   r<-raster(fi)
>
>   a[,,i]<-getValues(r,format="matrix")
>
>             i<-i+1
>
> }
>
> Best wishes,
>
> Windows 10 için Posta ile gönderildi
>
>
>
> Kimden: Jim Lemon
> Gönderilme: 10 Ağustos 2020 Pazartesi 06:28
> Kime: ahmet varlı
> Konu: Re: [R] find number of consecutive days in NC files by R
>
>
>
> That's right. If you want to get the result for all cells with valid
> readings, step through the cells, texting for valid data. The result
> will be quite large, so I suggest sending the output to a file:
>
> sink("soil_moisture_result.txt")
> for(i in 1:nrows(soil_moist)) {
>  for(j in 1:ncols(soil_moist)) {
>  if(sum(!is.na(soil_moist[i,j,]) > 0) {
>   # process the cell here and print out the result
>  }
> }
> sink()
>
> caution: untested
>
> Jim
>
> On Mon, Aug 10, 2020 at 2:02 PM ahmet varlı <varli61 using windowslive.com> wrote:
> >
> > Hi Jim,
> >
> >
> >
> > I would like to find out how many consecutive days each cell is under the specific value for a certain date range. İf I am right your code is for just one cell
> >
> >
> >
> >
> >
> > Kimden: Jim Lemon
> > Gönderilme: 10 Ağustos 2020 Pazartesi 04:23
> > Kime: ahmet varlı; r-help mailing list
> > Konu: Re: [R] find number of consecutive days in NC files by R
> >
> >
> >
> > 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