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

Coastline Not Mapping in fmap #30

Closed
wilkinbp opened this issue Dec 7, 2021 · 1 comment
Closed

Coastline Not Mapping in fmap #30

wilkinbp opened this issue Dec 7, 2021 · 1 comment

Comments

@wilkinbp
Copy link

wilkinbp commented Dec 7, 2021

For an unknown reason, large sections of the North American coastline are not mapping correctly using the fmap function. The locations of the fit_ssm output are mapped correctly, including dates and error ellipses, but much of the northern hemisphere is not. I have tried several different dependencies for the fmap function (e.g., rgeos, geos, ggmap) but nothing seems to fix it. I would very much like to use these maps. Based on the shading, I am guessing something is wrong with how the function is processing land cover, perhaps related the crossing the date line in the map? Unsure. Any help would be appreciated! Below is the code I am using and a representative figure.

library(dplyr)
library(foieGras)
library(lubridate)
library(ggmap)
library(ggplot2)
library(ggsn)

#read in raw data, organize

sheardata<-na.omit(read.csv("SOSH_GLS_filtered.csv"))
sheardata$Tag<-as.factor(sheardata$Tag)
sheardata$Band<-as.factor(sheardata$Band)
sheardata$TOPPID<-as.factor(sheardata$TOPPID)
sheardata$Date<-as.POSIXct(sheardata$Date, format = "%m/%d/%y")
sheardata$Date<-sheardata$Date + hours(12) + minutes(00) + seconds(00)
colnames(sheardata)<-c("Species","DepID","Band","GLSNum","Date","Long","Lat")

#make data compatible with package
#error estimates from Shaffer et al 2005
fgshear<-sheardata[,c(2,5:7)]
colnames(fgshear)<-c("id","date","lon","lat")
fgshear$lc<-as.character("GL")
fgshear<-fgshear %>% relocate(lc, .before = lon)
fgshear$lonerr<-1.68
fgshear$laterr<-1.95

#fit CRW SSM to one example bird
onebirdexample<-fgshear[fgshear$id == "3105004",]
onebirdexample$id<-as.character(onebirdexample$id)
fitwater<-fit_ssm(onebirdexample, model = "crw", time.step = 24, vmax = 12.5)
fitwater

#plot example
plot(fitwater, what = "predicted", type = 1, pages = 1)
plot(fitwater, what = "fitted", type = 2, pages = 1)
fmap(fitwater, what = "fitted")

Rplot

@ianjonsen
Copy link
Owner

ianjonsen commented Dec 9, 2021

Yes, this is an issue with the default Mercator projected fitted and predicted locations. You can overcome this by specifying a different projection in your call to fmap(), eg.

library(foieGras)
set.seed(10)
fit <- sim(N=300, 
           start = list(c(-20000, 4000), ISOdatetime(2021,12,08,12,00,00,tz="UTC")), 
           model = "crw", 
           D=0.5) %>% 
        mutate(id = 1) %>%
        select(id, date, lc, lon, lat) %>%
        fit_ssm(., model = "crw", time.step=24)
fmap(fit, what = "p", crs = "+proj=stere +lon_0=180 +lat_0=30 +unit=km", ext.rng = c(3,3)) # extending to see land

results in this:
image

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

2 participants