courtiol / IsoriX

This is the website dedicated to the development of the R package IsoriX
12 stars 5 forks source link

Plotting across the International Date Line #180

Open aelopez2 opened 3 months ago

aelopez2 commented 3 months ago

Hello, I am a student currently doing my undergrad thesis on molt origins of birds flying through the East Asian Australasian Flyway. I have tried different coordinates to plot all countries involved in this flyway - all of which are futile. I have data from GNIP of the countries involved, but some are excluded upon mapping. Is this problem inherent with this method? What should I do to fix this?

This was the best I could do with these coordinates: GNIPDataEAAF <- prepsources(data = GNIPData, long_min = 70, long_max = 170, lat_min = -20, lat_max = 110)

image

courtiol commented 3 months ago

You can mask any country you want since what IsoriX produces is just a set of spatial objects. What exactly would you like to do/see?

aelopez2 commented 3 months ago

Hello, I hope this message finds you well. I am aiming to produce in one plot the whole flyway (below) with assigned geographic inference from my feather data for all species. Then I will produce species-specific plots. Thank you for considering my query which I honestly am stuck with right now.

image

courtiol commented 3 months ago

It is true that IsoriX is a little clunky when you try to cross the International Date Line... I could improve that, but with little work around, the current IsoriX can be used:

library(IsoriX)

## Load here your own GNIP data
load("../material_for_maintainer/sources_for_datasets/saved_rda/GNIPDataALL_DONTSHARE.rda")

## Aggregate all GNIP data
GNIPDataWorld <- prepsources(data = GNIPDataALL,
                             long_min = -180, long_max = 180,
                             lat_min = -90, lat_max = 90)

plot(terra::vect(GNIPDataWorld, geom = c("long", "lat")), col = 2)
plot(CountryBorders, add = TRUE)

## Filter GNIP data
GNIPDataEAAFagg <- subset(GNIPDataWorld, (lat > -50 & lat < 70) & (long < -150 | long > 70))
plot(terra::vect(GNIPDataEAAFagg, geom = c("long", "lat")), col = 2)
plot(CountryBorders, add = TRUE)

## Fit isoscape
fit <- isofit(data = GNIPDataEAAFagg, mean_model_fix = list(elev = TRUE, lat_abs = TRUE))
plot(fit)

## Download world elevation
getelev(file = "~/elevation_world_z2.tif", z = 2, overwrite = TRUE) ## coarse resolution, for testing only

## Create elevation raster
elev_raster <- terra::rast('~/elevation_world_z2.tif')
plot(elev_raster)

## Prepare raster using manual crop
rasterEAAF <- prepraster(elev_raster, manual_crop = c(70, -150, -50, 70))

## Plot of the elevation across the IDL
plot(rasterEAAF)
polys(OceanMask, col = "blue")
polys(shift(OceanMask, dx = 360), col = "blue")
polys(CountryBorders)
polys(shift(CountryBorders, dx = 360))

image

There are a few plotting glitches here: the International Date Line is visible and the x-axis is wrong. Some of those could be avoided using lattice/rasterVis, but it should already get you going.

courtiol commented 3 months ago

I tried to plot the isoscape, again it needs fiddling, but it works:

## Create and plot the isoscape
rasterEAAF_lowres <- prepraster(elev_raster, manual_crop = c(70, -150, -50, 70), aggregation_factor = 10)
isoEAAF <- isoscape(raster = rasterEAAF_lowres, isofit = fit)
plot(isoEAAF) +
latticeExtra::layer(lattice::lpolygon(shift(OceanMask, dx = 360), col = "black", border = NA))

image

And this time, I used the right plotting functions to avoid glitches.

aelopez2 commented 3 months ago

And there it is! I can't thank you enough, Sir Alexandre for this. I am continuing to explore the applications of this package as I am considering to take up masters and pursue stable isotope ecology. Thank you so much for helping me.

courtiol commented 3 months ago

I am keeping this issue open as, ideally, IsoriX should handle all IDL-related difficulties "out of the box".