Preparation


In this example, we use python to access our data/products.

Import libraries

In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import geojson
from arcgis.gis import GIS
import pendulum
from owslib.wfs import WebFeatureService
from shapely.geometry import Polygon, mapping, asShape, shape
import cartopy.crs as ccrs
from cartopy.io.img_tiles import MapQuestOpenAerial, MapQuestOSM, OSM
%matplotlib inline

To access Texas Station data through SOS (Sensor Observation Service)

Useful information: https://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/index.jsp

In [2]:
#import pendulum
today = pendulum.today(tz='UTC')
yesterday = today.subtract(days=1)

sensor = 'sea_water_temperature'
station_id = '8775237' # Port Aransas, TX

# reference: https://opendap.co-ops.nos.noaa.gov/ioos-dif-sos-test/
url = (
    'https://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?'
    'service=SOS'
    '&request=GetObservation'
    '&version=1.0.0'
    f'&observedProperty={sensor}'
    f'&offering=urn:ioos:station:NOAA.NOS.CO-OPS:{station_id}'
    '&responseFormat=text/csv'
    f'&eventTime={yesterday:%Y-%m-%dT%H:%M:%SZ}/'
    f'{today:%Y-%m-%dT%H:%M:%SZ}'
    '&unit=Celsius'
)                                    
print(url)
https://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS?service=SOS&request=GetObservation&version=1.0.0&observedProperty=sea_water_temperature&offering=urn:ioos:station:NOAA.NOS.CO-OPS:8775237&responseFormat=text/csv&eventTime=2018-07-31T00:00:00Z/2018-08-01T00:00:00Z&unit=Celsius

Show data of a station in table

In [3]:
#import pandas as pd
df = pd.read_csv(url, index_col='date_time', parse_dates=True)
df.head()
Out[3]:
station_id sensor_id latitude (degree) longitude (degree) sea_water_temperature (C) quality_flags
date_time
2018-07-31 00:00:00 urn:ioos:station:NOAA.NOS.CO-OPS:8775237 urn:ioos:sensor:NOAA.NOS.CO-OPS:8775237:E1 27.8397 -97.0725 28.7 0;0;0
2018-07-31 00:06:00 urn:ioos:station:NOAA.NOS.CO-OPS:8775237 urn:ioos:sensor:NOAA.NOS.CO-OPS:8775237:E1 27.8397 -97.0725 28.7 0;0;0
2018-07-31 00:12:00 urn:ioos:station:NOAA.NOS.CO-OPS:8775237 urn:ioos:sensor:NOAA.NOS.CO-OPS:8775237:E1 27.8397 -97.0725 28.7 0;0;0
2018-07-31 00:18:00 urn:ioos:station:NOAA.NOS.CO-OPS:8775237 urn:ioos:sensor:NOAA.NOS.CO-OPS:8775237:E1 27.8397 -97.0725 28.7 0;0;0
2018-07-31 00:24:00 urn:ioos:station:NOAA.NOS.CO-OPS:8775237 urn:ioos:sensor:NOAA.NOS.CO-OPS:8775237:E1 27.8397 -97.0725 28.7 0;0;0

Show water temperature at the station

In [4]:
#%matplotlib inline

col = df.columns[df.columns.str.startswith(sensor)]
ax = df[col].plot.line(legend=False)
ax.grid(True)
ax.set_title(col.values[0]);
In [5]:
import pyoos
from datetime import datetime, timedelta
from pyoos.collectors.ioos.swe_sos import IoosSweSos

url_gcoos = 'http://data.gcoos.org:8080/52nSOS/sos/kvp'
collector_gcoos = IoosSweSos(url_gcoos)
offerings_gcoos = collector_gcoos.server.offerings
len(offerings_gcoos)
Out[5]:
219
In [6]:
of0 = offerings_gcoos[0]
of0.id, of0.name, of0.begin_position, of0.end_position, of0.observed_properties, of0.procedures
Out[6]:
('urn_ioos_network_gcoos_all',
 'urn:ioos:network:gcoos:all',
 datetime.datetime(2018, 5, 5, 22, 30, tzinfo=tzutc()),
 datetime.datetime(2018, 8, 1, 15, 2, tzinfo=tzutc()),
 ['NONE',
  'http://mmisw.org/ont/cf/parameter/air_pressure',
  'http://mmisw.org/ont/cf/parameter/air_temperature',
  'http://mmisw.org/ont/cf/parameter/dew_point_temperature',
  'http://mmisw.org/ont/cf/parameter/direction_of_sea_water_velocity',
  'http://mmisw.org/ont/cf/parameter/mass_concentration_of_chlorophyll_in_sea_water',
  'http://mmisw.org/ont/cf/parameter/mass_concentration_of_oxygen_in_sea_water',
  'http://mmisw.org/ont/cf/parameter/relative_humidity',
  'http://mmisw.org/ont/cf/parameter/sea_surface_height_above_sea_level',
  'http://mmisw.org/ont/cf/parameter/sea_water_practical_salinity',
  'http://mmisw.org/ont/cf/parameter/sea_water_speed',
  'http://mmisw.org/ont/cf/parameter/sea_water_temperature',
  'http://mmisw.org/ont/cf/parameter/sea_water_turbidity',
  'http://mmisw.org/ont/cf/parameter/upward_sea_water_velocity',
  'http://mmisw.org/ont/cf/parameter/wind_speed',
  'http://mmisw.org/ont/cf/parameter/wind_speed_of_gust',
  'http://mmisw.org/ont/cf/parameter/wind_to_direction'],
 ['urn:ioos:network:gcoos:all'])

