def run(self, *args, **kwargs): """ Run the command: Acquire Australian soils data. Arguments: verbose -- boolean Produce verbose output. Default: False. overwrite -- boolean Overwrite existing output. Default: False. """ verbose = kwargs.get('verbose', False) overwrite = kwargs.get('overwrite', False) self.checkMetadata() bbox = bboxFromString(self.studyArea['bbox_wgs84']) try: rasters = getSoilsRasterDataForBoundingBox( self.context.config, self.context.projectDir, bbox, srs=self.studyArea['dem_srs'], resx=self.studyArea['dem_res_x'], resy=self.studyArea['dem_res_y'], overwrite=overwrite, verbose=verbose, outfp=self.outfp) except Exception as e: traceback.print_exc(file=self.outfp) raise RunException(e) # Write metadata entries cmdline = GenericMetadata.getCommandLine() for attr in list(rasters.keys()): (filepath, url) = rasters[attr] filename = os.path.basename(filepath) asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = attr asset.dcIdentifier = filename asset.dcSource = url asset.dcTitle = attr asset.dcPublisher = soilwcs.DC_PUBLISHER asset.dcDescription = cmdline asset.writeToMetadata(self.context) # Write processing history GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)
def run(self, *args, **kwargs): """ Run the command: Acquire Australian soils data. Arguments: verbose -- boolean Produce verbose output. Default: False. overwrite -- boolean Overwrite existing output. Default: False. """ verbose = kwargs.get('verbose', False) overwrite = kwargs.get('overwrite', False) self.checkMetadata() bbox = bboxFromString(self.studyArea['bbox_wgs84']) try: rasters = getSoilsRasterDataForBoundingBox(self.context.config, self.context.projectDir, bbox, srs=self.studyArea['dem_srs'], resx=self.studyArea['dem_res_x'], resy=self.studyArea['dem_res_y'], overwrite=overwrite, verbose=verbose, outfp=self.outfp) except Exception as e: traceback.print_exc(file=self.outfp) raise RunException(e) # Write metadata entries cmdline = GenericMetadata.getCommandLine() for attr in rasters.keys(): (filepath, url) = rasters[attr] filename = os.path.basename(filepath) asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = attr asset.dcIdentifier = filename asset.dcSource = url asset.dcTitle = attr asset.dcPublisher = soilwcs.DC_PUBLISHER asset.dcDescription = cmdline asset.writeToMetadata(self.context) # Write processing history GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)
def run(self, *args, **kwargs): """ Run the command: Acquire USGS DEM data. Arguments: coverage -- string Source dataset from which DEM tile should be extracted. outfile -- string The name of the DEM file to be written. File extension ".tif" will be added. demResolution list<float>[2] Two floating point numbers representing the desired X and Y output resolution of soil property raster maps; unit: meters. srs -- string Target spatial reference system of output, in EPSG:num format. verbose -- boolean Produce verbose output. Default: False. overwrite -- boolean Overwrite existing output. Default: False. """ coverage = kwargs.get('coverage', self.DEFAULT_COVERAGE) outfile = kwargs.get('outfile', None) demResolution = kwargs.get('demResolution', None) srs = kwargs.get('srs', None) verbose = kwargs.get('verbose', False) overwrite = kwargs.get('overwrite', False) self.checkMetadata() bbox = bboxFromString(self.studyArea['bbox_wgs84']) if not outfile: outfile = 'DEM' demFilename = "%s.tif" % (outfile) demResolutionX = demResolutionY = None if demResolution: demResolutionX = demResolution[0] demResolutionY = demResolution[1] if srs: if not isValidSrs(srs): msg = "ERROR: '%s' is not a valid spatial reference. Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'. For more information, see: http://www.spatialreference.org/" % (srs,) raise RunException(msg) else: # Default for UTM (centerLon, centerLat) = calculateBoundingBoxCenter(bbox) (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat) srs = getEPSGStringForUTMZone(utmZone, isNorth) try: (dataFetched, urlFetched) = ecohydrolib.usgs.demwcs.getDEMForBoundingBox(self.context.config, self.context.projectDir, demFilename, bbox, srs, coverage=coverage, resx=demResolutionX, resy=demResolutionY, scale=0.01, overwrite=overwrite, verbose=verbose, outfp=self.outfp) except Exception as e: traceback.print_exc(file=self.outfp) raise RunException(e) if not dataFetched: raise RunException("Failed to download DEM data from URL {0}".format(urlFetched)) # Write metadata entries cmdline = GenericMetadata.getCommandLine() # Write metadata demFilepath = os.path.join(self.context.projectDir, demFilename) demSrs = getSpatialReferenceForRaster(demFilepath) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_res_x', demSrs[0]) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_res_y', demSrs[1]) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_srs', srs) # Get rows and columns for DEM (columns, rows) = getDimensionsForRaster(demFilepath) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_columns', columns) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_rows', rows) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'dem' asset.dcIdentifier = demFilename asset.dcSource = urlFetched asset.dcTitle = "Digital Elevation Model ({0})".format(coverage) asset.dcPublisher = 'U.S. Geological Survey' asset.dcDescription = cmdline asset.processingNotes = "Elevation values rescaled from centimeters to meters. " asset.processingNotes += "Spatial grid resampled to {srs} with X resolution {xres} and Y resolution {yres}." asset.processingNotes = asset.processingNotes.format(srs=srs, xres=demSrs[0], yres=demSrs[1]) asset.writeToMetadata(self.context) # Write processing history GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)
(configFile, 'PATH_OF_GDAL_WARP', 'GDAL/OGR')) if args.outfile: outfile = args.outfile else: outfile = "DEM" demFilename = "%s.tif" % (outfile) # Overwrite DEM if already present demFilepath = os.path.join(context.projectDir, demFilename) if os.path.exists(demFilepath): os.unlink(demFilepath) # Get study area parameters studyArea = GenericMetadata.readStudyAreaEntries(context) bbox = bboxFromString(studyArea['bbox_wgs84']) # Determine target spatial reference if args.t_srs: if not isValidSrs(args.t_srs): sys.exit(textwrap.fill("ERROR: '%s' is not a valid spatial reference. Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'. For more information, see: http://www.spatialreference.org/" % (args.t_srs,) ) ) t_srs = args.t_srs else: # Default for UTM (centerLon, centerLat) = calculateBoundingBoxCenter(bbox) (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat) t_srs = getEPSGStringForUTMZone(utmZone, isNorth) # Get DEM from DEMExplorer sys.stdout.write('Downloading DEM from DEMExplorer...') sys.stdout.flush()
(configFile, 'PATH_OF_GDAL_WARP', 'GDAL/OGR')) if args.outfile: outfile = args.outfile else: outfile = "DEM" demFilename = "%s.tif" % (outfile) # Overwrite DEM if already present demFilepath = os.path.join(context.projectDir, demFilename) if os.path.exists(demFilepath): os.unlink(demFilepath) # Get study area parameters studyArea = GenericMetadata.readStudyAreaEntries(context) bbox = bboxFromString(studyArea['bbox_wgs84']) # Determine target spatial reference if args.t_srs: if not isValidSrs(args.t_srs): sys.exit( textwrap.fill( "ERROR: '%s' is not a valid spatial reference. Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'. For more information, see: http://www.spatialreference.org/" % (args.t_srs, ))) t_srs = args.t_srs else: # Default for UTM (centerLon, centerLat) = calculateBoundingBoxCenter(bbox) (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat) t_srs = getEPSGStringForUTMZone(utmZone, isNorth)
context = Context(args.projectDir, configFile) if not context.config.has_option("GHCND", "PATH_OF_STATION_DB"): sys.exit("Config file %s does not define option %s in section %s" % (configFile, "PATH_OF_STATION_DB", "GHCND")) if args.outdir: outDir = args.outdir else: outDir = "climate" outDirPath = os.path.join(context.projectDir, outDir) if not os.path.exists(outDirPath): os.mkdir(outDirPath) # Get study area parameters studyArea = GenericMetadata.readStudyAreaEntries(context) bbox = bboxFromString(studyArea["bbox_wgs84"]) # Get centroid of bounding box (longitude, latitude) = calculateBoundingBoxCenter(bbox) # Find nearest GHCN station nearest = findStationNearestToCoordinates(context.config, longitude, latitude) # Get data for station outFile = os.path.join(outDir, nearest[0]) returnCode = getClimateDataForStation(context.config, context.projectDir, outFile, nearest[0]) assert returnCode # Write metadata station = ClimatePointStation() station.type = "GHCN" station.id = nearest[0] station.longitude = nearest[1]
def run(self, *args, **kwargs): """ Run the command: Acquire USGS DEM data. Arguments: coverage -- string Source dataset from which DEM tile should be extracted. outfile -- string The name of the DEM file to be written. File extension ".tif" will be added. demResolution list<float>[2] Two floating point numbers representing the desired X and Y output resolution of soil property raster maps; unit: meters. srs -- string Target spatial reference system of output, in EPSG:num format. verbose -- boolean Produce verbose output. Default: False. overwrite -- boolean Overwrite existing output. Default: False. """ coverage = kwargs.get('coverage', self.DEFAULT_COVERAGE) outfile = kwargs.get('outfile', None) demResolution = kwargs.get('demResolution', None) srs = kwargs.get('srs', None) verbose = kwargs.get('verbose', False) overwrite = kwargs.get('overwrite', False) self.checkMetadata() bbox = bboxFromString(self.studyArea['bbox_wgs84']) if not outfile: outfile = 'DEM' demFilename = "%s.tif" % (outfile) demResolutionX = demResolutionY = None if demResolution: demResolutionX = demResolution[0] demResolutionY = demResolution[1] if srs: if not isValidSrs(srs): msg = "ERROR: '%s' is not a valid spatial reference. Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'. For more information, see: http://www.spatialreference.org/" % (srs,) raise RunException(msg) else: # Default for UTM (centerLon, centerLat) = calculateBoundingBoxCenter(bbox) (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat) srs = getEPSGStringForUTMZone(utmZone, isNorth) try: (dataFetched, urlFetched) = ecohydrolib.usgs.demwcs.getDEMForBoundingBox(self.context.config, self.context.projectDir, demFilename, bbox, srs, coverage=coverage, resx=demResolutionX, resy=demResolutionY, scale=0.01, overwrite=overwrite, verbose=verbose, outfp=self.outfp) except Exception as e: traceback.print_exc(file=self.outfp) raise RunException(e) if not dataFetched: raise RunException("Failed to download DEM data from URL {0}".format(urlFetched)) # Write metadata entries cmdline = GenericMetadata.getCommandLine() # Write metadata demFilepath = os.path.join(self.context.projectDir, demFilename) demSrs = getSpatialReferenceForRaster(demFilepath) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_res_x', demSrs[0]) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_res_y', demSrs[1]) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_srs', srs) # Get rows and columns for DEM (columns, rows) = getDimensionsForRaster(demFilepath) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_columns', columns) GenericMetadata.writeStudyAreaEntry(self.context, 'dem_rows', rows) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'dem' asset.dcIdentifier = demFilename asset.dcSource = urlFetched asset.dcTitle = "Digital Elevation Model ({0})".format(coverage) asset.dcPublisher = 'U.S. Geological Survey' asset.dcDescription = cmdline asset.processingNotes = "Elevation values rescaled from centimeters to meters. " asset.processingNotes += "Spatial grid resampled to {srs} with X resolution {xres} and Y resolution {yres}." asset.processingNotes = asset.processingNotes.format(srs=srs, xres=demSrs[0], yres=demSrs[1]) asset.writeToMetadata(self.context) # Write processing history GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)