<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import argparse <EOL> from datetime import datetime <EOL> from ecohydrolib . context import Context <EOL> from ecohydrolib . metadata import GenericMetadata <EOL> from ecohydrolib . metadata import ClimatePointStation <EOL> from ecohydrolib . spatialdata . utils import bboxFromString <EOL> from ecohydrolib . spatialdata . utils import calculateBoundingBoxCenter <EOL> from ecohydrolib . climatedata . ghcndquery import findStationNearestToCoordinates <EOL> from ecohydrolib . climatedata . ghcndquery import getClimateDataForStation <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = False , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = False , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> cmdline = GenericMetadata . getCommandLine ( ) <EOL> configFile = None <EOL> if args . configfile : <EOL> configFile = args . configfile <EOL> context = Context ( args . projectDir , configFile ) <EOL> if not context . config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sys . exit ( "<STR_LIT>" % ( configFile , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if args . outdir : <EOL> outDir = args . outdir <EOL> else : <EOL> outDir = '<STR_LIT>' <EOL> outDirPath = os . path . join ( context . projectDir , outDir ) <EOL> if not os . path . exists ( outDirPath ) : <EOL> os . mkdir ( outDirPath ) <EOL> studyArea = GenericMetadata . readStudyAreaEntries ( context ) <EOL> bbox = bboxFromString ( studyArea [ '<STR_LIT>' ] ) <EOL> ( longitude , latitude ) = calculateBoundingBoxCenter ( bbox ) <EOL> nearest = findStationNearestToCoordinates ( context . config , longitude , latitude ) <EOL> outFile = os . path . join ( outDir , nearest [ <NUM_LIT:0> ] ) <EOL> returnCode = getClimateDataForStation ( context . config , context . projectDir , outFile , nearest [ <NUM_LIT:0> ] ) <EOL> assert ( returnCode ) <EOL> station = ClimatePointStation ( ) <EOL> station . type = "<STR_LIT>" <EOL> station . id = nearest [ <NUM_LIT:0> ] <EOL> station . longitude = nearest [ <NUM_LIT:1> ] <EOL> station . latitude = nearest [ <NUM_LIT:2> ] <EOL> station . elevation = nearest [ <NUM_LIT:3> ] <EOL> station . name = nearest [ <NUM_LIT:4> ] <EOL> station . data = outFile <EOL> station . writeToMetadata ( context ) <EOL> GenericMetadata . appendProcessingHistoryItem ( context , cmdline ) </s>