To access ERDDAP

In [7]:
from erddapy import ERDDAP

e = ERDDAP(server_url='https://data.ioos.us/gliders/erddap')
In [8]:
min_lat, max_lat = 20, 30
min_lon, max_lon = -82, -97
        
kw = {
    'standard_name': 'sea_water_temperature',
    'min_lon': min_lon,
    'max_lon': max_lon,
    'min_lat': min_lat,
    'max_lat': max_lat
}
In [9]:
import pandas as pd
search_url = e.get_search_url(response='csv', **kw)
search = pd.read_csv(search_url)
gliders = search['Dataset ID'].values
print('Found {} Glider Datasets:\n{}'.format(len(gliders), '\n'.join(gliders)))
Found 41 Glider Datasets:
alldrudnickGliders
allgcoos_dmacGliders
allmkhowardGliders
allrutgersGliders
bass-20150706T151619Z
bass-20150827T1909
Howdy-20160629T2207
Howdy-20160902T1836
mote-genie-20161015T1513
mote-genie-20161212T1714
mote-genie-20170224T1732
mote-genie-20170404T1922
mote-genie-20170624T0128
mote-genie-20170901T1757
mote-genie-20171027T2222
Murphy-20150809T1355
murphy-20160810T2233
Murphy-20170426T1610
Reveille-20161207T2001
Reveille-20170925T0946
Reveille-20180627T1500
Revellie-20160629T1744
roxy-20160914T2055
roxy-20161008T1900
ru31-20151028T1652
ru31-20160113T1728
ru31-20160322T1503
Sam-20160729T1659
Sam-20170103T1836
Sam-20170214T1609
Sam-20170516T1416
Stommel-20150805T0000Z
Stommel-20160805T1512
Stommel-20170120T2144
Stommel-20170627T1936
Stommel-20170727T1845
Sverdrup-20150822T1639
Sverdrup-20170902T1930
Sverdrup-20180509T1742
unit_308-20150701T222927Z
unit_540-20150701T181602Z
In [10]:
server = 'https://data.ioos.us/gliders/erddap'
dataset_id = 'Reveille-20180627T1500'
variables = [
 'depth',
 'latitude',
 'longitude',
 'salinity',
 'temperature',
 'time',
]

e = ERDDAP(server_url=server)

erddapcsv = e.get_download_url(
    dataset_id = dataset_id,
    variables = variables,
    response='csv'
)
df = pd.read_csv(
    erddapcsv,
    index_col='time',
    parse_dates=True,
    skiprows=(1,)
).dropna()

df.head()
Out[10]:
depth latitude longitude salinity temperature
time
2018-06-27 20:17:15 5.751695 27.867078 -93.539373 35.589043 28.8400
2018-06-27 20:17:15 8.900655 27.867078 -93.539373 35.603073 28.7908
2018-06-27 20:17:15 10.738354 27.867078 -93.539373 35.602642 28.7786
2018-06-27 20:17:15 12.486635 27.867078 -93.539373 35.606660 28.7730
2018-06-27 20:17:15 14.423635 27.867078 -93.539373 35.613537 28.7698
In [11]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

fig, ax = plt.subplots(figsize=(17, 2))
cs = ax.scatter(df.index, df['depth'], s=15, c=df['temperature'],
                marker='o', edgecolor='none')

ax.invert_yaxis()
ax.set_xlim(df.index[0], df.index[-1])
xfmt = mdates.DateFormatter('%H:%Mh\n%d-%b')
ax.xaxis.set_major_formatter(xfmt)

