Search in sources :

Example 76 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class AbstractHistogramPlotter method updateBinWidth.

/**
 * Updates ONLY the width of the bins.
 * @param binWidth the new bin width
 */
protected void updateBinWidth(final int binWidth) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    if (!vizModel.setBinWidth(binWidth)) {
        return;
    }
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    if (drawingSpace == null) {
        throw new IllegalStateException("Drawing space must not be null");
    }
    final double drawingWidth = drawingSpace.getWidth();
    final double drawingHeight = drawingSpace.getHeight();
    final Coordinate xCoordinates = getXCoordinate();
    final Coordinate aggrCoordinate = getAggregationCoordinate();
    final int baseLine = (int) (drawingHeight - aggrCoordinate.calculateMappedValue(new DoubleCell(0), drawingHeight));
    final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
    final int newBinWidth = vizModel.getBinWidth();
    final List<Color> barElementColors = vizModel.getRowColors();
    final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
    final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
    for (final BinDataModel bin : vizModel.getBins()) {
        final DataCell captionCell = bin.getXAxisCaptionCell();
        final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
        // subtract half of the bar width from the start position to place
        // the middle point of the bar on the mapped coordinate position
        final int xCoord = (int) (labelCoord - (newBinWidth / 2.0));
        bin.updateBinWidth(xCoord, newBinWidth, barElementColors, aggrColumns, baseLine, calculator);
    }
    // if only the bar width changes we don't need to update the properties
    // since the bar width change is triggered by the property component
    // itself
    drawingPane.setHistogramVizModel(vizModel, false);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) BinDataModel(org.knime.base.node.viz.histogram.datamodel.BinDataModel) Dimension(java.awt.Dimension) Point(java.awt.Point) HistogramHiliteCalculator(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataCell(org.knime.core.data.DataCell)

Example 77 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class BoxPlotter method updateOutliers.

/**
 * Sets the outliers as dotinfo to the scatterplotter drawing pane to
 * make them selectable and hilite-able.
 * @param yCoordinate the corresponding y coordinate.
 * @param box the box (column).
 * @return the mapped outliers for this column.
 */
protected List<DotInfo> updateOutliers(final Coordinate yCoordinate, final Box box) {
    int height = getDrawingPaneDimension().height - OFFSET;
    List<DotInfo> dotList = new ArrayList<DotInfo>();
    int x = box.getX();
    String colName = box.getColumnName();
    // the mild outliers
    Map<Double, Set<RowKey>> mildOutliers = ((BoxPlotDataProvider) getDataProvider()).getMildOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : mildOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CIRCLE));
            dotList.add(dot);
        }
    }
    // the extreme outliers
    Map<Double, Set<RowKey>> extremeOutliers = ((BoxPlotDataProvider) getDataProvider()).getExtremeOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : extremeOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CROSS));
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dotList.add(dot);
        }
    }
    return dotList;
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) Point(java.awt.Point) StringCell(org.knime.core.data.def.StringCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 78 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class Normalizer3NodeModel method calculate.

/**
 * New normalized {@link org.knime.core.data.DataTable} is created depending on the mode.
 */
/**
 * @param inData The input data.
 * @param exec For BufferedDataTable creation and progress.
 * @return the result of the calculation
 * @throws Exception If the node calculation fails for any reason.
 */
protected CalculationResult calculate(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inData[0];
    DataTableSpec inSpec = inTable.getSpec();
    // extract selected numeric columns
    String[] includedColumns = getIncludedComlumns(inSpec);
    Normalizer2 ntable = new Normalizer2(inTable, includedColumns);
    long rowcount = inTable.size();
    ExecutionContext prepareExec = exec.createSubExecutionContext(0.3);
    AffineTransTable outTable;
    boolean fixDomainBounds = false;
    switch(m_config.getMode()) {
        case MINMAX:
            fixDomainBounds = true;
            outTable = ntable.doMinMaxNorm(m_config.getMax(), m_config.getMin(), prepareExec);
            break;
        case Z_SCORE:
            outTable = ntable.doZScoreNorm(prepareExec);
            break;
        case DECIMALSCALING:
            outTable = ntable.doDecimalScaling(prepareExec);
            break;
        default:
            throw new InvalidSettingsException("No mode set");
    }
    if (outTable.getErrorMessage() != null) {
        // something went wrong, report and throw an exception
        throw new Exception(outTable.getErrorMessage());
    }
    if (ntable.getErrorMessage() != null) {
        // something went wrong during initialization, report.
        setWarningMessage(ntable.getErrorMessage());
    }
    DataTableSpec modelSpec = FilterColumnTable.createFilterTableSpec(inSpec, includedColumns);
    AffineTransConfiguration configuration = outTable.getConfiguration();
    DataTableSpec spec = outTable.getDataTableSpec();
    // the same transformation, which is not guaranteed to snap to min/max)
    if (fixDomainBounds) {
        DataColumnSpec[] newColSpecs = new DataColumnSpec[spec.getNumColumns()];
        for (int i = 0; i < newColSpecs.length; i++) {
            newColSpecs[i] = spec.getColumnSpec(i);
        }
        for (int i = 0; i < includedColumns.length; i++) {
            int index = spec.findColumnIndex(includedColumns[i]);
            DataColumnSpecCreator creator = new DataColumnSpecCreator(newColSpecs[index]);
            DataColumnDomainCreator domCreator = new DataColumnDomainCreator(newColSpecs[index].getDomain());
            domCreator.setLowerBound(new DoubleCell(m_config.getMin()));
            domCreator.setUpperBound(new DoubleCell(m_config.getMax()));
            creator.setDomain(domCreator.createDomain());
            newColSpecs[index] = creator.createSpec();
        }
        spec = new DataTableSpec(spec.getName(), newColSpecs);
    }
    ExecutionMonitor normExec = exec.createSubProgress(.7);
    BufferedDataContainer container = exec.createDataContainer(spec);
    long count = 1;
    for (DataRow row : outTable) {
        normExec.checkCanceled();
        normExec.setProgress(count / (double) rowcount, "Normalizing row no. " + count + " of " + rowcount + " (\"" + row.getKey() + "\")");
        container.addRowToTable(row);
        count++;
    }
    container.close();
    return new CalculationResult(container.getTable(), modelSpec, configuration);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Normalizer2(org.knime.base.data.normalize.Normalizer2) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ExecutionContext(org.knime.core.node.ExecutionContext) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) AffineTransTable(org.knime.base.data.normalize.AffineTransTable) AffineTransConfiguration(org.knime.base.data.normalize.AffineTransConfiguration) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 79 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class LinearInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 80 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class AverageInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round((prev + next) / 2);
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = (prev + next) / 2;
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Aggregations

DoubleCell (org.knime.core.data.def.DoubleCell)189 DataCell (org.knime.core.data.DataCell)129 IntCell (org.knime.core.data.def.IntCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)66 StringCell (org.knime.core.data.def.StringCell)65 DataRow (org.knime.core.data.DataRow)57 DataTableSpec (org.knime.core.data.DataTableSpec)55 ArrayList (java.util.ArrayList)42 DataColumnSpec (org.knime.core.data.DataColumnSpec)42 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)41 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)39 RowKey (org.knime.core.data.RowKey)37 DoubleValue (org.knime.core.data.DoubleValue)35 BufferedDataTable (org.knime.core.node.BufferedDataTable)28 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)22 DataType (org.knime.core.data.DataType)20 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 Point (java.awt.Point)12