コード例 #1
0
 def run(self, *args, **kwargs):
     """ Run the command: Acquire USGS DEM data.
     
     Arguments:
     auth hs_restclient.HydroShareAuth object
     title string representing the title of the resource
     hydroshare_host string representing DNS name of the HydroShare 
         server in which to create the resource
     hydroshare_port int representing the TCP port of the HydroShare 
         server
     use_https True if HTTPS should be used.  Default: False
     resource_type string representing the HydroShare resource type
         that should be used to create the resource
     abstract string representing the abstract of the resource
     keywords list of strings representing the keywords to assign
         to the resource
     create_callback user-defined callable that takes as input a 
         file size in bytes, and generates a callable to provide feedback 
         to the user about the progress of the upload of resource_file.  
         For more information, see:
         http://toolbelt.readthedocs.org/en/latest/uploading-data.html#monitoring-your-streaming-multipart-upload 
     verbose -- boolean    Produce verbose output. Default: False.
     overwrite -- boolean    Overwrite existing output.  Default: False.
     """
     auth = kwargs.get('auth', None)
     if auth is None:
         raise RunException("No HydroShare authentication mechanism was defined.")
     title = kwargs.get('title', None)
     if title is None: 
         raise RunException("Title for new HydroShare resource was not specified.")
     hydroshare_host = kwargs.get('hydroshare_host', None)
     hydroshare_port = kwargs.get('hydroshare_port', None)
     use_https = kwargs.get('use_https', False)
     resource_type = kwargs.get('resource_type', 'GenericResource')
     abstract = kwargs.get('abstract', None)
     keywords = kwargs.get('keywords', None)
     create_callback = kwargs.get('create_callback', None)
     
     verbose = kwargs.get('verbose', False)
     overwrite = kwargs.get('overwrite', False)
     
     self.checkMetadata(overwrite=overwrite)
     
     resource_id = create_hydroshare_resource(self.context, auth, title, 
                                              hydroshare_host=hydroshare_host, 
                                              hydroshare_port=hydroshare_port, use_https=use_https, 
                                              resource_type=resource_type, abstract=abstract, 
                                              keywords=keywords, create_callback=create_callback,
                                              verbose=verbose)
     
     # Write metadata entries
     cmdline = GenericMetadata.getCommandLine()
     
     # Write metadata
     GenericMetadata.writeHydroShareEntry(self.context, 'resource_id', resource_id)
     
     # Write processing history
     GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)
コード例 #2
0
 def deleteRHESSysEntry(context, key):
     """ Delete a RHESSys entry from the metadata store for a given project.
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be deleted from
         @param key The key to be deleted from the RHESSys section of the project metadata
         
         @exception IOError(errno.EACCES) if the metadata store for the project is not writable
     """
     GenericMetadata.deleteEntryFromSection(context, RHESSysMetadata.RHESSYS_SECTION, key, \
                                            RHESSysMetadata._writeWorkflowVersionToMetadata)
コード例 #3
0
 def deleteRHESSysEntry(context, key):
     """ Delete a RHESSys entry from the metadata store for a given project.
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be deleted from
         @param key The key to be deleted from the RHESSys section of the project metadata
         
         @exception IOError(errno.EACCES) if the metadata store for the project is not writable
     """
     GenericMetadata.deleteEntryFromSection(context, RHESSysMetadata.RHESSYS_SECTION, key, \
                                            RHESSysMetadata._writeWorkflowVersionToMetadata)
コード例 #4
0
 def test_empty_read(self):
     manifest = GenericMetadata.readManifestEntries(self.context)
     self.assertTrue(len(manifest) == 0)
     
     studyArea = GenericMetadata.readStudyAreaEntries(self.context)
     self.assertTrue(len(studyArea) == 0)
 
     climatePoint = GenericMetadata.readClimatePointEntries(self.context)
     self.assertTrue(len(climatePoint) == 0)
     
     climateGrid = GenericMetadata.readClimateGridEntries(self.context)
     self.assertTrue(len(climateGrid) == 0)
コード例 #5
0
 def writeRHESSysEntry(context, key, value):
     """ Write a RHESSys entry to the metadata store for a given project.
         
         @note Will overwrite the value for a key that already exists
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be written to
         @param key The key to be written to the RHESSys section of the project metadata
         @param value The value to be written for key stored in the RHESSys section of the project metadata
         
         @exception IOError(errno.EACCES) if the metadata store for the project is not writable
     """
     GenericMetadata.writeEntryToSection(context, RHESSysMetadata.RHESSYS_SECTION, key, value, \
                                         RHESSysMetadata._writeWorkflowVersionToMetadata)
コード例 #6
0
 def writeRHESSysEntry(context, key, value):
     """ Write a RHESSys entry to the metadata store for a given project.
         
         @note Will overwrite the value for a key that already exists
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be written to
         @param key The key to be written to the RHESSys section of the project metadata
         @param value The value to be written for key stored in the RHESSys section of the project metadata
         
         @exception IOError(errno.EACCES) if the metadata store for the project is not writable
     """
     GenericMetadata.writeEntryToSection(context, RHESSysMetadata.RHESSYS_SECTION, key, value, \
                                         RHESSysMetadata._writeWorkflowVersionToMetadata)
