Implementing a rolling window for stars object

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

Implementing a rolling window for stars object

Micha Silver

I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.

When I use subscript notation to slice out the window dimension with a looping variable I get an error:


Error in loadNamespace(name) : there is no package called ‘yr’
Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

However If I replace the subscript with integers it works fine. (see attached)

What is the correct way to work this out?


Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)


Thanks

 -- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

stars_window.R (43K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Andy Teucher
Hi Micha,

I can see two problems immediately with your code:
 1. you are using a double-colon (yr::last_yr) - the double colon is used for looking for an object in a package, so it is looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single colon to create a range (like you did with 2:6)
2.  the object ‘last_yr’ is never defined, so even if you used a single colon to define the range yr:last_yr, it would fail as it would not be able to find object ‘last_yr’

Cheers,
Andy Teucher

> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email]> wrote:
>
> I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.
> When I use subscript notation to slice out the window dimension with a looping variable I get an error:
>
> Error in loadNamespace(name) : there is no package called ‘yr’
> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
> Execution halted
>
> However If I replace the subscript with integers it works fine. (see attached)
> What is the correct way to work this out?
>
> Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)
>
> Thanks
>  --
> Micha Silver
> Ben Gurion Univ.
> Sde Boker, Remote Sensing Lab
> cell: +972-523-665918
> <stars_window.R>_______________________________________________
> R-sig-Geo mailing list
> [hidden email] <mailto:[hidden email]>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Micha Silver

On 23/10/2019 19:30, Andy Teucher wrote:

> Hi Micha,
>
> I can see two problems immediately with your code:
>  1. you are using a double-colon (yr::last_yr) - the double colon is
> used for looking for an object in a package, so it is looking for
> object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use
> a single colon to create a range (like you did with 2:6)
> 2.  the object ‘last_yr’ is never defined, so even if you used a
> single colon to define the range yr:last_yr, it would fail as it would
> not be able to find object ‘last_yr’
>
Thanks,

I fixed those typos (corrected script attached) and I still get this error:


micha@tp480:R$ Rscript stars_window.R
Loading required package: abind
Loading required package: sf
Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
Execution halted



> Cheers,
> Andy Teucher
>
>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>> I am trying to run a function (mk.test to find MannKendall trends)
>> using st_apply over a "rolling" window for a time series of rasters
>> in a stars object.
>> When I use subscript notation to slice out the window dimension with
>> a looping variable I get an error:
>>
>> Error in loadNamespace(name) : there is no package called ‘yr’
>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>> Execution halted
>>
>> However If I replace the subscript with integers it works fine. (see
>> attached)
>> What is the correct way to work this out?
>>
>> Attached is a reprex with a small subset of my data. (The script
>> starts with a long structure, code is at the end)
>>
>> Thanks
>>   --
>> Micha Silver
>> Ben Gurion Univ.
>> Sde Boker, Remote Sensing Lab
>> cell: +972-523-665918
>> <stars_window.R>_______________________________________________
>> R-sig-Geo mailing list
>> [hidden email] <mailto:[hidden email]>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

stars_window.R (43K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Andy Teucher
Interesting - there’s some rlang/tidy evaluation trickery going on there that I couldn’t quite figure out (I think it might be searching for yr in the wrong environment), but defining your range as a single variable, and putting that in the square brackets seems to work for me:

rng <- yr:last_yr
stars_window = ci_stars[,,,rng]


> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
>
>
> On 23/10/2019 19:30, Andy Teucher wrote:
>> Hi Micha,
>>
>> I can see two problems immediately with your code:
>>  1. you are using a double-colon (yr::last_yr) - the double colon is used for looking for an object in a package, so it is looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single colon to create a range (like you did with 2:6)
>> 2.  the object ‘last_yr’ is never defined, so even if you used a single colon to define the range yr:last_yr, it would fail as it would not be able to find object ‘last_yr’
>>
>
> Thanks,
>
> I fixed those typos (corrected script attached) and I still get this error:
>
>
> micha@tp480:R$ Rscript stars_window.R
> Loading required package: abind
> Loading required package: sf
> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
> Execution halted
>
>
>
>> Cheers,
>> Andy Teucher
>>
>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email] <mailto:[hidden email]>> wrote:
>>>
>>> I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.
>>> When I use subscript notation to slice out the window dimension with a looping variable I get an error:
>>>
>>> Error in loadNamespace(name) : there is no package called ‘yr’
>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>>> Execution halted
>>>
>>> However If I replace the subscript with integers it works fine. (see attached)
>>> What is the correct way to work this out?
>>>
>>> Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)
>>>
>>> Thanks
>>>  --
>>> Micha Silver
>>> Ben Gurion Univ.
>>> Sde Boker, Remote Sensing Lab
>>> cell: +972-523-665918
>>> <stars_window.R>_______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email] <mailto:[hidden email]>
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> --
> Micha Silver
> Ben Gurion Univ.
> Sde Boker, Remote Sensing Lab
> cell: +972-523-665918
>
> <stars_window.R>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Andy Teucher
I’m fairly certain this is a bug in stars; I opened an issue here: https://github.com/r-spatial/stars/issues/223 <https://github.com/r-spatial/stars/issues/223>

