help

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

help

Marco Antonio Pérez
 I am trying to write a function to make a matrix of precipitation with
this secuencie;
######## PRIMER PERIODO
cordex1 <-
nc_open("pr_CAM-44i_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_mon_200601-201012.nc")
fullmon1<-ncvar_get(cordex1,"pr")
lat<-ncvar_get(cordex1,"lat", start=c(35.5),count=c(20))
lon <-ncvar_get(cordex1,"lon", start=c(125),count=c(21.5))
t <- ncvar_get(cordex1,"time")
nlon <- dim(lon)
nlat <- dim(lat)
nt <- dim(t)
fulldatav <- as.vector(fullmon1)
fulldata <- matrix(fulldatav, nrow=nlon*nlat, ncol=nt)
lonlat <- expand.grid(lon,lat)
df_cordex1<- data.frame(lonlat,fulldata)

but with the expresion  fulldata <- matrix(fulldatav, nrow=nlon*nlat,
ncol=nt) this error appears
Warning message:
In matrix(fulldatav, nrow = nlon * nlat, ncol = nt) :
  data length [1378620] is not a sub-multiple or multiple of the number of
rows [420]

Somebody help me!!!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: help

R help mailing list-2
Marco,

The error message indicates that nlon*nlat is 420 and that 1378620/420 has a remainder. For the matrix to form, all rows have to be complete.

I am guessing you have at least one value incorrect among nlon, nlat, t or the length of fulldatav.

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
[hidden email]











> On Aug 10, 2018, at 10:00 AM, Marco Antonio Pérez <[hidden email]> wrote:
>
> I am trying to write a function to make a matrix of precipitation with
> this secuencie;
> ######## PRIMER PERIODO
> cordex1 <-
> nc_open("pr_CAM-44i_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_mon_200601-201012.nc")
> fullmon1<-ncvar_get(cordex1,"pr")
> lat<-ncvar_get(cordex1,"lat", start=c(35.5),count=c(20))
> lon <-ncvar_get(cordex1,"lon", start=c(125),count=c(21.5))
> t <- ncvar_get(cordex1,"time")
> nlon <- dim(lon)
> nlat <- dim(lat)
> nt <- dim(t)
> fulldatav <- as.vector(fullmon1)
> fulldata <- matrix(fulldatav, nrow=nlon*nlat, ncol=nt)
> lonlat <- expand.grid(lon,lat)
> df_cordex1<- data.frame(lonlat,fulldata)
>
> but with the expresion  fulldata <- matrix(fulldatav, nrow=nlon*nlat,
> ncol=nt) this error appears
> Warning message:
> In matrix(fulldatav, nrow = nlon * nlat, ncol = nt) :
>  data length [1378620] is not a sub-multiple or multiple of the number of
> rows [420]
>
> Somebody help me!!!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Writing .nc files

R help mailing list-2
Marco,

Always post to the r-help list to have a better chance of finding someone that can help.

There is a very nice tutorial that you should have found. See http://geog.uoregon.edu/bartlein/courses/geog490/week04-netCDF.html#create-and-write-a-netcdf-file

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
[hidden email]











> On Aug 28, 2018, at 8:26 AM, R. Mark Sharp <[hidden email]> wrote:
>
> Marco,
>
> You will need to ask the list. I have never worked with .nc files.
>
> Most are wanting to go the other direction .nc to .csv or dataframe. Google search with “.nc file in r”.
>
> R. Mark Sharp, Ph.D.
> Data Scientist and Biomedical Statistical Consultant
> 7526 Meadow Green St.
> San Antonio, TX 78251
> mobile: 210-218-2868
> [hidden email]
>
>
>
>
>
>
>
>
>
>
>
>> On Aug 27, 2018, at 10:12 AM, Marco Antonio Pérez <[hidden email]> wrote:
>>
>> Hello Mark:
>>
>> I appreciate your sopport in this subject. But now, I need your help again, please.
>> I wondering if you know how to transform a .csv file to .nc file_
>>
>> Thanks a lot!!
>>
>> 2018-08-10 17:08 GMT-03:00 R. Mark Sharp <[hidden email]>:
>> Marco,
>>
>> The error message indicates that nlon*nlat is 420 and that 1378620/420 has a remainder. For the matrix to form, all rows have to be complete.
>>
>> I am guessing you have at least one value incorrect among nlon, nlat, t or the length of fulldatav.
>>
>> Mark
>> R. Mark Sharp, Ph.D.
>> Data Scientist and Biomedical Statistical Consultant
>> 7526 Meadow Green St.
>> San Antonio, TX 78251
>> mobile: 210-218-2868
>> [hidden email]
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Aug 10, 2018, at 10:00 AM, Marco Antonio Pérez <[hidden email]> wrote:
>>>
>>> I am trying to write a function to make a matrix of precipitation with
>>> this secuencie;
>>> ######## PRIMER PERIODO
>>> cordex1 <-
>>> nc_open("pr_CAM-44i_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_mon_200601-201012.nc")
>>> fullmon1<-ncvar_get(cordex1,"pr")
>>> lat<-ncvar_get(cordex1,"lat", start=c(35.5),count=c(20))
>>> lon <-ncvar_get(cordex1,"lon", start=c(125),count=c(21.5))
>>> t <- ncvar_get(cordex1,"time")
>>> nlon <- dim(lon)
>>> nlat <- dim(lat)
>>> nt <- dim(t)
>>> fulldatav <- as.vector(fullmon1)
>>> fulldata <- matrix(fulldatav, nrow=nlon*nlat, ncol=nt)
>>> lonlat <- expand.grid(lon,lat)
>>> df_cordex1<- data.frame(lonlat,fulldata)
>>>
>>> but with the expresion  fulldata <- matrix(fulldatav, nrow=nlon*nlat,
>>> ncol=nt) this error appears
>>> Warning message:
>>> In matrix(fulldatav, nrow = nlon * nlat, ncol = nt) :
>>> data length [1378620] is not a sub-multiple or multiple of the number of
>>> rows [420]
>>>
>>> Somebody help me!!!
>>>
>>>      [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.