rafnuss / geopressurer Goto Github PK
View Code? Open in Web Editor NEWGlobal positioning by atmospheric pressure
Home Page: https://raphaelnussbaumer.com/GeoPressureR
License: GNU General Public License v3.0
Global positioning by atmospheric pressure
Home Page: https://raphaelnussbaumer.com/GeoPressureR
License: GNU General Public License v3.0
Current function is not really general
General paramter:
pathname
crop_start
crop_end
id
Modification
grl$p
in T
and O
graph_marginal()
graph_simulation()
If pressure data was unaivailable during some flight, the graph_add_wind
will return the following message:
Error in graph_add_wind(grl, pressure = pam$pressure, filename, thr_as = gpr$thr_as) :
Pressure not matching for 'data/5_wind_graph/xxx/xxx_xx.nc'
If you had look carefully, you might have noticed that during the download of wind data, there was already a warning message:
Warning messages:
1: In graph_download_wind(pam, area = static_prob, ) :
No pressure data available for sta_id=xx. All pressure level will be downloaded
As no pressure is availabe, it is not possible to determine the wind data easily.
Problem raised by @ksakuras, see ksakuras/Siberian-rubythroat-China#9.
Aiming for a compact worflows, with variable that follow each other.
Short version:
tag <- tag_create("18LX")
Detailed version:
tag <- tag_create(id = "18LX",
directory = glue::glue("data/raw-tag/{id}/"),
pressure_file = "*.pressure",
light_file = "*.glf",
acceleration_file = "*.acceleration",
crop_start = "2017-06-20",
crop_end = "2018-05-02")
tag <- tag_label(tag)
Details version:
# create the label file.
tag <- tag_label_auto(tag, min_duration = 30)
# Write the label
tag_label_write(tag,
file = glue::glue("data/tag-labels/{tag$id}.csv"))
# Read file
tag <- tag_label_read(tag,
file = glue::glue("data/tag-labels/{tag$id}-labeled.csv"))
# Compute stap from label
tag <- tag_label_stap(tag)
Short version:
tag <- tag_setmap(tag, extent = c(-16, 23, 0, 50))
Detailed version:
tag <- tag_setmap(tag,
extent = c(-16, 23, 0, 50),
scale = 4,
include_stap_id = NA,
include_min_duration = 5,
known = data.frame(
stap_id = c(1, 4),
known_lon = c( 17.05, 17.05),
known_lat = c(48.9, 48.9)
))
Short version:
tag <- geopressure_map(tag)
Detailed version:
tag <- geopressure_map_mismatch(tag
max_sample = 250,
margin = 30,
timeout = 60 * 5,
workers = 90)
tag <- geopressure_map_likelihood(tag,
sd = 1,
thr_mask = 0.9,
log_linear_pooling_weight = \(n) log(n)/n )
Detailed version:
tag <- twilight_create(tag) |>
twilight_label_read()
tag <- geolight_map(tag)
Detailed version:
# Create twilight
tag <- twilight_create(tag)
# Write twilight label
twilight_lable_write(tag)
# Read twilight label
tag <- twilight_label_read(tag)
# Compute likelihood map
tag <- geolight_map(tag)
graph <- graph_create(tag) |>
graph_add_movement()
map_marginal <- graph_marginal(graph)
path_mostl_likely <- graph_most_likely(graph)
path_simulation <- graph_simulation(graph)
tag_wind_download(tag)
graph <- graph_add_wind(graph) |>
graph_add_movement(bird = bird_create("scientific name"))
pressurepath <- pressurepath_create(tag, path = tag2path(tag))
tag <- tag_stap(tag)
tag <- tag_stap(tag, extent = c(-16, 23, 0, 50), scale = 1) |>
geopressure_map()
gpts <- geostap2path(tag) |>
geopressure_timeseries(tag)
update <- tag_label_update(file = "data/1_labels/18LX-labeled-modif.csv",
tag
gpts)
Error on windows only
Error during the reading of the file. We return the uris of the gee request, the filename to the file already downloaded and the pressure_maps already computed. Here is the original error:
error in evaluating the argument 'x' in selecting a method for function 'is.factor': Failure during raster IO
This seems to be related to an error when downloading the geotiff file with
Line 185 in aa87166
Possible error related to HTTPS connections, where download.file
is known to create some issues. Not exactly sure...
See also #9 for distantly issue.
elev
for the same stationary period stap
, so that the mismatch can be computed on longer timeseries and avoid having to label pressure data as oulier while they are not.Label are only assign to pressure so that no acceleration data is required. Instead of labeling data as 0
and 1
. Three type of label can be used:
flight
define the migratory flight, seperating stationary periods and informing on flight duration (same as before).discard
basically equivalent to previous outlier, can represent true outlier (error of sensor) or vertical movement of the bird that we don't want to match.elev_1
, elev_2
, ... Idenfier of period during which the bird was at a unique constant elevation level but different from the main elevation level of the stationary period. The same elev_
can be labbeled at different momement, for instance if the bird move back and forth between location. By default, no label is equivalent to being label with elev_0
. Label need to start by elev_
with any ending (exect elev_0
which is kept for the default elevation level.Flight are no unique between to consecutive stationary period. However, it will not be required to model all stationary period in the graph model, which essentially allow to combine multiple flights.
If acceleration is present, its labeling will over-write the pressure labeling for compuation stationary period and flight, but not elev_*
and discard
After updating my GeoPressureR to the latest version, I am getting several errors across multiple analysis scripts when working on my data. The first problem is in 1-pressure.R, in which I upload my pressure data. Was there a change in the pam_read() function? Because it now reads in my pressure data as incorrect values (0.38678, 0.39050, etc.). I have not changed my code and have no idea why it is doing this
How can we connect our output to other package?
See https://besjournals.onlinelibrary.wiley.com/doi/10.1111/1365-2656.13116
Animated (gif/video)
This would separate the R code (GeoPressureR) from the vignette which would be converted into a bookdown
not back compatible.
Present in:
not back compatible.
Error when using flight_bird()
on windows only
No match for 'Acrocephalus arundinaceus'. Please use the exact name.
Closest matches are:
[1] ï..species wing_length secondary mass
<0 rows> (or 0-length row.names)
--- failed re-building 'wind-graph.Rmd'
Which comes from reading the csv file "avonet_clements.csv":
Lines 38 to 40 in d7c6e91
This is apparently a common issue with UTF-8-BOM encoding.
Hitting a wall during 5-2-wind-graph_create.R when adding wind to grl, but ONLY for certain tags (CB594, 598, 599) while others run just fine. Here is my error:
> grl <- graph_add_wind(grl,
+ pressure = pam$pressure,
+ filename = paste0("data/5_wind_graph/", gdl, "/", gdl, "_"),
+ thr_as = gpr$thr_as
+ )
[1] "vobjtovarid4: error #F: I could not find the requsted var (or dimvar) in the file!"
[1] "var (or dimvar) name: level"
[1] "file name: data/5_wind_graph/CB594/CB594_1.nc"
Error in vobjtovarid4(nc, varid, verbose = verbose, allowdimvar = TRUE) :
Variable not found
I have re-run the wind download but it still can't find some variable in the .nc files? Any suggestions?
Should we change them to label_write()
and have label_check
instead of trainset?
Vignettes + Data makes the code too large for CRAN.
Should to put all the vignette into a seperate repo ? Maybe a bookdown?
Write function to make the code runable offline (from downloaded ERA5 pressure)
More widely, need to think of a more general system that works with any file type.
Main idea is to focus the process on the data that are needed:
pam <- list(
pressure=data.frame(date=c(), obs=c())
light=data.frame(date=c(), obs=c())
acceleration=data.frame(date=c(), obs=c())
id=folder
)
Notes:
act
with obs
everywhere (breaking change?) and remove pich
Typical error message:
Error in light2mat(light, shift_k) :
Temporal resolution of the light data is not the same. The code currently cannot work.
How can we fix this?
When uploading a file too large (around 1 year of 5min dataset), Trainset will become irresponsive like the scrreenshot below
This is a javascript error which can't handle too many datapoints at once. The error message visible in your browser console should be
Uncaught RangeError: Maximum call stack size exceeded
I've raised the issue on trainset : Geocene/trainset#117. Please add a +1 so that the author of the package accept my suggestion.
In the meantime, you can use trainset on herokuapp: https://trainset.herokuapp.com/. This is the same app with the fix implemented
The only way I can find to use data in a shiny app is to save the data in a .RData
in a specific folder (~
) and then read it from the app. I cannot find a good way to pass variable to a shiny app instance
Any suggestion?
#' @title Solar Zenith Angle
What should be the right standard output format?
We need to check that all these file are readable/documented and standard name.
Need to check with Movebank what they can upload.
terra
is the new package replacing raster
: https://github.com/rspatial/terra
terra:rast
cannot be saved: rspatial/terra#549, we we will convert it to matrix.
Also, metadata
has been removed in terra
, so we use a new structure to store the data.
[
{
stap = 1,
start = POSIXct(),
end = POSIXct(),
likelihood = matrix(),
extent = c(xmin, xmax, ymin, ymax)
},
...
]
Problem
If the lat,lon requested in geopressure_ts()
is over water, GeoPresseAPI returns an empty csv. Currently the error message warns the user of this issue with a link to google map to copy paste. For instance:
> Returned csv file is empty. Check that the time range is none-empty and that the location is not on water: maps.google.com/maps?q=0,0
This problem appear when we query the most likely map of pressure returned by geopressure_map()
and geopressure_map2path()
Solution 1
On GeoPressureAPI, we could accept location near water and move them to the closest shore, ideally return a warning message. @mgravey , is that possible? what could be done without reducing computational efficiency?
Solution 2
Check before making the query in R. This would require to use another package, download external data (ERA5-Land is 50MB) otherwise the code below get land polygon for 2MB
sf::sf_use_s2(FALSE)
pts <- st_as_sf(path, coords = c("lon","lat"), crs = st_crs(4326))
# poly <- ne_countries(returnclass="sf")
poly <- ne_download(category = "physical", type="land", returnclass="sf")
a <- st_join(pts, poly, join = st_intersects)
Quick initial check
Relying on geopressure_timeseries
Return suggestions
This would separate the R code (GeoPressureR) from the vignette which would be converted into a bookdown
create function to plot pam
and prob_map
Use of ggplot
for that, see #44
Write function to make the code runable offline (from downloaded ERA5 pressure)
See https://github.com/Rafnuss/GeoPressureR/wiki/Migration-v2-%E2%80%90--v3
🎉 Indicates import new exiting feature to check out!
❌ Removed
Old | New | Comment |
---|---|---|
pam |
tag |
|
sta |
stap |
Better suited for STAtionary Period. |
grl |
graph |
More explicit name. |
map |
tag . marginal is the only map not stored in tag |
|
path |
New created by graph_simulation() , graph_most_likely() or tag2path() . Data.frame |
|
pressurepath |
New Data.frame | |
param |
tag and graph keeping track of all parameters used in all functions. Do not edit manually, but useful to export at the end as json file. |
Old | New | Comment |
---|---|---|
pam_read |
tag_create |
|
pam_read_check |
❌ | |
pam_read_delim_dto |
tag_create_dto |
Not exported |
tag_label |
🎉 New This new single function group all the tag_label_* functions for a more efficient workflow |
|
pam_classify |
tag_label_auto |
|
trainset_read |
tag_label_read |
trainset_read is not the same as the previous (see Utility section) |
trainset_write |
tag_label_write |
trainset_read is not the same as the previous |
pam_sta |
tag_label_stap |
|
tag_set_map |
🎉 New Define parameters for the map and stap | |
tag_update |
🎉 New Update a tag with a new label file. Allows to recompute pressure maps only for stap that have change. |
|
tag_assert |
New Check status of a tag object. Not exported | |
print.tag |
New | |
plot.tag |
New | |
plot_tag_pressure |
New | |
plot_tag_light |
New | |
plot_tag_twilight |
New | |
plot_tag_acceleration |
New | |
geopressure_map2path |
tag2path |
|
tag2map |
New return a GeoPressureR map from a tag |
Old | New | Comment |
---|---|---|
geopressure_map |
🎉 Run both geopressure_mismatch and geopressure_likelihood together to make the workflow more efficient. Also doesn't store mse and mask by default to save space. |
|
geopressure_map |
geopressure_map_mismatch |
make more explicit and consider mismatch to incorporate both mse and mask |
geopressure_prob_map |
geopressure_map_likelihood |
replace probability by likelihood |
geopressure_map_preprocess |
New Convert the pressure timeseries into an optimal pressure for geopressureapi | |
geopressure_ts |
geopressure_timseries |
Old | New | Comment |
---|---|---|
find_twilights |
twilight_create |
|
twilight_label_write |
New | |
twilight_label_read |
New | |
geolight_map |
🎉 New function that create the light likelihood map in tag , similar to geopressure_map . |
|
solar |
geolight_solar |
|
zenith |
geolight_zenith |
|
refracted |
geolight_refracted |
|
ligh2mat |
New Convert a timeserie of light into a matrix of day of year, time of day |
Old | New | Comment |
---|---|---|
graph_create |
||
graph_trim |
graph_create_prune |
Not exported |
graph_download_wind |
tag_download_wind |
tag object and not graph |
graph_add_wind |
||
graph_set_movement |
🎉 New Defining all parameters for the movement model without actually computin anything. | |
graph_transition |
New Allow to compute the transition matrix on the fly, thus saving memory | |
flight_bird |
create_bird |
|
print.bird |
New Check a bird object | |
flight_power |
speed2power |
Not exported |
flight_prob |
speed2prob |
More descriptive of what the function does |
graph_marginal |
||
graph_simulation |
||
graph_most_likely |
🎉 New more efficient implementation than using the igraph package. |
|
graph_assert |
New Check status of a graph object | |
print.graph |
New |
Old | New | Comment |
---|---|---|
map_create |
🎉 New GeoPreussreR map are now S3 objects |
|
print.map |
New | |
plot.map |
New | |
rast.map |
New convert a map to a terra::rast |
|
map_expend |
New map are defined by only extend and scale, this function allows to compute lat, lon and dim |
Old | New | Comment |
---|---|---|
path2df |
ind2path |
|
graph_path2edge |
path2edge |
|
plot.path |
New |
Old | New | Comment |
---|---|---|
geopressure_ts_path |
pressurepath_create |
pressurepath ) |
pressurepath_update |
🎉 New Update a pressurepath with a new label file. similar to tag_update . |
|
plot.pressurepath |
New | |
pressurepath2altitude |
New |
Old | New | Comment |
---|---|---|
param_create |
New | |
print.param |
New |
❌ Avoid flight
which can be computed "on the fly" from stap
using stap2flight()
Old | New | Comment |
---|---|---|
trainset_read |
New more generic function taking any df as input as to work with tag_label and twilight_label . Not exported |
|
trainset_write |
New more generic function taking any df as input as to work with tag_label and twilight_label . Not exported |
|
stap2flight |
New | |
stap2duration |
New | |
graph_path2lonlat |
❌ | |
geopressureviz |
Old | New | Comment |
---|---|---|
pam |
tag |
|
id |
||
min_duration |
||
pathname |
directory |
see this |
file |
basename would be better but less user friendly see this |
|
pressure_file |
||
light_file |
||
acceleration_file |
||
path |
sensor_path |
dirname+basename |
crop_start |
||
crop_end |
||
skip |
||
col |
||
date_format |
Old | New | Comment |
---|---|---|
extent |
||
scale |
||
known |
New data.frame defining the knwon position (e.g., equipement and retrieval). Use to avoid computing the likelihood map for nothing and calibration of light | |
include_stap_id |
New | |
include_min_duration |
New |
Old | New | Comment |
---|---|---|
pressure |
||
max_sample |
||
margin |
||
timeout |
||
workers |
||
presssure_maps |
❌ | geostap |
s |
sd |
Match classic R base function name for standard deviation. |
thr |
thr_mask |
Make more explicit |
fun_w |
log_linear_pooling_weight |
Aligned with geolight aggregation |
keep_mse_mask |
||
lon |
||
lat |
||
start_time |
||
end_time |
||
verbose |
quiet |
|
path |
||
include_flight |
Old | New | Comment |
---|---|---|
light |
||
threshold |
twl_thr |
|
shift_k |
twl_offset |
Align with TwGeos but adds twl in front |
twl |
twilight |
|
adjust_calib |
twl_calib_adjust |
|
w_llp |
twl_llp |
|
zenith |
||
sun |
||
tm |
date |
Align with the format |
Old | New | Comment |
---|---|---|
grl |
graph |
|
static_prob |
❌ | tag_set_map |
field |
Define which field in geostap should be use as likelihood | |
thr_prob_percentile |
thr_likelihood |
|
thr_gs |
||
thr_as |
||
area |
extent |
|
cds_key |
||
cds_user |
||
type |
||
nj |
Field of graph
Old | New | Comment |
---|---|---|
s |
||
t |
||
as |
❌ | avoid storing unnecessary (computable from gs and ws ) |
gs |
||
ws |
||
ps |
obs |
Stored as 3D matrix rather than edge level for memory efficiency. |
p |
transition |
movement which can compute trans on the flight with graph_trans and save memory |
movement |
Parameter to be used in graph_trans |
|
Parameter to be used in graph_trans |
||
sz |
||
equipment |
||
retrieval |
||
flight_duration |
❌ | Computable with stap2flight |
lat |
❌ | Computable with extent_scale2grid |
lon |
❌ | Computable with extent_scale2grid |
extent |
||
resolution |
❌ | |
temporal_extent |
❌ | |
stap |
||
scale |
||
mask_water |
Old | New | Comment | |
---|---|---|---|
species_name |
|||
mass |
|||
wing_span |
|||
wing_aspect |
|||
wing_area |
|||
body_frontal_area |
|||
bird |
not super specific | ||
speed |
slightly different than as,gs, ws | ||
method |
|||
shape |
|||
scale |
|||
location |
|||
fun_power |
power2prob |
||
low_speed_fix |
transfer=FALSE
, in which case, it returns the requests and have an optional field request which simply perform the requests. I guess we could be using wf_transfer
and wf_request
(without batch)sta_id
to download only specific sta_id.Here are the vignettes I'm planning to work on
pam$acceleration$class
and pam$pressure$class
to isMig and isOutliarThe only way I can find to use data in a shiny app is to save the data in a .RData
in a specific folder (~
) and then read it from the app. I cannot find a good way to pass variable to a shiny app instance
Any suggestion?
If no acceleration data is available for your track, some functions won't work. With the error message:
Error in pam_classify(pam_data) :
"date" %in% names(pam$acceleration) is not TRUE
This is the case for
Running a simple request of geopressure_map
on a ubuntu machine returns the following error:
Generate requests:
Requests generated successfully for 1 stationary periods (1, )
Send requests:
[==================================================] 1 / 1
Download geotiff:
[ ] 0 / 1
Error in .rasterObjectFromFile(x, objecttype = "RasterBrick", ...): Cannot create a RasterLayer object from this file. (file does not exist)
Traceback:
1. geopressure_map(pressure, extent)
2. future::value(f[[i_u]])
3. value.Future(f[[i_u]])
4. signalConditions(future, exclude = getOption("future.relay.immediate",
. "immediateCondition"), resignal = TRUE)
This error comes from reading the line:
Line 182 in 29dc1e7
If I run it separately i get more information on the error:
Error in .local(.Object, ...): An error occurred while creating a virtual connection to the DAP server:
Error while reading the URL: https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/thumbnails/772ae2eefc3bebadd6131ff354c024cb-ea5496300e42cb031021bb837f34f37d:getPixels.ver.
The OPeNDAP server returned the following message:
Not Found: The data source or server could not be found.
Often this means that the OPeNDAP server is missing or needs attention;
Please contact the server administrator.
Traceback:
1. GDALinfo(uris[i_u])
2. GDAL.open(fname, silent = silent, allowedDrivers = allowedDrivers,
. options = options)
3. new("GDALReadOnlyDataset", filename, silent = silent, allowedDrivers = allowedDrivers,
. options = options)
4. initialize(value, ...)
5. initialize(value, ...)
6. .local(.Object, ...)
I couldn't find a good solution, it seems to come from the driver dods. See https://trac.osgeo.org/gdal/ticket/2696. I have tried to set Sys.setenv(GDAL_SKIP="DODS")
but this wouldn't work.
We need to check that all these file are readable/documented and standard name.
Need to check with Movebank what they can upload.
See also
Parrallel compute progress bar not really working
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.