コード例 #7
0
 def test_write_climate_point1_overwrite(self):
     """ Test case where there is a single data file the station, the entry is overwritten """
     station = ClimatePointStation()
     station.type = "GHCN"
     station.id = "US1MDBL0027"
     station.longitude = -76.716
     station.latitude = 39.317
     station.elevation = 128.0
     station.name = "My station name"
     station.data = "clim.txt"
     station.startDate = datetime.strptime("201007", "%Y%m")
     station.endDate = datetime.strptime("201110", "%Y%m")
     station.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station.writeToMetadata(self.context)
     
     climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0]  
     self.assertTrue(station.type.lower() == climatePointStation.type)
     self.assertTrue(station.id.lower() == climatePointStation.id)
     self.assertTrue(station.longitude == climatePointStation.longitude)
     self.assertTrue(station.latitude == climatePointStation.latitude)
     self.assertTrue(station.elevation == climatePointStation.elevation)
     self.assertTrue(station.name == climatePointStation.name)
     self.assertTrue(station.data == climatePointStation.data)
     self.assertTrue(station.startDate == climatePointStation.startDate)
     self.assertTrue(station.endDate == climatePointStation.endDate)
     self.assertTrue(station.variables == climatePointStation.variables)
     
     station.longitude = -76.716
     station.latitude = 39.317
     station.elevation = 128.0
     station.name = "My (longer) station name"
     station.data = "clim.dat"
     station.startDate = datetime.strptime("201006", "%Y%m")
     station.endDate = datetime.strptime("201310", "%Y%m")
     station.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station.writeToMetadata(self.context)
     
     climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0]  
     self.assertTrue(station.type.lower() == climatePointStation.type)
     self.assertTrue(station.id.lower() == climatePointStation.id)
     self.assertTrue(station.longitude == climatePointStation.longitude)
     self.assertTrue(station.latitude == climatePointStation.latitude)
     self.assertTrue(station.elevation == climatePointStation.elevation)
     self.assertTrue(station.name == climatePointStation.name)
     self.assertTrue(station.data == climatePointStation.data)
     self.assertTrue(station.startDate == climatePointStation.startDate)
     self.assertTrue(station.endDate == climatePointStation.endDate)
     self.assertTrue(station.variables == climatePointStation.variables)
コード例 #8
0
ファイル: base.py プロジェクト: selimnairb/EcohydroLib
    def checkMetadata(self, *args, **kwargs):
        """ Check to make sure the project directory has the necessary metadata to run this command.
        
            @note Concrete commands must call this super class method in their own
            implementation of checkMetadata(), and must call their implementation
            near the beginning of their run method.
        
        """
        super(GrassCommand, self).checkMetadata()
        self.grassMetadata = GenericMetadata.readGRASSEntries(self.context)

        if not "grass_dbase" in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS Dbase" % (self.context.projectDir,)
            )
        if not "grass_location" in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS location" % (self.context.projectDir,)
            )
        if not "grass_mapset" in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS mapset" % (self.context.projectDir,)
            )

        self.setupGrassEnv()
コード例 #9
0
    def checkMetadata(self, *args, **kwargs):
        """ Check to make sure the project directory has the necessary metadata to run this command.
        
            @note Concrete commands must call this super class method in their own
            implementation of checkMetadata(), and must call their implementation
            near the beginning of their run method.
        
        """
        super(GrassCommand, self).checkMetadata()
        self.grassMetadata = GenericMetadata.readGRASSEntries(self.context)

        if not 'grass_dbase' in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS Dbase"
                % (self.context.projectDir, ))
        if not 'grass_location' in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS location"
                % (self.context.projectDir, ))
        if not 'grass_mapset' in self.metadata:
            raise MetadataException(
                "Metadata in project directory %s does not contain a GRASS mapset"
                % (self.context.projectDir, ))

        self.setupGrassEnv()
コード例 #10
0
    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)
コード例 #11
0
 def checkMetadata(self, *args, **kwargs):
     """ Check to make sure the project directory has the necessary metadata to run this command.
     
         @note Concrete commands must call this super class method in their own
         implementation of checkMetadata(), and must call their implementation
         near the beginning of their run method.
     
     """
     self.studyArea = GenericMetadata.readStudyAreaEntries(self.context)
コード例 #12
0
 def readRHESSysEntries(context):
     """ Read all RHESSys entries from the metadata store for a given project
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be read from
         
         @exception A dictionary of key/value pairs from the RHESSys section of the project metadata
     """
     return GenericMetadata._readEntriesForSection(context.projectDir, RHESSysMetadata.RHESSYS_SECTION)
コード例 #13
0
 def test_version_conflict(self):
     """ Induce a version conflict """
     
     step1 = "mkdir foo; cd foo"
     step2 = "touch README.txt"
     
     GenericMetadata.appendProcessingHistoryItem(self.context, step1)
     # For testing purposes only, users should not modify 
     #   GenericMetadata._ecohydrolibVersion
     _prevVersion = GenericMetadata._ecohydrolibVersion
     GenericMetadata._ecohydrolibVersion = '11'
     caughtMetadataVersionError = False
     try:
         GenericMetadata.appendProcessingHistoryItem(self.context, step2)
     except MetadataVersionError:
         caughtMetadataVersionError = True
     self.assertTrue(caughtMetadataVersionError, "Expected metadata version mismatch, but none found.")
     GenericMetadata._ecohydrolibVersion = _prevVersion
コード例 #14
0
ファイル: base.py プロジェクト: selimnairb/EcohydroLib
 def checkMetadata(self, *args, **kwargs):
     """ Check to make sure the project directory has the necessary metadata to run this command.
     
         @note Concrete commands must call this super class method in their own
         implementation of checkMetadata(), and must call their implementation
         near the beginning of their run method.
     
     """
     self.studyArea = GenericMetadata.readStudyAreaEntries(self.context)
コード例 #15
0
ファイル: soil.py プロジェクト: dblodgett-usgs/EcohydroLib
 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)
コード例 #16
0
 def readRHESSysEntries(context):
     """ Read all RHESSys entries from the metadata store for a given project
     
         @param context Context object containing projectDir, the path of the project whose 
         metadata store is to be read from
         
         @exception A dictionary of key/value pairs from the RHESSys section of the project metadata
     """
     return GenericMetadata._readEntriesForSection(
         context.projectDir, RHESSysMetadata.RHESSYS_SECTION)
コード例 #17
0
 def checkMetadata(self, *args, **kwargs):
     """ Check to make sure the project directory has the necessary metadata to run this command.
     """
     super(HydroShareCreateResource, self).checkMetadata(args, kwargs)
     
     overwrite = kwargs.get('overwrite', False)
     
     self.hydroshare = GenericMetadata.readHydroShareEntries(self.context)
     if not overwrite and 'resource_id' in self.hydroshare:
         raise MetadataException("HydroShare resource ID is already defined, but overwrite was not specified")