Cheers,
Andy Teucher

> On Oct 23, 2019, at 10:42 AM, Andy Teucher <[hidden email]> wrote:
>
> Interesting - there’s some rlang/tidy evaluation trickery going on there that I couldn’t quite figure out (I think it might be searching for yr in the wrong environment), but defining your range as a single variable, and putting that in the square brackets seems to work for me:
>
> rng <- yr:last_yr
> stars_window = ci_stars[,,,rng]
>
>
>> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
>>
>>
>> On 23/10/2019 19:30, Andy Teucher wrote:
>>> Hi Micha,
>>>
>>> I can see two problems immediately with your code:
>>> 1. you are using a double-colon (yr::last_yr) - the double colon is used for looking for an object in a package, so it is looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single colon to create a range (like you did with 2:6)
>>> 2.  the object ‘last_yr’ is never defined, so even if you used a single colon to define the range yr:last_yr, it would fail as it would not be able to find object ‘last_yr’
>>>
>>
>> Thanks,
>>
>> I fixed those typos (corrected script attached) and I still get this error:
>>
>>
>> micha@tp480:R$ Rscript stars_window.R
>> Loading required package: abind
>> Loading required package: sf
>> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
>> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
>> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
>> Execution halted
>>
>>
>>
>>> Cheers,
>>> Andy Teucher
>>>
>>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email] <mailto:[hidden email]>> wrote:
>>>>
>>>> I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.
>>>> When I use subscript notation to slice out the window dimension with a looping variable I get an error:
>>>>
>>>> Error in loadNamespace(name) : there is no package called ‘yr’
>>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>>>> Execution halted
>>>>
>>>> However If I replace the subscript with integers it works fine. (see attached)
>>>> What is the correct way to work this out?
>>>>
>>>> Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)
>>>>
>>>> Thanks
>>>> --
>>>> Micha Silver
>>>> Ben Gurion Univ.
>>>> Sde Boker, Remote Sensing Lab
>>>> cell: +972-523-665918
>>>> <stars_window.R>_______________________________________________
>>>> R-sig-Geo mailing list
>>>> [hidden email] <mailto:[hidden email]>
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>> --
>> Micha Silver
>> Ben Gurion Univ.
>> Sde Boker, Remote Sensing Lab
>> cell: +972-523-665918
>>
>> <stars_window.R>
>


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Vijay Lulla
 Andy, you're spot on!  This is because stars:::`[.stars` is only looking
for variables and not expressions (line 44 in the function!).  Your example
gets around it by creating an object in the environment (parent.frame)
which is then consulted in the `eval`.  Sorry for tmi!
HTH,
Vijay.

On Wed, Oct 23, 2019 at 2:22 PM Andy Teucher <[hidden email]> wrote:

