예제 #1
0
def get_wqp(station_id, **kwargs):
    wq = WqpRest()

    params = {
        "siteid" : station_id,
        "sampleMedia" : "Water"
    }

    obs_props = kwargs.get("observedProperties", None)

    if obs_props is not None:
        params["characteristicName"] = ";".join(obs_props)

    st = kwargs.get("starting", None)
    et = kwargs.get("ending", None)
    if st is not None:
        wq.start_time = st
    if et is not None:
        wq.end_time = et
    
    s = wq.get_station(**params)
    if s is not None:
        s.calculate_bounds()
        publisher = {"name": "Water Quality Monitoring Portal", "url" : "http://waterqualitydata.us"}
        return s, publisher
    return None, None
예제 #2
0
    def response(self):
        if self.procedure is None:
            return render_template("error.xml", parameter="procedure", value="Value missing")

        wq = WqpRest()
        station = wq.get_metadata(siteid=self.procedure)
        if station.failed:
            return render_template("error.xml", parameter="procedure", value="Invalid value")

        activities = wq.get_data(siteid=self.procedure).activities

        # Get unique observedProperties
        ops = []
        op_names = []
        for a in activities:
            for r in a.results:
                if r.name not in op_names:
                    op_names.append(r.name)
                    ops.append(r)

        return render_template("describesensor.xml", station=station, observedProperties=set(ops))
예제 #3
0
def get_wqp(station_id, mimeType, **kwargs):
    wq = WqpRest()

    params = {
        "siteid"      : station_id,
        "mimeType"    : mimeType,
        "sampleMedia" : "Water"
    }

    obs_props = kwargs.get("observedProperties", None)
    if obs_props is not None:
        params["characteristicName"] = ";".join(obs_props)

    st = kwargs.get("starting", None)
    et = kwargs.get("ending", None)
    if st is not None:
        wq.start_time = st
    if et is not None:
        wq.end_time = et
    
    return wq.get_raw_results_data(**params)
예제 #4
0
파일: test_wqp.py 프로젝트: jameshgrn/pyoos
 def setUp(self):
     self.c = WqpRest()
예제 #5
0
파일: test_wqp.py 프로젝트: jameshgrn/pyoos
class WqpTest(unittest.TestCase):
    def setUp(self):
        self.c = WqpRest()

    def test_wqp_sites_metadata(self):
        """
        <WQX xmlns="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/ http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/index.xsd">  # noqa
            <Organization>
                <OrganizationDescription>
                    <OrganizationIdentifier>21IOWA</OrganizationIdentifier>
                    <OrganizationFormalName>Iowa Dept. of  Natural Resources</OrganizationFormalName>
                </OrganizationDescription>
                <MonitoringLocation>
                    <MonitoringLocationIdentity>
                        <MonitoringLocationIdentifier>21IOWA-10070005</MonitoringLocationIdentifier>
                        <MonitoringLocationName>Cedar River Upstream of Waterloo/Cedar Falls</MonitoringLocationName>
                        <MonitoringLocationTypeName>River/Stream</MonitoringLocationTypeName>
                        <MonitoringLocationDescriptionText>Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site.</MonitoringLocationDescriptionText>
                        <HUCEightDigitCode>07080205</HUCEightDigitCode>
                    </MonitoringLocationIdentity>
                    <MonitoringLocationGeospatial>
                        <LatitudeMeasure>42.5392</LatitudeMeasure>
                        <LongitudeMeasure>-92.4495</LongitudeMeasure>
                        <SourceMapScaleNumeric>000</SourceMapScaleNumeric>
                        <HorizontalCollectionMethodName>Interpolation-Map</HorizontalCollectionMethodName>
                        <HorizontalCoordinateReferenceSystemDatumName>NAD27</HorizontalCoordinateReferenceSystemDatumName>
                        <VerticalMeasure>
                            <MeasureValue>854</MeasureValue>
                            <MeasureUnitCode>ft</MeasureUnitCode>
                        </VerticalMeasure>
                        <VerticalCollectionMethodName>Topographic Map Interpolation</VerticalCollectionMethodName>
                        <VerticalCoordinateReferenceSystemDatumName>NGVD29</VerticalCoordinateReferenceSystemDatumName>
                        <CountryCode>US</CountryCode>
                        <StateCode>19</StateCode>
                        <CountyCode>013</CountyCode>
                    </MonitoringLocationGeospatial>
                </MonitoringLocation>
            </Organization>
        </WQX>
        """
        self.c.filter(features=["21IOWA-10070005"])
        meta, data = self.c.raw()

        org = WqxOutbound(meta).organizations[0]

        # OrganizationDescription
        assert org.description.name == u"Iowa Dept. of  Natural Resources"
        assert org.description.id == u"21IOWA"

        # MonitoringLocation
        assert org.locations[0].id == u"21IOWA-10070005"
        assert (org.locations[0].name ==
                u"Cedar River Upstream of Waterloo/Cedar Falls")
        assert org.locations[0].type == u"River/Stream"
        assert org.locations[0].description.startswith(
            u"Below the dam of Old Highway 218 in Cedar Falls")
        assert org.locations[0].huc == u"07080205"
        assert org.locations[0].latitude == u"42.5392"
        assert org.locations[0].longitude == u"-92.4495"
        assert org.locations[0].vertical_measure_value == u"854"
        assert org.locations[0].vertical_measure_units == u"ft"
        assert org.locations[0].country == u"US"
        assert org.locations[0].state == u"19"
        assert org.locations[0].county == u"013"

    def test_wqp_results_metadata(self):
        self.c.filter(features=["21IOWA-10070005"])
        meta, data = self.c.raw()

        # OrganizationDescription
        org = WqxOutbound(data).organizations[0]
        assert org.description.name == u"Iowa Dept. of  Natural Resources"
        assert org.description.id == u"21IOWA"

    def test_bad_wqp_site(self):
        self.c.filter(features=["s"])
        rmeta, data = self.c.raw()

        with raises(AttributeError):
            getattr(data, "organization")

    def test_into_dsg(self):
        # First feature filter
        self.c.filter(features=["21IOWA-10070005"])
        station_collection = self.c.collect()
        station_collection.calculate_bounds()

        assert station_collection.size == 1
        station = station_collection.elements[0]
        assert len(station.get_unique_members()) == 240
        assert station.location.x == -92.4495
        assert station.location.y == 42.5392
        assert station.location.z == float(854 / 3.28084)

        # Second variable filter
        self.c.filter(variables=["Mercury"])
        station_collection = self.c.collect()
        station_collection.calculate_bounds()

        assert station_collection.size == 1
        station = station_collection.elements[0]
        assert len(station.get_unique_members()) == 1