コード例 #18
0
ファイル: context.py プロジェクト: dblodgett-usgs/EcohydroLib
 def __init__(self, projectDir, configFile=None):
     """ Constructor for Context class
     
         @param projectDir Path of the project whose metadata store is to be read from
         @param configFile Path of ecohydrolib configuration file to use.  If none,
         will attempt to read configuration from a file named in the environment
         variable Context.CONFIG_FILE_ENV
         
         @raise IOError if project directory path is not a directory
         @raise IOError if project directory is not writable
         @raise MetadataVersionError if a version already exists in the 
         metadata store and is different than GenericMetadata._ecohydrolibVersion
         @raise EnvironmentError if configuration file name could not be read from the 
         environment
         @raise IOError if configuration file could not be read
     """
     if not os.path.isdir(projectDir):
         raise IOError(errno.ENOTDIR, "Specified project directory %s is not a directory" % \
                       (projectDir,))
     if not os.access(projectDir, os.W_OK):
         raise IOError(errno.EACCES, "Unable to write to project directory %s" % \
                       (projectDir,))
     self.projectDir = os.path.abspath(projectDir)
     
     # Make sure metadata version is compatible with this version of ecohydrolib
     #   will raise MetadataVersionError if there is a version mismatch
     GenericMetadata.checkMetadataVersion(projectDir)
     
     if not configFile:
         try:
             self._configFile = os.environ[CONFIG_FILE_ENV]
         except KeyError:
             raise EnvironmentError("Configuration file not specified via environmental variable %s" %\
                                    CONFIG_FILE_ENV)
     else:
         self._configFile = configFile
     
     if not os.access(self._configFile, os.R_OK):
         raise IOError(errno.EACCES, "Unable to read configuration file %s" %
                       self._configFile)
     self.config = ConfigParser.RawConfigParser()
     self.config.read(self._configFile)
コード例 #19
0
 def __init__(self, projectDir, configFile=None):
     """ Constructor for Context class
     
         @param projectDir Path of the project whose metadata store is to be read from
         @param configFile Path of ecohydrolib configuration file to use.  If none,
         will attempt to read configuration from a file named in the environment
         variable Context.CONFIG_FILE_ENV
         
         @raise IOError if project directory path is not a directory
         @raise IOError if project directory is not writable
         @raise MetadataVersionError if a version already exists in the 
         metadata store and is different than GenericMetadata._ecohydrolibVersion
         @raise EnvironmentError if configuration file name could not be read from the 
         environment
         @raise IOError if configuration file could not be read
     """
     if not os.path.isdir(projectDir):
         raise IOError(errno.ENOTDIR, "Specified project directory %s is not a directory" % \
                       (projectDir,))
     if not os.access(projectDir, os.W_OK):
         raise IOError(errno.EACCES, "Unable to write to project directory %s" % \
                       (projectDir,))
     self.projectDir = os.path.abspath(projectDir)
     
     # Make sure metadata version is compatible with this version of ecohydrolib
     #   will raise MetadataVersionError if there is a version mismatch
     GenericMetadata.checkMetadataVersion(projectDir)
     
     if not configFile:
         try:
             self._configFile = os.environ[CONFIG_FILE_ENV]
         except KeyError:
             raise EnvironmentError("Configuration file not specified via environmental variable %s" %\
                                    CONFIG_FILE_ENV)
     else:
         self._configFile = configFile
     
     if not os.access(self._configFile, os.R_OK):
         raise IOError(errno.EACCES, "Unable to read configuration file %s" %
                       self._configFile)
     self.config = configparser.RawConfigParser()
     self.config.read(self._configFile)
コード例 #20
0
 def test_provenance_overwrite(self):
     """ Test case writing provenance metadata, with overwrite """
     asset = AssetProvenance()
     asset.section = GenericMetadata.MANIFEST_SECTION
     asset.name = "dem"
     asset.dcIdentifier = "dem.tif"
     asset.dcSource = "http://www.demexplorer.com/..."
     asset.dcTitle = "Study area DEM"
     asset.dcDate = datetime.strptime("201303", "%Y%m")
     asset.dcPublisher = "USGS"
     asset.dcDescription = "RegisterDEM.py ..."
     asset.writeToMetadata(self.context)
     
     assetProvenance = GenericMetadata.readAssetProvenanceObjects(self.context)[0]
     self.assertTrue(asset.section == assetProvenance.section)
     self.assertTrue(asset.name == assetProvenance.name)
     self.assertTrue(asset.dcIdentifier == assetProvenance.dcIdentifier)
     self.assertTrue(asset.dcSource == assetProvenance.dcSource)
     self.assertTrue(asset.dcTitle == assetProvenance.dcTitle)
     self.assertTrue(asset.dcDate == assetProvenance.dcDate)
     self.assertTrue(asset.dcPublisher == assetProvenance.dcPublisher)
     self.assertTrue(asset.dcDescription == assetProvenance.dcDescription)
     
     asset.dcIdentifier = 'foo.img'
     asset.dcSource = "http://a.different.url/..."
     asset.dcTitle = "A different study area DEM"
     asset.dcDate = datetime.strptime("201304", "%Y%m")
     asset.dcPublisher = "NASA"
     asset.dcDescription = "GetDEMExplorerDEM.py ..."
     asset.writeToMetadata(self.context)
     
     assetProvenance = GenericMetadata.readAssetProvenanceObjects(self.context)[0]
     self.assertTrue(asset.section == assetProvenance.section)
     self.assertTrue(asset.name == assetProvenance.name)
     self.assertTrue(asset.dcIdentifier == assetProvenance.dcIdentifier)
     self.assertTrue(asset.dcSource == assetProvenance.dcSource)
     self.assertTrue(asset.dcTitle == assetProvenance.dcTitle)
     self.assertTrue(asset.dcDate == assetProvenance.dcDate)
     self.assertTrue(asset.dcPublisher == assetProvenance.dcPublisher)
     self.assertTrue(asset.dcDescription == assetProvenance.dcDescription)
