Search in sources :

Example 1 with KdeCommand

use of org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand in project geowave by locationtech.

the class KDEJobRunner method main.

public static void main(final String[] args) throws Exception {
    final ConfigOptions opts = new ConfigOptions();
    final OperationParser parser = new OperationParser();
    parser.addAdditionalObject(opts);
    final KdeCommand command = new KdeCommand();
    final CommandLineOperationParams params = parser.parse(command, args);
    opts.prepare(params);
    final int res = ToolRunner.run(new Configuration(), command.createRunner(params), args);
    System.exit(res);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CommandLineOperationParams(org.locationtech.geowave.core.cli.parser.CommandLineOperationParams) KdeCommand(org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand) OperationParser(org.locationtech.geowave.core.cli.parser.OperationParser) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions)

Example 2 with KdeCommand

use of org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand in project geowave by locationtech.

the class ComparisonStatsJobRunner method main.

public static void main(final String[] args) throws Exception {
    final ConfigOptions opts = new ConfigOptions();
    final ComparisonCommandLineOptions comparisonOptions = new ComparisonCommandLineOptions();
    final OperationParser parser = new OperationParser();
    parser.addAdditionalObject(opts);
    parser.addAdditionalObject(comparisonOptions);
    final KdeCommand kdeCommand = new KdeCommand();
    final CommandLineOperationParams params = parser.parse(kdeCommand, args);
    // Load the params for config file.
    opts.prepare(params);
    final File configFile = (File) params.getContext().get(ConfigOptions.PROPERTIES_FILE_CONTEXT);
    // Don't care about output, but this will set the datastore options.
    kdeCommand.createRunner(params);
    final ComparisonStatsJobRunner runner = new ComparisonStatsJobRunner(comparisonOptions, kdeCommand.getKdeOptions(), kdeCommand.getInputStoreOptions(), kdeCommand.getOutputStoreOptions(), configFile, null);
    final int res = ToolRunner.run(new Configuration(), runner, args);
    System.exit(res);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CommandLineOperationParams(org.locationtech.geowave.core.cli.parser.CommandLineOperationParams) KdeCommand(org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand) OperationParser(org.locationtech.geowave.core.cli.parser.OperationParser) File(java.io.File) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions)

Example 3 with KdeCommand

use of org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand in project geowave by locationtech.

the class GeoWaveGrpcAnalyticMapreduceService method kdeCommand.

@Override
public void kdeCommand(final KdeCommandParametersProtos request, final StreamObserver<VoidResponseProtos> responseObserver) {
    final KdeCommand cmd = new KdeCommand();
    final Map<FieldDescriptor, Object> m = request.getAllFields();
    GeoWaveGrpcServiceCommandUtil.setGrpcToCommandFields(m, cmd);
    final File configFile = GeoWaveGrpcServiceOptions.geowaveConfigFile;
    final OperationParams params = new ManualOperationParams();
    params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
    cmd.prepare(params);
    try {
        cmd.computeResults(params);
    } catch (final Exception e) {
        LOGGER.error("Exception encountered executing command", e);
        responseObserver.onError(e);
    }
    LOGGER.info("Executing KdeCommand...");
    try {
        final VoidResponseProtos resp = VoidResponseProtos.newBuilder().build();
        responseObserver.onNext(resp);
        responseObserver.onCompleted();
    } catch (final Exception e) {
        LOGGER.error("Exception encountered executing command", e);
        responseObserver.onError(e);
    }
}
Also used : VoidResponseProtos(org.locationtech.geowave.service.grpc.protobuf.GeoWaveReturnTypesProtos.VoidResponseProtos) OperationParams(org.locationtech.geowave.core.cli.api.OperationParams) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) KdeCommand(org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand) File(java.io.File) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams)

Example 4 with KdeCommand

use of org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand in project geowave by locationtech.

the class CustomCRSKDERasterResizeIT method testKDEAndRasterResize.

