def step(taskName, parameterByName, folderStore, options): # Get parameters trainingSize = parameterByName.get("training size") testSize = parameterByName.get("test size") positiveFraction = parameterByName.get("positive fraction") # Get names windowNames = parameterByName.get("window names", []) windowPaths = map(folderStore.getWindowPath, windowNames) windowFolderPaths = map(os.path.dirname, windowPaths) windowInformations = map(folderStore.getWindowInformation, windowNames) patchNames = parameterByName.get("patch names", []) patchPaths = map(folderStore.getPatchPath, patchNames) patchFolderPaths = map(os.path.dirname, patchPaths) patchInformations = map(folderStore.getPatchInformation, patchNames) # Set sourceInformations = windowInformations + patchInformations sourceFolderPaths = windowFolderPaths + patchFolderPaths # Make sure that each dataset has the same windowGeoLength windowLengthInMeters = store.validateSame( [x.getWindowLengthInMeters() for x in sourceInformations], "Datasets must have the same window length in meters: %s" % taskName, ) # Make sure that each dataset has the same spatialReference spatialReference = store.validateSame( [x.getSpatialReference() for x in sourceInformations], "Datasets must have the same spatial reference: %s" % taskName, ) # Set targetDatasetPath = folderStore.fillDatasetPath(taskName) targetDatasetFolderPath = os.path.dirname(targetDatasetPath) # Record information = { "parameters": {"training size": trainingSize, "test size": testSize, "positive fraction": positiveFraction}, "windows": {"spatial reference": spatialReference, "window length in meters": windowLengthInMeters}, "sources": { "window names": store.stringifyList(windowNames), "window paths": store.stringifyList(windowPaths), "patch names": store.stringifyList(patchNames), "patch paths": store.stringifyList(patchPaths), }, } # Combine training and test sets if not options.is_test: print "Combining datasets...\n\ttargetDatasetPath = %s" % targetDatasetPath information["training set"] = sample_process.combineDatasets( sample_process.makeTrainingPath(targetDatasetFolderPath), map(sample_process.makeTrainingPath, sourceFolderPaths), trainingSize, positiveFraction, ).getStatistics() information["test set"] = sample_process.combineDatasets( sample_process.makeTestPath(targetDatasetFolderPath), map(sample_process.makeTestPath, sourceFolderPaths), testSize, positiveFraction, ).getStatistics() # Save store.saveInformation(targetDatasetPath, information)
def add(imageName, ownerID, parameterByName): """ Add an image to a database """ # Show feedback print 'Registering image: ' + imageName # Check whether the image has already been registered image = meta.Session.query(model.Image).filter_by(name=imageName).first() # If the image does not exist, if not image: # Register the image in the database image = model.Image(imageName, ownerID) meta.Session.add(image) # Prepare path basePath = parameterByName.get('path', '') # Load multispectral image multispectralImagePath = store.fillPath(basePath, parameterByName['multispectral image']) multispectralImage = image_store.load(multispectralImagePath) multispectralSpatialReference = multispectralImage.getSpatialReference() # Load panchromatic image panchromaticImagePath = store.fillPath(basePath, parameterByName['panchromatic image']) panchromaticImage = image_store.load(panchromaticImagePath) panchromaticSpatialReference = panchromaticImage.getSpatialReference() # Validate spatialReference = store.validateSame([multispectralSpatialReference, panchromaticSpatialReference], 'Spatial references do not match: %s' % imageName) # Update image image.multispectral_path = multispectralImagePath image.panchromatic_path = panchromaticImagePath image.spatial_reference = spatialReference image.is_complete = True meta.Session.commit()