NDBC package

Primary Classes

class NDBC.NDBC.DataBuoy(station_id=False)[source]

Bases: object

This class contains functions used to fetch and parse data from National Data Buoy Center stations.

Example:

>>> from NDBC.NDBC import DataBuoy
>>> N42 = DataBuoy('46042')
>>> N42.get_data()
        'June not available.'
>>> N42.data
        {'stdmet':       WDIR  WSPD   GST  WVHT  ...    WTMP   DEWP   VIS   TIDE
    2018-04-30 23:50:00  309   9.6  11.6  2.84  ...    12.6  999.0  99.0  99.00
            ....
    2018-05-31 22:50:00  304   9.3  11.4  2.02  ...    12.8  999.0  99.0  99.00
    [742 rows x 13 columns]}
ATTR_PAT = '<b>(.*):</b>\\s*(.*)<br/>'
BASE_URL = 'https://www.ndbc.noaa.gov/'
DATA_PACKAGES = {'cwind': {'name': 'Continuos Wind Data', 'url_char': 'c'}, 'srad': {'name': 'Solar radiation data', 'url_char': 'r'}, 'stdmet': {'name': 'Standard meteorological data', 'url_char': 'h'}, 'swden': {'name': 'Spectral Wave Density data', 'url_char': 'w'}, 'swdir': {'name': 'Spectral wave (alpha1) direction data', 'url_char': 'd'}, 'swdir2': {'name': 'Spectral wave (alpha2) direction data', 'url_char': 'i'}, 'swr1': {'name': 'Spectral wave (r1) direction data', 'url_char': 'j'}, 'swr2': {'name': 'Spectral wave (r2) direction data', 'url_char': 'k'}}
LAT_PAT = '\\d+\\.\\d+\\s+N'
LON_PAT = '\\d+\\.\\d+\\s+W'
OBS_TYPES = {'all': 'A', 'buoy': 'B', 'ship': 'S'}
SEARCH_TYPES = {'box': 'box_search.php', 'radial': 'radial_search.php'}
STATION_URL = 'https://www.ndbc.noaa.gov/station_page.php?station={}'
UOMS = {'english': 'E', 'metric': 'M'}
property cwind
data_monthurls = ['https://www.ndbc.noaa.gov/data/{dtype}/{month_abbrv}/{station}.txt', 'https://www.ndbc.noaa.gov/view_text_file.php?filename={station}{month_num}{year}.txt.gz&dir=data/{dtype}/{month_abbrv}/']
data_to_json(file_name=False, date_format='iso', orient='columns', data_type='stdmet')[source]

Return specific data package data as JSON to specified file :param file_name: Desired filename. If not provided will be station_id_data_type.json :param date_format: Format for datetime values :param orient: Cofigure orientation of DataFrame to JSON :param data_type: Which data pacakge to return :return: Success/Failure message

data_yearurls = ['https://www.ndbc.noaa.gov/view_text_file.php?filename={station}{url_char}{year}.txt.gz&dir=data/historical/{dtype}/']
get_data(years=[], months=[], datetime_index=False, data_type='stdmet')[source]

Fetch data paylod for a given NDBC data station. :param years: List of years :param months: List of months :param datetime_index: Whether to use datetime as DataFrame index or column :param data_type: Data payload type :return: None, data stored as part of Class object

get_station_metadata() None[source]

Define method to capture and store station metadata :return: None

get_stdmet(years=[], months=[], datetime_index=False) None[source]

Identify valid data files to append to stdmet data and call load_std() :param years: A list of years for which to gather data :param months: A list of months for which to gather data :return: None or string, if times are unavailable

Deprecated since version 1.0.2: This will be removed in 2.0.0. Use get_data with “stdmet” data_type parameter instead

classmethod load(filename)[source]
load_stdmet(url, datetime_index=False) None[source]

Transform NDBC Standard Meteorological text data into pandas Dataframe and append to results :param url: Location of text data :return: None

save(filename=False, orient='records', date_format='iso')[source]
set_station_id(station_id) None[source]
property srad

Station search function. Defaults to radial search. Uses lat/lon coordinates if supplied, otherwise will default to the coordinates of the DataBuoy instance (if available). UOM determines which distance unit is used (defaults to metric) and time determines the time offset in which measurements must have occurred for a station to be included. Obs_type determines the type of stations to be included ( buoy: moored buoy, ship: Ships and drifters, all: All station types). Distance determines how wide an area to include (only applies to radial search).

property stdmet
stdmet_to_json(file_name, date_format='iso', orient='columns')[source]

A simple method for returning the existing stdmet data to a json file

Deprecated since version 1.1.1: This will be removed in 2.0.0. Use data_to_json instead (defaults to stdmet)

property swden
property swdir
property swdir2
property swr1
property swr2

Accessory Classes

class NDBC.models.DataPackage(data_type: str, data: DataFrame, metadata: dict)[source]

Bases: object

Define data package

This class defines a custom data class for individual NDBC data packages.

data: DataFrame
data_type: str
metadata: dict
class NDBC.models.DataStation(station_id=False)[source]

Bases: object

Define basic data station class/object

This class is focused on only the data properties necessary to identify a station

set_station_id(station_id: Union[int, str]) None[source]

Set ID for data station

Provide a mechanism to set a station ID if an object was instantiated without one

Args:

station_id (Union[int, str]): The alphanumeric station identifier