Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various catalog fixes #165

Merged
merged 6 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ def __init__(self, catalog_url):
The URL of a THREDDS client catalog

"""
# top level server url
self.catalog_url = catalog_url
self.base_tds_url = _find_base_tds_url(catalog_url)

session = create_http_session()

# get catalog.xml file
resp = session.get(self.catalog_url)
resp = session.get(catalog_url)
resp.raise_for_status()

# top level server url
self.catalog_url = resp.url
self.base_tds_url = _find_base_tds_url(self.catalog_url)

# If we were given an HTML link, warn about it and try to fix to xml
if 'html' in resp.headers['content-type']:
import warnings
Expand All @@ -186,7 +186,7 @@ def __init__(self, catalog_url):
resp.raise_for_status()

# begin parsing the xml doc
root = ET.fromstring(resp.text)
root = ET.fromstring(resp.content)
self.catalog_name = root.attrib.get('name', 'No name found')

self.datasets = DatasetCollection()
Expand Down Expand Up @@ -305,8 +305,8 @@ def __init__(self, base_url, element_node):
An :class:`~xml.etree.ElementTree.Element` representing a catalogRef node

"""
self.name = element_node.attrib['name']
self.title = element_node.attrib['{http://www.w3.org/1999/xlink}title']
self.name = element_node.attrib.get('name', self.title)

# Resolve relative URLs
href = element_node.attrib['{http://www.w3.org/1999/xlink}href']
Expand Down Expand Up @@ -440,21 +440,19 @@ def make_access_urls(self, catalog_url, all_services, metadata=None):
# for each SimpleService
if isinstance(service, CompoundService):
for subservice in service.services:
access_urls[subservice.service_type] = (server_url +
subservice.base +
self.url_path)
server_base = urljoin(server_url, subservice.base)
access_urls[subservice.service_type] = urljoin(server_base,
self.url_path)
else:
access_urls[service.service_type] = (server_url +
service.base +
self.url_path)
server_base = urljoin(server_url, service.base)
access_urls[service.service_type] = urljoin(server_base, self.url_path)

# process access children of dataset elements
for service_type in self.access_element_info:
url_path = self.access_element_info[service_type]
if service_type in all_service_dict:
access_urls[service_type] = (server_url +
all_service_dict[service_type].base +
url_path)
server_base = urljoin(server_url, all_service_dict[service_type].base)
access_urls[service_type] = urljoin(server_base, url_path)

self.access_urls = access_urls

Expand Down
7 changes: 3 additions & 4 deletions siphon/cdmr/tests/test_coveragedataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
# SPDX-License-Identifier: MIT
"""Test Coverage Dataset."""

import warnings
import pytest

from siphon.cdmr.coveragedataset import CoverageDataset
from siphon.testing import get_recorder

recorder = get_recorder(__file__)

# Ignore warnings about CoverageDataset
warnings.simplefilter('ignore')


@pytest.mark.filterwarnings('ignore: CoverageDataset')
@recorder.use_cassette('hrrr_cdmremotefeature')
def test_simple_cdmremotefeature():
"""Smoke test for CDMRemoteFeature."""
Expand All @@ -22,6 +20,7 @@ def test_simple_cdmremotefeature():
assert cd.grids


@pytest.mark.filterwarnings('ignore: CoverageDataset')
@recorder.use_cassette('hrrr_cdmremotefeature')
def test_simple_cdmremotefeature_str():
"""Smoke test for converting CoverageDataset to str."""
Expand Down
2 changes: 1 addition & 1 deletion siphon/radarserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_metadata(self):

def _get_stations(self, station_file='stations.xml'):
resp = self.get_path(station_file)
self.stations = parse_station_table(ET.fromstring(resp.text))
self.stations = parse_station_table(ET.fromstring(resp.content))

