Web sources internal API
These modules are abstracted by kadlu.load
, which
should generally be used instead for fetching and loading from web sources.
These docs are provided for contributors wishing to add new web data source
modules that can be accessed by kadlu.load
.
kadlu.load
works
by mapping strings to function calls in kadlu.geospatial.data_sources.source_map
as a convenience by passing the source and variable name; new data source
modules should have a corresponding entry within the fetch and load maps there.
A general pattern for adding fetch/load modules is that fetching is an implicit action of the load function. each fetch and load function should accept a set of boundary arguments equal to or subsetting the following function signature, such that keyword args can be passed as a dict by fetch_handler:
(south=-90, west=-180, north=90, east=180, top=0, bottom=5000, start=datetime(2000,1,1), end=datetime(2000,1,1,1))
Source Map
used for generating fetch requests for web data sources
data fetching utils, function maps, and constant variables collection of objects
ERA5
API for Era5 dataset from Copernicus Climate Datastore
- Metadata regarding the dataset can be found here:
https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=overview
- class kadlu.geospatial.data_sources.era5.Era5[source]
Bases:
object
collection of module functions for fetching and loading
- kadlu.geospatial.data_sources.era5.fetch_era5(var, *, west, east, south, north, start, end, **_)[source]
fetch global era5 data for specified variable and time range
- args:
- var: string
the variable short name of desired wave parameter according to ERA5 docs. the complete list can be found here (table 7 for wave params): https://confluence.ecmwf.int/display/CKB/ERA5+data+documentation#ERA5datadocumentation-Temporalfrequency
- kwargs: dict
keyword arguments passed from the Era5() class as a dictionary
- return:
True if new data was fetched, else False
- kadlu.geospatial.data_sources.era5.load_era5(var, *, west, east, south, north, start, end, **_)[source]
load era5 data from local database
- args:
- var:
variable to be fetched (string)
- kwargs:
dictionary containing the keyword arguments used for the fetch request. must contain south, north, west, east keys as float values, and start, end keys as datetimes
- return:
- values:
values of the fetched var
- lat:
y grid coordinates
- lon:
x grid coordinates
- epoch:
timestamps in epoch hours since jan 1 2000
GEBCO
HYCOM
- data source:
- web interface for manual hycom data retrieval:
https://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015.html
- class kadlu.geospatial.data_sources.hycom.Hycom[source]
Bases:
object
collection of module functions for fetching and loading
- attributes:
- lat, lon: arrays
spatial grid arrays. used to convert grid index to coordinate point
- epoch: dict
dictionary containing yearly time indexes. times formatted as epoch hours since 2000-01-01 00:00
- depth: array
depth scale. used to convert depth index to metres
- callback(var, **kwargs)[source]
build indices for query, fetch from hycom, insert into database
- args:
- var: string
variable to be fetched. complete list of variables here https://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015.html
- kwargs: dict
boundaries as keyword arguments
- load_hycom(var, kwargs)[source]
load hycom data from local database
- args:
- var:
variable to be fetched. complete list of variables here https://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015.html
- south, north: float
ymin, ymax coordinate values. range: -90, 90
- kwargs: dict (boundaries as keyword arguments)
- west, east: float
xmin, xmax coordinate values. range: -180, 180
- start, end: datetime
temporal boundaries in datetime format
- return:
- values: array
values of the fetched variable
- lat: array
y grid coordinates
- lon: array
x grid coordinates
- epoch: array
timestamps in epoch hours since jan 1 2000
- depth: array
measured in meters
- kadlu.geospatial.data_sources.hycom.fetch_grid(**_)[source]
download lat/lon/time/depth arrays for grid indexing. times are formatted as epoch hours since 2000-01-01 00:00
- kadlu.geospatial.data_sources.hycom.slices_str(var, slices, steps=(1, 1, 1, 1))
IFREMER
WWIII
Kadlu API for the NOAA WaveWatch III Datastore
- User guides:
https://github.com/NOAA-EMC/WW3/wiki/WAVEWATCH-III-User-Guide
- Data model description (boundary definitions, map visualizations, etc)
- class kadlu.geospatial.data_sources.wwiii.Wwiii[source]
Bases:
object
collection of module functions for fetching and loading
- kadlu.geospatial.data_sources.wwiii.fetch_wwiii(var, **kwargs)[source]
download wwiii data and return associated filepaths
- args:
- var: string
the variable name of desired parameter according to WWIII docs the complete list of variables can be found at the following URL under ‘model output’ https://polar.ncep.noaa.gov/waves/implementations.php
- south, north: float
ymin, ymax coordinate boundaries (latitude). range: -90, 90
- west, east: float
xmin, xmax coordinate boundaries (longitude). range: -180, 180
- start: datetime
the start of the desired time range
- end: datetime
the end of the desired time range
- return:
True if new data was fetched, else False
- kadlu.geospatial.data_sources.wwiii.insert(table, agg)[source]
insert parsed data into local database
- kadlu.geospatial.data_sources.wwiii.load_wwiii(var, kwargs)[source]
return downloaded wwiii data for specified wavevar according to given time, lat, lon boundaries
- args:
- var: string
the variable short name of desired wave parameter according to WWIII docs the complete list of variable short names can be found here (under ‘model output’) https://polar.ncep.noaa.gov/waves/implementations.php
- south, north: float
ymin, ymax coordinate boundaries (latitude). range: -90, 90
- west, east: float
xmin, xmax coordinate boundaries (longitude). range: -180, 180
- start: datetime
the start of the desired time range
- end: datetime
the end of the desired time range
- return:
val, lat, lon, epoch as np arrays of floats
Data Utils
additional tools and utils used across data loading modules
- class kadlu.geospatial.data_sources.data_util.Boundary(south, north, west, east, fetchvar='', **_)[source]
Bases:
object
compute intersecting boundaries with separating axis theorem
- kadlu.geospatial.data_sources.data_util.database_cfg()[source]
configure and connect to sqlite database
time is stored as an integer in the database, where each value is epoch hours since 2000-01-01 00:00
- returns:
- conn:
database connection object
- db:
connection cursor object
- kadlu.geospatial.data_sources.data_util.dt_2_epoch(dt_arr, t0=datetime.datetime(2000, 1, 1, 0, 0))[source]
convert datetimes to epoch hours
- kadlu.geospatial.data_sources.data_util.epoch_2_dt(ep_arr, t0=datetime.datetime(2000, 1, 1, 0, 0), unit='hours')[source]
convert epoch hours to datetimes
- kadlu.geospatial.data_sources.data_util.ext(filepath, extensions)
- kadlu.geospatial.data_sources.data_util.flatten(cols, frames)[source]
dimensional reduction by taking average of time frames
- kadlu.geospatial.data_sources.data_util.index_arr(val, sorted_arr)[source]
converts value in coordinate array to grid index
- kadlu.geospatial.data_sources.data_util.ll_2_regionstr(south, north, west, east, regions, default=[])[source]
convert input bounds to region strings with seperating axis theorem
- kadlu.geospatial.data_sources.data_util.reshape_3D(cols)[source]
prepare loaded data for interpolation
- args:
- cols: flattened numpy array of shape (4, n)
cols[0]: values cols[1]: latitude cols[2]: longitude cols[3]: depth
- return: gridded
dict(values=gridspace, lats=ygrid, lons=xgrid, depths=zgrid)
- class kadlu.geospatial.data_sources.data_util.storage_cfg(setdir=None)[source]
Bases:
PathLike
return filepath containing storage configuration string
first checks the config.ini file in kadlu root folder, then defaults to kadlu/storage
- cfg = <configparser.ConfigParser object>