def _get_collection_summary_elems(self):
     extension_elem = get_elements("Contents/Extension", self.root,
                                   single_elem=True, namespace=self.wcs)
     col_summary_elems = get_elements("CoverageCollectionSummary",
                                      extension_elem,
                                      namespace=self.metocean)
     return col_summary_elems
 def get_operations(self):
     op_meta_elem = get_elements("OperationsMetadata",
                                 self.root,
                                 single_elem=True,
                                 namespace=self.ows)
     op_elems = get_elements("Operation", op_meta_elem, namespace=self.ows)
     operations = [elem.attrib["name"] for elem in op_elems]
     return operations
 def get_address(self):
     op_meta_elem = get_elements("OperationsMetadata", self.root,
                                 single_elem=True, namespace=self.ows)
     op_elems = get_elements("Operation", op_meta_elem, namespace=self.ows)
     # Just use firt element.
     get_elem = get_elements("DCP/HTTP/Get", op_elems[0], single_elem=True,
                             namespace=self.ows)
     return get_elements_attr("href", get_elem, namespace=self.xlink)
 def _get_collection_summary_elems(self):
     extension_elem = get_elements("Contents/Extension",
                                   self.root,
                                   single_elem=True,
                                   namespace=self.wcs)
     col_summary_elems = get_elements("CoverageCollectionSummary",
                                      extension_elem,
                                      namespace=self.metocean)
     return col_summary_elems
    def test_namespace(self):
        # Get first element under the root, this is elemOne.
        required_elem = xml_simple_ns_root[0]
        # This xml has a namespace called "test_namespace".
        found_elems  = xml_reader.get_elements("elemOne", xml_simple_ns_root,
                                    namespace="test_namespace")
        # get_elements returns a list, there is only one elemOne element.
        self.assertEqual(found_elems[0], required_elem)

        # Nothing should be returned if namespace not given.
        found_elems  = xml_reader.get_elements("elemOne", xml_simple_ns_root)
        self.assertEqual(found_elems, [])
 def get_address(self):
     op_meta_elem = get_elements("OperationsMetadata",
                                 self.root,
                                 single_elem=True,
                                 namespace=self.ows)
     op_elems = get_elements("Operation", op_meta_elem, namespace=self.ows)
     # Just use firt element.
     get_elem = get_elements("DCP/HTTP/Get",
                             op_elems[0],
                             single_elem=True,
                             namespace=self.ows)
     return get_elements_attr("href", get_elem, namespace=self.xlink)
 def get_ref_time(self):
     extension_elem = get_elements("metadata/Extension", self.root,
                                   single_elem=True, namespace=self.gmlcov)
     source_obs_elem = get_elements("extensionProperty/"\
                                    "MetOceanCoverageMetadata/"\
                                    "sourceObservationProperty/"\
                                    "SourceObservation", extension_elem,
                                    single_elem=True,
                                    namespace=self.metocean)
     value_elem = get_elements("parameter/NamedValue/value",
                               source_obs_elem, single_elem=True,
                               namespace=self.om)
     return get_elements_text("TimeInstant/timePosition", value_elem,
                              single_elem=True, namespace=self.gml)
 def get_components(self):
     components = []
     extension_elem = get_elements("metadata/Extension", self.root,
                                   single_elem=True, namespace=self.gmlcov)
     member_list_elems = get_elements("extensionProperty/"\
                                      "MetOceanCoverageMetadata/"\
                                      "dataMaskReferenceProperty/"\
                                      "DataMaskReferenceMemberList/"\
                                      "dataMaskReference",
                                      extension_elem,
                                      namespace=self.metocean)
     for elem in member_list_elems:
         components.append(get_elements_attr("fieldName", elem))
     return components
 def get_coverages(self):
     cov_ids_elem = get_elements("coverageIdList", self.root,
                                 single_elem=True,
                                 namespace=self.metocean)
     cov_ids = get_elements_text("CoverageSummary/CoverageId", cov_ids_elem,
                                 namespace=self.wcs)
     return CoverageList([Coverage(cov_id) for cov_id in cov_ids])
 def __init__(self, xml_str):
     super(CoverageReader, self).__init__(xml_str)
     # Describe coverage XML only contains one coverage description.
     self.root = get_elements("CoverageDescription",
                              self.root,
                              single_elem=True,
                              namespace=self.wcs)
 def get_components(self):
     components = []
     extension_elem = get_elements("metadata/Extension",
                                   self.root,
                                   single_elem=True,
                                   namespace=self.gmlcov)
     member_list_elems = get_elements("extensionProperty/"\
                                      "MetOceanCoverageMetadata/"\
                                      "dataMaskReferenceProperty/"\
                                      "DataMaskReferenceMemberList/"\
                                      "dataMaskReference",
                                      extension_elem,
                                      namespace=self.metocean)
     for elem in member_list_elems:
         components.append(get_elements_attr("fieldName", elem))
     return components
    def _get_axis_describer_values(self, name, root, namespace=None):
        """
        Get all elements that come under the AxisDescription element;
        e.g. initialisation, forecast time, elevation.

        Args:

        * name: string
            The name of the axis describer.

        * root: xml.etree.ElementTree.Element
            The element inside which the values are nested.

        Kwargs:

        * namespace: string or None
            The xml namespace for the AxisDescription element.

        """
        axis_elems = get_elements("rangeSet/RangeSet/axisDescription/"\
                                  "AxisDescription",
                                  root, namespace=namespace)
        for axis_elem in axis_elems:
            elem_name = get_elements_text("name", root=axis_elem,
                                          single_elem=True,
                                          namespace=namespace)
            if elem_name == name:
                return self._get_values(axis_elem, namespace=namespace)
        return []
 def test_return_val(self):
     expected_bbox = [-10, 0, 10, 20]
     # The bbox (lonLatEnvelope) element must be directly under the given
     # root.
     root_elem = get_elements("elemThree", self.reader.root,
                                         single_elem=True)
     bbox = self.reader._get_bbox(root_elem, namespace=None)
     self.assertEqual(bbox, expected_bbox)
 def _get_reference_times(self, root):
     ref_time_elem = get_elements("referenceTimeList/ReferenceTime",
                                  root,
                                  single_elem=True,
                                  namespace=self.metocean)
     return get_elements_text("timePosition",
                              ref_time_elem,
                              namespace=self.gml)
 def get_ref_time(self):
     ref_time_elem = get_elements("referenceTime",
                                  self.root,
                                  single_elem=True,
                                  namespace=self.metocean)
     return get_elements_text("TimeInstant/timePosition",
                              ref_time_elem,
                              namespace=self.gml)
 def get_coverage_ids(self):
     contents_elem = get_elements("Contents",
                                  self.root,
                                  single_elem=True,
                                  namespace=self.wcs)
     return get_elements_text("CoverageSummary/CoverageId",
                              contents_elem,
                              namespace=self.wcs)
 def get_crss(self):
     extension_elem = get_elements("metadata/Extension",
                                   self.root,
                                   single_elem=True,
                                   namespace=self.gmlcov)
     source_obs_elem = get_elements("extensionProperty/"\
                                    "MetOceanCoverageMetadata/"\
                                    "sourceObservationProperty/"\
                                    "SourceObservation", extension_elem,
                                    single_elem=True,
                                    namespace=self.metocean)
     intrst_elem = get_elements("featureOfInterest",
                                source_obs_elem,
                                single_elem=True,
                                namespace=self.om)
     SF_spatial_elem = get_elements("SF_SpatialSamplingFeature",
                                    intrst_elem,
                                    single_elem=True,
                                    namespace=self.sams)
     sample_feat_elem = get_elements("sampledFeature",
                                     SF_spatial_elem,
                                     single_elem=True,
                                     namespace=self.sam)
     horzon_proj_elem = get_elements("ModelDescription/geometryComponent/"\
                                     "ModelDomain/horizontalProjection",
                                     sample_feat_elem, single_elem=True,
                                     namespace=self.metocean)
     poly_elem = get_elements("Polygon",
                              horzon_proj_elem,
                              single_elem=True,
                              namespace=self.gml)
     return get_elements_attr("srsName", poly_elem)
 def test_return_val(self):
     expected_bbox = [-10, 0, 10, 20]
     # The bbox (lonLatEnvelope) element must be directly under the given
     # root.
     root_elem = get_elements("elemThree",
                              self.reader.root,
                              single_elem=True)
     bbox = self.reader._get_bbox(root_elem, namespace=None)
     self.assertEqual(bbox, expected_bbox)
 def get_coverages(self):
     cov_ids_elem = get_elements("coverageIdList",
                                 self.root,
                                 single_elem=True,
                                 namespace=self.metocean)
     cov_ids = get_elements_text("CoverageSummary/CoverageId",
                                 cov_ids_elem,
                                 namespace=self.wcs)
     return CoverageList([Coverage(cov_id) for cov_id in cov_ids])
 def get_ref_time(self):
     extension_elem = get_elements("metadata/Extension",
                                   self.root,
                                   single_elem=True,
                                   namespace=self.gmlcov)
     source_obs_elem = get_elements("extensionProperty/"\
                                    "MetOceanCoverageMetadata/"\
                                    "sourceObservationProperty/"\
                                    "SourceObservation", extension_elem,
                                    single_elem=True,
                                    namespace=self.metocean)
     value_elem = get_elements("parameter/NamedValue/value",
                               source_obs_elem,
                               single_elem=True,
                               namespace=self.om)
     return get_elements_text("TimeInstant/timePosition",
                              value_elem,
                              single_elem=True,
                              namespace=self.gml)
    def test_single_elem(self):
        required_elem = xml_simple_root[0]
        # If single_elem true, a single element (not a list) should be
        # returned.
        founds_elem = xml_reader.get_elements("elemOne", xml_simple_root,
                                   single_elem=True)
        self.assertEqual(founds_elem, required_elem)

        # An error should be raised if more than one are found.
        self.assertRaises(UserWarning, xml_reader.get_elements,
                          "elemTwo/values/singleValue", xml_simple_root,
                          single_elem=True)
    def get_coverages(self):
        cov_elems = get_elements("ContentMetadata/CoverageOffering", self.root,
                                 namespace=self.xmlns)
        coverages = []
        for cov_elem in cov_elems:
            name = get_elements_text("name", cov_elem, single_elem=True,
                                     namespace=self.xmlns)
            label = get_elements_text("label", cov_elem, single_elem=True,
                                      namespace=self.xmlns)
            bbox = self._get_bbox(cov_elem, namespace=self.xmlns)
            coverages.append(Coverage(name=name, label=label, bbox=bbox))

        return CoverageList(coverages)
    def _get_bbox(root, namespace=None):
        """
        There are two elements within the LonLatEnvelope element, the first is
        the longitude min and max, the second is the latitude. Extact this data
        and return a a list.

        returns:
            list

        """
        lon_lat_elem = get_elements("lonLatEnvelope", root, single_elem=True,
                                    namespace=namespace)
        lon_vals = lon_lat_elem[0].text.split()
        lat_vals = lon_lat_elem[1].text.split()
        return [float(lon_vals[0]), float(lat_vals[0]),
                float(lon_vals[1]), float(lat_vals[1])]
 def get_crss(self):
     extension_elem = get_elements("metadata/Extension", self.root,
                                   single_elem=True, namespace=self.gmlcov)
     source_obs_elem = get_elements("extensionProperty/"\
                                    "MetOceanCoverageMetadata/"\
                                    "sourceObservationProperty/"\
                                    "SourceObservation", extension_elem,
                                    single_elem=True,
                                    namespace=self.metocean)
     intrst_elem = get_elements("featureOfInterest", source_obs_elem,
                                single_elem=True, namespace=self.om)
     SF_spatial_elem = get_elements("SF_SpatialSamplingFeature",
                                    intrst_elem, single_elem=True,
                                    namespace=self.sams)
     sample_feat_elem = get_elements("sampledFeature", SF_spatial_elem,
                                     single_elem=True, namespace=self.sam)
     horzon_proj_elem = get_elements("ModelDescription/geometryComponent/"\
                                     "ModelDomain/horizontalProjection",
                                     sample_feat_elem, single_elem=True,
                                     namespace=self.metocean)
     poly_elem = get_elements("Polygon", horzon_proj_elem, single_elem=True,
                              namespace=self.gml)
     return get_elements_attr("srsName", poly_elem)
 def test_simple_path(self):
     # Get first element under the root, this is elemOne.
     required_elem = xml_simple_root[0]
     found_elems  = xml_reader.get_elements("elemOne", xml_simple_root)
     # get_elements returns a list, there is only one elemTwo element.
     self.assertEqual(found_elems[0], required_elem)
 def get_ref_time(self):
     ref_time_elem = get_elements("referenceTime", self.root,
                                  single_elem=True,
                                  namespace=self.metocean)
     return get_elements_text("TimeInstant/timePosition", ref_time_elem,
                              namespace=self.gml)
 def get_coverage_ids(self):
     contents_elem = get_elements("Contents", self.root, single_elem=True,
                                  namespace=self.wcs)
     return get_elements_text("CoverageSummary/CoverageId", contents_elem,
                              namespace=self.wcs)
 def _get_reference_times(self, root):
     ref_time_elem = get_elements("referenceTimeList/ReferenceTime",
                                  root, single_elem=True,
                                  namespace=self.metocean)
     return get_elements_text("timePosition", ref_time_elem,
                              namespace=self.gml)
 def test_returned_vals(self):
     expected_vals = ["1","2","3"]
     # The values live under elemTwo.
     root_elem = get_elements("elemTwo", xml_simple_root, single_elem=True)
     vals = self.reader._get_values(root_elem, namespace=None)
     self.assertEqual(vals, expected_vals)
 def __init__(self, xml_str):
     super(CoverageReader, self).__init__(xml_str)
     # For the describeCoverage xml, only one coverage element is returned
     # under the root.
     self.root = get_elements("CoverageOffering", self.root,
                              single_elem=True, namespace=self.xmlns)
 def get_operations(self):
     op_meta_elem = get_elements("OperationsMetadata", self.root,
                                 single_elem=True, namespace=self.ows)
     op_elems = get_elements("Operation", op_meta_elem, namespace=self.ows)
     operations = [elem.attrib["name"] for elem in op_elems]
     return operations
 def test_returned_vals(self):
     expected_vals = ["1", "2", "3"]
     # The values live under elemTwo.
     root_elem = get_elements("elemTwo", xml_simple_root, single_elem=True)
     vals = self.reader._get_values(root_elem, namespace=None)
     self.assertEqual(vals, expected_vals)
 def __init__(self, xml_str):
     super(CoverageReader, self).__init__(xml_str)
     # Describe coverage XML only contains one coverage description.
     self.root = get_elements("CoverageDescription", self.root,
                              single_elem=True, namespace=self.wcs)