コード例 #21
0
 def checkMetadata(self):
     """ Check to make sure the project directory has the necessary metadata to run this command.
     """
     super(USGSWCSNLCD, self).checkMetadata()
     
     # Check for necessary information in metadata 
     self.manifest = GenericMetadata.readManifestEntries(self.context)
     if not 'dem' in self.manifest:
         raise MetadataException("Metadata in project directory %s does not contain a DEM" % (self.context.projectDir,)) 
     if not 'dem_srs' in self.studyArea:
         raise MetadataException("Metadata in project directory %s does not contain a spatial reference system" % (self.context.projectDir,))
     if not 'dem_res_x' in self.studyArea:
         raise MetadataException("Metadata in project directory %s does not contain a raster X resolution" % (self.context.projectDir,))
     if not 'dem_res_y' in self.studyArea:
         raise MetadataException("Metadata in project directory %s does not contain a raster Y resolution" % (self.context.projectDir,))    
コード例 #22
0
 def test_write_climate_point2(self):
     """ Test case where there are separate data files for each variable and there are two climate stations """
     station = ClimatePointStation()
     station.type = "GHCN"
     station.id = "US1MDBL0027"
     station.longitude = -76.716
     station.latitude = 39.317
     station.elevation = 128.0
     station.name = "My station name"
     station.startDate = datetime.strptime("201007", "%Y%m")
     station.endDate = datetime.strptime("201110", "%Y%m")
     station.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station.variablesData[ClimatePointStation.VAR_PRECIP] = ClimatePointStation.VAR_PRECIP + '.txt'
     station.variablesData[ClimatePointStation.VAR_SNOW] = ClimatePointStation.VAR_SNOW + '.txt'
     station.writeToMetadata(self.context)
     
     station2 = ClimatePointStation()
     station2.type = "GHCN"
     station2.id = "US1MDBL4242"
     station2.longitude = -42.716
     station2.latitude = 42.317
     station2.elevation = 42.0
     station2.name = "My 42 station"
     station2.startDate = datetime.strptime("199907", "%Y%m")
     station2.endDate = datetime.strptime("200110", "%Y%m")
     station2.variables = [ClimatePointStation.VAR_PRECIP, \
                          ClimatePointStation.VAR_SNOW]
     station2.variablesData[ClimatePointStation.VAR_PRECIP] = ClimatePointStation.VAR_PRECIP + '.txt'
     station2.variablesData[ClimatePointStation.VAR_SNOW] = ClimatePointStation.VAR_SNOW + '.txt'
     station2.writeToMetadata(self.context)
     
     climatePointStation = GenericMetadata.readClimatePointStations(self.context)[0]        
     self.assertTrue(station.type.lower() == climatePointStation.type)
     self.assertTrue(station.id.lower() == climatePointStation.id)
     self.assertTrue(station.longitude == climatePointStation.longitude)
     self.assertTrue(station.latitude == climatePointStation.latitude)
     self.assertTrue(station.elevation == climatePointStation.elevation)
     self.assertTrue(station.name == climatePointStation.name)
     self.assertTrue(station.startDate == climatePointStation.startDate)
     self.assertTrue(station.endDate == climatePointStation.endDate)
     self.assertTrue(station.variables == climatePointStation.variables)
     self.assertTrue(station.variablesData[ClimatePointStation.VAR_PRECIP] == climatePointStation.variablesData[ClimatePointStation.VAR_PRECIP])
     self.assertTrue(station.variablesData[ClimatePointStation.VAR_SNOW] == climatePointStation.variablesData[ClimatePointStation.VAR_SNOW])
コード例 #23
0
 def test_processing_history(self):
     """ Test processing history metadata """
     projectDir = "/tmp"
     
     step1 = "mkdir foo; cd foo"
     step2 = "touch README.txt"
     step3 = "git init"
     
     GenericMetadata.appendProcessingHistoryItem(self.context, step1)
     GenericMetadata.appendProcessingHistoryItem(self.context, step2)
     GenericMetadata.appendProcessingHistoryItem(self.context, step3)
     
     history = GenericMetadata.getProcessingHistoryList(self.context)
     self.assertTrue(len(history) == 3, "Expected history length to be 3, but it is %d" % (len(history),) )
     self.assertTrue(history[0] == step1)
     self.assertTrue(history[1] == step2)
     self.assertTrue(history[2] == step3)
コード例 #24
0
    def checkMetadata(self):
        """ Check to make sure the project directory has the necessary metadata to run this command.
        """
        super(USGSWCSNLCD, self).checkMetadata()

        # Check for necessary information in metadata
        self.manifest = GenericMetadata.readManifestEntries(self.context)
        if not 'dem' in self.manifest:
            raise MetadataException(
                "Metadata in project directory %s does not contain a DEM" %
                (self.context.projectDir, ))
        if not 'dem_srs' in self.studyArea:
            raise MetadataException(
                "Metadata in project directory %s does not contain a spatial reference system"
                % (self.context.projectDir, ))
        if not 'dem_res_x' in self.studyArea:
            raise MetadataException(
                "Metadata in project directory %s does not contain a raster X resolution"
                % (self.context.projectDir, ))
        if not 'dem_res_y' in self.studyArea:
            raise MetadataException(
                "Metadata in project directory %s does not contain a raster Y resolution"
                % (self.context.projectDir, ))
コード例 #25
0
 def test_check_metadata_version(self):
     """ Test check metadata version """       
     step1 = "mkdir foo; cd foo"
     
     GenericMetadata.appendProcessingHistoryItem(self.context, step1)
     GenericMetadata.checkMetadataVersion(self.context.projectDir)
     # For testing purposes only, users should not modify 
     #   GenericMetadata._ecohydrolibVersion
     _prevVersion = GenericMetadata._ecohydrolibVersion
     GenericMetadata._ecohydrolibVersion = '11'
     caughtMetadataVersionError = False
     try:
         GenericMetadata.checkMetadataVersion(self.context.projectDir)
     except MetadataVersionError:
         caughtMetadataVersionError = True
     self.assertTrue(caughtMetadataVersionError, "Expected metadata version mismatch, but none found.")
     GenericMetadata._ecohydrolibVersion = _prevVersion
     
     
