private String getDefaultBandName(String nameBase) { String defaultName = nameBase; Product product = sourceBand.getProduct(); int i = 0; while (product.getRasterDataNode(defaultName) != null) { defaultName = nameBase + (++i); } return defaultName; }
private void validateTargExpression() { final String targExpression = targetExprArea.getText(); final Product product = sourceBand.getProduct(); try { if (!BandArithmetic.areRastersEqualInSize(product, sourceExprArea.getText(), targExpression)) { expressionIsCompatibleLabel.setText("Referenced rasters must be of the same size"); expressionIsCompatibleLabel.setForeground(WARN_MSG_OLOR); } else { expressionIsCompatibleLabel.setText("Ok, no errors"); expressionIsCompatibleLabel.setForeground(OK_MSG_COLOR); } } catch (ParseException e) { expressionIsCompatibleLabel.setText("Expression is invalid"); expressionIsCompatibleLabel.setForeground(WARN_MSG_OLOR); } }
@Override protected boolean verifyUserInput() { String uncertaintyExpression = targetExprArea.getText(); if (uncertaintyExpression == null || uncertaintyExpression.trim().isEmpty()) { Dialogs.showError("Uncertainty expression is empty."); return false; } if (uncertaintyExpression.startsWith(ERROR_PREFIX)) { Dialogs.showError(uncertaintyExpression.substring(ERROR_PREFIX.length())); return false; } if (sourceBand.getProduct().containsBand(getBandName())) { Dialogs.showError("A raster with name '" + getBandName() + "' already exists."); return false; } return super.verifyUserInput(); }
private String generateUncertaintyExpression() throws ParseException, UnsupportedOperationException { StandardUncertaintyGenerator propagator = new StandardUncertaintyGenerator(order, false); return propagator.generateUncertainty(sourceBand.getProduct(), relation, sourceBand.getExpression()); }
@Override protected void onOK() { String uncertaintyExpression = targetExprArea.getText(); Product targetProduct = sourceBand.getProduct(); int width = sourceBand.getRasterWidth(); int height = sourceBand.getRasterHeight(); ProductNodeGroup<Band> bandGroup = targetProduct.getBandGroup(); VirtualBand uncertaintyBand = new VirtualBand(getBandName(), ProductData.TYPE_FLOAT32, width, height, uncertaintyExpression); uncertaintyBand.setDescription("Uncertainty propagated from band " + sourceBand.getName() + " = " + sourceBand.getExpression()); uncertaintyBand.setUnit(sourceBand.getUnit()); uncertaintyBand.setNoDataValue(Double.NaN); uncertaintyBand.setNoDataValueUsed(true); uncertaintyBand.setValidPixelExpression(sourceBand.getValidPixelExpression()); ProductUtils.copySpectralBandProperties(sourceBand, uncertaintyBand); bandGroup.add(uncertaintyBand); sourceBand.addAncillaryVariable(uncertaintyBand, relation); UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(targetProduct); if (undoManager != null) { undoManager.addEdit(new UndoableProductNodeInsertion<>(bandGroup, uncertaintyBand)); } hide(); uncertaintyBand.setModified(true); if (SnapApp.getDefault().getPreferences().getBoolean(BandMathsDialog.PREF_KEY_AUTO_SHOW_NEW_BANDS, true)) { OpenImageViewAction.openImageView(uncertaintyBand); } }
private BindingContext createBindingContext() { final PropertyContainer container = PropertyContainer.createObjectBacked(this); final BindingContext context = new BindingContext(container); PropertyDescriptor descriptor; descriptor = container.getDescriptor(PROPERTY_NAME_BAND_NAME); descriptor.setDisplayName("Uncertainty band name"); descriptor.setDescription("The name for the new uncertainty band."); descriptor.setNotEmpty(true); descriptor.setValidator(new ProductNodeNameValidator(sourceBand.getProduct())); descriptor.setDefaultValue(getDefaultBandName(sourceBand.getName() + "_unc")); descriptor = container.getDescriptor(PROPERTY_NAME_ORDER); descriptor.setDisplayName("Order of Taylor polynomial"); descriptor.setDescription("The number of Taylor series expansion terms used for the Standard Combined Uncertainty (GUM 1995)."); descriptor.setDefaultValue(1); descriptor.setValueSet(new ValueSet(new Integer[]{1, 2, 3})); descriptor = container.getDescriptor(PROPERTY_NAME_RELATION); descriptor.setDisplayName("Relation name of ancillary bands"); descriptor.setDescription("Relation name of ancillary variables that represent uncertainties (NetCDF-U 'rel' attribute)."); descriptor.setDefaultValue("uncertainty"); descriptor.setNotNull(true); descriptor.setNotEmpty(true); container.setDefaultValues(); PropertyChangeListener targetExprUpdater = evt -> { updateTargetExprArea(); }; context.addPropertyChangeListener(PROPERTY_NAME_ORDER, targetExprUpdater); context.addPropertyChangeListener(PROPERTY_NAME_RELATION, targetExprUpdater); return context; }