> I’m fairly certain this is a bug in stars; I opened an issue here:
> https://github.com/r-spatial/stars/issues/223 <
> https://github.com/r-spatial/stars/issues/223>
>
> Cheers,
> Andy Teucher
>
> > On Oct 23, 2019, at 10:42 AM, Andy Teucher <[hidden email]>
> wrote:
> >
> > Interesting - there’s some rlang/tidy evaluation trickery going on there
> that I couldn’t quite figure out (I think it might be searching for yr in
> the wrong environment), but defining your range as a single variable, and
> putting that in the square brackets seems to work for me:
> >
> > rng <- yr:last_yr
> > stars_window = ci_stars[,,,rng]
> >
> >
> >> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
> >>
> >>
> >> On 23/10/2019 19:30, Andy Teucher wrote:
> >>> Hi Micha,
> >>>
> >>> I can see two problems immediately with your code:
> >>> 1. you are using a double-colon (yr::last_yr) - the double colon is
> used for looking for an object in a package, so it is looking for object
> ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single
> colon to create a range (like you did with 2:6)
> >>> 2.  the object ‘last_yr’ is never defined, so even if you used a
> single colon to define the range yr:last_yr, it would fail as it would not
> be able to find object ‘last_yr’
> >>>
> >>
> >> Thanks,
> >>
> >> I fixed those typos (corrected script attached) and I still get this
> error:
> >>
> >>
> >> micha@tp480:R$ Rscript stars_window.R
> >> Loading required package: abind
> >> Loading required package: sf
> >> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
> >> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
> >> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
> >> Execution halted
> >>
> >>
> >>
> >>> Cheers,
> >>> Andy Teucher
> >>>
> >>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email] <mailto:
> [hidden email]>> wrote:
> >>>>
> >>>> I am trying to run a function (mk.test to find MannKendall trends)
> using st_apply over a "rolling" window for a time series of rasters in a
> stars object.
> >>>> When I use subscript notation to slice out the window dimension with
> a looping variable I get an error:
> >>>>
> >>>> Error in loadNamespace(name) : there is no package called ‘yr’
> >>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
> >>>> Execution halted
> >>>>
> >>>> However If I replace the subscript with integers it works fine. (see
> attached)
> >>>> What is the correct way to work this out?
> >>>>
> >>>> Attached is a reprex with a small subset of my data. (The script
> starts with a long structure, code is at the end)
> >>>>
> >>>> Thanks
> >>>> --
> >>>> Micha Silver
> >>>> Ben Gurion Univ.
> >>>> Sde Boker, Remote Sensing Lab
> >>>> cell: +972-523-665918
> >>>> <stars_window.R>_______________________________________________
> >>>> R-sig-Geo mailing list
> >>>> [hidden email] <mailto:[hidden email]>
> >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >>>
> >> --
> >> Micha Silver
> >> Ben Gurion Univ.
> >> Sde Boker, Remote Sensing Lab
> >> cell: +972-523-665918
> >>
> >> <stars_window.R>
> >
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


--
Vijay Lulla

Assistant Professor,
Dept. of Geography, IUPUI
425 University Blvd, CA-207C.
Indianapolis, IN-46202
[hidden email]
ORCID: https://orcid.org/0000-0002-0823-2522
Webpage: http://vijaylulla.com

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Micha Silver

Thanks to both of you for identifying the problem so quickly, and
offering a workaround!


On 23/10/2019 21:25, Vijay Lulla wrote:

