2014-07-02 67 views
0
檢索數據

有通過http://opendap.co-ops.nos.noaa.gov/axis/基於R SOAP(SSOAP)從NOAA

library(SSOAP) 
pred.wsdl<-"http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl" 
pred.params<-c("8454000","20140702","20140702","MLLW",0,0,60) # from NOAA's java example 
# and the docs on http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/samples/request.xml 
tmp<-processWSDL(pred.wsdl) 
ff<-genSOAPClientInterface(def=tmp,verbose=TRUE) 
[email protected]$getPredictions(pred.params) 

可以從NOAA幾個SOAP服務這得到:

>  pred.wsdl<-"http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl" 
>  pred.params<-c("8454000","20140702","20140702","MLLW",0,0,60) # from NOAA's java example 
>  tmp<-processWSDL(pred.wsdl) 
>  ff<-genSOAPClientInterface(def=tmp,verbose=TRUE) 
<defClass> stationId.beginDate.endDate.datum.unit.timeZone.dataInterval 
finished stationId.beginDate.endDate.datum.unit.timeZone.dataInterval 
<defClass> Data 
finished Data 
<defClass> ArrayOfData 
finished ArrayOfData 
<defClass> data 
finished data 
<defClass> stationId.stationName.latitude.longitude.state.dataSource.COOPSDisclaimer.beginDate.endDate.datum.unit.timeZone.dataInterval.data 
finished stationId.stationName.latitude.longitude.state.dataSource.COOPSDisclaimer.beginDate.endDate.datum.unit.timeZone.dataInterval.data 
Operation getPredictions 
Operation getPredictionsAndMetadata 
>  [email protected]$getPredictions(pred.params) 
Error in as(Parameters, "stationId.beginDate.endDate.datum.unit.timeZone.dataInterval") : 
    no method or default for coercing 「character」 to 「stationId.beginDate.endDate.datum.unit.timeZone.dataInterval」 
> 

我似乎無法找到stationId.beginDate.endDate.datum.unit.timeZone.dataInterval類隨處可用來做一個新的(....)。

> getAnywhere(stationId.beginDate.endDate.datum.unit.timeZone.dataInterval) 
no object named ‘stationId.beginDate.endDate.datum.unit.timeZone.dataInterval’ was found 

ETA:

我發現類的定義:

getClassDef('stationId.beginDate.endDate.datum.unit.timeZone.dataInterval') 

當時我能夠來填充一個S對象有:

pred.Sparams=new('stationId.beginDate.endDate.datum.unit.timeZone.dataInterval',stationId=pred.params[1],beginDate=pred.params[2],endDate=pred.params[3],datum=pred.params[4],unit=as.integer(pred.params[5]),timeZone=as.integer(pred.params[6]),dataInterval=as.integer(pred.params[7])) 

,並調用它:

pred.dataAOD <- [email protected]$getPredictions(pred.Sparams) 

,並把它轉換成更多的東西R-像:

pred.data <- t(mapply([email protected],FUN=function(x){c([email protected],[email protected])},USE.NAMES=FALSE)) 

head(pred.data) 

     time    pred 
[1,] "07/02/2014 00:00" "0.706" 
[2,] "07/02/2014 01:00" "0.866" 
[3,] "07/02/2014 02:00" "1.078" 
[4,] "07/02/2014 03:00" "1.266" 
[5,] "07/02/2014 04:00" "1.322" 
[6,] "07/02/2014 05:00" "1.192" 

如何做任何提示,這更好的?

+1

CRAN不再提供SSOAP軟件包。看起來它不再被支持。您可以使用其他方法來檢索數據,例如http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/? – MrFlick

回答

0

感謝MrFlick,這裏是一個問題的答案對獲取NOAA數據的部分,而不是通過他們的SOAP服務:

# build a URL from the page at http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/ 
sosURL='http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?service=SOS&request=GetObservation&version=1.0.0&observedProperty=sea_surface_height_amplitude_due_to_equilibrium_ocean_tide&offering=urn:ioos:station:NOAA.NOS.CO-OPS:8454000&responseFormat=text%2Fcsv&eventTime=2014-07-02T00:00:00Z/2014-07-02T23:59:00Z&result=VerticalDatum%3D%3Durn:ogc:def:datum:epsg::5103&dataType=HourlyTidePredictions&unit=Meters' 
x=read.csv(url(sosURL)) 

