Module Expr Str Import alias alias Import alias Import alias ImportFrom alias identifier Assign NameStore Str Assign NameStore Str Assign NameStore Call NameLoad Num Assign NameStore BinOpMult Num Num FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore ListLoad Assign NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr For NameStore NameLoad body Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Assert NameLoad Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Num Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr ListLoad SubscriptLoad NameLoad Index Num NameLoad NameLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad Call NameLoad NameLoad Call NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num Assert NameLoad Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Num Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Num Return TupleLoad SubscriptLoad NameLoad Index Num NameLoad NameLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults NameLoad body Expr Str Assign NameStore NameLoad If UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Raise Call NameLoad AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad If UnaryOpNot Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr body Raise Call NameLoad AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad If Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body If NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad orelse Raise Call NameLoad AttributeLoad NameLoad attr BinOpMod Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assert CompareEq Num AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad If NameLoad body Assign NameStore Call NameLoad NameLoad Str Assign NameStore NameLoad While NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list
N/A N/A @package ecohydrolib.climatedata.ghcndquery
    
@brief 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:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the University of North Carolina at Chapel Hill nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

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_miles@unc.edu>
 N/A os errno N/A re N/A httplib pyspatialite dbapi2 spatialite N/A HOST www1.ncdc.noaa.gov N/A URL_PROTO /pub/data/ghcn/daily/all/{station_id}.dly N/A _SRS N/A int 4326 N/A _BUFF_LEN N/A 4096 10 findStationsWithinBoundingBox N/A N/A config bbox N/A N/A N/A  Find stations that lie within a bounding box
    
        @param config ConfigParser containing the section 'GHCND' and option 
        'PATH_OF_STATION_DB'
        @param bbox A dict containing keys: minX, minY, maxX, maxY, srs, where srs='EPSG:4326'
        
        @return A list of GHCN station attributes for each station within the bounding box:
        [id, lat, lon, elevation, name]
        
        @code
        import os
        import ConfigParser
        from ecohydrolib.metadata import GenericMetadata
        from ecohydrolib.climatedata.ghcndquery import findStationsWithinBoundingBox
        studyArea = GenericMetadata.readStudyAreaEntries(projectDir)
        bbox = studyArea['bbox_wgs84'].split()
        bbox = dict({'minX': float(bbox[0]), 'minY': float(bbox[1]), 'maxX': float(bbox[2]), 'maxY': float(bbox[3]), 'srs': 'EPSG:4326'})
            
        configFile = os.environ['ECOHYDROWORKFLOW_CFG']
        config = ConfigParser.RawConfigParser()
        config.read(configFile)
        
        stations = findStationsWithinBoundingBox(config,bbox)
        @endcode 
     N/A stations N/A N/A pattern N/A N/A re compile ^POINT\((-?\d+\.?\d*) (-?\d+\.?\d*)\)$ N/A ghcnDB N/A N/A config get GHCND PATH_OF_STATION_DB N/A conn N/A N/A spatialite connect ghcnDB N/A cursor N/A N/A conn cursor N/A sql N/A SELECT id,AsText(coord),elevation_m,name FROM ghcn_station WHERE Within(coord, BuildMbr(%f,%f,%f,%f)); N/A N/A bbox N/A minX N/A bbox N/A minY N/A bbox N/A maxX N/A bbox N/A maxY N/A N/A N/A cursor execute sql N/A results N/A N/A cursor fetchall N/A N/A N/A conn close N/A result results N/A N/A match N/A N/A pattern match N/A result N/A 1 N/A match N/A lon N/A float N/A N/A match group 1 N/A lat N/A float N/A N/A match group 2 N/A N/A N/A stations append N/A N/A result N/A 0 lat lon N/A result N/A 2 N/A result N/A 3 N/A stations N/A findStationNearestToCoordinates N/A N/A config longitude latitude N/A N/A N/A Determine identifier of station nearest to longitude, latitude coordinates.
    
        @param config ConfigParser containing the section 'GHCND' and option 
        'PATH_OF_STATION_DB'
        @param longitude Float representing WGS84 longitude
        @param latitude Float representing WGS84 latitude
        
        @return Tuple of the form (station_id, longitude, latitude, elevation_meters, name, distance),
        None if no gage is found.
        
        @code
        from ecohydrolib.climatedata.ghcndquery import findStationNearestToCoordinates
        import ConfigParser
        config = ConfigParser.RawConfigParser()
        config.read('./bin/macosx2.cfg')
        lon = -76.7443397486
        lat = 39.2955590994
        nearest = findStationNearestToCoordinates(config, lon, lat)
        from ecohydrolib.climatedata.ghcndquery import getClimateDataForStation
        outputDir = '/tmp'
        outfileName = 'clim.txt'
        getClimateDataForStation(config, outputDir, outfileName, nearest[0])
        @endcode
     N/A ghcnDB N/A N/A config get GHCND PATH_OF_STATION_DB N/A conn N/A N/A spatialite connect ghcnDB N/A cursor N/A N/A conn cursor N/A sql N/A SELECT id,AsText(coord),elevation_m,name,Distance(GeomFromText('POINT(%f %f)', %d), coord) as dist FROM ghcn_station order by dist asc limit 1 N/A N/A float longitude N/A float latitude _SRS N/A N/A N/A cursor execute sql N/A nearest N/A N/A cursor fetchone N/A N/A N/A conn close N/A nearest N/A N/A pattern N/A N/A re compile ^POINT\((-?\d+\.\d+) (-?\d+\.\d+)\)$ N/A match N/A N/A pattern match N/A nearest N/A 1 N/A match N/A lon N/A float N/A N/A match group 1 N/A lat N/A float N/A N/A match group 2 N/A N/A N/A nearest N/A 0 lon lat N/A nearest N/A 2 N/A nearest N/A 3 N/A nearest N/A 4 N/A None N/A getClimateDataForStation N/A N/A config outputDir outFilename stationID overwrite N/A True N/A N/A Fetch climate timeseries data for a GHCN daily station
    
        @param config A Python ConfigParser (not currently used)
        @param outputDir String representing the absolute/relative path of the directory into which output DEM should be written
        @param outDEMFilename String representing the name of the DEM file to be written
        @param stationID String representing unique identifier of station
        @param overwrite Boolean 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
        @param overwrite Boolean 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
    
        @raise IOError if outputDir is not a writable directory
        @raise IOError if outFilename already exists and overwrite is False (see above)
        
        @return True if timeseries data were fetched and False if not
     N/A dataFetched False N/A N/A N/A N/A N/A os path isdir outputDir N/A N/A N/A IOError N/A errno ENOTDIR N/A Output directory %s is not a directory N/A outputDir N/A N/A N/A N/A os access outputDir N/A os W_OK N/A N/A N/A IOError N/A errno EACCES N/A Not allowed to write to output directory %s N/A outputDir N/A outputDir N/A N/A N/A os path abspath outputDir N/A outFilepath N/A N/A N/A os path join outputDir outFilename N/A N/A N/A N/A os path exists outFilepath N/A N/A overwrite N/A N/A N/A N/A os unlink outFilepath N/A N/A N/A IOError N/A errno EEXIST N/A File %s already exists outFilepath N/A url N/A N/A URL_PROTO format station_id stationID N/A conn N/A N/A httplib HTTPConnection HOST N/A N/A N/A conn request GET url N/A res N/A N/A conn getresponse buffering True N/A N/A 200 N/A res status N/A data N/A N/A res read _BUFF_LEN N/A data N/A N/A dataOut N/A open outFilepath wb N/A dataFetched True N/A data N/A N/A N/A N/A dataOut write data N/A data N/A N/A res read _BUFF_LEN N/A N/A N/A dataOut close N/A dataFetched N/A