from ecohydrolib.metadata import GenericMetadata
from ecohydrolib.metadata import AssetProvenance
from ecohydrolib.hydro1k.basins import getCatchmentShapefileForHYDRO1kBasins

# Handle command line options
parser = argparse.ArgumentParser(description='Get shapefile for the drainage area of an NHDPlus2 streamflow gage')
parser.add_argument('-i', '--configfile', dest='configfile', required=False,
                    help='The configuration file')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-f', '--outfile', dest='outfile', required=False,
                    help='The name of the catchment shapefile to be written.  File extension ".shp" will be added.  If a file of this name exists, program will silently exit.')
parser.add_argument('-b', '--basins', dest='basins', nargs='+', required=True,
                    help='HYDRO1k basins to extract')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('GDAL/OGR', 'PATH_OF_OGR2OGR'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_OGR2OGR'))
if not context.config.has_option('HYDRO1k', 'PATH_OF_HYDRO1K_BAS'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (args.configfile, 'HYDRO1k', 'PATH_OF_HYDRO1K_BAS'))
if not context.config.has_option('HYDRO1k', 'HYDRO1k_BAS_LAYER_NAME'):
    sys.exit("Config file %s does not define option %s in section %s" % \
コード例 #27
0
    def run(self, *args, **kwargs):
        """ Run the command: Acquire NLCD data from USGS WCS web service.
        
        Arguments:
        lctype -- string    Source dataset from which NLCD tile should be extracted.
        outfile -- string    The name of the NLCD file to be written.  File extension ".tif" will be added.
        verbose -- boolean    Produce verbose output. Default: False.
        overwrite -- boolean    Overwrite existing output.  Default: False.
        """
        lctype = kwargs.get('lctype', DEFAULT_LC_TYPE)
        outfile = kwargs.get('outfile', None)
        verbose = kwargs.get('verbose', False)
        overwrite = kwargs.get('overwrite', False)
        
        if lctype not in ecohydrolib.usgs.nlcdwcs.LC_TYPE_TO_COVERAGE:
            msg = "Land cover type {lctype} is not in the list of supported types {types}"
            raise CommandException(msg.format(lctype=lctype, 
                                              types=ecohydrolib.usgs.nlcdwcs.LC_TYPE_TO_COVERAGE))
        
        self.checkMetadata()
        
        demFilename = self.manifest['dem']
        demFilepath = os.path.join(self.context.projectDir, demFilename)
        demFilepath = os.path.abspath(demFilepath)
        bbox = getRasterExtentAsBbox(demFilepath)
 
        if not outfile:
            outfile = 'NLCD'
        try:
            (resp, urlFetched, fname) = getNLCDRasterDataForBoundingBox(self.context.config, 
                                                                        self.context.projectDir,
                                                                        bbox,
                                                                        coverage=LC_TYPE_TO_COVERAGE[lctype],
                                                                        filename=outfile,
                                                                        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)
        
        if not resp:
            raise RunException("Failed to download NLCD data from URL {0}".format(urlFetched))
        
        # Write metadata entries
        cmdline = GenericMetadata.getCommandLine()
        GenericMetadata.writeStudyAreaEntry(self.context, "landcover_type", lctype)
        
        # Write provenance
        asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION)
        asset.name = 'landcover'
        asset.dcIdentifier = fname
        asset.dcSource = urlFetched
        asset.dcTitle = "The National Landcover Database: {0}".format(lctype)
        asset.dcPublisher = 'USGS'
        asset.dcDescription = cmdline
        asset.writeToMetadata(self.context)
        
        # Write processing history
        GenericMetadata.appendProcessingHistoryItem(self.context, cmdline)
コード例 #28
0
    '--demResolution',
    dest='demResolution',
    required=False,
    nargs=2,
    type=float,
    help=
    'Two floating point numbers representing the desired X and Y output resolution of soil property raster maps; unit: meters'
)
parser.add_argument(
    '-t',
    '--t_srs',
    dest='t_srs',
    required=False,
    help='Target spatial reference system of output, in EPSG:num format')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (configFile, 'PATH_OF_GDAL_WARP', 'GDAL/OGR'))

if args.outfile:
    outfile = args.outfile
else:
    outfile = "DEM"
parser.add_argument(
    "-p",
    "--projectDir",
    dest="projectDir",
    required=True,
    help="The directory to which metadata, intermediate, and final files should be saved",
)
parser.add_argument(
    "-d",
    "--outdir",
    dest="outdir",
    required=False,
    help="The name of the subdirectory within the project directory to write the climate data to.",
)
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

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)
コード例 #30
0
    '--projectDir',
    dest='projectDir',
    required=True,
    help=
    'The directory to which metadata, intermediate, and final files should be saved'
)
parser.add_argument(
    '-d',
    '--outdir',
    dest='outdir',
    required=False,
    help=
    'The name of the subdirectory within the project directory to write the climate data to.'
)
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

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'
コード例 #31
0
ファイル: dem.py プロジェクト: dblodgett-usgs/EcohydroLib
    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)
コード例 #32
0
    required=True,
    help=
    'The directory to which metadata, intermediate, and final files should be saved'
)
parser.add_argument('command')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

# Run command
cmd = ecohydrolib.util.getAbsolutePathOfExecutable(args.command)
if cmd == None:
    sys.exit("Enable able to find command '%s'" % (args.command, ))

result = subprocess.call([cmd] + args.args)
if result != 0:
    sys.exit("Command '%s' failed returning %d" % (args.command, result))

# Build representation of command with absolute path of all command arguments
cmdline = cmd
for arg in args.args:
    cmdline += ' ' + ecohydrolib.util.getAbsolutePathOfItem(arg)

# Write processing history
GenericMetadata.appendProcessingHistoryItem(context, cmdline)
コード例 #33
0
    help='The iRODS collection corresponding to the project directory')
args = parser.parse_args()

context = Context(args.projectDir, None)

