def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "statistics" super(zonalStatistics, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.RAM = 1024.0 * get_RAM(self.resources["ram"]) self.workingDirectory = workingDirectory self.outputPath = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.outfilesvectpath = os.path.join(self.outputPath, 'final', 'simplification', 'vectors') self.rastclass = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'classification') self.rastconf = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'confidence') self.rastval = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'validity') self.seed = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'seed') self.bingdal = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'bingdal') self.chunk = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'chunk') self.statslist = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'statslist') self.nomenclature = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'nomenclature') self.systemcall = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'systemcall') if self.rastclass is None: if self.seed is not None: self.rastclass = os.path.join( self.outputPath, 'final', 'Classif_Seed_{}.tif'.format(self.seed)) if self.rastconf is None: self.rastconf = os.path.join( self.outputPath, 'final', 'Confidence_Seed_{}.tif'.format(self.seed)) else: if os.path.exists( os.path.join(self.outputPath, 'final', 'Classifications_fusion.tif')): self.rastclass = os.path.join( self.outputPath, 'final', 'Classifications_fusion.tif') else: self.rastclass = os.path.join(self.outputPath, 'final', 'Classif_Seed_0.tif') # Pas de fusion de confidence ? if self.rastval is None: self.rastval = os.path.join(self.outputPath, 'final', 'PixelsValidity.tif') if self.rastconf is None: self.rastconf = os.path.join(self.outputPath, 'final', 'Confidence_Seed_0.tif')
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ from iota2.Common import FileUtils as fut from iota2.Classification.ImageClassifier import autoContext_classification_param from iota2.Common.ServiceConfigFile import iota2_parameters if self.enable_autoContext is False and self.use_scikitlearn is False: parameters = fut.parseClassifCmd( os.path.join(self.output_path, "cmd", "cla", "class.txt")) elif self.enable_autoContext is True: parameters = autoContext_classification_param( self.output_path, self.data_field) elif self.use_scikitlearn: parameters = fut.parseClassifCmd( os.path.join(self.output_path, "cmd", "cla", "class.txt")) running_parameters = iota2_parameters(self.cfg) parameters = [{ "mask": param[1], "model": param[2], "stat": param[3], "out_classif": param[4], "out_confidence": param[5], "out_proba": None, "working_dir": param[6], "tile_name": param[8], "sar_optical_post_fusion": SCF.serviceConfigFile(self.cfg).getParam( 'argTrain', 'dempster_shafer_SAR_Opt_fusion'), "output_path": SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath'), "sensors_parameters": running_parameters.get_sensors_parameters(tile_name=param[8]), "pixel_type": param[17], "number_of_chunks": self.scikit_tile_split, "targeted_chunk": target_chunk, "ram": param[19] } for param in parameters for target_chunk in range(self.scikit_tile_split)] return parameters
def step_execute(self): """ Return ------ lambda the function to execute as a lambda function. The returned object must be a lambda function. """ from iota2.Sampling import SplitSamples as splitS from iota2.Common import ServiceConfigFile as SCF step_function = lambda x: splitS.split_samples( SCF.serviceConfigFile(x).getParam("chain", "outputPath"), SCF.serviceConfigFile(x).getParam("chain", "dataField"), SCF.serviceConfigFile(x).getParam("chain", "enableCrossValidation" ), SCF.serviceConfigFile(x).getParam("chain", "mode_outside_RegionSplit"), SCF.serviceConfigFile(x).getParam("chain", "regionField"), SCF.serviceConfigFile(x).getParam("chain", "ratio"), SCF.serviceConfigFile(x).getParam("chain", "random_seed"), SCF.serviceConfigFile(x).getParam("chain", "runs"), SCF.serviceConfigFile(x).getParam("GlobChain", "proj"), self. workingDirectory) return step_function
def get_steps_number(self): start = SCF.serviceConfigFile(self.cfg).getParam('chain', 'firstStep') end = SCF.serviceConfigFile(self.cfg).getParam('chain', 'lastStep') start_ind = list(self.steps_group.keys()).index(start) end_ind = list(self.steps_group.keys()).index(end) steps = [] for key in list(self.steps_group.keys())[start_ind:end_ind + 1]: steps.append(self.steps_group[key]) step_to_compute = [step for step_group in steps for step in step_group] return step_to_compute
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "mergeOutStats" super(additionalStatisticsMerge, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.runs = SCF.serviceConfigFile(self.cfg).getParam('chain', 'runs')
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "samplesStatistics" super(statsSamplesModel, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.data_field = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'dataField')
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "samplesSelection" super(samplingLearningPolygons, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.enable_cross_validation = SCF.serviceConfigFile( self.cfg).getParam('chain', 'enableCrossValidation')
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "envelope" super(Envelope, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.outputPath = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.proj = int( SCF.serviceConfigFile(self.cfg).getParam('GlobChain', 'proj').split(":")[-1])
def step_execute(self): """ Return ------ lambda the function to execute as a lambda function. The returned object must be a lambda function. """ from iota2.Validation import ClassificationShaping as CS region_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'regionPath') classif_mode = SCF.serviceConfigFile(self.cfg).getParam( "argClassification", "classifMode") ds_fusion_sar_opt = SCF.serviceConfigFile(self.cfg).getParam( "argTrain", "dempster_shafer_SAR_Opt_fusion") proj = int( SCF.serviceConfigFile(self.cfg).getParam('GlobChain', 'proj').split(":")[-1]) nomenclature_path = SCF.serviceConfigFile(self.cfg).getParam( "chain", "nomenclaturePath") enable_proba_map = SCF.serviceConfigFile(self.cfg).getParam( "argClassification", "enable_probability_map") spatial_res = SCF.serviceConfigFile(self.cfg).getParam( "chain", "spatialResolution") output_statistics = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputStatistics') step_function = lambda x: CS.classification_shaping( x, self.runs, os.path.join(self.output_path, "final"), self. workingDirectory, classif_mode, self.output_path, ds_fusion_sar_opt, proj, nomenclature_path, output_statistics, spatial_res, enable_proba_map, region_path, self.color_table) return step_function
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "dimensionalityReduction" super(samplesDimReduction, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.targetDimension = SCF.serviceConfigFile(self.cfg).getParam( 'dimRed', 'targetDimension') self.reductionMode = SCF.serviceConfigFile(self.cfg).getParam( 'dimRed', 'reductionMode')
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "confusionMatrixFusion" super(confusionsMerge, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.data_field = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'dataField') self.ground_truth = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'groundTruth')
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "training" super(learnModel, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.data_field = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'dataField') self.region_field = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'regionField') self.runs = SCF.serviceConfigFile(self.cfg).getParam('chain', 'runs') self.enable_autoContext = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'enable_autoContext') self.autoContext_iterations = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'autoContext_iterations') self.RAM = 1024.0 * get_RAM(self.resources["ram"]) self.superpix_data_field = "superpix" self.tiles = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'listTile').split("_") self.available_ram = 1024.0 * get_RAM(self.resources["ram"]) self.use_scikitlearn = SCF.serviceConfigFile(self.cfg).getParam( 'scikit_models_parameters', 'model_type') is not None
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "cmdClassifications" super(classiCmd, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.field_region = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'regionField') self.runs = SCF.serviceConfigFile(self.cfg).getParam('chain', 'runs') self.region_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'regionPath') self.ram_classification = 1024.0 * get_RAM(self.resources["ram"])
def test_samples_selection(self): """ test sampling of a shape file (main function of SamplesSelection.py) """ from iota2.Sampling.SamplesSelection import samples_selection from iota2.Common import IOTA2Directory from iota2.Common import ServiceConfigFile as SCF from iota2.Tests.UnitTests.Iota2Tests import compareSQLite from iota2.Common.FileUtils import cpShapeFile from iota2.Common import FileUtils as fut # prepare test input cfg = SCF.serviceConfigFile(self.config_test) cfg.setParam( "chain", "outputPath", os.path.join(self.test_working_directory, "samplesSelTest")) cfg.setParam("chain", "runs", 2) cfg.setParam("argTrain", "sampleSelection", { "sampler": "random", "strategy": "all" }) # create IOTA2 directories IOTA2Directory.generate_directories(os.path.join( self.test_working_directory, "samplesSelTest"), check_inputs=False) shutil.copytree( self.features_ref, os.path.join(self.test_working_directory, "samplesSelTest", "features", "T31TCJ")) shutil.copy( self.in_xml, os.path.join(self.test_working_directory, "samplesSelTest", "samplesSelection", "T31TCJ_region_1_seed_0_stats.xml")) _, in_shape_name = os.path.split(self.in_shape) in_shape_dir = os.path.join(self.test_working_directory, "samplesSelTest", "samplesSelection") in_shape = os.path.join(in_shape_dir, in_shape_name) cpShapeFile(self.in_shape.replace(".shp", ""), in_shape.replace(".shp", ""), extensions=[".prj", ".shp", ".dbf", ".shx"]) #~ # launch function output_path = cfg.getParam("chain", "outputPath") runs = cfg.getParam('chain', 'runs') epsg = cfg.getParam('GlobChain', 'proj') random_seed = cfg.getParam('chain', 'random_seed') data_field = cfg.getParam('chain', 'dataField').lower() parameters = dict(cfg.getParam('argTrain', 'sampleSelection')) masks_name = "MaskCommunSL.tif" samples_selection(in_shape, self.test_working_directory, output_path, runs, epsg, masks_name, parameters, data_field, random_seed) #~ # assert selection_test = fut.FileSearch_AND( os.path.join(self.test_working_directory, "samplesSelTest"), True, os.path.basename(self.selection_ref))[0] same = compareSQLite(self.selection_ref, selection_test, CmpMode='coordinates') self.assertTrue(same, msg="sample selection generation failed")
def setUpClass(self): from iota2.Common import ServiceConfigFile as SCF # We initialize the expected mergeSamples for the function get_models() self.expectedOutputGetModels = [('1', ['T31TCJ'], 0), ('1', ['T31TCJ'], 1)] # Copy and remove files in the test folder if os.path.exists(IOTA2_DATATEST + '/test_vector/test_mergeSamples'): shutil.rmtree(IOTA2_DATATEST + '/test_vector/test_mergeSamples') shutil.copytree(IOTA2_DATATEST + '/references/mergeSamples/Input', IOTA2_DATATEST + '/test_vector/test_mergeSamples') if not os.path.exists(IOTA2_DATATEST + '/test_vector/test_mergeSamples/' 'samples_merge/samplesSelection/'): os.mkdir(IOTA2_DATATEST + '/test_vector/test_mergeSamples/' 'samples_merge/samplesSelection/') # We define several parameters for the configuration file self.cfg = SCF.serviceConfigFile( IOTA2_DATATEST + '/test_vector/test_mergeSamples/config.cfg') self.cfg.setParam( 'chain', 'outputPath', IOTA2_DATATEST + '/test_vector/test_mergeSamples/samples_merge') self.cfg.setParam('chain', 'regionField', 'region')
def setUp(self): self.input_sample_file_name = IOTA2_DATATEST + 'dim_red_samples.sqlite' self.target_dimension = 6 self.fl_date = [ 'landsat8_b1_20140118', 'landsat8_b2_20140118', 'landsat8_b3_20140118', 'landsat8_b4_20140118', 'landsat8_b5_20140118', 'landsat8_b6_20140118', 'landsat8_b7_20140118', 'landsat8_ndvi_20140118', 'landsat8_ndwi_20140118', 'landsat8_brightness_20140118' ] self.stats_file = os.path.join(IOTA2_DATATEST, 'dim_red_stats.xml') self.test_stats_file = os.path.join(IOTA2_DATATEST, 'tmp', 'stats.xml') self.output_model_file_name = os.path.join(IOTA2_DATATEST, 'model.pca') self.test_output_model_file_name = os.path.join( IOTA2_DATATEST, 'tmp', 'model.pca') self.reduced_output_file_name = os.path.join(IOTA2_DATATEST, 'reduced.sqlite') self.test_reduced_output_file_name = os.path.join( IOTA2_DATATEST, 'tmp', 'reduced.sqlite') self.test_joint_reduced_file = os.path.join(IOTA2_DATATEST, 'tmp', 'joint.sqlite') self.joint_reduced_file = os.path.join(IOTA2_DATATEST, 'joint.sqlite') self.output_sample_file_name = 'reduced_output_samples.sqlite' self.test_output_sample_file_name = ('reduced_output_' 'samples_test.sqlite') self.config_file = os.path.join( IOTA2DIR, "config", "Config_4Tuiles_Multi_FUS_Confidence.cfg") self.cfg = SCF.serviceConfigFile(self.config_file)
def test_reorder_proba_map(self): """ TEST : ImageClassifier.iota2Classification.reorder_proba_map() """ from iota2.Common import ServiceConfigFile as SCF from iota2.Classification.ImageClassifier import iota2Classification # prepare inputs probamap_arr = [ np.array([[268, 528, 131], [514, 299, 252], [725, 427, 731]]), np.array([[119, 241, 543], [974, 629, 626], [3, 37, 819]]), np.array([[409, 534, 710], [916, 43, 993], [207, 68, 282]]), np.array([[820, 169, 423], [710, 626, 525], [377, 777, 461]]), np.array([[475, 116, 395], [838, 297, 262], [650, 828, 595]]), np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) ] probamap_path = os.path.join(self.test_working_directory, "PROBAMAP_T31TCJ_model_1_seed_0.tif") TUR.array_to_raster(probamap_arr, probamap_path) cfg = SCF.serviceConfigFile(self.config_test) fake_model = "model_1_seed_0.txt" fake_tile = "T31TCJ" fake_output_directory = "fake_output_directory" classifier = iota2Classification( features_stack=None, classifier_type=None, model=fake_model, tile=fake_tile, output_directory=fake_output_directory, models_class=None) class_model = [1, 2, 3, 4, 6] all_class = [1, 2, 3, 4, 5, 6] proba_map_path_out = os.path.join( self.test_working_directory, "PROBAMAP_T31TCJ_model_1_seed_0_ORDERED.tif") classifier.reorder_proba_map(probamap_path, proba_map_path_out, class_model, all_class) # assert probamap_arr_ref = [ np.array([[268, 528, 131], [514, 299, 252], [725, 427, 731]]), np.array([[119, 241, 543], [974, 629, 626], [3, 37, 819]]), np.array([[409, 534, 710], [916, 43, 993], [207, 68, 282]]), np.array([[820, 169, 423], [710, 626, 525], [377, 777, 461]]), np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]), np.array([[475, 116, 395], [838, 297, 262], [650, 828, 595]]) ] reordered_test_arr = rasterToArray(proba_map_path_out) self.assertEqual(len(all_class), len(reordered_test_arr)) is_bands_ok = [] for band in range(len(reordered_test_arr)): band_ref = probamap_arr_ref[band] band_test = reordered_test_arr[band] for ref_val, test_val in zip(band_ref.flat, band_test.flat): is_bands_ok.append(int(ref_val) == int(test_val)) self.assertTrue(all(is_bands_ok), msg="reordering probability maps failed")
def step_execute(self): """ Return ------ lambda the function to execute as a lambda function. The returned object must be a lambda function. """ from iota2.Common.Tools import CoRegister cfg = SCF.serviceConfigFile(self.cfg) l5_path = None l8_path = None s2_path = None s2_s2c_path = None correg_pattern = None if cfg.getParam('chain', 'L5Path_old').lower() != "none": l5_path = cfg.getParam('chain', 'L5Path_old') if cfg.getParam('chain', 'S2Path').lower() != "none": l8_path = cfg.getParam('chain', 'L8Path_old') if cfg.getParam('chain', 'S2Path').lower() != "none": s2_path = cfg.getParam('chain', 'S2Path') if cfg.getParam('chain', 'S2_S2C_Path').lower() != "none": s2_s2c_path = cfg.getParam('chain', 'S2_S2C_Path') if cfg.getParam('coregistration', 'pattern').lower != "none": correg_pattern = cfg.getParam('coregistration', 'pattern') sensors_parameters = SCF.iota2_parameters(self.cfg) return lambda x: CoRegister.launch_coregister( x, self.workingDirectory, cfg.getParam('coregistration', 'VHRPath' ), cfg.getParam('coregistration', 'bandSrc'), cfg.getParam('coregistration', 'bandRef'), cfg.getParam('coregistration', 'resample'), cfg.getParam('coregistration', 'step'), cfg.getParam('coregistration', 'minstep'), cfg.getParam('coregistration', 'minsiftpoints'), cfg.getParam('coregistration', 'iterate'), cfg.getParam('coregistration', 'prec'), cfg.getParam('coregistration', 'mode'), cfg.getParam("chain", "outputPath"), cfg.getParam('coregistration', 'dateVHR'), cfg.getParam('coregistration', 'dateSrc'), cfg.getParam('chain', 'listTile'), l5_path, l8_path, s2_path, s2_s2c_path, correg_pattern, True, sensors_parameters.get_sensors_parameters(x))
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "smoothing" super(largeSmoothing, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.RAM = 1024.0 * get_RAM(self.resources["ram"]) self.workingDirectory = workingDirectory self.outputPath = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.grasslib = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'grasslib') self.hermite = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'hermite') self.mmu = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'mmu') self.outmos = os.path.join(self.outputPath, 'final', 'simplification', 'mosaic') self.clipfile = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'clipfile') self.clipfield = SCF.serviceConfigFile(self.cfg).getParam( 'Simplification', 'clipfield') self.grid = os.path.join(self.outputPath, 'final', 'simplification', 'grid.shp') self.epsg = int( SCF.serviceConfigFile(self.cfg).getParam('GlobChain', 'proj').split(":")[-1])
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "classifShaping" super(mosaic, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath') self.runs = SCF.serviceConfigFile(self.cfg).getParam('chain', 'runs') self.enable_cross_validation = SCF.serviceConfigFile( self.cfg).getParam('chain', 'enableCrossValidation') if self.enable_cross_validation: self.runs = self.runs - 1 self.fieldEnv = "FID" self.color_table = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'colorTable')
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ return [ SCF.serviceConfigFile(self.cfg).getParam('chain', 'outputPath') ]
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ shapeRegion = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'regionPath') return [shapeRegion]
def __init__(self, cfg, cfg_resources_file): # heritage init resources_block_name = "mergeSample" super(samplesByModels, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath')
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ tiles = SCF.serviceConfigFile(self.cfg).getParam('chain', 'listTile').split(" ") return tiles
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "regionShape" super(genRegionVector, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.outputPath = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath')
def step_execute(self): """ Return ------ lambda the function to execute as a lambda function. The returned object must be a lambda function. """ from iota2.Validation import ConfusionFusion as confFus step_function = lambda x: confFus.confusion_fusion( x, self.data_field, os.path.join(self.output_path, "final", "TMP"), os.path.join(self.output_path, "final", "TMP"), os.path.join(self.output_path, "final", "TMP"), SCF.serviceConfigFile(self.cfg).getParam('chain', 'runs'), SCF.serviceConfigFile(self.cfg).getParam('argTrain', 'cropMix'), SCF.serviceConfigFile(self.cfg).getParam('argTrain', 'annualCrop'), (SCF.serviceConfigFile(self.cfg).getParam( 'argTrain', 'ACropLabelReplacement').data)[0]) return step_function
def __init__(self, cfg, cfg_resources_file, workingDirectory=None): # heritage init resources_block_name = "fusion" super(classificationsFusion, self).__init__(cfg, cfg_resources_file, resources_block_name) # step variables self.workingDirectory = workingDirectory self.output_path = SCF.serviceConfigFile(self.cfg).getParam( 'chain', 'outputPath')
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ return vs.get_vectors_to_sample( os.path.join(self.output_path, "formattingVectors"), SCF.serviceConfigFile(self.cfg).getParam( 'argTrain', 'dempster_shafer_SAR_Opt_fusion'))
def step_inputs(self): """ Return ------ the return could be and iterable or a callable """ from iota2.Learning import TrainingCmd as TC from iota2.Learning import TrainSkLearn from iota2.Learning.trainAutoContext import train_autoContext_parameters parameters = [] pathToModelConfig = os.path.join(self.output_path, "config_model", "configModel.cfg") configModel = config_model(self.output_path, self.region_field) if not os.path.exists(pathToModelConfig): with open(pathToModelConfig, "w") as configFile: configFile.write(configModel) if self.use_scikitlearn is True and self.enable_autoContext is True: raise ValueError( "scikit-learn and autoContext modes are not compatibles") elif self.use_scikitlearn is True and self.enable_autoContext is False: parameters = TrainSkLearn.get_learning_samples( os.path.join(self.output_path, "learningSamples"), self.cfg) elif self.enable_autoContext is True: parameters = train_autoContext_parameters(self.output_path, self.region_field) else: parameters = TC.launch_training( classifier_name=SCF.serviceConfigFile(self.cfg).getParam( "argTrain", "classifier"), classifier_options=SCF.serviceConfigFile(self.cfg).getParam( "argTrain", "options"), output_path=self.output_path, ground_truth=SCF.serviceConfigFile(self.cfg).getParam( "chain", "groundTruth"), data_field=self.data_field, region_field=SCF.serviceConfigFile(self.cfg).getParam( "chain", "regionField"), path_to_cmd_train=os.path.join(self.output_path, "cmd", "train"), out=os.path.join(self.output_path, "model")) return parameters
def test_ds_fusion(self): """ TEST : Fusion.dempster_shafer_fusion. Every functions called in Fusion.dempster_shafer_fusion are tested above. This test check the runnability of Fusion.dempster_shafer_fusion """ from iota2.Classification import Fusion from iota2.Common import IOTA2Directory from iota2.Common import ServiceConfigFile as SCF # define inputs cfg = SCF.serviceConfigFile(self.config_test) iota2_dir = os.path.join(self.test_working_directory, "fusionTest") cfg.setParam('chain', 'outputPath', iota2_dir) IOTA2Directory.generate_directories(iota2_dir, check_inputs=False) sar_raster = os.path.join(iota2_dir, "classif", "Classif_T31TCJ_model_1_seed_0_SAR.tif") opt_raster = os.path.join(iota2_dir, "classif", "Classif_T31TCJ_model_1_seed_0.tif") array_to_raster(self.sar_classif, sar_raster) array_to_raster(self.optical_classif, opt_raster) sar_confid_raster = os.path.join( iota2_dir, "classif", "T31TCJ_model_1_confidence_seed_0_SAR.tif") opt_confid_raster = os.path.join( iota2_dir, "classif", "T31TCJ_model_1_confidence_seed_0.tif") array_to_raster(self.sar_confidence, sar_confid_raster, output_format="float") array_to_raster(self.optical_confidence, opt_confid_raster, output_format="float") fusion_dic = { "sar_classif": sar_raster, "opt_classif": opt_raster, "sar_model": self.sar_confusion, "opt_model": self.opt_confusion } workingDirectory = None # Launch function (fusion_path, confidence_path, probamap_path, choice_path) = Fusion.dempster_shafer_fusion( iota2_dir, fusion_dic, mob="precision", workingDirectory=workingDirectory) self.assertEqual("/classif/Classif_T31TCJ_model_1_seed_0_DS.tif", fusion_path.replace(iota2_dir, "")) self.assertEqual("/classif/T31TCJ_model_1_confidence_seed_0_DS.tif", confidence_path.replace(iota2_dir, "")) self.assertEqual("/final/TMP/DSchoice_T31TCJ_model_1_seed_0.tif", choice_path.replace(iota2_dir, "")) self.assertTrue(probamap_path is None)