Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R SOAP(SSOAP)从NOAA检索数据_R_Soap - Fatal编程技术网

使用R SOAP(SSOAP)从NOAA检索数据

使用R SOAP(SSOAP)从NOAA检索数据,r,soap,R,Soap,有几个SOAP服务可从NOAA到 预计到达时间: 我发现类定义包含: 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.

有几个SOAP服务可从NOAA到

预计到达时间:

我发现类定义包含:

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 <- ff@functions$getPredictions(pred.Sparams)

pred.dataAOD多亏了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

GetNoAtidalPredictionsSSOAP包不再可从CRAN获得。它似乎不再受支持。您可以使用不同的方法来检索数据,例如?
pred.dataAOD <- ff@functions$getPredictions(pred.Sparams)
pred.data <- t(mapply(pred.dataAOD@data,FUN=function(x){c(time=x@timeStamp,pred=x@pred)},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"
# 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
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

}