From 29a34615a62e0e60b228ce57424d72618848892c Mon Sep 17 00:00:00 2001 From: James Munroe Date: Wed, 14 Oct 2020 15:54:15 -0400 Subject: [PATCH] basic catalog functionality --- examples/intake-erddap.ipynb | 359 +++++++++++++++++++++++++++++++++++ intake_erddap/erddap_cat.py | 3 +- requirements.txt | 1 + tests/cat.yaml | 7 +- tests/test_erddap_cat.py | 4 +- 5 files changed, 367 insertions(+), 7 deletions(-) create mode 100644 examples/intake-erddap.ipynb diff --git a/examples/intake-erddap.ipynb b/examples/intake-erddap.ipynb new file mode 100644 index 0000000..26bcfbf --- /dev/null +++ b/examples/intake-erddap.ipynb @@ -0,0 +1,359 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Intake-ERDDAP" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from intake_erddap.erddap_cat import ERDDAPCatalog\n", + "import intake\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "server = 'https://cioosatlantic.ca/erddap'\n", + "cat = ERDDAPCatalog(server)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['coastal_action_7471_9460_c025',\n", + " 'SMA_bay_of_exploits',\n", + " 'SMA_bay_of_islands',\n", + " 'bb1_bop_level1',\n", + " 'SMA_bonavista',\n", + " 'SMA_port_aux_basques',\n", + " 'SMA_port_aux_basqes_wharf',\n", + " 'coast-of-bays-hydrographic-2009-2013',\n", + " 'SMA_corner_brook_wharf',\n", + " 'SMA_saint_john_cruise_terminal',\n", + " 'SMA_Fortune_Bay_Buoy',\n", + " 'SMA_halifax',\n", + " 'SMA_halifax_fairview',\n", + " 'SMA_halifax_anemometer1',\n", + " 'SMA_halifax_pier9c',\n", + " 'SMA_head_of_placentia_bay-come_by_chance_point',\n", + " 'SMA_Holyrood_Buoy2',\n", + " 'SMA_holyrood_wharf',\n", + " 'SMA_bay_of_exploits_wharf',\n", + " 'SMA_manolis_buoy',\n", + " 'SMA_MouthofPlacentiaBayBuoy',\n", + " 'sma_negl_black_tickle_nlqu0003',\n", + " 'sma_negl_cartwright_junction_nlqu0004',\n", + " 'sma_negl_north_west_river_nlqu0007',\n", + " 'sma_negl_postville_nlqu0001',\n", + " 'sma_negl_red_bay_nlqu0005',\n", + " 'sma_negl_rigolet_nlqu0002',\n", + " 'SMA_red_island_shoal',\n", + " 'DFO_Sutron_NHARB',\n", + " 'DFO_Sutron_KLUMI',\n", + " 'SMA_saint_john_wharf',\n", + " 'SMA_saint_john',\n", + " 'SMA_st_johns',\n", + " 'SMA_st_johns_wharf',\n", + " 'SmartAtlantic_XEOS_hk4_buoy']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(cat)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'name': 'SMA_bay_of_exploits',\n", + " 'container': 'dataframe',\n", + " 'plugin': ['erddap'],\n", + " 'description': 'ERDDAP dataset_id SMA_bay_of_exploits from https://cioosatlantic.ca/erddap',\n", + " 'direct_access': True,\n", + " 'user_parameters': [],\n", + " 'metadata': {},\n", + " 'args': {'server': 'https://cioosatlantic.ca/erddap',\n", + " 'dataset_id': 'SMA_bay_of_exploits',\n", + " 'protocol': 'tabledap'}}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat.SMA_bay_of_exploits.describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "df = cat.SMA_manolis_buoy.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
station_nametime (UTC)longitude (degrees_east)latitude (degrees_north)wind_spd_avgwind_spd_maxwind_dir_avgair_temp_avgair_pressure_avgair_humidity_avgair_dewpoint_avgsurface_temp_avgwave_ht_maxwave_ht_sigwave_period_maxwave_dir_avgwave_spread_avgcurr_dir_avgcurr_spd_avg
0smb_manolis2018-07-10T00:23:41Z-54.50783749.6753025.97.2222.018.91008.1NaNNaN10.90.80.58.726.046.0274.1104.9
1smb_manolis2018-07-10T00:53:41Z-54.50782849.6752854.86.1218.018.41008.5NaNNaN10.90.80.58.726.046.0271.585.4
2smb_manolis2018-07-10T01:23:41Z-54.50779749.6752937.89.9235.019.81008.3NaNNaN10.90.80.58.726.046.0301.860.2
3smb_manolis2018-07-10T01:53:41Z-54.50780549.6752857.89.7237.019.11008.3NaNNaN10.90.80.58.726.046.0326.364.3
4smb_manolis2018-07-10T02:23:41Z-54.50778849.6753106.97.6233.017.31008.3NaNNaN10.80.80.58.726.046.0337.157.5
\n", + "
" + ], + "text/plain": [ + " station_name time (UTC) longitude (degrees_east) \\\n", + "0 smb_manolis 2018-07-10T00:23:41Z -54.507837 \n", + "1 smb_manolis 2018-07-10T00:53:41Z -54.507828 \n", + "2 smb_manolis 2018-07-10T01:23:41Z -54.507797 \n", + "3 smb_manolis 2018-07-10T01:53:41Z -54.507805 \n", + "4 smb_manolis 2018-07-10T02:23:41Z -54.507788 \n", + "\n", + " latitude (degrees_north) wind_spd_avg wind_spd_max wind_dir_avg \\\n", + "0 49.675302 5.9 7.2 222.0 \n", + "1 49.675285 4.8 6.1 218.0 \n", + "2 49.675293 7.8 9.9 235.0 \n", + "3 49.675285 7.8 9.7 237.0 \n", + "4 49.675310 6.9 7.6 233.0 \n", + "\n", + " air_temp_avg air_pressure_avg air_humidity_avg air_dewpoint_avg \\\n", + "0 18.9 1008.1 NaN NaN \n", + "1 18.4 1008.5 NaN NaN \n", + "2 19.8 1008.3 NaN NaN \n", + "3 19.1 1008.3 NaN NaN \n", + "4 17.3 1008.3 NaN NaN \n", + "\n", + " surface_temp_avg wave_ht_max wave_ht_sig wave_period_max wave_dir_avg \\\n", + "0 10.9 0.8 0.5 8.7 26.0 \n", + "1 10.9 0.8 0.5 8.7 26.0 \n", + "2 10.9 0.8 0.5 8.7 26.0 \n", + "3 10.9 0.8 0.5 8.7 26.0 \n", + "4 10.8 0.8 0.5 8.7 26.0 \n", + "\n", + " wave_spread_avg curr_dir_avg curr_spd_avg \n", + "0 46.0 274.1 104.9 \n", + "1 46.0 271.5 85.4 \n", + "2 46.0 301.8 60.2 \n", + "3 46.0 326.3 64.3 \n", + "4 46.0 337.1 57.5 " + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:intake-erddap]", + "language": "python", + "name": "conda-env-intake-erddap-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/intake_erddap/erddap_cat.py b/intake_erddap/erddap_cat.py index b0997e2..c721333 100644 --- a/intake_erddap/erddap_cat.py +++ b/intake_erddap/erddap_cat.py @@ -38,7 +38,8 @@ def _load(self): continue description = 'ERDDAP dataset_id %s from %s' % (dataset_id, self.server) - args = {'server': self.server, + args = {'server': self.server, + 'dataset_id': dataset_id, 'protocol': 'tabledap', } diff --git a/requirements.txt b/requirements.txt index 17da2bd..a8a4c19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ intake pandas erddapy +panel diff --git a/tests/cat.yaml b/tests/cat.yaml index 1385d9b..4149614 100644 --- a/tests/cat.yaml +++ b/tests/cat.yaml @@ -1,13 +1,12 @@ sources: tables: args: - uri: "{{URI}}" + server: "{{URI}}" parameters: # User defined parameters URI: description: sqlite type: str - default: "env(TEST_SQLITE_URI)" - description: "points to sqlite database" - driver: sql_cat + description: "points to ERDDAP server" + driver: erddap_cat direct_access: forbid metadata: {} diff --git a/tests/test_erddap_cat.py b/tests/test_erddap_cat.py index 77c916b..a0f991f 100644 --- a/tests/test_erddap_cat.py +++ b/tests/test_erddap_cat.py @@ -31,8 +31,8 @@ def test_yaml_cat(): assert False table, table_nopk, uri = temp_db - os.environ['TEST_SQLITE_URI'] = uri # used in catalog default - cat = intake.Catalog(os.path.join(here, 'cat.yaml')) + cat = intake.Catalog(os.path.join(here, 'cat.yaml') + assert 'tables' in cat cat2 = cat.tables() assert isinstance(cat2, SQLCatalog)