# Make sure there's no trailing PATH_SEP_IRODS on the collection
collection = args.collection.rstrip(PATH_SEP_IRODS)

outfilePath = os.path.join(context.projectDir, OUTFILE_NAME)
outfile = codecs.getwriter('utf-8')(open(outfilePath, 'w'))
outfile.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
outfile.write('<metadata>\n')

# Write study area metadata to collection root
writeDictToXMLFile(outfile, collection,
                   GenericMetadata.readStudyAreaEntries(context))

# Write processing history to collection root
history = GenericMetadata.getProcessingHistoryList(context)
i = 1
for entry in history:
    attribute = "processing_step_%d" % (i, )
    i += 1
    writeAVUToXMLFile(outfile, collection, attribute, entry)

# Write provenance to each item in the manifest
provenance = GenericMetadata.readAssetProvenanceObjects(context)
for entry in provenance:
    target = collection + PATH_SEP_IRODS + entry.dcIdentifier
    writeAVUToXMLFile(outfile, target, 'name', entry.name)
    writeAVUToXMLFile(outfile, target, 'dc.source', entry.dcSource)
コード例 #34
0
    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)
コード例 #35
0
    help='Target spatial reference system of output, in EPSG:num format')
parser.add_argument(
    '-s',
    '--resampleMethod',
    dest='resampleMethod',
    required=False,
    choices=RASTER_RESAMPLE_METHOD,
    default='bilinear',
    help='Method to use to resample DEM (if necessary). Defaults to bilinear.')
parser.add_argument('--scale',
                    dest='scale',
                    required=False,
                    type=float,
                    help='Amount to scale input DEM by')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_GDAL_WARP'))

if not os.access(args.demfile, os.R_OK):
    raise IOError(errno.EACCES,
                  "Not allowed to read input DEM %s" (args.demfile, ))
inDEMPath = os.path.abspath(args.demfile)
コード例 #36
0
from ecohydrolib.spatialdata.utils import getRasterExtentAsBbox
from ecohydrolib.nlcd.daacquery import getNLCDForBoundingBox
from ecohydrolib.nlcd.daacquery import HOST

# Handle command line options
parser = argparse.ArgumentParser(description='Get NLCD data (in GeoTIFF format) for DEM extent from a local copy of the entire NLCD 2006 dataset.')
parser.add_argument('-i', '--configfile', dest='configfile', required=False,
                    help='The configuration file')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-s', '--source', dest='source', required=False, choices=['local', 'wcs'], default='wcs',
                    help='Source for NLCD data')
parser.add_argument('-f', '--outfile', dest='outfile', required=False,
                    help='The name of the NLCD file to be written.  File extension ".tif" will be added.')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_GDAL_WARP'))

if args.outfile:
    outfile = args.outfile
else:
    outfile = "NLCD"
コード例 #37
0
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-g', '--gageFile', dest='gageFile', required=True,
                    help='The name of the gage shapefile to be registered.')
parser.add_argument('-l', '--layerName', dest='layerName', required=True,
                    help='The name of the layer within the gage shapefile where gage points are located.')
parser.add_argument('-a', '--idAttribute', dest='idAttribute', required=True,
                    help='The name of the attribute field that uniquely identifies gage points.')
parser.add_argument('-d', '--idValue', dest='idValue', required=True,
                    help='The gage ID that uniquely identifies the gage point.')
parser.add_argument('-f', '--outfile', dest='outfile', required=False,
                    help='The name of the gage shapefile to be written to the project directory.  File extension ".shp" will be added.')
parser.add_argument('-b', '--publisher', dest='publisher', required=False,
                    help="The publisher of the stream flow gage location dataset, if not supplied 'SELF PUBLISHED' will be used")
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not os.access(args.gageFile, os.R_OK):
    raise IOError(errno.EACCES, "Not allowed to read input gage shapefile %s" %
                  args.gageFile)
inGagePath = os.path.abspath(args.gageFile)

if args.publisher:
    publisher = args.publisher
else:
コード例 #38
0
parser.add_argument(
    '-p',
    '--projectDir',
    dest='projectDir',
    required=True,
    help=
    'The directory to which metadata, intermediate, and final files should be saved'
)
parser.add_argument(
    '-b',
    '--buffer',
    dest='buffer',
    required=False,
    help='Number of WGS84 degrees by which to buffer the bounding box')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

context = Context(args.projectDir, None)

buffer = 0.01
if args.buffer:
    buffer = float(args.buffer)

# Get name of study area shapefile
manifest = GenericMetadata.readManifestEntries(context)
shapefileName = manifest['study_area_shapefile']

shapefilePath = os.path.join(context.projectDir, shapefileName)
if not os.access(shapefilePath, os.R_OK):
    raise IOError(errno.EACCES, "Unable to read shapefile %s" % args.shapefile)
コード例 #39
0
 def test_delete(self):
     GenericMetadata.writeManifestEntry(self.context, "key1", "value_one")
     manifest = GenericMetadata.readManifestEntries(self.context)
     self.assertTrue(manifest["key1"] == "value_one")
     GenericMetadata.deleteManifestEntry(self.context, "key1")
     manifest = GenericMetadata.readManifestEntries(self.context)
     self.assertTrue(not 'key1' in manifest)
     
     GenericMetadata.writeStudyAreaEntry(self.context, "key1", "value_one")
     studyArea = GenericMetadata.readStudyAreaEntries(self.context)
     self.assertTrue(studyArea["key1"] == "value_one")
     GenericMetadata.deleteStudyAreaEntry(self.context, 'key1')
     studyArea = GenericMetadata.readStudyAreaEntries(self.context)
     self.assertTrue(not 'key1' in studyArea)
     
     GenericMetadata.writeClimatePointEntry(self.context, "key1", "value_one")
     climatePoint = GenericMetadata.readClimatePointEntries(self.context)
     self.assertTrue(climatePoint["key1"] == "value_one")
     GenericMetadata.deleteClimatePointEntry(self.context, 'key1')
     climatePoint = GenericMetadata.readClimatePointEntries(self.context)
     self.assertTrue(not 'key1' in climatePoint)
     
     GenericMetadata.writeClimateGridEntry(self.context, "key1", "value_one")
     climateGrid = GenericMetadata.readClimateGridEntries(self.context)
     self.assertTrue(climateGrid["key1"] == "value_one")
     GenericMetadata.deleteClimateGridEntry(self.context, 'key1')
     climateGrid = GenericMetadata.readClimateGridEntries(self.context)
     self.assertTrue(not 'key1' in climateGrid)
     # Delete and empty entry
     GenericMetadata.deleteClimateGridEntry(self.context, "not_in_store")
     
     GenericMetadata.writeHydroShareEntry(self.context, "resource_id", "fae3688aa1354fb2a558380669229a66")
     hydroshare = GenericMetadata.readHydroShareEntries(self.context)
     self.assertTrue(hydroshare["resource_id"] == "fae3688aa1354fb2a558380669229a66")
     GenericMetadata.deleteHydroShareEntry(self.context, "resource_id")
     hydroshare = GenericMetadata.readHydroShareEntries(self.context)
     self.assertTrue(not 'resource_id' in hydroshare)