def query(self):
"""Return a new query for the radar server.
Expand Down
3 changes: 3 additions & 0 deletions siphon/simplewebservice/wyoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"""Read upper air data from the Wyoming archives."""

from io import StringIO
import warnings

from bs4 import BeautifulSoup
import numpy as np
import pandas as pd
from .._tools import get_wind_components
from ..http_util import HTTPEndPoint

warnings.filterwarnings('ignore', 'Pandas doesn\'t allow columns to be created', UserWarning)


class WyomingUpperAir(HTTPEndPoint):
"""Download and parse data from the University of Wyoming's upper air archive."""
Expand Down
40 changes: 40 additions & 0 deletions siphon/tests/fixtures/rsmas_ramadda
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [Siphon (0.6.0+16.gce11082.dirty)]
method: GET
uri: http://weather.rsmas.miami.edu/repository?output=thredds.catalog
response:
body: {string: "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><catalog name=\"RSMAS-UM
Repository for atm-ocean data and its science\" xmlns=\"http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0\"
xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <dataset name=\"RSMAS-UM
Repository for atm-ocean data and its science\">\n <catalogRef xlink:href=\"/repository/entry/show?entryid=5c0355aa-bcc1-4b90-808f-48ecc03b7989&amp;output=thredds.catalog\"
xlink:title=\"AMIE-DYNAMO data archive\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=e1ae1cc5-4a1e-4bcf-bc24-8497c9c2bffd&amp;output=thredds.catalog\"
xlink:title=\"Annual Cycle Explorer software and description: tinyurl.com/MapesACE\"/>\n
\ <catalogRef xlink:href=\"/repository/entry/show?entryid=d7ce4aa0-7266-47d7-89d7-e84a505d89e2&amp;output=thredds.catalog\"
xlink:title=\"CAROB Miami observatory data archive\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=07f6a773-fee4-4dd6-9a09-619db75e157f&amp;output=thredds.catalog\"
xlink:title=\"Chen lab\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=424f384c-91ad-42b3-b6c5-a5b0cc90b53d&amp;output=thredds.catalog\"
xlink:title=\"Datasets hosted on this UM server\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=0f166334-728e-4344-87ee-7a847399eca6&amp;output=thredds.catalog\"
xlink:title=\"GCM nudging project\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=e0ab8229-9dad-431a-b478-71e5607e37e9&amp;output=thredds.catalog\"
xlink:title=\"South Asian Monsoon loops\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=45e3b50b-dbe2-408b-a6c2-2c009749cd53&amp;output=thredds.catalog\"
xlink:title=\"The Mapes IDV collection\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=b221d8d3-46d5-44f1-8d8e-d1d5ebc24d2d&amp;output=thredds.catalog\"
xlink:title=\"UM course related stuff\"/>\n <catalogRef xlink:href=\"/repository/entry/show?entryid=08512ac5-7509-411c-971b-88efdc283bda&amp;output=thredds.catalog\"
xlink:title=\"Users\"/>\n <catalogRef xlink:href=\"http://esrl.noaa.gov/gsd/thredds/hrrr.xml\"
xlink:title=\"HRRR model from NOAA-GSD\"/>\n <catalogRef xlink:href=\"http://weather.rsmas.miami.edu/thredds/catalog.xml\"
xlink:title=\"THREDDS data catalog on weather.rsmas.miami.edu\"/>\n </dataset>\n</catalog>\n"}
headers:
Connection: [Keep-Alive]
Content-Length: ['2258']
Content-Type: [text/xml;charset=UTF-8]
Date: ['Tue, 31 Oct 2017 21:17:47 GMT']
Keep-Alive: ['timeout=5, max=100']
Server: [Apache]
Set-Cookie: ['ramadda_repository_session=b95d312c-74c4-464e-81d2-1ba4be8597f0_0.468476777107967;
path=/repository; expires=Tue, 26-Oct-2021 23:59:59 GMT']
X-Frame-Options: [SAMEORIGIN]
status: {code: 200, message: '200'}
version: 1
Loading