ioos / pyoos

A Python library for collecting Met/Ocean observations
GNU Lesser General Public License v3.0
34 stars 33 forks source link

Coops Get Observations as Collections #31

Open DanielJMaher opened 10 years ago

DanielJMaher commented 10 years ago

When attempting to Get Coop Observations, pyoos encounters an issue: Because Coops does not support xml generation for a collection of observations, the collector can not properly collect the data. The solution would either be to allow the parsing and collecting of CSV/TSV files, or to get observations from Coop as several single observation.

birdage commented 10 years ago

@DanielJMaher i get round this by making a separate get request, and parsing the xml, the following creates a dict of station in that bounding box

url=(sos_urls[0].split("?")[0]+'?'
     'service=SOS&request=GetObservation&version=1.0.0&'
     'observedProperty=%s&offering=urn:ioos:network:NOAA.NOS.CO-OPS:WaterLevelActive&'
     'featureOfInterest=BBOX:%s&responseFormat=text/tab-separated-values&eventTime=%s') % (sos_name,box_str,iso_end)

r = requests.get(url)
data = r.text
#get the headers for the cols
data = data.split("\n")
headers =  data[0]
station_list_dict = dict()
#parse the headers so i can create a dict
c = 0
for h in headers.split("\t"):
    field = h.split(":")[0].split(" ")[0]
    station_list_dict[field] = {"id":c}
    c+=1
#create dict of stations
station_list = []
for i in range(1,len(data)):
    station_info = data[i].split("\t")
    station = dict()
    for field in station_list_dict.keys():        
        col = station_list_dict[field]["id"]
        if col < len(station_info):
            station[field] = station_info[col]     
    station_list.append(station)     
DanielJMaher commented 10 years ago

@birdage I don't think you are using pyoos at all in your work around. I think you are on the right track here though. Once we grab the data we don't need to use etree to parse the xml. instead we can parse the data how we want.

dpsnowden commented 10 years ago

Let's bring Mohammed into the conversation. I think they implemented collection support and it may be a syntax issue. @mchaouchi can you clarify?

mchaouchi commented 10 years ago

CO-OPS implemented collection support for CSV, TSV, and KML.

In the next release (in 2 to 3 months from now), the SWE common implementation will have collection support for XML.

Date: Tue, 20 May 2014 13:19:05 -0700 From: notifications@github.com To: pyoos@noreply.github.com CC: mchaouchi@hotmail.com Subject: Re: [pyoos] Coops Get Observations as Collections (#31)

Let's bring Mohammed into the conversation. I think they implemented collection support and it may be a syntax issue. @mchaouchi can you clarify?

— Reply to this email directly or view it on GitHub.