예제 #6
0
    def response(self):
        if self.offering is None:
            return render_template("error.xml", parameter="offering", value="Value missing")
        if self.obs_props is None:
            return render_template("error.xml", parameter="observedProperty", value="Value missing")
        else:
            self.obs_props = list(set(self.obs_props.split(",")))

        wq = WqpRest()
        station = wq.get_metadata(siteid=self.offering)
        if station.failed:
            return render_template("error.xml", parameter="offering", value="Invalid value")

        activities = wq.get_data(siteid=self.offering).activities

        # Filter by observedProperties
        activities = [a for a in activities if len(set(self.obs_props) & set([p.name for p in a.results])) > 0]

        # Filter by eventtime
        if self.eventtime is not None and (isinstance(self.eventtime, unicode) or isinstance(self.eventtime, str)):
            if len(activities) > 0:
                if self.eventtime.lower() == "latest":
                    starting = max([a.start_time for a in activities])
                    ending = starting + timedelta(minutes=1)
                else:
                    starting = dateparser.parse(self.eventtime.split("/")[0])
                    ending = dateparser.parse(self.eventtime.split("/")[1])

                activities = [a for a in activities if starting <= a.start_time and a.start_time <= ending]

        min_time = "never"
        max_time = "never"
        if len(activities) > 0:
            # Extract timerange using Python here, instead of in Jinja2
            all_times = [a.start_time for a in activities]
            min_time = min(all_times)
            max_time = max(all_times)

        # Get observedProperties
        ops = []
        op_names = []
        for a in activities:
            for r in a.results:
                if r.name in self.obs_props and r.name not in op_names:
                    op_names.append(r.name)
                    ops.append(r)

        rows = []
        for a in activities:
            match = False
            row = [(a.start_time.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%SZ"))]
            for obp in ops:
                for r in a.results:
                    if r.name == obp.name:
                        row.append(unicode(r.value))
                        match = True
                        break
                if match == True:
                    break
                else:
                    row.append("None")
            rows.append(",".join(row))

        data_block = "\n".join(rows)

        return render_template(
            "getobservation.xml",
            min_time=min_time,
            max_time=max_time,
            station=station,
            data_block=data_block,
            observedProperties=set(ops),
        )
예제 #7
0
class WqpTest(unittest.TestCase):
    def setUp(self):
        self.c = WqpRest()

    def test_wqp_sites_metadata(self):
        """
        <WQX xmlns="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/ http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/index.xsd">
            <Organization>
                <OrganizationDescription>
                    <OrganizationIdentifier>21IOWA</OrganizationIdentifier>
                    <OrganizationFormalName>Iowa Dept. of  Natural Resources</OrganizationFormalName>
                </OrganizationDescription>
                <MonitoringLocation>
                    <MonitoringLocationIdentity>
                        <MonitoringLocationIdentifier>21IOWA-10070005</MonitoringLocationIdentifier>
                        <MonitoringLocationName>Cedar River Upstream of Waterloo/Cedar Falls</MonitoringLocationName>
                        <MonitoringLocationTypeName>River/Stream</MonitoringLocationTypeName>
                        <MonitoringLocationDescriptionText>Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site.</MonitoringLocationDescriptionText>
                        <HUCEightDigitCode>07080205</HUCEightDigitCode>
                    </MonitoringLocationIdentity>
                    <MonitoringLocationGeospatial>
                        <LatitudeMeasure>42.5392</LatitudeMeasure>
                        <LongitudeMeasure>-92.4495</LongitudeMeasure>
                        <SourceMapScaleNumeric>000</SourceMapScaleNumeric>
                        <HorizontalCollectionMethodName>Interpolation-Map</HorizontalCollectionMethodName>
                        <HorizontalCoordinateReferenceSystemDatumName>NAD27</HorizontalCoordinateReferenceSystemDatumName>
                        <VerticalMeasure>
                            <MeasureValue>854</MeasureValue>
                            <MeasureUnitCode>ft</MeasureUnitCode>
                        </VerticalMeasure>
                        <VerticalCollectionMethodName>Topographic Map Interpolation</VerticalCollectionMethodName>
                        <VerticalCoordinateReferenceSystemDatumName>NGVD29</VerticalCoordinateReferenceSystemDatumName>
                        <CountryCode>US</CountryCode>
                        <StateCode>19</StateCode>
                        <CountyCode>013</CountyCode>
                    </MonitoringLocationGeospatial>
                </MonitoringLocation>
            </Organization>
        </WQX>
        """
        #self.c.start_time = AsaTime.parse("2009-08-01")
        #self.c.end_time = AsaTime.parse("2009-09-10")

        results = self.c.get_metadata(siteid="21IOWA-10070005")

        # OrganizationDescription
        assert results.organization.name == u"Iowa Dept. of  Natural Resources"
        assert results.organization.id == u"21IOWA"

        # MonitoringLocation
        assert results.location.id == u"21IOWA-10070005"
        assert results.location.name == u"Cedar River Upstream of Waterloo/Cedar Falls"
        assert results.location.type == u"River/Stream"
        assert results.location.description == u"Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site."
        assert results.location.huc == u"07080205"
        assert results.location.latitude == u"42.5392"
        assert results.location.longitude == u"-92.4495"
        assert results.location.vertical_measure_value == u"854"
        assert results.location.vertical_measure_units == u"ft"
        assert results.location.country == u"US"
        assert results.location.state == u"19"
        assert results.location.county == u"013"

    def test_wqp_results_metadata(self):
        results = self.c.get_data(siteid="21IOWA-10070005")

        # OrganizationDescription
        assert results.organization.name == u"Iowa Dept. of  Natural Resources"
        assert results.organization.id == u"21IOWA"

        #for a in results.activities:
        #    for r in a.results:
        #        assert r is not None
        #        if r.name == "Escherichia coli":
        #            print r.value

    def test_bad_wqp_site(self):
        results = self.c.get_metadata(siteid="s")
        with raises(AttributeError):
            print results.organization

    def test_into_dsg(self):
        results = self.c.get_station(siteid="21IOWA-10070005")
        results.calculate_bounds()

        assert len(results.get_unique_members()) == 240
        assert results.location.x == -92.4495
        assert results.location.y == 42.5392
        assert results.location.z == float(854 / 3.28084)

        results = self.c.get_station(siteid="21IOWA-10070005",
                                     characteristicName="Mercury")
        results.calculate_bounds()
        assert len(results.get_unique_members()) == 1
예제 #8
0
파일: test_wqp.py 프로젝트: acrosby/pyoos
class WqpTest(unittest.TestCase):

    def setUp(self):
        self.c = WqpRest()

    def test_wqp_sites_metadata(self):
        """
        <WQX xmlns="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/ http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/index.xsd">
            <Organization>
                <OrganizationDescription>
                    <OrganizationIdentifier>21IOWA</OrganizationIdentifier>
                    <OrganizationFormalName>Iowa Dept. of  Natural Resources</OrganizationFormalName>
                </OrganizationDescription>
                <MonitoringLocation>
                    <MonitoringLocationIdentity>
                        <MonitoringLocationIdentifier>21IOWA-10070005</MonitoringLocationIdentifier>
                        <MonitoringLocationName>Cedar River Upstream of Waterloo/Cedar Falls</MonitoringLocationName>
                        <MonitoringLocationTypeName>River/Stream</MonitoringLocationTypeName>
                        <MonitoringLocationDescriptionText>Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site.</MonitoringLocationDescriptionText>
                        <HUCEightDigitCode>07080205</HUCEightDigitCode>
                    </MonitoringLocationIdentity>
                    <MonitoringLocationGeospatial>
                        <LatitudeMeasure>42.5392</LatitudeMeasure>
                        <LongitudeMeasure>-92.4495</LongitudeMeasure>
                        <SourceMapScaleNumeric>000</SourceMapScaleNumeric>
                        <HorizontalCollectionMethodName>Interpolation-Map</HorizontalCollectionMethodName>
                        <HorizontalCoordinateReferenceSystemDatumName>NAD27</HorizontalCoordinateReferenceSystemDatumName>
                        <VerticalMeasure>
                            <MeasureValue>854</MeasureValue>
                            <MeasureUnitCode>ft</MeasureUnitCode>
                        </VerticalMeasure>
                        <VerticalCollectionMethodName>Topographic Map Interpolation</VerticalCollectionMethodName>
                        <VerticalCoordinateReferenceSystemDatumName>NGVD29</VerticalCoordinateReferenceSystemDatumName>
                        <CountryCode>US</CountryCode>
                        <StateCode>19</StateCode>
                        <CountyCode>013</CountyCode>
                    </MonitoringLocationGeospatial>
                </MonitoringLocation>
            </Organization>
        </WQX>
        """
        self.c.filter(features=["21IOWA-10070005"])
        meta, data = self.c.raw()

        org = WqxOutbound(meta).organizations[0]

        # OrganizationDescription
        assert org.description.name == u"Iowa Dept. of  Natural Resources"
        assert org.description.id == u"21IOWA"

        # MonitoringLocation
        assert org.locations[0].id == u"21IOWA-10070005"
        assert org.locations[0].name == u"Cedar River Upstream of Waterloo/Cedar Falls"
        assert org.locations[0].type == u"River/Stream"
        assert org.locations[0].description == u"Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site."
        assert org.locations[0].huc == u"07080205"
        assert org.locations[0].latitude == u"42.5392"
        assert org.locations[0].longitude == u"-92.4495"
        assert org.locations[0].vertical_measure_value == u"854"
        assert org.locations[0].vertical_measure_units == u"ft"
        assert org.locations[0].country == u"US"
        assert org.locations[0].state == u"19"
        assert org.locations[0].county == u"013"
        

    def test_wqp_results_metadata(self):
        self.c.filter(features=["21IOWA-10070005"])
        meta, data = self.c.raw()
        
        # OrganizationDescription
        org = WqxOutbound(data).organizations[0]
        assert org.description.name == u"Iowa Dept. of  Natural Resources"
        assert org.description.id == u"21IOWA"

    def test_bad_wqp_site(self):
        self.c.filter(features=["s"])
        rmeta, data = self.c.raw()

        with raises(AttributeError):
            print data.organization

    def test_into_dsg(self):
        # First feature filter
        self.c.filter(features=["21IOWA-10070005"])
        station_collection = self.c.collect()
        station_collection.calculate_bounds()

        assert station_collection.size == 1
        station = station_collection.elements[0]
        assert len(station.get_unique_members()) == 240
        assert station.location.x == -92.4495
        assert station.location.y == 42.5392
        assert station.location.z == float(854 / 3.28084)

        # Second variable filter
        self.c.filter(variables=["Mercury"])
        station_collection = self.c.collect()
        station_collection.calculate_bounds()

        assert station_collection.size == 1
        station = station_collection.elements[0]
        assert len(station.get_unique_members()) == 1
예제 #9
0
파일: test_wqp.py 프로젝트: acrosby/pyoos
 def setUp(self):
     self.c = WqpRest()
예제 #10
0
파일: test_wqp.py 프로젝트: CowanSM/pyoos
class WqpTest(unittest.TestCase):

    def setUp(self):
        self.c = WqpRest()

    def test_wqp_sites_metadata(self):
        """
        <WQX xmlns="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/ http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/index.xsd">
            <Organization>
                <OrganizationDescription>
                    <OrganizationIdentifier>21IOWA</OrganizationIdentifier>
                    <OrganizationFormalName>Iowa Dept. of  Natural Resources</OrganizationFormalName>
                </OrganizationDescription>
                <MonitoringLocation>
                    <MonitoringLocationIdentity>
                        <MonitoringLocationIdentifier>21IOWA-10070005</MonitoringLocationIdentifier>
                        <MonitoringLocationName>Cedar River Upstream of Waterloo/Cedar Falls</MonitoringLocationName>
                        <MonitoringLocationTypeName>River/Stream</MonitoringLocationTypeName>
                        <MonitoringLocationDescriptionText>Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site.</MonitoringLocationDescriptionText>
                        <HUCEightDigitCode>07080205</HUCEightDigitCode>
                    </MonitoringLocationIdentity>
                    <MonitoringLocationGeospatial>
                        <LatitudeMeasure>42.5392</LatitudeMeasure>
                        <LongitudeMeasure>-92.4495</LongitudeMeasure>
                        <SourceMapScaleNumeric>000</SourceMapScaleNumeric>
                        <HorizontalCollectionMethodName>Interpolation-Map</HorizontalCollectionMethodName>
                        <HorizontalCoordinateReferenceSystemDatumName>NAD27</HorizontalCoordinateReferenceSystemDatumName>
                        <VerticalMeasure>
                            <MeasureValue>854</MeasureValue>
                            <MeasureUnitCode>ft</MeasureUnitCode>
                        </VerticalMeasure>
                        <VerticalCollectionMethodName>Topographic Map Interpolation</VerticalCollectionMethodName>
                        <VerticalCoordinateReferenceSystemDatumName>NGVD29</VerticalCoordinateReferenceSystemDatumName>
                        <CountryCode>US</CountryCode>
                        <StateCode>19</StateCode>
                        <CountyCode>013</CountyCode>
                    </MonitoringLocationGeospatial>
                </MonitoringLocation>
            </Organization>
        </WQX>
        """
        #self.c.start_time = AsaTime.parse("2009-08-01")
        #self.c.end_time = AsaTime.parse("2009-09-10")
        
        results = self.c.get_metadata(siteid="21IOWA-10070005")

        # OrganizationDescription
        assert results.organization.name == u"Iowa Dept. of  Natural Resources"
        assert results.organization.id == u"21IOWA"

        # MonitoringLocation
        assert results.location.id == u"21IOWA-10070005"
        assert results.location.name == u"Cedar River Upstream of Waterloo/Cedar Falls"
        assert results.location.type == u"River/Stream"
        assert results.location.description == u"Below the dam of Old Highway 218 in Cedar Falls.¿Upstream City Site."
        assert results.location.huc == u"07080205"
        assert results.location.latitude == u"42.5392"
        assert results.location.longitude == u"-92.4495"
        assert results.location.vertical_measure_value == u"854"
        assert results.location.vertical_measure_units == u"ft"
        assert results.location.country == u"US"
        assert results.location.state == u"19"
        assert results.location.county == u"013"
        

    def test_wqp_results_metadata(self):       
        results = self.c.get_data(siteid="21IOWA-10070005")
        
        # OrganizationDescription
        assert results.organization.name == u"Iowa Dept. of  Natural Resources"
        assert results.organization.id == u"21IOWA"
        
        #for a in results.activities:
        #    for r in a.results:
        #        assert r is not None
        #        if r.name == "Escherichia coli":
        #            print r.value

    def test_bad_wqp_site(self):
        results = self.c.get_metadata(siteid="s")
        with raises(AttributeError):
            print results.organization

    def test_into_dsg(self):
        results = self.c.get_station(siteid="21IOWA-10070005")
        results.calculate_bounds()

        assert len(results.get_unique_members()) == 240
        assert results.location.x == -92.4495
        assert results.location.y == 42.5392
        assert results.location.z == float(854 / 3.28084)

        results = self.c.get_station(siteid="21IOWA-10070005", characteristicName="Mercury")
        results.calculate_bounds()
        assert len(results.get_unique_members()) == 1