當前位置: 首頁>>代碼示例>>Python>>正文


Python metadata.GenericMetadata類代碼示例

本文整理匯總了Python中ecohydrolib.metadata.GenericMetadata的典型用法代碼示例。如果您正苦於以下問題:Python GenericMetadata類的具體用法?Python GenericMetadata怎麽用?Python GenericMetadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GenericMetadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:58,代碼來源:hydroshare.py

示例2: deleteRHESSysEntry

 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)
開發者ID:Kirubaharan,項目名稱:RHESSysWorkflows,代碼行數:11,代碼來源:metadata.py

示例3: test_empty_read

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:12,代碼來源:test_metadata.py

示例4: writeRHESSysEntry

 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)
開發者ID:Kirubaharan,項目名稱:RHESSysWorkflows,代碼行數:14,代碼來源:metadata.py

示例5: test_write_climate_point1_overwrite

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:50,代碼來源:test_metadata.py

示例6: checkMetadata

    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()
開發者ID:selimnairb,項目名稱:EcohydroLib,代碼行數:25,代碼來源:base.py

示例7: test_version_conflict

 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
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:18,代碼來源:test_metadata.py

示例8: readRHESSysEntries

 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)
開發者ID:Kirubaharan,項目名稱:RHESSysWorkflows,代碼行數:9,代碼來源:metadata.py

示例9: run

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:44,代碼來源:soil.py

示例10: checkMetadata

 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")
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:10,代碼來源:hydroshare.py

示例11: __init__

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:42,代碼來源:context.py

示例12: test_provenance_overwrite

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:40,代碼來源:test_metadata.py

示例13: checkMetadata

 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,))    
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:15,代碼來源:landcover.py

示例14: test_write_climate_point2

 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])
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:44,代碼來源:test_metadata.py

示例15: test_processing_history

 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)
開發者ID:dblodgett-usgs,項目名稱:EcohydroLib,代碼行數:17,代碼來源:test_metadata.py


注:本文中的ecohydrolib.metadata.GenericMetadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。