/** Tries to read all required parameter from the request. */ protected void loadRequestParameter() throws ProcessorException { getLogger().info(ProcessorConstants.LOG_MSG_LOAD_REQUEST); Parameter param = null; // database directory param = getParameter(L3Constants.DATABASE_PARAM_NAME, L3Constants.MSG_MISSING_BINDB); databaseDir = (File) param.getValue(); ensureDBLocationForLoad(databaseDir); // output product loadOutputProductFromRequest(); // keep or remove database param = getParameter(L3Constants.DELETE_DB_PARAMETER_NAME, L3Constants.MSG_MISSING_DELETE_BINDB); deleteDb = (Boolean) param.getValue(); final Parameter tailoringParam = getRequest().getParameter(L3Constants.TAILORING_PARAM_NAME); if (tailoringParam != null) { tailorOutputProduct = (Boolean) tailoringParam.getValue(); } else { tailorOutputProduct = L3Constants.TAILORING_DEFAULT_VALUE; } getLogger().info(ProcessorConstants.LOG_MSG_SUCCESS); }
private static ParamGroup createDefaultParamGroup(final InputProductValidator validator) { final ParamGroup paramGroup = new ParamGroup(); final DefaultRequestElementFactory factory = DefaultRequestElementFactory.getInstance(); final Parameter inputProductParameter = factory.createDefaultInputProductParameter(); inputProductParameter.addParamChangeListener( new ParamChangeListener() { public void parameterValueChanged(final ParamChangeEvent event) { validateInputProduct(event.getParameter(), validator); } }); paramGroup.addParameter(inputProductParameter); final Parameter outputProductParameter = factory.createDefaultOutputProductParameter(); final Object defaultValue = outputProductParameter.getProperties().getDefaultValue(); if (defaultValue instanceof File) { outputProductParameter .getProperties() .setDefaultValue(new File((File) defaultValue, _defaultOutputProductFileName)); } paramGroup.addParameter(outputProductParameter); paramGroup.addParameter(factory.createOutputFormatParameter()); paramGroup.addParameter(factory.createDefaultLogPatternParameter(_defaultLogPrefix)); try { paramGroup.addParameter(factory.createLogToOutputParameter(_defaultLogToOutput)); } catch (ParamValidateException e) { Debug.trace("Unable to validate parameter '" + LOG_TO_OUTPUT_PARAM_NAME + "'"); /*I18N*/ Debug.trace(e); } return paramGroup; }
/** Loads the bitmask expression for a MERIS product from the request */ private void loadMerisBitmaskExpression() { Parameter param = getRequest().getParameter(SmacConstants.BITMASK_PARAM_NAME); if (param != null) { _bitMaskExpression = param.getValueAsText(); } else { _bitMaskExpression = ""; } }
/** * Sets the default output product file name. * * @param name the output product file name */ public void setDefaultOutputProductFileName(final String name) { final Parameter param = getParamGroup().getParameter(OUTPUT_PRODUCT_PARAM_NAME); final Object defaultValue = param.getProperties().getDefaultValue(); if (defaultValue instanceof File) { final File file = (File) defaultValue; param.getProperties().setDefaultValue(new File(file.getParentFile(), name)); } }
// Creates the appropriate <code>Product</code> for the current request and assembles a list of // <code>RsBands</code> // to be processed. This method does NOT load the tie point ADS because these are product // specific. private void loadInputProduct() throws IOException, ProcessorException { Request request = getRequest(); Band band; Parameter bandParam; String[] bandNames; // clear vector of bands // --------------------- _inputBandList.clear(); // only the first product - there might be more but these will be ignored // ---------------------------------------------------------------------- _inputProduct = loadInputProduct(0); // check what product type the input is and load the appropriate tie point ADS // --------------------------------------------------------------------------- _sensorType = SmacUtils.getSensorType(_inputProduct.getProductType()); if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.MERIS_NAME)) { loadMerisBitmaskExpression(); loadMERIS_ADS(_inputProduct); } else if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.AATSR_NAME)) { loadAatsrBitmaskExpression(); loadAATSR_ADS(_inputProduct); _useMerisADS = false; // then we must set this to false anyway } else { throw new ProcessorException(SmacConstants.LOG_MSG_UNSUPPORTED_SENSOR); } // set up the bands we need for this request // ----------------------------------------- bandParam = request.getParameter(SmacConstants.BANDS_PARAM_NAME); checkParamNotNull(bandParam, "bands"); bandNames = (String[]) bandParam.getValue(); if ((bandNames == null) || (bandNames.length < 1)) { throw new ProcessorException(SmacConstants.LOG_MSG_NO_INPUT_BANDS); } for (String bandName : bandNames) { band = _inputProduct.getBand(bandName); if (band == null) { _logger.warning( "The requested band '" + bandName + "' is not contained in the input product!"); } else { if (band.getSpectralBandIndex() != -1) { _inputBandList.add(band); } else { _logger.warning( "The requested band '" + bandName + "' is not a spectral band! It is excluded from processing"); } } } }
private void updateParamOutputFormat(final Request request) { final Parameter parameter = request.getParameter(OUTPUT_FORMAT_PARAM_NAME); if (parameter != null) { final String format = parameter.getValueAsText(); final ProductIOPlugInManager instance = ProductIOPlugInManager.getInstance(); final String[] allowedformats = instance.getAllProductWriterFormatStrings(); if (ArrayUtils.isMemberOf(format, allowedformats)) { getParamGroup().getParameter(OUTPUT_FORMAT_PARAM_NAME).setValue(format, null); } } }
/** * Fills the given {@link Request request} with parameters. * * @param request the request to fill * @throws ProcessorException if an error occurred */ @Override public void initRequestFromUI(final Request request) throws ProcessorException { request.addInputProduct(createInputProductRef()); final Parameter outputProductParam = getParamGroup().getParameter(OUTPUT_PRODUCT_PARAM_NAME); if (StringUtils.isNullOrEmpty(outputProductParam.getValueAsText())) { throw new ProcessorException("No output product specified."); /*I18N*/ } request.addOutputProduct(createOutputProductRef()); request.addParameter(createOutputFormatParamForRequest()); request.addParameter(getParamGroup().getParameter(LOG_PREFIX_PARAM_NAME)); request.addParameter(getParamGroup().getParameter(LOG_TO_OUTPUT_PARAM_NAME)); }
private void addGeoParameter(ParamGroup pg) { paramNorthLat1 = new Parameter("geo_lat1", 90.0f); paramNorthLat1.getProperties().setDescription("North bound latitude"); paramNorthLat1.getProperties().setPhysicalUnit("°"); paramNorthLat1.getProperties().setMinValue(-90.0f); paramNorthLat1.getProperties().setMaxValue(90.0f); pg.addParameter(paramNorthLat1); paramWestLon1 = new Parameter("geo_lon1", -180.0f); paramWestLon1.getProperties().setDescription("West bound longitude"); paramWestLon1.getProperties().setPhysicalUnit("°"); paramWestLon1.getProperties().setMinValue(-180.0f); paramWestLon1.getProperties().setMaxValue(180.0f); pg.addParameter(paramWestLon1); paramSouthLat2 = new Parameter("geo_lat2", -90.0f); paramSouthLat2.getProperties().setDescription("South bound latitude"); paramSouthLat2.getProperties().setPhysicalUnit("°"); paramSouthLat2.getProperties().setMinValue(-90.0f); paramSouthLat2.getProperties().setMaxValue(90.0f); pg.addParameter(paramSouthLat2); paramEastLon2 = new Parameter("geo_lon2", 180.0f); paramEastLon2.getProperties().setDescription("East bound longitude"); paramEastLon2.getProperties().setPhysicalUnit("°"); paramEastLon2.getProperties().setMinValue(-180.0f); paramEastLon2.getProperties().setMaxValue(180.0f); pg.addParameter(paramEastLon2); if (canUseGeoCoordinates(product)) { syncLatLonWithXYParams(); } }
/** Loads the bitmask expression for an AATSR product from the request */ private void loadAatsrBitmaskExpression() { Request request = getRequest(); Parameter paramNadir = request.getParameter(SmacConstants.BITMASK_NADIR_PARAM_NAME); if (paramNadir != null) { _bitMaskExpression = paramNadir.getValueAsText(); } else { _bitMaskExpression = ""; } Parameter paramForward = request.getParameter(SmacConstants.BITMASK_FORWARD_PARAM_NAME); if (paramForward != null) { _bitMaskExpressionForward = paramForward.getValueAsText(); } else { _bitMaskExpressionForward = ""; } }
private void updateUIState(ParamChangeEvent event) { if (updatingUI.compareAndSet(false, true)) { try { if (event != null && canUseGeoCoordinates(product)) { final String parmName = event.getParameter().getName(); if (parmName.startsWith("geo_")) { final GeoPos geoPos1 = new GeoPos((Float) paramNorthLat1.getValue(), (Float) paramWestLon1.getValue()); final GeoPos geoPos2 = new GeoPos((Float) paramSouthLat2.getValue(), (Float) paramEastLon2.getValue()); updateXYParams(geoPos1, geoPos2); } else if (parmName.startsWith("source_x") || parmName.startsWith("source_y")) { syncLatLonWithXYParams(); } } int x1 = ((Number) paramX1.getValue()).intValue(); int y1 = ((Number) paramY1.getValue()).intValue(); int x2 = ((Number) paramX2.getValue()).intValue(); int y2 = ((Number) paramY2.getValue()).intValue(); int sx = ((Number) paramSX.getValue()).intValue(); int sy = ((Number) paramSY.getValue()).intValue(); updateSubsetDefRegion(x1, y1, x2, y2, sx, sy); Dimension s = productSubsetDef.getSceneRasterSize( product.getSceneRasterWidth(), product.getSceneRasterHeight()); subsetWidthLabel.setText(String.valueOf(s.getWidth())); subsetHeightLabel.setText(String.valueOf(s.getHeight())); int sliderBoxX1 = x1 / thumbNailSubSampling; int sliderBoxY1 = y1 / thumbNailSubSampling; int sliderBoxX2 = x2 / thumbNailSubSampling; int sliderBoxY2 = y2 / thumbNailSubSampling; int sliderBoxW = sliderBoxX2 - sliderBoxX1 + 1; int sliderBoxH = sliderBoxY2 - sliderBoxY1 + 1; Rectangle box = getScaledRectangle(new Rectangle(sliderBoxX1, sliderBoxY1, sliderBoxW, sliderBoxH)); imageCanvas.setSliderBoxBounds(box); } finally { updatingUI.set(false); } } }
/** Invoked when an action occurs. */ @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(fixSceneWidthCheck)) { imageCanvas.setImageWidthFixed(fixSceneWidthCheck.isSelected()); final boolean enable = !fixSceneWidthCheck.isSelected(); paramX1.setUIEnabled(enable); paramX2.setUIEnabled(enable); } if (e.getSource().equals(fixSceneHeightCheck)) { imageCanvas.setImageHeightFixed(fixSceneHeightCheck.isSelected()); final boolean enable = !fixSceneHeightCheck.isSelected(); paramY1.setUIEnabled(enable); paramY2.setUIEnabled(enable); } if (e.getSource().equals(setToVisibleButton)) { imageCanvas.setSliderBoxBounds(imageScrollPane.getViewport().getViewRect(), true); } }
private static JPanel createLogginPanel(final ParamGroup paramGroup) { final JPanel loggingPanel = GridBagUtils.createPanel(); final GridBagConstraints gbc = GridBagUtils.createConstraints("anchor=NORTHWEST, weightx = 1, fill=HORIZONTAL, gridx=0"); // logging // ------- Parameter param; param = paramGroup.getParameter(LOG_PREFIX_PARAM_NAME); gbc.gridy++; GridBagUtils.addToPanel(loggingPanel, param.getEditor().getLabelComponent(), gbc); gbc.gridy++; GridBagUtils.addToPanel(loggingPanel, param.getEditor().getComponent(), gbc); param = paramGroup.getParameter(LOG_TO_OUTPUT_PARAM_NAME); gbc.gridy++; GridBagUtils.addToPanel(loggingPanel, param.getEditor().getComponent(), gbc); return loggingPanel; }
private static void validateInputProduct( final Parameter parameter, final InputProductValidator validator) { final File file = (File) parameter.getValue(); if (file == null || "".equals(file.getPath().trim())) { return; } String msg = null; if (file.exists()) { Product product = null; try { product = ProductIO.readProduct(file); if (product != null) { if (validator != null) { final boolean valid = validator.validate(product); if (!valid) { msg = validator.getErrorMessage(); if (msg == null) { msg = "Unknown error."; } } } } else { msg = "Unknown product file format."; } } catch (IOException e) { msg = e.getMessage(); } finally { if (product != null) { product.dispose(); } } } else { msg = "File '" + file.getPath() + "' does not exists."; } if (msg != null) { JOptionPane.showMessageDialog( parameter.getEditor().getEditorComponent(), "Invalid input product file:\n" + msg, "Invalid Input Product", JOptionPane.ERROR_MESSAGE); Debug.trace(msg); } }
private void updateXYParams(GeoPos geoPos1, GeoPos geoPos2) { final GeoCoding geoCoding = product.getGeoCoding(); final PixelPos pixelPos1 = geoCoding.getPixelPos(geoPos1, null); if (!pixelPos1.isValid()) { pixelPos1.setLocation(0, 0); } final PixelPos pixelPos2 = geoCoding.getPixelPos(geoPos2, null); if (!pixelPos2.isValid()) { pixelPos2.setLocation(product.getSceneRasterWidth(), product.getSceneRasterHeight()); } final Rectangle.Float region = new Rectangle.Float(); region.setFrameFromDiagonal(pixelPos1.x, pixelPos1.y, pixelPos2.x, pixelPos2.y); final Rectangle.Float productBounds = new Rectangle.Float(0, 0, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Rectangle2D finalRegion = productBounds.createIntersection(region); paramX1.setValue((int) finalRegion.getMinX(), null); paramY1.setValue((int) finalRegion.getMinY(), null); paramX2.setValue((int) finalRegion.getMaxX() - 1, null); paramY2.setValue((int) finalRegion.getMaxY() - 1, null); }
private void syncLatLonWithXYParams() { final PixelPos pixelPos1 = new PixelPos( ((Number) paramX1.getValue()).intValue(), ((Number) paramY1.getValue()).intValue()); final PixelPos pixelPos2 = new PixelPos( ((Number) paramX2.getValue()).intValue(), ((Number) paramY2.getValue()).intValue()); final GeoCoding geoCoding = product.getGeoCoding(); final GeoPos geoPos1 = geoCoding.getGeoPos(pixelPos1, null); final GeoPos geoPos2 = geoCoding.getGeoPos(pixelPos2, null); paramNorthLat1.setValue(geoPos1.getLat(), null); paramWestLon1.setValue(geoPos1.getLon(), null); paramSouthLat2.setValue(geoPos2.getLat(), null); paramEastLon2.setValue(geoPos2.getLon(), null); }
@Override public void sliderBoxChanged(Rectangle sliderBoxBounds) { int x1 = sliderBoxBounds.x * thumbNailSubSampling; int y1 = sliderBoxBounds.y * thumbNailSubSampling; int x2 = x1 + sliderBoxBounds.width * thumbNailSubSampling; int y2 = y1 + sliderBoxBounds.height * thumbNailSubSampling; int w = product.getSceneRasterWidth(); int h = product.getSceneRasterHeight(); if (x1 < 0) { x1 = 0; } if (x1 > w - 2) { x1 = w - 2; } if (y1 < 0) { y1 = 0; } if (y1 > h - 2) { y1 = h - 2; } if (x2 < 1) { x2 = 1; } if (x2 > w - 1) { x2 = w - 1; } if (y2 < 1) { y2 = 1; } if (y2 > h - 1) { y2 = h - 1; } // first reset the bounds, otherwise negative regions can occur paramX1.setValue(0, null); paramY1.setValue(0, null); paramX2.setValue(w - 1, null); paramY2.setValue(h - 1, null); paramX1.setValue(x1, null); paramY1.setValue(y1, null); paramX2.setValue(x2, null); paramY2.setValue(y2, null); }
private void updateLogParameter(final Request request) { Parameter param; Parameter toUpdate; param = request.getParameter(LOG_PREFIX_PARAM_NAME); final ParamGroup paramGroup = getParamGroup(); if (param != null) { toUpdate = paramGroup.getParameter(LOG_PREFIX_PARAM_NAME); toUpdate.setValue(param.getValue(), null); } param = request.getParameter(LOG_TO_OUTPUT_PARAM_NAME); if (param != null) { toUpdate = paramGroup.getParameter(LOG_TO_OUTPUT_PARAM_NAME); toUpdate.setValue(param.getValue(), null); } }
private static JPanel createProductsPanel(final ParamGroup paramGroup) { final JPanel productsPanel = GridBagUtils.createPanel(); final GridBagConstraints gbc = GridBagUtils.createConstraints("anchor=NORTHWEST, fill=HORIZONTAL, weightx = 1"); gbc.gridy = 0; // input product // ------------- Parameter param; param = paramGroup.getParameter(INPUT_PRODUCT_PARAM_NAME); gbc.gridy++; GridBagUtils.addToPanel(productsPanel, param.getEditor().getLabelComponent(), gbc); gbc.gridy++; GridBagUtils.addToPanel(productsPanel, param.getEditor().getComponent(), gbc); // output product // -------------- param = paramGroup.getParameter(OUTPUT_PRODUCT_PARAM_NAME); gbc.gridy++; GridBagUtils.setAttributes(gbc, "insets.top=7"); GridBagUtils.addToPanel(productsPanel, param.getEditor().getLabelComponent(), gbc); gbc.gridy++; GridBagUtils.setAttributes(gbc, "insets.top=0"); GridBagUtils.addToPanel(productsPanel, param.getEditor().getComponent(), gbc); // output format // ------------- param = paramGroup.getParameter(OUTPUT_FORMAT_PARAM_NAME); gbc.gridy++; GridBagUtils.setAttributes(gbc, "insets.top=7, anchor=SOUTHWEST, fill=NONE"); GridBagUtils.addToPanel(productsPanel, param.getEditor().getLabelComponent(), gbc); gbc.gridy++; GridBagUtils.setAttributes(gbc, "insets.top=0, anchor=NORTHWEST"); GridBagUtils.addToPanel(productsPanel, param.getEditor().getComponent(), gbc); return productsPanel; }
private void addPixelParameter(ParamGroup pg) { int w = product.getSceneRasterWidth(); int h = product.getSceneRasterHeight(); int x1 = 0; int y1 = 0; int x2 = w - 1; int y2 = h - 1; int sx = 1; int sy = 1; if (givenProductSubsetDef != null) { Rectangle region = givenProductSubsetDef.getRegion(); if (region != null) { x1 = region.x; y1 = region.y; final int preX2 = x1 + region.width - 1; if (preX2 < x2) { x2 = preX2; } final int preY2 = y1 + region.height - 1; if (preY2 < y2) { y2 = preY2; } } sx = givenProductSubsetDef.getSubSamplingX(); sy = givenProductSubsetDef.getSubSamplingY(); } final int wMin = MIN_SUBSET_SIZE; final int hMin = MIN_SUBSET_SIZE; paramX1 = new Parameter("source_x1", x1); paramX1.getProperties().setDescription("Start X co-ordinate given in pixels"); /*I18N*/ paramX1.getProperties().setMinValue(0); paramX1.getProperties().setMaxValue((w - wMin - 1) > 0 ? w - wMin - 1 : 0); paramY1 = new Parameter("source_y1", y1); paramY1.getProperties().setDescription("Start Y co-ordinate given in pixels"); /*I18N*/ paramY1.getProperties().setMinValue(0); paramY1.getProperties().setMaxValue((h - hMin - 1) > 0 ? h - hMin - 1 : 0); paramX2 = new Parameter("source_x2", x2); paramX2.getProperties().setDescription("End X co-ordinate given in pixels"); /*I18N*/ paramX2.getProperties().setMinValue(wMin - 1); final Integer maxValue = w - 1; paramX2.getProperties().setMaxValue(maxValue); paramY2 = new Parameter("source_y2", y2); paramY2.getProperties().setDescription("End Y co-ordinate given in pixels"); /*I18N*/ paramY2.getProperties().setMinValue(hMin - 1); paramY2.getProperties().setMaxValue(h - 1); paramSX = new Parameter("source_sx", sx); paramSX .getProperties() .setDescription("Sub-sampling in X-direction given in pixels"); /*I18N*/ paramSX.getProperties().setMinValue(1); paramSX.getProperties().setMaxValue(w / wMin + 1); paramSY = new Parameter("source_sy", sy); paramSY .getProperties() .setDescription("Sub-sampling in Y-direction given in pixels"); /*I18N*/ paramSY.getProperties().setMinValue(1); paramSY.getProperties().setMaxValue(h / hMin + 1); pg.addParameter(paramX1); pg.addParameter(paramY1); pg.addParameter(paramX2); pg.addParameter(paramY2); pg.addParameter(paramSX); pg.addParameter(paramSY); }
// Scans the current request for parameters needed by the algorithm. Sets these parameters to // fileds of the class private void loadRequestParams() throws ProcessorException { Parameter param; ProcessorUtils.setProcessorLoggingHandler( SmacConstants.DEFAULT_LOG_PREFIX, getRequest(), getName(), getVersion(), getCopyrightInformation()); // get aerosol optical depth // DELETE param = getRequest().getParameter(SmacConstants.AEROSOL_OPTICAL_DEPTH_PARAM_NAME); checkParamNotNull(param, SmacConstants.AEROSOL_OPTICAL_DEPTH_PARAM_NAME); _tau_aero_550 = (Float) (param.getValue()); // DELETE // check for MERIS ads flag // DELETE param = getRequest().getParameter(SmacConstants.USE_MERIS_ADS_PARAM_NAME); checkParamNotNull(param, SmacConstants.USE_MERIS_ADS_PARAM_NAME); _useMerisADS = (Boolean) param.getValue(); // DELETE // load the other parameters only if needed // ---------------------------------------- if (!_useMerisADS) { // DELETE // water vapour content param = getRequest().getParameter(SmacConstants.RELATIVE_HUMIDITY_PARAM_NAME); checkParamNotNull(param, SmacConstants.RELATIVE_HUMIDITY_PARAM_NAME); _u_h2o = (Float) (param.getValue()); // DELETE // DELETE // ozone content param = getRequest().getParameter(SmacConstants.OZONE_CONTENT_PARAM_NAME); checkParamNotNull(param, SmacConstants.OZONE_CONTENT_PARAM_NAME); _u_o3 = (Float) (param.getValue()); // DELETE // DELETE // surface pressure param = getRequest().getParameter(SmacConstants.SURFACE_AIR_PRESSURE_PARAM_NAME); checkParamNotNull(param, SmacConstants.SURFACE_AIR_PRESSURE_PARAM_NAME); _surf_press = (Float) (param.getValue()); // DELETE } // DELETE // get aerosol type param = getRequest().getParameter(SmacConstants.AEROSOL_TYPE_PARAM_NAME); checkParamNotNull(param, SmacConstants.AEROSOL_TYPE_PARAM_NAME); setAerosolType((String) param.getValue()); // DELETE // DELETE // get invalid pixel value param = getRequest().getParameter(SmacConstants.DEFAULT_REFLECT_FOR_INVALID_PIX_PARAM_NAME); if (param == null) { _logger.warning(ProcessorConstants.LOG_MSG_NO_INVALID_PIXEL); _logger.warning(ProcessorConstants.LOG_MSG_USING + "0.0"); _invalidPixel = 0.f; } else { _invalidPixel = (Float) param.getValue(); } // DELETE }