> Andy, you're spot on!  This is because stars:::`[.stars` is only
> looking for variables and not expressions (line 44 in the function!). 
> Your example gets around it by creating an object in the environment
> (parent.frame) which is then consulted in the `eval`.  Sorry for tmi!
> HTH,
> Vijay.
>
> On Wed, Oct 23, 2019 at 2:22 PM Andy Teucher <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     I’m fairly certain this is a bug in stars; I opened an issue here:
>     https://github.com/r-spatial/stars/issues/223
>     <https://github.com/r-spatial/stars/issues/223>
>
>     Cheers,
>     Andy Teucher
>
>     > On Oct 23, 2019, at 10:42 AM, Andy Teucher
>     <[hidden email] <mailto:[hidden email]>> wrote:
>     >
>     > Interesting - there’s some rlang/tidy evaluation trickery going
>     on there that I couldn’t quite figure out (I think it might be
>     searching for yr in the wrong environment), but defining your
>     range as a single variable, and putting that in the square
>     brackets seems to work for me:
>     >
>     > rng <- yr:last_yr
>     > stars_window = ci_stars[,,,rng]
>     >
>     >
>     >> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]
>     <mailto:[hidden email]>> wrote:
>     >>
>     >>
>     >> On 23/10/2019 19:30, Andy Teucher wrote:
>     >>> Hi Micha,
>     >>>
>     >>> I can see two problems immediately with your code:
>     >>> 1. you are using a double-colon (yr::last_yr) - the double
>     colon is used for looking for an object in a package, so it is
>     looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t
>     make sense. Use a single colon to create a range (like you did
>     with 2:6)
>     >>> 2.  the object ‘last_yr’ is never defined, so even if you used
>     a single colon to define the range yr:last_yr, it would fail as it
>     would not be able to find object ‘last_yr’
>     >>>
>     >>
>     >> Thanks,
>     >>
>     >> I fixed those typos (corrected script attached) and I still get
>     this error:
>     >>
>     >>
>     >> micha@tp480:R$ Rscript stars_window.R
>     >> Loading required package: abind
>     >> Loading required package: sf
>     >> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
>     >> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
>     >> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
>     >> Execution halted
>     >>
>     >>
>     >>
>     >>> Cheers,
>     >>> Andy Teucher
>     >>>
>     >>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email]
>     <mailto:[hidden email]> <mailto:[hidden email]
>     <mailto:[hidden email]>>> wrote:
>     >>>>
>     >>>> I am trying to run a function (mk.test to find MannKendall
>     trends) using st_apply over a "rolling" window for a time series
>     of rasters in a stars object.
>     >>>> When I use subscript notation to slice out the window
>     dimension with a looping variable I get an error:
>     >>>>
>     >>>> Error in loadNamespace(name) : there is no package called ‘yr’
>     >>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne ->
>     <Anonymous>
>     >>>> Execution halted
>     >>>>
>     >>>> However If I replace the subscript with integers it works
>     fine. (see attached)
>     >>>> What is the correct way to work this out?
>     >>>>
>     >>>> Attached is a reprex with a small subset of my data. (The
>     script starts with a long structure, code is at the end)
>     >>>>
>     >>>> Thanks
>     >>>> --
>     >>>> Micha Silver
>     >>>> Ben Gurion Univ.
>     >>>> Sde Boker, Remote Sensing Lab
>     >>>> cell: +972-523-665918
>     >>>> <stars_window.R>_______________________________________________
>     >>>> R-sig-Geo mailing list
>     >>>> [hidden email] <mailto:[hidden email]>
>     <mailto:[hidden email] <mailto:[hidden email]>>
>     >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>     >>>
>     >> --
>     >> Micha Silver
>     >> Ben Gurion Univ.
>     >> Sde Boker, Remote Sensing Lab
>     >> cell: +972-523-665918
>     >>
>     >> <stars_window.R>
>     >
>
>
>             [[alternative HTML version deleted]]
>
>     _______________________________________________
>     R-sig-Geo mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> Vijay Lulla
>
> Assistant Professor,
> Dept. of Geography, IUPUI
> 425 University Blvd, CA-207C.
> Indianapolis, IN-46202
> [hidden email] <mailto:[hidden email]>
> ORCID: https://orcid.org/0000-0002-0823-2522
> Webpage: http://vijaylulla.com

--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

edzer
In reply to this post by Andy Teucher
Thanks for reporting Micha, and creating a reprex on github Andy; the
problem seems to be fixed, now.

Best regards,

On 10/23/19 2:22 PM, Andy Teucher wrote:

