Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align_move does not preserve data (colour) column #114

Open
nmasto opened this issue Feb 12, 2023 · 2 comments
Open

align_move does not preserve data (colour) column #114

nmasto opened this issue Feb 12, 2023 · 2 comments

Comments

@nmasto
Copy link

nmasto commented Feb 12, 2023

Hi Jakob,

I searched but couldn't find an answer. I'm trying to color each track by a behavioral class. This worked fine with a smaller dataset (one month), two colours (sex = male/female), and 20 individuals. However, I'm trying on a larger dataset of 39 individuals, each with ~2,000 locations. At first I thought it was because the timezone was "America/Chicago" which would switch from 'CDT' to 'CST' in these migratory tracks. However, I switched to UTC and encounter the same issue. I then found that when using df2move there were issues with a single individual...so I removed that individual. Everything seemed fine however, despite trying different temporal alignments, I can't seem to get align_move to preserve my data. See below my code. Any assistance is appreciated.

# Data Management
dat <- read.csv("data/full_dat_env_cov_classify.csv") %>% 
  mutate(time = ymd_hms(time, tz = "America/Chicago"),
         time_utc = ymd_hms(time_utc, tz = "UTC"))

# Time is handled; make study_season a factor
dat$study_season <- as.factor(dat$study_season)

# Make a `colour` column for behavioral states
dat <- dat %>% group_by(ID) %>%
  distinct(time_utc, .keep_all = TRUE) %>%   # keep distinct records
  mutate(colour = case_when(class == "postbreeding" ~ "red",
                            class == "migrating" ~ "green",
                            class == "stopover" ~ "purple",
                            class == "winter" ~ "blue",
                            TRUE ~ "red")) %>%                      # Give post-breeding color to those NAs that will be before segmentation began
  filter(ID != "LLR-b1142021-F_fall_winter_4") %>%  # Filter ID that was previously giving me trouble (390 NAs when `df2move`
  ungroup()

# Separate yrs. Wish I knew how to do all years but can't
yr1 <- dat %>% filter(study_season == "fall_winter_2")
yr2 <- dat %>% filter(study_season == "fall_winter_3")
yr3 <- dat %>% filter(study_season == "fall_winter_4")

# Order
yr1 <- yr1[order(yr1$ID, yr1$time_utc),]
yr2 <- yr2[order(yr2$ID, yr2$time_utc),]
yr3 <- yr3[order(yr3$ID, yr3$time_utc),]

# Year 3----

check_locs <- yr3 %>% group_by(BirdsID_season) %>% count() # at least 400 locs

yr3 <- as.data.frame(yr3) # not a tibble

yr3 <- df2move(yr3, x = "x", y = "y",
                    time = "time_utc", track_id = "BirdsID_season",
                    proj = "+proj=longlat +datum=WGS84 +no_defs", data = yr3) # append data; importantly "colour"

sum(table(yr3$colour))  # 46273
sum(is.na(yr3$colour))  # 0 NAs

lag = unlist(timeLag(yr3, unit = "mins")) # sampling varies
median(lag)  # 60 min
mean(lag)     # 77 min
sd(lag)          # 328 min -- maybe the lag? Try different temporal alignments

# Maybe something to do with the standard deviation/timelag?
mdat <- align_move(yr3, res = 240, digit = 0, unit = "mins") # Every 4 hrs
mdat2 <- align_move(yr3, res = 360, digit = 0, unit = "mins") # Every 6 hrs

# `align_move` does not preserve colour column
 sum(is.na(mdat$colour))
[1] 14866
sum(is.na(mdat2$colour)) 
[1] 9904

What am I missing? Align move worked fine and did not convert colour class to NAs when using a much smaller dataframe of only a single month and only two "colours". Any help appreciated. Best, Nick

@J4SJA
Copy link

J4SJA commented Jun 19, 2023

I've had the same. Because I keep the resolution the same as it was, I 'just' take the colour out and then put it back after i've used align_move

@kaijagahm
Copy link

@nmasto I'm curious if you ever found a solution to this? I am not keeping the resolution the same unfortunately so I can't use @J4SJA's solution. Manually annotating the behavioral segments is really onerous and won't work in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants