Beispiel #1
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")
Beispiel #2
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)
Beispiel #3
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)
 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)
 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)
Beispiel #6
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")
 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")
    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"

demFilename = "%s.tif" % (outfile)
# Overwrite DEM if already present
demFilepath = os.path.join(context.projectDir, demFilename)
if os.path.exists(demFilepath):
    os.unlink(demFilepath)

# Get study area parameters
studyArea = GenericMetadata.readStudyAreaEntries(context)
bbox = bboxFromString(studyArea['bbox_wgs84'])

# Determine target spatial reference
if args.t_srs:
    if not isValidSrs(args.t_srs):
        sys.exit(textwrap.fill("ERROR: '%s' is not a valid spatial reference.  Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'.  For more information, see: http://www.spatialreference.org/" % (args.t_srs,) ) )
    t_srs = args.t_srs
else:
    # Default for UTM
    (centerLon, centerLat) = calculateBoundingBoxCenter(bbox)
    (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat)
    t_srs = getEPSGStringForUTMZone(utmZone, isNorth)

# Get DEM from DEMExplorer
sys.stdout.write('Downloading DEM from DEMExplorer...')
    sys.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"

demFilename = "%s.tif" % (outfile)
# Overwrite DEM if already present
demFilepath = os.path.join(context.projectDir, demFilename)
if os.path.exists(demFilepath):
    os.unlink(demFilepath)

# Get study area parameters
studyArea = GenericMetadata.readStudyAreaEntries(context)
bbox = bboxFromString(studyArea['bbox_wgs84'])

# Determine target spatial reference
if args.t_srs:
    if not isValidSrs(args.t_srs):
        sys.exit(
            textwrap.fill(
                "ERROR: '%s' is not a valid spatial reference.  Spatial reference must be of the form 'EPSG:XXXX', e.g. 'EPSG:32617'.  For more information, see: http://www.spatialreference.org/"
                % (args.t_srs, )))
    t_srs = args.t_srs
else:
    # Default for UTM
    (centerLon, centerLat) = calculateBoundingBoxCenter(bbox)
    (utmZone, isNorth) = getUTMZoneFromCoordinates(centerLon, centerLat)
    t_srs = getEPSGStringForUTMZone(utmZone, isNorth)
parser.add_argument('-c', '--collection', dest='collection', required=True,
                    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)
    writeAVUToXMLFile(outfile, target, 'dc.title', entry.dcTitle)