jmsigner / amt

37 stars 13 forks source link

Error in random_steps even with fix from issue #109 #119

Open bvpurse opened 5 days ago

bvpurse commented 5 days ago

Hi everyone,

I am using random_steps within the code to prep the data for the SSF. I was previously getting the error listed in issue #109 and downloaded and ran the new version of random_steps.R from github as directed. I then tried to rerun the code and got the following error.

Error in UseMethod("random_steps", x) : no applicable method for 'random_steps' applied to an object of class "c('bursted_steps_xyt', 'steps_xyt', 'steps_xy', 'tbl_df', 'tbl', 'data.frame')"

My code is below (trying to run in a loop but commented out for now and just running for i=1). I have appended a sample RData file. Any advice would be much appreciated. cow_amt_single_18102024.csv Thanks a lot in advance,

Beth ############# READ IN DATA AND DEFINE PROJECTION ################################################ EA <- "+proj=aea +lat_1=7 +lat_2=-32 +lat_0=-15 +lon_0=125 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; load("Single_cow_several_days_SOQ_18102024.RData") str(cow_amt_single)

trk <- cow_amt_single |> make_track(x, y, t, day=day, SiteTag=SiteTag, id = id, crs=EA) str(trk)

############# SUMMARISING SAMPLING RATE INTO TIMESTATS ################# timestats <- summarize_sampling_rate_many(trk, c("id")) print(timestats)

############# SSF PREP CODE FROM MOVEBANK WORKSHOP ###################### ssfdat<-NULL temptrk<-with(trk, track(x=x, y=y, t=t_, SiteTag=SiteTag, id=id)) print(temptrk) uid<-unique(trk$id) # individual identifiers luid<-length(uid) # number of unique individuals uid luid

for(i in 1:luid){

Subset individuals & regularize track

i=1 temp<-temptrk|> filter(id==uid[i]) |> track_resample(rate=minutes(round(timestats$median[i])), tolerance=minutes(max(10,round(timestats$median[i]/5)))) print(temp)

Get rid of any bursts without at least 2 points

temp<-filter_min_n_burst(temp, 2)

burst steps

stepstemp<-steps_by_burst(temp)

create random steps using fitted gamma and von mises distributions and append

rnd_stps <- random_steps(stepstemp, n = 15)

append id

rnd_stps<-rnd_stps|>mutate(id=uid[i])

append new data to data from other individuals

ssfdat<-rbind(rnd_stps, ssfdat)

}

ssfdat<-as_tibble(ssfdat)

ssfdat

Error in UseMethod("random_steps", x) :

no applicable method for 'random_steps' applied to an object of class "c('bursted_steps_xyt',

'steps_xyt', 'steps_xy', 'tbl_df', 'tbl', 'data.frame')"

bsmity13 commented 4 days ago

Hi Beth,

I get no error when I run your code on the sample data you shared. It is somewhat strange that it would return that particular error, because there is an S3 method defined for an object with that class in amt. When you say that you, "downloaded and ran the new version of random_steps.R from github as directed," do you mean you downloaded only that script? That could possibly explain that error. Instead, you should reinstall all of amt and not source an individual script. You can do that like this:

remotes::install_github("jmsigner/amt")

(Assuming you already have the remotes package installed from CRAN).

Once you've reinstalled the latest version of amt, can you try to rerun the script and see if you still get the error? If you are still getting the error, can you share the output of sessionInfo() right after you get the error?

Hope that helps!

bvpurse commented 1 day ago

Dear Brian,

Enormous thanks for the advice, great that you could get it running. I will reinstall all of amt and hopefully get this running. Thanks a lot,

Beth

From: Brian J. Smith @.> Sent: Friday, October 18, 2024 8:19 PM To: jmsigner/amt @.> Cc: Bethan Purse @.>; Author @.> Subject: Re: [jmsigner/amt] Error in random_steps even with fix from issue #109 (Issue #119)

CAUTION: This email originated from outside of the organisation. Do not click links or open attachments unless you recognise the senders email address and know the content is safe.

Hi Beth,

I get no error when I run your code on the sample data you shared. It is somewhat strange that it would return that particular error, because there is an S3 method defined for an object with that class in amt. When you say that you, "downloaded and ran the new version of random_steps.R from github as directed," do you mean you downloaded only that script? That could possibly explain that error. Instead, you should reinstall all of amt and not source an individual script. You can do that like this:

remotes::install_github("jmsigner/amt")

(Assuming you already have the remotes package installed from CRAN).

Once you've reinstalled the latest version of amt, can you try to rerun the script and see if you still get the error? If you are still getting the error, can you share the output of sessionInfo() right after you get the error?

Hope that helps!

— Reply to this email directly, view it on GitHubhttps://github.com/jmsigner/amt/issues/119#issuecomment-2423091407, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACXQ4ORUTAZQYR7Y4X4NOWTZ4FNIRAVCNFSM6AAAAABQGBG4ICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRTGA4TCNBQG4. You are receiving this because you authored the thread.Message ID: @.**@.>>

This email and any attachments are intended solely for the named recipients and are confidential. If you are not the intended recipient, please reply to the email to highlight the error and delete this email from your system; you must not use, disclose, copy, or distribute this email or any of its attachments. UK Centre for Ecology & Hydrology (UKCEH) has taken reasonable precautions to minimise risk of this email or any attachments containing viruses or malware, but the recipient should carry out its own virus and malware checks before opening the attachments. UKCEH does not accept any liability for any losses or damages which the recipient may sustain due to presence of any viruses. Opinions, conclusions or other information in this message and attachments that are not related directly to UKCEH business are solely those of the author and do not represent the views of UKCEH. We process your personal data in accordance with our Privacy Notice, available on the UKCEH website. https://www.ceh.ac.uk/privacy-notice Registered office address; Maclean Building Benson Lane, Crowmarsh Gifford, Wallingford, Oxfordshire, United Kingdom, OX10 8BB Companies Registered Name; UK Centre for Ecology & Hydrology Place of Registration; England Registered Company Number; 11314957