> I’m fairly certain this is a bug in stars; I opened an issue here: https://github.com/r-spatial/stars/issues/223 <https://github.com/r-spatial/stars/issues/223>
>
> Cheers,
> Andy Teucher
>
>> On Oct 23, 2019, at 10:42 AM, Andy Teucher <[hidden email]> wrote:
>>
>> Interesting - there’s some rlang/tidy evaluation trickery going on there that I couldn’t quite figure out (I think it might be searching for yr in the wrong environment), but defining your range as a single variable, and putting that in the square brackets seems to work for me:
>>
>> rng <- yr:last_yr
>> stars_window = ci_stars[,,,rng]
>>
>>
>>> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
>>>
>>>
>>> On 23/10/2019 19:30, Andy Teucher wrote:
>>>> Hi Micha,
>>>>
>>>> I can see two problems immediately with your code:
>>>> 1. you are using a double-colon (yr::last_yr) - the double colon is used for looking for an object in a package, so it is looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single colon to create a range (like you did with 2:6)
>>>> 2.  the object ‘last_yr’ is never defined, so even if you used a single colon to define the range yr:last_yr, it would fail as it would not be able to find object ‘last_yr’
>>>>
>>>
>>> Thanks,
>>>
>>> I fixed those typos (corrected script attached) and I still get this error:
>>>
>>>
>>> micha@tp480:R$ Rscript stars_window.R
>>> Loading required package: abind
>>> Loading required package: sf
>>> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
>>> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
>>> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
>>> Execution halted
>>>
>>>
>>>
>>>> Cheers,
>>>> Andy Teucher
>>>>
>>>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email] <mailto:[hidden email]>> wrote:
>>>>>
>>>>> I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.
>>>>> When I use subscript notation to slice out the window dimension with a looping variable I get an error:
>>>>>
>>>>> Error in loadNamespace(name) : there is no package called ‘yr’
>>>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>>>>> Execution halted
>>>>>
>>>>> However If I replace the subscript with integers it works fine. (see attached)
>>>>> What is the correct way to work this out?
>>>>>
>>>>> Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)
>>>>>
>>>>> Thanks
>>>>> --
>>>>> Micha Silver
>>>>> Ben Gurion Univ.
>>>>> Sde Boker, Remote Sensing Lab
>>>>> cell: +972-523-665918
>>>>> <stars_window.R>_______________________________________________
>>>>> R-sig-Geo mailing list
>>>>> [hidden email] <mailto:[hidden email]>
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>>> --
>>> Micha Silver
>>> Ben Gurion Univ.
>>> Sde Boker, Remote Sensing Lab
>>> cell: +972-523-665918
>>>
>>> <stars_window.R>
>>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pEpkey.asc (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

Micha Silver

On 25/10/2019 15:55, Edzer Pebesma wrote:
> Thanks for reporting Micha, and creating a reprex on github Andy; the
> problem seems to be fixed, now.


Great, thanks for the quick response.

I guess reinstalling stars from CRAN should get the fix?


> Best regards,
>
> On 10/23/19 2:22 PM, Andy Teucher wrote:
>> I’m fairly certain this is a bug in stars; I opened an issue here: https://github.com/r-spatial/stars/issues/223 <https://github.com/r-spatial/stars/issues/223>
>>
>> Cheers,
>> Andy Teucher
>>
>>> On Oct 23, 2019, at 10:42 AM, Andy Teucher <[hidden email]> wrote:
>>>
>>> Interesting - there’s some rlang/tidy evaluation trickery going on there that I couldn’t quite figure out (I think it might be searching for yr in the wrong environment), but defining your range as a single variable, and putting that in the square brackets seems to work for me:
>>>
>>> rng <- yr:last_yr
>>> stars_window = ci_stars[,,,rng]
>>>
>>>
>>>> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
>>>>
>>>>
>>>> On 23/10/2019 19:30, Andy Teucher wrote:
>>>>> Hi Micha,
>>>>>
>>>>> I can see two problems immediately with your code:
>>>>> 1. you are using a double-colon (yr::last_yr) - the double colon is used for looking for an object in a package, so it is looking for object ‘yrs’ in package ‘yr’, which obviously doesn’t make sense. Use a single colon to create a range (like you did with 2:6)
>>>>> 2.  the object ‘last_yr’ is never defined, so even if you used a single colon to define the range yr:last_yr, it would fail as it would not be able to find object ‘last_yr’
>>>>>
>>>> Thanks,
>>>>
>>>> I fixed those typos (corrected script attached) and I still get this error:
>>>>
>>>>
>>>> micha@tp480:R$ Rscript stars_window.R
>>>> Loading required package: abind
>>>> Loading required package: sf
>>>> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
>>>> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
>>>> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
>>>> Execution halted
>>>>
>>>>
>>>>
>>>>> Cheers,
>>>>> Andy Teucher
>>>>>
>>>>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email] <mailto:[hidden email]>> wrote:
>>>>>>
>>>>>> I am trying to run a function (mk.test to find MannKendall trends) using st_apply over a "rolling" window for a time series of rasters in a stars object.
>>>>>> When I use subscript notation to slice out the window dimension with a looping variable I get an error:
>>>>>>
>>>>>> Error in loadNamespace(name) : there is no package called ‘yr’
>>>>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>>>>>> Execution halted
>>>>>>
>>>>>> However If I replace the subscript with integers it works fine. (see attached)
>>>>>> What is the correct way to work this out?
>>>>>>
>>>>>> Attached is a reprex with a small subset of my data. (The script starts with a long structure, code is at the end)
>>>>>>
>>>>>> Thanks
>>>>>> --
>>>>>> Micha Silver
>>>>>> Ben Gurion Univ.
>>>>>> Sde Boker, Remote Sensing Lab
>>>>>> cell: +972-523-665918
>>>>>> <stars_window.R>_______________________________________________
>>>>>> R-sig-Geo mailing list
>>>>>> [hidden email] <mailto:[hidden email]>
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>> --
>>>> Micha Silver
>>>> Ben Gurion Univ.
>>>> Sde Boker, Remote Sensing Lab
>>>> cell: +972-523-665918
>>>>
>>>> <stars_window.R>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a rolling window for stars object

edzer


