# import Python packages
import pandas as pd
import numpy as np
import datetime
import time
import calendar
import netCDF4
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import gridspec
from matplotlib import cm
This analysis…
Read data and metadata
= '071'
stn # CDIP Archived Dataset URL
= 'http://thredds.cdip.ucsd.edu/thredds/dodsC/cdip/archive/' + stn + 'p1/' + stn + 'p1_historic.nc'
data_url = netCDF4.Dataset(data_url) data
data
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF3_CLASSIC data model, file format DAP2):
naming_authority: edu.ucsd.cdip
keywords_vocabulary: Global Change Master Directory (GCMD) Earth Science Keywords
date_created: 2024-11-08T23:29:52Z
date_issued: 2024-11-08T23:29:52Z
date_modified: 2024-11-08T23:29:52Z
creator_name: Coastal Data Information Program, SIO/UCSD
creator_url: http://cdip.ucsd.edu
creator_email: www@cdip.ucsd.edu
creator_institution: Scripps Institution of Oceanography, UCSD
creator_country: USA
creator_sector: academic
publisher_name: Coastal Data Information Program, SIO/UCSD
publisher_url: http://cdip.ucsd.edu
publisher_email: www@cdip.ucsd.edu
publisher_country: USA
publisher_institution: Scripps Institution of Oceanography, UCSD
institution: Scripps Institution of Oceanography, University of California San Diego
project: Coastal Data Information Program (CDIP)
processing_level: QA/QC information available at http://cdip.ucsd.edu/documentation
standard_name_vocabulary: CF Standard Name Table v79
Conventions: ACDD-1.3, CF-1.8, IOOS-1.2
license: These data may be redistributed and used without restriction.
cdm_data_type: Station
featureType: timeSeries
ncei_template_version: NCEI_NetCDF_TimeSeries_Orthogonal_Template_v2.0
references: http://cdip.ucsd.edu/documentation
uuid: FE88B271-A3A2-4DB2-93EB-B9E8BBAB6DCE
title: Directional wave and sea surface temperature measurements collected in situ by Datawell Waverider buoys located near HARVEST, CA from 1991/10/22 to 2024/11/08.
summary: Directional wave and sea surface temperature measurements collected in situ by Datawell Waverider buoys located near HARVEST, CA from 1991/10/22 to 2024/11/08. This dataset includes publicly-released data only, excluding all records flagged bad by quality control procedures. A total of 466717 wave samples were analyzed for this area, where the water depth is approximately 183 to 558 meters.
keywords: EARTH SCIENCE, OCEANS, OCEAN WAVES, GRAVITY WAVES, WIND WAVES, SIGNIFICANT WAVE HEIGHT, WAVE FREQUENCY, WAVE PERIOD, WAVE SPECTRA, OCEAN TEMPERATURE, SEA SURFACE TEMPERATURE, WATER TEMPERATURE, OCEAN, PACIFIC OCEAN, EASTERN PACIFIC OCEAN
id: CDIP_071p1_19911022-20241108_historic
history: 2024-11-08T23:29:52Z: dataset created; user, program, arguments: uproc, wnc_append_to_hist v1.0, 071. If date_modified is after date_created, contact CDIP for details of changes.
comment: Multiple deployments may be included in this dataset. Please refer to the per-deployment datasets - as referenced by sourceFilename and the xxxSourceIndex variables - for more complete metadata. All values are decoded directly from the instruments in accordance with the manufacturers documentation EXCEPT for those with the attribute :additional_processing which describes further data handling performed by CDIP.
acknowledgment: CDIP is primarily supported by the U.S. Army Corps of Engineers (USACE). Station partner: CDBW ; Field operator: CDIP
metadata_link: http://cdip.ucsd.edu/metadata/071p1
infoUrl: http://cdip.ucsd.edu/metadata/071p1
contributor_name: CDIP, CDBW/USACE
contributor_role: station operation, station funding
geospatial_lat_min: 34.440964
geospatial_lat_max: 34.486687
geospatial_lat_units: degrees_north
geospatial_lat_resolution: 1e-04
geospatial_lon_min: -120.7961
geospatial_lon_max: -120.685455
geospatial_lon_units: degrees_east
geospatial_lon_resolution: 1e-04
geospatial_vertical_min: 0.0
geospatial_vertical_max: 0.0
geospatial_vertical_units: meters
geospatial_vertical_origin: sea surface
geospatial_vertical_positive: up
geospatial_vertical_resolution: 1.0
time_coverage_start: 1991-10-22T07:00:00Z
time_coverage_end: 2024-11-08T16:59:59Z
time_coverage_duration: P1724W3DT09H
time_coverage_resolution: PT30M
source: insitu observations
platform: metaPlatform
instrument: metaInstrumentation
DODS.strlen: 0
DODS.dimName: metaStationNameLength
dimensions(sizes): dwrTime(468936), gpsTime(433684), maxStrlen64(64), metaBoundsCount(2), metaDeployCount(23), sourceCount(23), sstTime(466624), waveFrequency(64), waveTime(466717)
variables(dimensions): |S1 sourceFilename(sourceCount, maxStrlen64), int32 waveTime(waveTime), int32 waveTimeBounds(waveTime, metaBoundsCount), int8 waveFlagPrimary(waveTime), int8 waveFlagSecondary(waveTime), float32 waveHs(waveTime), float32 waveTp(waveTime), float32 waveTa(waveTime), float32 waveDp(waveTime), float32 wavePeakPSD(waveTime), float32 waveTz(waveTime), int32 waveSourceIndex(waveTime), float32 waveFrequency(waveFrequency), float32 waveFrequencyBounds(waveFrequency, metaBoundsCount), int8 waveFrequencyFlagPrimary(waveFrequency), int8 waveFrequencyFlagSecondary(waveFrequency), float32 waveBandwidth(waveFrequency), int32 sstTime(sstTime), int32 sstTimeBounds(sstTime, metaBoundsCount), int8 sstFlagPrimary(sstTime), int8 sstFlagSecondary(sstTime), float32 sstSeaSurfaceTemperature(sstTime), int32 sstSourceIndex(sstTime), float32 sstReferenceTemp(sstTime), int32 gpsTime(gpsTime), int32 gpsTimeBounds(gpsTime, metaBoundsCount), int8 gpsStatusFlags(gpsTime), float32 gpsLatitude(gpsTime), float32 gpsLongitude(gpsTime), int32 gpsSourceIndex(gpsTime), int32 dwrTime(dwrTime), int32 dwrTimeBounds(dwrTime, metaBoundsCount), int32 dwrSourceIndex(dwrTime), int32 dwrBatteryLevel(dwrTime), float32 dwrZAccelerometerOffset(dwrTime), float32 dwrXAccelerometerOffset(dwrTime), float32 dwrYAccelerometerOffset(dwrTime), float32 dwrOrientation(dwrTime), float32 dwrInclination(dwrTime), int32 dwrBatteryWeeksOfLife(dwrTime), float32 metaDeployLatitude(metaDeployCount), float32 metaDeployLongitude(metaDeployCount), float32 metaWaterDepth(metaDeployCount), float32 metaDeclination(metaDeployCount), |S1 metaStationName(maxStrlen64), float32 metaStationLatitude(), float32 metaStationLongitude(), |S1 metaPlatform(maxStrlen64), |S1 metaInstrumentation(maxStrlen64), |S1 metaGridMapping(maxStrlen64), float32 waveEnergyDensity(waveTime, waveFrequency), float32 waveMeanDirection(waveTime, waveFrequency), float32 waveA1Value(waveTime, waveFrequency), float32 waveB1Value(waveTime, waveFrequency), float32 waveA2Value(waveTime, waveFrequency), float32 waveB2Value(waveTime, waveFrequency), float32 waveCheckFactor(waveTime, waveFrequency), float32 waveSpread(waveTime, waveFrequency), float32 waveM2Value(waveTime, waveFrequency), float32 waveN2Value(waveTime, waveFrequency)
groups:
data.summary
'Directional wave and sea surface temperature measurements collected in situ by Datawell Waverider buoys located near HARVEST, CA from 1991/10/22 to 2024/11/08. This dataset includes publicly-released data only, excluding all records flagged bad by quality control procedures. A total of 466717 wave samples were analyzed for this area, where the water depth is approximately 183 to 558 meters.'
# return all variables included in the dataset
print(data.variables.keys())
dict_keys(['sourceFilename', 'waveTime', 'waveTimeBounds', 'waveFlagPrimary', 'waveFlagSecondary', 'waveHs', 'waveTp', 'waveTa', 'waveDp', 'wavePeakPSD', 'waveTz', 'waveSourceIndex', 'waveFrequency', 'waveFrequencyBounds', 'waveFrequencyFlagPrimary', 'waveFrequencyFlagSecondary', 'waveBandwidth', 'sstTime', 'sstTimeBounds', 'sstFlagPrimary', 'sstFlagSecondary', 'sstSeaSurfaceTemperature', 'sstSourceIndex', 'sstReferenceTemp', 'gpsTime', 'gpsTimeBounds', 'gpsStatusFlags', 'gpsLatitude', 'gpsLongitude', 'gpsSourceIndex', 'dwrTime', 'dwrTimeBounds', 'dwrSourceIndex', 'dwrBatteryLevel', 'dwrZAccelerometerOffset', 'dwrXAccelerometerOffset', 'dwrYAccelerometerOffset', 'dwrOrientation', 'dwrInclination', 'dwrBatteryWeeksOfLife', 'metaDeployLatitude', 'metaDeployLongitude', 'metaWaterDepth', 'metaDeclination', 'metaStationName', 'metaStationLatitude', 'metaStationLongitude', 'metaPlatform', 'metaInstrumentation', 'metaGridMapping', 'waveEnergyDensity', 'waveMeanDirection', 'waveA1Value', 'waveB1Value', 'waveA2Value', 'waveB2Value', 'waveCheckFactor', 'waveSpread', 'waveM2Value', 'waveN2Value'])
# learn more about a variable including long name, units, valid min/max values
print(data['sstSeaSurfaceTemperature'])
<class 'netCDF4._netCDF4.Variable'>
float32 sstSeaSurfaceTemperature(sstTime)
long_name: sea surface temperature
units: Celsius
_FillValue: -999.99
standard_name: sea_surface_temperature
coordinates: metaStationLatitude metaStationLongitude
grid_mapping: metaGridMapping
valid_min: -5.0
valid_max: 46.15
ancillary_variables: sstFlagPrimary sstFlagSecondary
ncei_name: SEA SURFACE TEMPERATURE
cell_methods: sstTime: point
unlimited dimensions:
current shape = (466624,)
filling off
# Get SST timestamp variable
= data.variables['sstTime']
sst_time_var
# Get SST variable
= data.variables['sstSeaSurfaceTemperature'][:]
sst
# Get wave height timestamp variable
= data.variables['waveTime']
wave_time_var
# Get wave height variable
= data.variables['waveHs'][:] wave
# Use num2date on sst_time_var
= netCDF4.num2date(sst_time_var[:], sst_time_var.units, only_use_cftime_datetimes=False) sst_time
# Make an empty pandas dataframe
= pd.DataFrame()
sst_df
# Fill it with SST and the date time it was collected
'date_time'] = sst_time
sst_df['sst'] = sst
sst_df[ sst_df
date_time sst
0 1991-10-22 08:21:00 16.000000
1 1991-10-22 08:51:00 16.000000
2 1991-10-22 09:21:00 15.900000
3 1991-10-22 09:51:00 15.900000
4 1991-10-22 10:21:00 15.850000
... ... ...
466619 2024-11-08 14:58:20 13.950001
466620 2024-11-08 15:28:20 14.000000
466621 2024-11-08 15:58:20 14.000000
466622 2024-11-08 16:28:20 14.049999
466623 2024-11-08 16:58:20 14.100000
[466624 rows x 2 columns]
Citation
BibTeX citation:
@online{rivers,
author = {Rivers, Marie},
title = {Buoy {Data}},
url = {https://marierivers.github.io/code_samples/buoy_data/},
langid = {en}
}
For attribution, please cite this work as:
Rivers, Marie. n.d. “Buoy Data.” https://marierivers.github.io/code_samples/buoy_data/.