コード例 #40
0
# Handle command line options
parser = argparse.ArgumentParser(description='Get DEM raster (in GeoTIFF format) for a bounding box from GeoBrain WCS4DEM')
parser.add_argument('-i', '--configfile', dest='configfile', required=False,
                    help='The configuration file')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-d', '--demType', dest='demType', required=False, choices=demquery.SUPPORTED_COVERAGE, default=demquery.SUPPORTED_COVERAGE[0],
                    help='Source dataset from which DEM tile should be extracted.')
parser.add_argument('-f', '--outfile', dest='outfile', required=False,
                    help='The name of the DEM file to be written.  File extension ".tif" will be added.')
parser.add_argument('-c', '--demResolution', dest='demResolution', required=False, nargs=2, type=float,
                    help='Two floating point numbers representing the desired X and Y output resolution of soil property raster maps; unit: meters')
parser.add_argument('-t', '--t_srs', dest='t_srs', required=False, 
                    help='Target spatial reference system of output, in EPSG:num format')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (configFile, 'PATH_OF_GDAL_WARP', 'GDAL/OGR'))

if args.outfile:
    outfile = args.outfile
else:
    outfile = "DEM"
コード例 #41
0
    'The directory to which metadata, intermediate, and final files should be saved'
)
parser.add_argument('-s',
                    '--source',
                    dest='source',
                    required=False,
                    choices=['local', 'webservice'],
                    default='webservice',
                    help='Source to query NHDPlusV2 dataset')
parser.add_argument('-g',
                    '--gageid',
                    dest='gageid',
                    required=True,
                    help='An integer representing the USGS site identifier')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

if args.source == 'local':
    sys.stdout.write(
        'Getting identifiers and location from local NHDPlus dataset...')
    sys.stdout.flush()
    if not context.config.has_option('NHDPLUS2', 'PATH_OF_NHDPLUS2_DB'):
        sys.exit("Config file %s does not define option %s in section %s" & \
              (args.configfile, 'NHDPLUS2', 'PATH_OF_NHDPLUS2_DB'))
コード例 #42
0
parser.add_argument(
    '-f',
    '--outfile',
    dest='outfile',
    required=False,
    help=
    'The name of the catchment shapefile to be written.  File extension ".shp" will be added.  If a file of this name exists, program will silently exit.'
)
parser.add_argument('-b',
                    '--basins',
                    dest='basins',
                    nargs='+',
                    required=True,
                    help='HYDRO1k basins to extract')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