@Test
public void testKDEAndRasterResize() throws Exception {
    TestUtils.deleteAll(inputDataStorePluginOptions);
    TestUtils.testLocalIngest(inputDataStorePluginOptions, DimensionalityType.SPATIAL, "EPSG:4901", KDE_SHAPEFILE_FILE, "geotools-vector", 1);
    final File configFile = File.createTempFile("test_export", null);
    final ManualOperationParams params = new ManualOperationParams();
    params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
    final AddStoreCommand addStore = new AddStoreCommand();
    addStore.setParameters("test-in");
    addStore.setPluginOptions(inputDataStorePluginOptions);
    addStore.execute(params);
    addStore.setParameters("raster-spatial");
    addStore.setPluginOptions(outputDataStorePluginOptions);
    addStore.execute(params);
    final String outputIndexName = "raster-spatial-idx";
    final IndexPluginOptions outputIndexOptions = new IndexPluginOptions();
    outputIndexOptions.selectPlugin("spatial");
    outputIndexOptions.setName(outputIndexName);
    ((SpatialOptions) outputIndexOptions.getDimensionalityOptions()).setCrs("EPSG:4240");
    final DataStore outputDataStore = outputDataStorePluginOptions.createDataStore();
    final Index outputIndex = outputIndexOptions.createIndex(outputDataStore);
    outputDataStore.addIndex(outputIndex);
    // use the min level to define the request boundary because it is the
    // most coarse grain
    final double decimalDegreesPerCellMinLevel = 180.0 / Math.pow(2, BASE_MIN_LEVEL);
    final double cellOriginXMinLevel = Math.round(TARGET_MIN_LON / decimalDegreesPerCellMinLevel);
    final double cellOriginYMinLevel = Math.round(TARGET_MIN_LAT / decimalDegreesPerCellMinLevel);
    final double numCellsMinLevel = Math.round(TARGET_DECIMAL_DEGREES_SIZE / decimalDegreesPerCellMinLevel);
    final GeneralEnvelope queryEnvelope = new GeneralEnvelope(new double[] { // scaling on the tile composition/rendering
    decimalDegreesPerCellMinLevel * cellOriginXMinLevel, decimalDegreesPerCellMinLevel * cellOriginYMinLevel }, new double[] { // scaling
    decimalDegreesPerCellMinLevel * (cellOriginXMinLevel + numCellsMinLevel), decimalDegreesPerCellMinLevel * (cellOriginYMinLevel + numCellsMinLevel) });
    final MapReduceTestEnvironment env = MapReduceTestEnvironment.getInstance();
    final String geomField = ((FeatureDataAdapter) inputDataStorePluginOptions.createDataStore().getTypes()[0]).getFeatureType().getGeometryDescriptor().getLocalName();
    final Envelope cqlEnv = JTS.transform(new Envelope(155.12, 155.17, 16.07, 16.12), CRS.findMathTransform(CRS.decode("EPSG:4326"), CRS.decode("EPSG:4901"), true));
    final String cqlStr = String.format("BBOX(%s, %f, %f, %f, %f)", geomField, cqlEnv.getMinX(), cqlEnv.getMinY(), cqlEnv.getMaxX(), cqlEnv.getMaxY());
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running mapreduce kde: " + i);
        final String tileSizeCoverageName = TEST_COVERAGE_NAME_MR_PREFIX + i;
        final KdeCommand command = new KdeCommand();
        command.setParameters("test-in", "raster-spatial");
        command.getKdeOptions().setCqlFilter(cqlStr);
        command.getKdeOptions().setOutputIndex(outputIndexName);
        command.getKdeOptions().setFeatureType(KDE_FEATURE_TYPE_NAME);
        command.getKdeOptions().setMinLevel(BASE_MIN_LEVEL);
        command.getKdeOptions().setMaxLevel(BASE_MAX_LEVEL);
        command.getKdeOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getKdeOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getKdeOptions().setCoverageName(tileSizeCoverageName);
        command.getKdeOptions().setHdfsHostPort(env.getHdfs());
        command.getKdeOptions().setJobTrackerOrResourceManHostPort(env.getJobtracker());
        command.getKdeOptions().setTileSize((int) Math.pow(2, i));
        ToolRunner.run(command.createRunner(params), new String[] {});
    }
    final int numLevels = (BASE_MAX_LEVEL - BASE_MIN_LEVEL) + 1;
    final double[][][][] initialSampleValuesPerRequestSize = new double[numLevels][][][];
    LOGGER.warn("testing mapreduce kdes");
    for (int l = 0; l < numLevels; l++) {
        initialSampleValuesPerRequestSize[l] = testSamplesMatch(TEST_COVERAGE_NAME_MR_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), null);
    }
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running spark kde: " + i);
        final String tileSizeCoverageName = TEST_COVERAGE_NAME_SPARK_PREFIX + i;
        final KDESparkCommand command = new KDESparkCommand();
        // We're going to override these anyway.
        command.setParameters("test-in", "raster-spatial");
        command.getKDESparkOptions().setOutputIndex(outputIndexName);
        command.getKDESparkOptions().setCqlFilter(cqlStr);
        command.getKDESparkOptions().setTypeName(KDE_FEATURE_TYPE_NAME);
        command.getKDESparkOptions().setMinLevel(BASE_MIN_LEVEL);
        command.getKDESparkOptions().setMaxLevel(BASE_MAX_LEVEL);
        command.getKDESparkOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getKDESparkOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getKDESparkOptions().setCoverageName(tileSizeCoverageName);
        command.getKDESparkOptions().setMaster("local[*]");
        command.getKDESparkOptions().setTileSize((int) Math.pow(2, i));
        command.execute(params);
    }
    LOGGER.warn("testing spark kdes");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_COVERAGE_NAME_SPARK_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
    // go from the original mr KDEs to a resized version using the MR command
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running mapreduce resize: " + i);
        final String originalTileSizeCoverageName = TEST_COVERAGE_NAME_MR_PREFIX + i;
        final String resizeTileSizeCoverageName = TEST_RESIZE_COVERAGE_NAME_MR_PREFIX + i;
        final ResizeMRCommand command = new ResizeMRCommand();
        // We're going to override these anyway.
        command.setParameters("raster-spatial", "raster-spatial");
        command.getOptions().setInputCoverageName(originalTileSizeCoverageName);
        command.getOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.setHdfsHostPort(env.getHdfs());
        command.setJobTrackerOrResourceManHostPort(env.getJobtracker());
        command.getOptions().setOutputCoverageName(resizeTileSizeCoverageName);
        command.getOptions().setIndexName(TestUtils.createWebMercatorSpatialIndex().getName());
        // due to time considerations when running the test, downsample to
        // at most 2 powers of 2 lower
        int targetRes = (MAX_TILE_SIZE_POWER_OF_2 - i);
        if ((i - targetRes) > 2) {
            targetRes = i - 2;
        }
        command.getOptions().setOutputTileSize((int) Math.pow(2, targetRes));
        ToolRunner.run(command.createRunner(params), new String[] {});
    }
    LOGGER.warn("testing mapreduce resize");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_RESIZE_COVERAGE_NAME_MR_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
    // Spark command
    for (int i = MIN_TILE_SIZE_POWER_OF_2; i <= MAX_TILE_SIZE_POWER_OF_2; i += INCREMENT) {
        LOGGER.warn("running spark resize: " + i);
        final String originalTileSizeCoverageName = TEST_COVERAGE_NAME_SPARK_PREFIX + i;
        final String resizeTileSizeCoverageName = TEST_RESIZE_COVERAGE_NAME_SPARK_PREFIX + i;
        final ResizeSparkCommand command = new ResizeSparkCommand();
        // We're going to override these anyway.
        command.setParameters("raster-spatial", "raster-spatial");
        command.getOptions().setInputCoverageName(originalTileSizeCoverageName);
        command.getOptions().setMinSplits(MapReduceTestUtils.MIN_INPUT_SPLITS);
        command.getOptions().setMaxSplits(MapReduceTestUtils.MAX_INPUT_SPLITS);
        command.getOptions().setOutputCoverageName(resizeTileSizeCoverageName);
        command.getOptions().setIndexName(TestUtils.createWebMercatorSpatialIndex().getName());
        command.setMaster("local[*]");
        // due to time considerations when running the test, downsample to
        // at most 2 powers of 2 lower
        int targetRes = (MAX_TILE_SIZE_POWER_OF_2 - i);
        if ((i - targetRes) > 2) {
            targetRes = i - 2;
        }
        command.getOptions().setOutputTileSize((int) Math.pow(2, targetRes));
        command.execute(params);
    }
    LOGGER.warn("testing spark resize");
    for (int l = 0; l < numLevels; l++) {
        testSamplesMatch(TEST_RESIZE_COVERAGE_NAME_SPARK_PREFIX, ((MAX_TILE_SIZE_POWER_OF_2 - MIN_TILE_SIZE_POWER_OF_2) / INCREMENT) + 1, queryEnvelope, new Rectangle((int) (numCellsMinLevel * Math.pow(2, l)), (int) (numCellsMinLevel * Math.pow(2, l))), initialSampleValuesPerRequestSize[l]);
    }
}
Also used : Rectangle(java.awt.Rectangle) KDESparkCommand(org.locationtech.geowave.analytic.spark.kde.operations.KDESparkCommand) Index(org.locationtech.geowave.core.store.api.Index) KdeCommand(org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) Envelope(org.locationtech.jts.geom.Envelope) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DataStore(org.locationtech.geowave.core.store.api.DataStore) IndexPluginOptions(org.locationtech.geowave.core.store.index.IndexPluginOptions) ResizeSparkCommand(org.locationtech.geowave.analytic.spark.resize.ResizeSparkCommand) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) File(java.io.File) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) ResizeMRCommand(org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand) Test(org.junit.Test)

Aggregations

KdeCommand (org.locationtech.geowave.analytic.mapreduce.operations.KdeCommand)4 File (java.io.File)3 Configuration (org.apache.hadoop.conf.Configuration)2 ConfigOptions (org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions)2 CommandLineOperationParams (org.locationtech.geowave.core.cli.parser.CommandLineOperationParams)2 ManualOperationParams (org.locationtech.geowave.core.cli.parser.ManualOperationParams)2 OperationParser (org.locationtech.geowave.core.cli.parser.OperationParser)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 Rectangle (java.awt.Rectangle)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 Test (org.junit.Test)1 ResizeMRCommand (org.locationtech.geowave.adapter.raster.operations.ResizeMRCommand)1 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)1 KDESparkCommand (org.locationtech.geowave.analytic.spark.kde.operations.KDESparkCommand)1 ResizeSparkCommand (org.locationtech.geowave.analytic.spark.resize.ResizeSparkCommand)1 OperationParams (org.locationtech.geowave.core.cli.api.OperationParams)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 AddStoreCommand (org.locationtech.geowave.core.store.cli.store.AddStoreCommand)1