EcohydroLib  1.29
Functions | Variables
ecohydrolib.climatedata.ghcndquery Namespace Reference

Query NCDC Global Historical Climatology Network dataset for daily climate data. More...

Functions

def findStationsWithinBoundingBox (config, bbox)
 Find stations that lie within a bounding box. More...
 
def findStationNearestToCoordinates (config, longitude, latitude)
 Determine identifier of station nearest to longitude, latitude coordinates. More...
 
def getClimateDataForStation
 Fetch climate timeseries data for a GHCN daily station. More...
 

Variables

string HOST = 'www1.ncdc.noaa.gov'
 
string URL_PROTO = '/pub/data/ghcn/daily/all/{station_id}.dly'
 
tuple _SRS = int(4326)
 
int _BUFF_LEN = 4096
 

Detailed Description

Query NCDC Global Historical Climatology Network dataset for daily climate data.

Note
Requires pyspatialite 3.0.1

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Function Documentation

def ecohydrolib.climatedata.ghcndquery.findStationNearestToCoordinates (   config,
  longitude,
  latitude 
)

Determine identifier of station nearest to longitude, latitude coordinates.

Parameters
configConfigParser containing the section 'GHCND' and option 'PATH_OF_STATION_DB'
longitudeFloat representing WGS84 longitude
latitudeFloat representing WGS84 latitude
Returns
Tuple of the form (station_id, longitude, latitude, elevation_meters, name, distance), None if no gage is found.
1 from ecohydrolib.climatedata.ghcndquery import findStationNearestToCoordinates
2 import ConfigParser
3 config = ConfigParser.RawConfigParser()
4 config.read('./bin/macosx2.cfg')
5 lon = -76.7443397486
6 lat = 39.2955590994
7 nearest = findStationNearestToCoordinates(config, lon, lat)
8 from ecohydrolib.climatedata.ghcndquery import getClimateDataForStation
9 outputDir = '/tmp'
10 outfileName = 'clim.txt'
11 getClimateDataForStation(config, outputDir, outfileName, nearest[0])
def ecohydrolib.climatedata.ghcndquery.findStationsWithinBoundingBox (   config,
  bbox 
)

Find stations that lie within a bounding box.

Parameters
configConfigParser containing the section 'GHCND' and option 'PATH_OF_STATION_DB'
bboxA dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
Returns
A list of GHCN station attributes for each station within the bounding box: [id, lat, lon, elevation, name]
1 import os
2 import ConfigParser
3 from ecohydrolib.metadata import GenericMetadata
4 from ecohydrolib.climatedata.ghcndquery import findStationsWithinBoundingBox
5 studyArea = GenericMetadata.readStudyAreaEntries(projectDir)
6 bbox = studyArea['bbox_wgs84'].split()
7 bbox = dict({'minX': float(bbox[0]), 'minY': float(bbox[1]), 'maxX': float(bbox[2]), 'maxY': float(bbox[3]), 'srs': 'EPSG:4326'})
8 
9 configFile = os.environ['ECOHYDROWORKFLOW_CFG']
10 config = ConfigParser.RawConfigParser()
11 config.read(configFile)
12 
13 stations = findStationsWithinBoundingBox(config,bbox)
def ecohydrolib.climatedata.ghcndquery.getClimateDataForStation (   config,
  outputDir,
  outFilename,
  stationID,
  overwrite = True 
)

Fetch climate timeseries data for a GHCN daily station.

Parameters
configA Python ConfigParser (not currently used)
outputDirString representing the absolute/relative path of the directory into which output DEM should be written
outDEMFilenameString representing the name of the DEM file to be written
stationIDString representing unique identifier of station
overwriteBoolean value indicating whether or not the file indicated by filename should be overwritten. If False and filename exists, IOError exception will be thrown with errno.EEXIST
overwriteBoolean value indicating whether or not the file indicated by filename should be overwritten. If False and filename exists, IOError exception will be thrown with errno.EEXIST

IOError if outputDir is not a writable directory IOError if outFilename already exists and overwrite is False (see above)

Returns
True if timeseries data were fetched and False if not

Variable Documentation

int ecohydrolib.climatedata.ghcndquery._BUFF_LEN = 4096
tuple ecohydrolib.climatedata.ghcndquery._SRS = int(4326)
string ecohydrolib.climatedata.ghcndquery.HOST = 'www1.ncdc.noaa.gov'
string ecohydrolib.climatedata.ghcndquery.URL_PROTO = '/pub/data/ghcn/daily/all/{station_id}.dly'