-
Notifications
You must be signed in to change notification settings - Fork 0
enRichment
Norbert IRD edited this page Mar 20, 2014
·
3 revisions
data enrichment from an OPeNDAP dataset
This process take in parameter a spatio-temporal dataset and an OPeNDAP dataset URL and try to enrich the input dataset with OPeNDAP data. Input dataset must be point only geometry (actually).
require(IRDTunaAtlas)
df <- readData(dataType="WFS",
url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/dbTaggingRTTP?REQUEST=getFeature&SERVICE=WFS&VERSION=2.0.0&typeNames=query_all_schools_biological_datasampling")
enriched.df <- enRichment(data=df,
opendapUrl="http://oceanwatch.pfeg.noaa.gov/thredds/dodsC/satellite/PH/sstd/1day",
varName="sea_surface_temperature",
timeName="bio_timestamp",
verbose=TRUE)
> names(enriched.df)[! names(enriched.df) %in% names(df)]
[1] "sea_surface_temperature" "sea_surface_temperature_longitude" "sea_surface_temperature_latitude" "sea_surface_temperature_time"
> enriched.df$sea_surface_temperature[smp]
[1] 28.2 NA NA NA NA NA NA NA NA NA
> enriched.df$time <- strptime(enriched.df$bio_timestamp, format="%Y-%m-%dT%H:%M:%OSZ")
> smp <- sample(1:nrow(enriched.df), 10)
> data.frame(obs.time=enriched.df$time, sst.time=enriched.df$sea_surface_temperature_time, diff.time=enriched.df$time - enriched.df$sea_surface_temperature_time)[smp,]
obs.time sst.time diff.time
272 2006-04-18 22:00:00 2006-04-18 13:00:00 9 hours
1808 2006-10-08 22:00:00 2006-10-08 13:00:00 9 hours
2426 2006-04-26 22:00:00 2006-04-26 13:00:00 9 hours
2553 2007-07-11 22:00:00 2007-07-11 13:00:00 9 hours
1212 2005-08-16 22:00:00 2005-08-16 13:00:00 9 hours
2214 2006-10-08 22:00:00 2006-10-08 13:00:00 9 hours
1761 2006-10-20 22:00:00 2006-10-20 13:00:00 9 hours
3209 2007-04-25 22:00:00 2007-04-25 13:00:00 9 hours
1018 2006-04-24 22:00:00 2006-04-24 13:00:00 9 hours
3150 2007-02-25 23:00:00 2007-02-25 12:00:00 11 hours
> myDistFun <- function(x)
+ {
+ return(spDistsN1( matrix(c(x[1],x[2]), ncol=2), c(x[3],x[4]), longlat=TRUE))
+ }
> res <- apply(cbind(coordinates(enriched.df)[,1], coordinates(enriched.df)[,2], enriched.df$sea_surface_temperature_longitude, enriched.df$sea_surface_temperature_latitude), c(1), myDistFun)
> res[smp]
[1] 1.4150088 1.1159907 1.4378368 2.0110477 1.2079209 2.4496984 0.9213724 2.1955204 0.2455549 1.3299811