if not context.config.has_option('GDAL/OGR', 'PATH_OF_OGR2OGR'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_OGR2OGR'))
if not context.config.has_option('HYDRO1k', 'PATH_OF_HYDRO1K_BAS'):
    sys.exit("Config file %s does not define option %s in section %s" % \
          (args.configfile, 'HYDRO1k', 'PATH_OF_HYDRO1K_BAS'))
if not context.config.has_option('HYDRO1k', 'HYDRO1k_BAS_LAYER_NAME'):
    sys.exit("Config file %s does not define option %s in section %s" % \
コード例 #43
0
parser = argparse.ArgumentParser(
    description=
    'Dump point climate station information from EcohydroLib metadata to standard output'
)
parser.add_argument('-p',
                    '--projectDir',
                    dest='projectDir',
                    required=True,
                    help='The directory from which metadata should be read')
parser.add_argument('-s',
                    '--separator',
                    dest='separator',
                    required=False,
                    default=',',
                    help='Field separator for output')
args = parser.parse_args()

context = Context(args.projectDir, None)

s = args.separator

sys.stderr.write("Getting stations from metadata... ")
stations = GenericMetadata.readClimatePointStations(context)
sys.stderr.write("done\n")

for station in stations:
    output = station.id.upper() + s + str(station.latitude) + s + str(
        station.longitude) + s + str(
            station.elevation) + s + station.name + os.linesep
    sys.stdout.write(output)
コード例 #44
0
                    help='The name of the DEM file to be registered.')
parser.add_argument('-f', '--outfile', dest='outfile', required=False,
                    help='The name of the DEM file to be written to the project directory.  File extension ".tif" will be added.')
parser.add_argument('-b', '--publisher', dest='publisher', required=False,
                    help="The publisher of the DEM dataset, if not supplied 'SELF PUBLISHED' will be used")
parser.add_argument('-c', '--demResolution', dest='demResolution', required=False, nargs=2, type=float,
                    help='Two floating point numbers representing the desired X and Y output resolution of soil property raster maps; unit: meters')
parser.add_argument('-t', '--t_srs', dest='t_srs', required=False, 
                    help='Target spatial reference system of output, in EPSG:num format')
parser.add_argument('-s', '--resampleMethod', dest='resampleMethod', required=False,
                    choices=RASTER_RESAMPLE_METHOD, default='bilinear',
                    help='Method to use to resample DEM (if necessary). Defaults to bilinear.')
parser.add_argument('--scale', dest='scale', required=False, type=float,
                    help='Amount to scale input DEM by')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_GDAL_WARP'))

if not os.access(args.demfile, os.R_OK):
    raise IOError(errno.EACCES, "Not allowed to read input DEM %s" (args.demfile,))
inDEMPath = os.path.abspath(args.demfile)
inSpatialMetadata = getSpatialReferenceForRaster(inDEMPath)
コード例 #45
0
 def test_write_and_read(self):
     GenericMetadata.writeManifestEntry(self.context, "key1", "value_one")
     GenericMetadata.writeManifestEntry(self.context, "key2", "value_two")
     manifest = GenericMetadata.readManifestEntries(self.context)
     self.assertTrue(manifest["key1"] == "value_one")
     
     GenericMetadata.writeStudyAreaEntry(self.context, "key1", "value_one")
     GenericMetadata.writeStudyAreaEntry(self.context, "key2", "value_two")
     studyArea = GenericMetadata.readStudyAreaEntries(self.context)
     self.assertTrue(studyArea["key1"] == "value_one")
     
     GenericMetadata.writeClimatePointEntry(self.context, "key1", "value_one")
     GenericMetadata.writeClimatePointEntry(self.context, "key2", "value_two")
     climatePoint = GenericMetadata.readClimatePointEntries(self.context)
     self.assertTrue(climatePoint["key1"] == "value_one")
     
     GenericMetadata.writeClimateGridEntry(self.context, "key1", "value_one")
     GenericMetadata.writeClimateGridEntry(self.context, "key2", "value_two")
     climateGrid = GenericMetadata.readClimateGridEntries(self.context)
     self.assertTrue(climateGrid["key1"] == "value_one")
     
     GenericMetadata.writeHydroShareEntry(self.context, "resource_id", "fae3688aa1354fb2a558380669229a66")
     hydroshare = GenericMetadata.readHydroShareEntries(self.context)
     self.assertTrue(hydroshare["resource_id"] == "fae3688aa1354fb2a558380669229a66")
コード例 #46
0
import argparse

from ecohydrolib.context import Context
from ecohydrolib.metadata import GenericMetadata
from ecohydrolib.metadata import AssetProvenance
import ecohydrolib.ssurgo.attributequery
from ecohydrolib.solim.inference import inferSoilPropertiesForSSURGOAndTerrainData     

# Handle command line options
parser = argparse.ArgumentParser(description='Get SSURGO features for a bounding box')
parser.add_argument('-i', '--configfile', dest='configfile', required=False,
                    help='The configuration file')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('SOLIM', 'PATH_OF_SOLIM'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'SOLIM', 'PATH_OF_SOLIM'))

# Get provenance data for SSURGO
ssurgoProvenance = [i for i in GenericMetadata.readAssetProvenanceObjects(context) if i.name == 'soil_features'][0]
if ssurgoProvenance is None:
    sys.exit("Unable to load SSURGO provenance information from metadata")
import os
import errno
import argparse

from ecohydrolib.context import Context
from ecohydrolib.metadata import GenericMetadata
from ecohydrolib.spatialdata.utils import getBoundingBoxForShapefile

# Handle command line options
parser = argparse.ArgumentParser(description='Get bounding box from study area shapefile')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                    help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-b', '--buffer', dest='buffer', required=False,
                    help='Number of WGS84 degrees by which to buffer the bounding box')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

context = Context(args.projectDir, None)

buffer = 0.01
if args.buffer:
    buffer = float(args.buffer)

# Get name of study area shapefile
manifest = GenericMetadata.readManifestEntries(context)
shapefileName = manifest['study_area_shapefile']

shapefilePath = os.path.join(context.projectDir, shapefileName)
if not os.access(shapefilePath, os.R_OK):
    raise IOError(errno.EACCES, "Unable to read shapefile %s" %
                  args.shapefile)
コード例 #48
0
from ecohydrolib.metadata import GenericMetadata
from ecohydrolib.metadata import AssetProvenance
from ecohydrolib.nhdplus2.networkanalysis import getNHDReachcodeAndMeasureForGageSourceFea
from ecohydrolib.nhdplus2.networkanalysis import getLocationForStreamGageByGageSourceFea
from ecohydrolib.spatialdata.utils import writeCoordinatePairsToPointShapefile

# Handle command line options
parser = argparse.ArgumentParser(description='Get NHDPlus2 streamflow gage identifiers for a USGS gage.')
parser.add_argument('-i', '--configfile', dest='configfile', required=False,
                    help='The configuration file')
parser.add_argument('-p', '--projectDir', dest='projectDir', required=True,
                  help='The directory to which metadata, intermediate, and final files should be saved')
parser.add_argument('-g', '--gageid', dest='gageid', required=True,
                    help='An integer representing the USGS site identifier')
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile) 

if not context.config.has_option('NHDPLUS2', 'PATH_OF_NHDPLUS2_DB'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'NHDPLUS2', 'PATH_OF_NHDPLUS2_DB'))

if not context.config.has_option('NHDPLUS2', 'PATH_OF_NHDPLUS2_GAGELOC'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'NHDPLUS2', 'PATH_OF_NHDPLUS2_GAGELOC'))
コード例 #49
0
    dest='clip',
    required=False,
    action='store_true',
    help=
    'Clip raster to DEM extent.  Will re-sample raster using method specified by resamplingMethod option'
)
parser.add_argument(
    '-b',
    '--publisher',
    dest='publisher',
    required=False,
    help=
    "The publisher of the raster, if not supplied 'SELF PUBLISHED' will be used"
)
args = parser.parse_args()
cmdline = GenericMetadata.getCommandLine()

configFile = None
if args.configfile:
    configFile = args.configfile

context = Context(args.projectDir, configFile)

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_WARP'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_GDAL_WARP'))

if not context.config.has_option('GDAL/OGR', 'PATH_OF_GDAL_TRANSLATE'):
    sys.exit("Config file %s does not define option %s in section %s" & \
          (args.configfile, 'GDAL/OGR', 'PATH_OF_GDAL_TRANSLATE'))