On 10/26/19 4:43 AM, Micha Silver wrote:
>
> On 25/10/2019 15:55, Edzer Pebesma wrote:
>> Thanks for reporting Micha, and creating a reprex on github Andy; the
>> problem seems to be fixed, now.
>
>
> Great, thanks for the quick response.
>
> I guess reinstalling stars from CRAN should get the fix?

Sorry, I meant no: use

remotes::install_github("r-spatial/stars")

>
>
>> Best regards,
>>
>> On 10/23/19 2:22 PM, Andy Teucher wrote:
>>> I’m fairly certain this is a bug in stars; I opened an issue here:
>>> https://github.com/r-spatial/stars/issues/223
>>> <https://github.com/r-spatial/stars/issues/223>
>>>
>>> Cheers,
>>> Andy Teucher
>>>
>>>> On Oct 23, 2019, at 10:42 AM, Andy Teucher <[hidden email]>
>>>> wrote:
>>>>
>>>> Interesting - there’s some rlang/tidy evaluation trickery going on
>>>> there that I couldn’t quite figure out (I think it might be
>>>> searching for yr in the wrong environment), but defining your range
>>>> as a single variable, and putting that in the square brackets seems
>>>> to work for me:
>>>>
>>>> rng <- yr:last_yr
>>>> stars_window = ci_stars[,,,rng]
>>>>
>>>>
>>>>> On Oct 23, 2019, at 10:20 AM, Micha Silver <[hidden email]> wrote:
>>>>>
>>>>>
>>>>> On 23/10/2019 19:30, Andy Teucher wrote:
>>>>>> Hi Micha,
>>>>>>
>>>>>> I can see two problems immediately with your code:
>>>>>> 1. you are using a double-colon (yr::last_yr) - the double colon
>>>>>> is used for looking for an object in a package, so it is looking
>>>>>> for object ‘yrs’ in package ‘yr’, which obviously doesn’t make
>>>>>> sense. Use a single colon to create a range (like you did with 2:6)
>>>>>> 2.  the object ‘last_yr’ is never defined, so even if you used a
>>>>>> single colon to define the range yr:last_yr, it would fail as it
>>>>>> would not be able to find object ‘last_yr’
>>>>>>
>>>>> Thanks,
>>>>>
>>>>> I fixed those typos (corrected script attached) and I still get
>>>>> this error:
>>>>>
>>>>>
>>>>> micha@tp480:R$ Rscript stars_window.R
>>>>> Loading required package: abind
>>>>> Loading required package: sf
>>>>> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
>>>>> Error in eval(rlang::expr(x[[i]][!!!args])) : object 'yr' not found
>>>>> Calls: RunMK -> [ -> [.stars -> structure -> eval -> eval
>>>>> Execution halted
>>>>>
>>>>>
>>>>>
>>>>>> Cheers,
>>>>>> Andy Teucher
>>>>>>
>>>>>>> On Oct 23, 2019, at 8:28 AM, Micha Silver <[hidden email]
>>>>>>> <mailto:[hidden email]>> wrote:
>>>>>>>
>>>>>>> I am trying to run a function (mk.test to find MannKendall
>>>>>>> trends) using st_apply over a "rolling" window for a time series
>>>>>>> of rasters in a stars object.
>>>>>>> When I use subscript notation to slice out the window dimension
>>>>>>> with a looping variable I get an error:
>>>>>>>
>>>>>>> Error in loadNamespace(name) : there is no package called ‘yr’
>>>>>>> Calls: [ ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
>>>>>>> Execution halted
>>>>>>>
>>>>>>> However If I replace the subscript with integers it works fine.
>>>>>>> (see attached)
>>>>>>> What is the correct way to work this out?
>>>>>>>
>>>>>>> Attached is a reprex with a small subset of my data. (The script
>>>>>>> starts with a long structure, code is at the end)
>>>>>>>
>>>>>>> Thanks
>>>>>>> --
>>>>>>> Micha Silver
>>>>>>> Ben Gurion Univ.
>>>>>>> Sde Boker, Remote Sensing Lab
>>>>>>> cell: +972-523-665918
>>>>>>> <stars_window.R>_______________________________________________
>>>>>>> R-sig-Geo mailing list
>>>>>>> [hidden email] <mailto:[hidden email]>
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>> -- 
>>>>> Micha Silver
>>>>> Ben Gurion Univ.
>>>>> Sde Boker, Remote Sensing Lab
>>>>> cell: +972-523-665918
>>>>>
>>>>> <stars_window.R>
>>>
>>>     [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email]
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pEpkey.asc (3K) Download Attachment