cbar = fig.colorbar(cs, orientation='vertical', extend='both')
cbar.ax.set_ylabel('Temperature ($^\circ$C)')
ax.set_ylabel('Depth (m)');
In [12]:
import cartopy.crs as ccrs

fig, ax = plt.subplots(
    subplot_kw={'projection': ccrs.PlateCarree()},
    figsize=(7, 7)
)
ax.plot(df['longitude'], df['latitude'], 'o')
ax.gridlines(draw_labels=True)
ax.coastlines('10m')
ax.set_extent([df['longitude'].min()-2, df['longitude'].max()+2,
               df['latitude'].min()-0.25, df['latitude'].max()+3]);
In [13]:
gis = GIS()
items = gis.content.search("Landsat 8 Views", item_type="Imagery Layer", max_items=2)
for item in items:
    display(item)
Pansharpened Landsat
Landsat 8 OLI, 15m multitemporal PanSharpened Natural Color images. This imagery layer is sourced from the Landsat on AWS collections and is updated daily with new imagery. Imagery Layer by esri
Last Modified: May 03, 2018
0 comments, 16,749 views
Panchromatic Landsat
Landsat 8 OLI, 15m multitemporal Panchromatic images. This imagery layer is sourced from the Landsat on AWS collections and is updated daily with new imagery. Imagery Layer by esri
Last Modified: May 03, 2018
0 comments, 17,655 views
In [14]:
l8_views = gis.content.get('4ca13f0e4e29403fa68c46d188c4be73')
l8_views
Out[14]:
Landsat 8 Views
Landsat 8 OLI, 30m multispectral and multitemporal 8-band imagery, with on-the-fly renderings and indices. This imagery layer is sourced from the Landsat on AWS collections and is updated daily with new imagery. Imagery Layer by esri
Last Modified: May 03, 2018
0 comments, 147,936 views
In [15]:
# Gulf of Mexico Bathymetry Image
img_server_url="http://gcoos3.tamu.edu/arcgis/rest/services/Bathymetry/CoastalReliefModel_3arc_GoM_WM/ImageServer"

from arcgis.raster import ImageryLayer

bathy_lyr = ImageryLayer(img_server_url)
bathy_lyr
Out[15]:
In [16]:
map = gis.map("Gulf of Mexico", zoomlevel=6)
map.add_layer(bathy_lyr)
map
In [17]:
map2 = gis.map("Gulf of Mexico", zoomlevel=6)
img_svc_url = 'https://landsat2.arcgis.com/arcgis/rest/services/Landsat8_Views/ImageServer'
landsat_lyr = ImageryLayer(img_svc_url)
map2.add_layer(landsat_lyr)
map2
In [18]:
# Create an anonymous connection to ArcGIS Online
arcgis_online = GIS()
hurricane_pts = arcgis_online.content.search("Hurricane_tracks_points AND owner:atma.mani", "Feature Layer")[0]
hurricane_pts
Out[18]:
Hurricane_tracks_points
Years 1932 - 1942 Feature Layer Collection by atma.mani
Last Modified: September 15, 2016
0 comments, 884 views
In [19]:
subset_map = arcgis_online.map("USA")
subset_map.add_layer(hurricane_pts)
subset_map
In [20]:
hurricane_pts.layers[0].query().df.head()
Out[20]:
ATC_eye ATC_grade ATC_poci ATC_pres ATC_rmw ATC_roci ATC_w34_r1 ATC_w34_r2 ATC_w34_r3 ATC_w34_r4 ... day hour min_ month wmo_pres wmo_pres__ wmo_wind wmo_wind__ year SHAPE
0 -999 -999. -999 -999 -999 -999 -999 -999 -999 -999 ... 1 0 0 1 -999 -999.0 -999 -999.0 1932 {'x': 58.749999999600334, 'y': -18.07999992365...
1 -999 -999. -999 -999 -999 -999 -999 -999 -999 -999 ... 1 6 0 1 0 -100.0 0 -100.0 1932 {'x': 58.40000152555001, 'y': -18.499999999800...
2 -999 -999. -999 -999 -999 -999 -999 -999 -999 -999 ... 1 12 0 1 -999 -999.0 -999 -999.0 1932 {'x': 58.06999969483013, 'y': -18.899999618587...
3 -999 -999. -999 -999 -999 -999 -999 -999 -999 -999 ... 1 18 0 1 -999 -999.0 -999 -999.0 1932 {'x': 57.729999542445, 'y': -19.3099994656028,...
4 -999 -999. -999 -999 -999 -999 -999 -999 -999 -999 ... 2 0 0 1 -999 -999.0 -999 -999.0 1932 {'x': 57.3499984744501, 'y': -19.7600002291272...

5 rows × 148 columns