Subset Rasterbrick by time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Subset Rasterbrick by time

Miluji Sb
 Dear all,

I have a rasterbrick with the date/time information provided which I would
like to subset by year.

However, when I use the following code for sub-setting;

new_brick <- subset(original, which(getZ( original ) >= as.Date("2000-01-01
10:30:00") & getZ(original ) <= as.Date("2014-12-31 10:30:00")))

The date/time information seems to be lost.

Furthermore, the class of the date/time seems to be character;

##
class(getZ( original ))
[1] "character"

Is it possible to convert this string to date before sub-setting or retain
the date/time information after sub-setting?

### original RasterBrick ###
class       : RasterBrick
dimensions  : 600, 1440, 864000, 11320  (nrow, ncol, ncell, nlayers)
resolution  : 0.25, 0.25  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source :
/work/mm01117/GLDAS_025_deg/daily/gldas_tavg_tmin_tmax_precip_windspd_sphum_daily_1986_2016.nc4
names       : X1986.01.01.10.30.00, X1986.01.02.10.30.00,
X1986.01.03.10.30.00, X1986.01.04.10.30.00, X1986.01.05.10.30.00,
X1986.01.06.10.30.00, X1986.01.07.10.30.00, X1986.01.08.10.30.00,
X1986.01.09.10.30.00, X1986.01.10.10.30.00, X1986.01.11.10.30.00,
X1986.01.12.10.30.00, X1986.01.13.10.30.00, X1986.01.14.10.30.00,
X1986.01.15.10.30.00, ...
Date/time   : 1986-01-01 10:30:00, 2016-12-31 10:30:00 (min, max)
varname     : v1

### new RasterBrick ###
class       : RasterStack
dimensions  : 600, 1440, 864000, 5477  (nrow, ncol, ncell, nlayers)
resolution  : 0.25, 0.25  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
names       : X2000.01.01.10.30.00, X2000.01.02.10.30.00,
X2000.01.03.10.30.00, X2000.01.04.10.30.00, X2000.01.05.10.30.00,
X2000.01.06.10.30.00, X2000.01.07.10.30.00, X2000.01.08.10.30.00,
X2000.01.09.10.30.00, X2000.01.10.10.30.00, X2000.01.11.10.30.00,
X2000.01.12.10.30.00, X2000.01.13.10.30.00, X2000.01.14.10.30.00,
X2000.01.15.10.30.00, ...

Any help will be greatly appreciated.

Sincerely,

Milu

        [[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: Subset Rasterbrick by time

David Winsemius


> On Jun 18, 2018, at 7:21 AM, Miluji Sb <[hidden email]> wrote:
>
> Dear all,
>
> I have a rasterbrick with the date/time information provided which I would
> like to subset by year.
>
> However, when I use the following code for sub-setting;
>
> new_brick <- subset(original, which(getZ( original ) >= as.Date("2000-01-01
> 10:30:00") & getZ(original ) <= as.Date("2014-12-31 10:30:00")))
>
> The date/time information seems to be lost.
>
> Furthermore, the class of the date/time seems to be character;
>
> ##
> class(getZ( original ))
> [1] "character"
>
> Is it possible to convert this string to date before sub-setting or retain
> the date/time information after sub-setting?

Yes, it is certainly possible, but why bother? R's Comparison operators work on character values so you should be able to do this (if the subsetting is syntactically correct:

 new_brick <- subset(original, which(getZ( original ) >= "2000-01-01
10:30:00" & getZ(original ) <= "2014-12-31 10:30:00") )


As always if you had presented the output of dput(head(original)) assuming that head is a meaningful operation on such an object, the demonstration would have been possible. An alternate would be to offer a library call to a package and then load a relevant example.


Best;
David

>
> ### original RasterBrick ###
> class       : RasterBrick
> dimensions  : 600, 1440, 864000, 11320  (nrow, ncol, ncell, nlayers)
> resolution  : 0.25, 0.25  (x, y)
> extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source :
> /work/mm01117/GLDAS_025_deg/daily/gldas_tavg_tmin_tmax_precip_windspd_sphum_daily_1986_2016.nc4
> names       : X1986.01.01.10.30.00, X1986.01.02.10.30.00,
> X1986.01.03.10.30.00, X1986.01.04.10.30.00, X1986.01.05.10.30.00,
> X1986.01.06.10.30.00, X1986.01.07.10.30.00, X1986.01.08.10.30.00,
> X1986.01.09.10.30.00, X1986.01.10.10.30.00, X1986.01.11.10.30.00,
> X1986.01.12.10.30.00, X1986.01.13.10.30.00, X1986.01.14.10.30.00,
> X1986.01.15.10.30.00, ...
> Date/time   : 1986-01-01 10:30:00, 2016-12-31 10:30:00 (min, max)
> varname     : v1
>
> ### new RasterBrick ###
> class       : RasterStack
> dimensions  : 600, 1440, 864000, 5477  (nrow, ncol, ncell, nlayers)
> resolution  : 0.25, 0.25  (x, y)
> extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> names       : X2000.01.01.10.30.00, X2000.01.02.10.30.00,
> X2000.01.03.10.30.00, X2000.01.04.10.30.00, X2000.01.05.10.30.00,
> X2000.01.06.10.30.00, X2000.01.07.10.30.00, X2000.01.08.10.30.00,
> X2000.01.09.10.30.00, X2000.01.10.10.30.00, X2000.01.11.10.30.00,
> X2000.01.12.10.30.00, X2000.01.13.10.30.00, X2000.01.14.10.30.00,
> X2000.01.15.10.30.00, ...
>
> Any help will be greatly appreciated.
>
> Sincerely,
>
> Milu
>
> [[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
|

Help, zero-truncated Binomial distribution

Juggler_IN
Hi,

Is there a code available for zero-truncated Binomial distribution on the lines of zero-truncated Poisson distribution available at:
https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html

Regards,
Gagandeep

        [[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, zero-truncated Binomial distribution

Peter Dalgaard-2
I think you can pretty much copy what is in that reference while substituting "binom" for "pois" (not quite, but you get the point?)

-pd

> On 18 Jun 2018, at 17:31 , Gagandeep S. Datta <[hidden email]> wrote:
>
> Hi,
>
> Is there a code available for zero-truncated Binomial distribution on the lines of zero-truncated Poisson distribution available at:
> https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html
>
> Regards,
> Gagandeep
>
> [[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.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[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, zero-truncated Binomial distribution

Jeff Newmiller
In reply to this post by Juggler_IN
Mailing list etiquette requires that you don't start a new thread by replying to an existing thread. Start a new thread with a fresh email.

Also, this is a plain text mailing list... HTML formatting gets removed and what is left often does not look to the list readers like what you sent. Read the Posting Guide mentioned below for more about interacting with the list.

On June 18, 2018 8:31:36 AM PDT, "Gagandeep S. Datta" <[hidden email]> wrote:

>Hi,
>
>Is there a code available for zero-truncated Binomial distribution on
>the lines of zero-truncated Poisson distribution available at:
>https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html
>
>Regards,
>Gagandeep
>
> [[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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[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, zero-truncated Binomial distribution

Bert Gunter-2
Search!

My first hit on a google search of "zero truncated binomial" was this:

https://rdrr.io/cran/actuar/man/ZeroTruncatedBinomial.html

which appears to be what you want.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Jun 18, 2018 at 8:59 AM, Jeff Newmiller <[hidden email]>
wrote:

> Mailing list etiquette requires that you don't start a new thread by
> replying to an existing thread. Start a new thread with a fresh email.
>
> Also, this is a plain text mailing list... HTML formatting gets removed
> and what is left often does not look to the list readers like what you
> sent. Read the Posting Guide mentioned below for more about interacting
> with the list.
>
> On June 18, 2018 8:31:36 AM PDT, "Gagandeep S. Datta" <
> [hidden email]> wrote:
> >Hi,
> >
> >Is there a code available for zero-truncated Binomial distribution on
> >the lines of zero-truncated Poisson distribution available at:
> >https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html
> >
> >Regards,
> >Gagandeep
> >
> >       [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> [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.
>

        [[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: Subset Rasterbrick by time

Michael Sumner-2
In reply to this post by David Winsemius
On Mon, 18 Jun 2018, 22:09 David Winsemius, <[hidden email]> wrote:

>
>
> > On Jun 18, 2018, at 7:21 AM, Miluji Sb <[hidden email]> wrote:
> >
> > Dear all,
> >
> > I have a rasterbrick with the date/time information provided which I
> would
> > like to subset by year.
> >
> > However, when I use the following code for sub-setting;
> >
> > new_brick <- subset(original, which(getZ( original ) >=
> as.Date("2000-01-01
> > 10:30:00") & getZ(original ) <= as.Date("2014-12-31 10:30:00")))
> >
> > The date/time information seems to be lost.
> >
>

This is a bug, I tend to extract (getZ) the dates, do the subset logic on
both and restore (setZ).

It takes a bit of learning and practice, good luck. I can't expand more at
the moment. See R-Sig-Geo for more specific discussion forum, and #rstats
on twitter is really good.

Cheers, Mike

> > Furthermore, the class of the date/time seems to be character;
> >
> > ##
> > class(getZ( original ))
> > [1] "character"
> >
> > Is it possible to convert this string to date before sub-setting or
> retain
> > the date/time information after sub-setting?
>
> Yes, it is certainly possible, but why bother? R's Comparison operators
> work on character values so you should be able to do this (if the
> subsetting is syntactically correct:
>
>  new_brick <- subset(original, which(getZ( original ) >= "2000-01-01
> 10:30:00" & getZ(original ) <= "2014-12-31 10:30:00") )
>
>
> As always if you had presented the output of dput(head(original)) assuming
> that head is a meaningful operation on such an object, the demonstration
> would have been possible. An alternate would be to offer a library call to
> a package and then load a relevant example.
>
>
> Best;
> David
> >
> > ### original RasterBrick ###
> > class       : RasterBrick
> > dimensions  : 600, 1440, 864000, 11320  (nrow, ncol, ncell, nlayers)
> > resolution  : 0.25, 0.25  (x, y)
> > extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> > data source :
> >
> /work/mm01117/GLDAS_025_deg/daily/gldas_tavg_tmin_tmax_precip_windspd_sphum_daily_1986_2016.nc4
> > names       : X1986.01.01.10.30.00, X1986.01.02.10.30.00,
> > X1986.01.03.10.30.00, X1986.01.04.10.30.00, X1986.01.05.10.30.00,
> > X1986.01.06.10.30.00, X1986.01.07.10.30.00, X1986.01.08.10.30.00,
> > X1986.01.09.10.30.00, X1986.01.10.10.30.00, X1986.01.11.10.30.00,
> > X1986.01.12.10.30.00, X1986.01.13.10.30.00, X1986.01.14.10.30.00,
> > X1986.01.15.10.30.00, ...
> > Date/time   : 1986-01-01 10:30:00, 2016-12-31 10:30:00 (min, max)
> > varname     : v1
> >
> > ### new RasterBrick ###
> > class       : RasterStack
> > dimensions  : 600, 1440, 864000, 5477  (nrow, ncol, ncell, nlayers)
> > resolution  : 0.25, 0.25  (x, y)
> > extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> > names       : X2000.01.01.10.30.00, X2000.01.02.10.30.00,
> > X2000.01.03.10.30.00, X2000.01.04.10.30.00, X2000.01.05.10.30.00,
> > X2000.01.06.10.30.00, X2000.01.07.10.30.00, X2000.01.08.10.30.00,
> > X2000.01.09.10.30.00, X2000.01.10.10.30.00, X2000.01.11.10.30.00,
> > X2000.01.12.10.30.00, X2000.01.13.10.30.00, X2000.01.14.10.30.00,
> > X2000.01.15.10.30.00, ...
> >
> > Any help will be greatly appreciated.
> >
> > Sincerely,
> >
> > Milu
> >
> >       [[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.
>
--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

        [[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: Subset Rasterbrick by time

Miluji Sb
Dear David,

Subsetting works but the 'date' information is lost in the new file.

Thanks, Mike. I was not aware of the bug but will work on learning
about (getZ) and (setZ). Thanks again!

Sincerely,

Milu

On Tue, Jun 19, 2018 at 7:32 AM, Michael Sumner <[hidden email]> wrote:

>
>
> On Mon, 18 Jun 2018, 22:09 David Winsemius, <[hidden email]>
> wrote:
>
>>
>>
>> > On Jun 18, 2018, at 7:21 AM, Miluji Sb <[hidden email]> wrote:
>> >
>> > Dear all,
>> >
>> > I have a rasterbrick with the date/time information provided which I
>> would
>> > like to subset by year.
>> >
>> > However, when I use the following code for sub-setting;
>> >
>> > new_brick <- subset(original, which(getZ( original ) >=
>> as.Date("2000-01-01
>> > 10:30:00") & getZ(original ) <= as.Date("2014-12-31 10:30:00")))
>> >
>> > The date/time information seems to be lost.
>> >
>>
>
> This is a bug, I tend to extract (getZ) the dates, do the subset logic on
> both and restore (setZ).
>
> It takes a bit of learning and practice, good luck. I can't expand more at
> the moment. See R-Sig-Geo for more specific discussion forum, and #rstats
> on twitter is really good.
>
> Cheers, Mike
>
>> > Furthermore, the class of the date/time seems to be character;
>> >
>> > ##
>> > class(getZ( original ))
>> > [1] "character"
>> >
>> > Is it possible to convert this string to date before sub-setting or
>> retain
>> > the date/time information after sub-setting?
>>
>> Yes, it is certainly possible, but why bother? R's Comparison operators
>> work on character values so you should be able to do this (if the
>> subsetting is syntactically correct:
>>
>>  new_brick <- subset(original, which(getZ( original ) >= "2000-01-01
>> 10:30:00" & getZ(original ) <= "2014-12-31 10:30:00") )
>>
>>
>> As always if you had presented the output of dput(head(original))
>> assuming that head is a meaningful operation on such an object, the
>> demonstration would have been possible. An alternate would be to offer a
>> library call to a package and then load a relevant example.
>>
>>
>> Best;
>> David
>> >
>> > ### original RasterBrick ###
>> > class       : RasterBrick
>> > dimensions  : 600, 1440, 864000, 11320  (nrow, ncol, ncell, nlayers)
>> > resolution  : 0.25, 0.25  (x, y)
>> > extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
>> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>> > data source :
>> > /work/mm01117/GLDAS_025_deg/daily/gldas_tavg_tmin_tmax_
>> precip_windspd_sphum_daily_1986_2016.nc4
>> > names       : X1986.01.01.10.30.00, X1986.01.02.10.30.00,
>> > X1986.01.03.10.30.00, X1986.01.04.10.30.00, X1986.01.05.10.30.00,
>> > X1986.01.06.10.30.00, X1986.01.07.10.30.00, X1986.01.08.10.30.00,
>> > X1986.01.09.10.30.00, X1986.01.10.10.30.00, X1986.01.11.10.30.00,
>> > X1986.01.12.10.30.00, X1986.01.13.10.30.00, X1986.01.14.10.30.00,
>> > X1986.01.15.10.30.00, ...
>> > Date/time   : 1986-01-01 10:30:00, 2016-12-31 10:30:00 (min, max)
>> > varname     : v1
>> >
>> > ### new RasterBrick ###
>> > class       : RasterStack
>> > dimensions  : 600, 1440, 864000, 5477  (nrow, ncol, ncell, nlayers)
>> > resolution  : 0.25, 0.25  (x, y)
>> > extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
>> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>> > names       : X2000.01.01.10.30.00, X2000.01.02.10.30.00,
>> > X2000.01.03.10.30.00, X2000.01.04.10.30.00, X2000.01.05.10.30.00,
>> > X2000.01.06.10.30.00, X2000.01.07.10.30.00, X2000.01.08.10.30.00,
>> > X2000.01.09.10.30.00, X2000.01.10.10.30.00, X2000.01.11.10.30.00,
>> > X2000.01.12.10.30.00, X2000.01.13.10.30.00, X2000.01.14.10.30.00,
>> > X2000.01.15.10.30.00, ...
>> >
>> > Any help will be greatly appreciated.
>> >
>> > Sincerely,
>> >
>> > Milu
>> >
>> >       [[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.
>>
> --
> Dr. Michael Sumner
> Software and Database Engineer
> Australian Antarctic Division
> 203 Channel Highway
> <https://maps.google.com/?q=203+Channel+Highway+Kingston+Tasmania+7050+Australia&entry=gmail&source=g>
> Kingston Tasmania 7050 Australia
> <https://maps.google.com/?q=203+Channel+Highway+Kingston+Tasmania+7050+Australia&entry=gmail&source=g>
>
>

        [[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.