人們可以在一個函數把它包裝,更換站,開始,結束,基準和單位。

getNOAATidalPredictions<-function(
    station=8454000,start=Sys.time(), end=start+3600*24){ 
# Use the http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/ SOS services 
# to read tidal prediction data. 
sosURL='http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?service=SOS&request=GetObservation&version=1.0.0&observedProperty=sea_surface_height_amplitude_due_to_equilibrium_ocean_tide&offering=urn:ioos:station:NOAA.NOS.CO-OPS:STATIONTAG&responseFormat=text%2Fcsv&eventTime=STARTTAG/ENDTAG&result=VerticalDatum%3D%3Durn:ogc:def:datum:epsg::5103&dataType=HourlyTidePredictions&unit=Meters' 
sosURL=gsub('STATIONTAG',station,sosURL) 
sosURL=gsub('STARTTAG',format(start,"%Y-%m-%dT%H:%M:%SZ",tz='UTC'),sosURL) 
sosURL=gsub('ENDTAG',format(end,"%Y-%m-%dT%H:%M:%SZ",tz='UTC'),sosURL) 
read.csv(url(sosURL)) 
dt$date_time<-strptime(dt$date_time,format='%Y-%m-%dT%H:%M:%S',tz='GMT') 
dt 
} 



> getNOAATidalPredictions()[,c(5:6)] 
     date_time sea_surface_height_amplitude_due_to_equilibrium_ocean_tide..m. 
1 2015-03-21T09:00:00Z               -0.749 
2 2015-03-21T10:00:00Z               -0.474 
3 2015-03-21T11:00:00Z               0.005 
4 2015-03-21T12:00:00Z               0.575 
5 2015-03-21T13:00:00Z               0.981 
6 2015-03-21T14:00:00Z               1.017 
7 2015-03-21T15:00:00Z               0.660 
8 2015-03-21T16:00:00Z               0.074 
9 2015-03-21T17:00:00Z               -0.535 
10 2015-03-21T18:00:00Z               -0.976 
11 2015-03-21T19:00:00Z               -1.093 
12 2015-03-21T20:00:00Z               -0.939 
13 2015-03-21T21:00:00Z               -0.717 
14 2015-03-21T22:00:00Z               -0.464 
15 2015-03-21T23:00:00Z               -0.056 
16 2015-03-22T00:00:00Z               0.490 
17 2015-03-22T01:00:00Z               0.965 
18 2015-03-22T02:00:00Z               1.138 
19 2015-03-22T03:00:00Z               0.911 
20 2015-03-22T04:00:00Z               0.387 
21 2015-03-22T05:00:00Z               -0.234 
22 2015-03-22T06:00:00Z               -0.772 
23 2015-03-22T07:00:00Z               -1.050 
24 2015-03-22T08:00:00Z               -1.021 
25 2015-03-22T09:00:00Z               -0.860 

下面是使用SOS搶觀察的進一步的開發功能:

NOAA_water_levels_sos<-function(station,start,end){ 
# data grabber based on a URL built from http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/ 
    ts<-format(start,"%Y-%m-%dT%H:%M:%SZ") 
    te<-format(end,"%Y-%m-%dT%H:%M:%SZ") 
    uri<-'http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?service=SOS&request=GetObservation&version=1.0.0&observedProperty=water_surface_height_above_reference_datum&offering=urn:ioos:station:NOAA.NOS.CO-OPS:8454000&responseFormat=text%2Fcsv&eventTime=2012-10-01T00:00:00Z/2012-11-01T23:59:00Z&result=VerticalDatum%3D%3Durn:ogc:def:datum:epsg::5103&dataType=VerifiedHourlyHeight' 

    uri<-gsub('offering=[^&]*&',sprintf("offering=urn:ioos:station:NOAA.NOS.CO-OPS:%s&",station),uri) 
    uri<-gsub('eventTime[^&]*&',sprintf("eventTime=%s/%s&",ts,te),uri) 
    #print(uri) 
    x<-read.csv(url(uri)) 
    x$time=as.POSIXct(strptime(x$date_time,format="%Y-%m-%dT%H:%M:%SZ",tz="UTC")) 
    x 

} 

NOAAs SOS服務似乎掩蓋自己的SOAP服務的功能,並且更容易包裝和解析。