use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AppendedRowsTable method merge.
/*
* Merges two domains of the same column, i.e. emerging from different
* tables, min max will be updated (if possible) and the possible value set.
*/
private static final DataColumnDomain merge(final DataColumnDomain d1, final DataColumnDomain d2, final DataValueComparator comp) {
final DataCell d1Min = d1.getLowerBound();
final DataCell d1Max = d1.getUpperBound();
final DataCell d2Min = d2.getLowerBound();
final DataCell d2Max = d2.getUpperBound();
final Set<DataCell> d1Poss = d1.getValues();
final Set<DataCell> d2Poss = d2.getValues();
final DataCell newMin;
if (d1Min == null || d2Min == null) {
newMin = null;
} else {
newMin = comp.compare(d1Min, d2Min) < 0 ? d1Min : d2Min;
}
final DataCell newMax;
if (d1Max == null || d2Max == null) {
newMax = null;
} else {
newMax = comp.compare(d1Max, d2Max) > 0 ? d1Max : d2Max;
}
final Set<DataCell> newPoss;
if (d1Poss == null || d2Poss == null) {
newPoss = null;
} else {
newPoss = new LinkedHashSet<DataCell>(d1Poss);
newPoss.addAll(d2Poss);
}
return new DataColumnDomainCreator(newPoss, newMin, newMax).createDomain();
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AffineTransTable method generateNewSpec.
/**
* Creates a new DataTableSpec. The target column's type is set to
* DoubleType, the domain is adjusted.
*/
private static DataTableSpec generateNewSpec(final DataTableSpec spec, final AffineTransConfiguration configuration) {
String[] names = configuration.getNames();
HashMap<String, Integer> hash = new HashMap<String, Integer>();
for (int i = 0; i < names.length; i++) {
hash.put(names[i], i);
}
for (int i = 0; i < spec.getNumColumns(); i++) {
DataColumnSpec col = spec.getColumnSpec(i);
Integer index = hash.get(col.getName());
if (index != null) {
DataType type = col.getType();
// do we need to support IntValue also?
if (!type.isCompatible(DoubleValue.class)) {
throw new IllegalArgumentException("Not supported: " + type);
}
}
}
DataColumnSpec[] specs = new DataColumnSpec[spec.getNumColumns()];
double[] newmin = configuration.getMin();
double[] newmax = configuration.getMax();
double[] scales = configuration.getScales();
double[] translations = configuration.getTranslations();
for (int i = 0; i < specs.length; i++) {
DataColumnSpec colSpec = spec.getColumnSpec(i);
DataColumnDomain colDomain = colSpec.getDomain();
Integer indexObject = hash.get(colSpec.getName());
if (indexObject == null) {
specs[i] = colSpec;
} else {
int index = indexObject.intValue();
assert !Double.isNaN(scales[index]);
// determine domain
double interval = newmax[index] - newmin[index];
DataCell up = null;
DataCell oldUp = colDomain.getUpperBound();
if (oldUp != null && !oldUp.isMissing()) {
double oldVal = ((DoubleValue) oldUp).getDoubleValue();
double newVal = scales[index] * oldVal + translations[index];
if (!Double.isNaN(newmax[index])) {
if (newVal > newmax[index] && ((newVal - newmax[index]) / interval) < VERY_SMALL) {
newVal = newmax[index];
}
}
up = new DoubleCell(newVal);
}
DataCell low = null;
DataCell oldLow = colDomain.getLowerBound();
if (oldLow != null && !oldLow.isMissing()) {
double oldVal = ((DoubleValue) oldLow).getDoubleValue();
double newVal = scales[index] * oldVal + translations[index];
if (!Double.isNaN(newmin[index])) {
if (newVal < newmin[index] && ((newmin[index] - newVal) / interval) < VERY_SMALL) {
newVal = newmin[index];
}
}
low = new DoubleCell(newVal);
}
DataColumnDomain dom = new DataColumnDomainCreator(low, up).createDomain();
DataType type = DoubleCell.TYPE;
DataColumnSpecCreator c = new DataColumnSpecCreator(colSpec);
// IntType must be converted to DoubleType!
c.setType(type);
c.setDomain(dom);
specs[i] = c.createSpec();
}
}
return new DataTableSpec(specs);
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AbstractHistogramPlotter method createColumnSpec.
/**
* Returns <code>DataColumnSpec</code> object with the given properties.
*
* @param columnName name of the column.
* @param type the <code>DataType</code> of the column
* @param lowerBound the lower bound if available if not set it to
* <code>Double.NaN</code> @param upperBoundthe upper bound if available if
* not set it to <code>Double.NaN</code>
* @param values the possible values for nominal types or <code>null</code>
* for discrete types
* @return the <code>DataColumnSpec</code> object created using the
* given values
*/
private DataColumnSpec createColumnSpec(final String columnName, final DataType type, final double lowerBound, final double upperBound, final Set<DataCell> values) {
final DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
if (!Double.isNaN(lowerBound) && !Double.isNaN(upperBound)) {
DataCell lowerBoundCell = null;
DataCell upperBoundCell = null;
if (type.isCompatible(IntValue.class)) {
lowerBoundCell = new IntCell((int) lowerBound);
upperBoundCell = new IntCell((int) upperBound);
} else {
lowerBoundCell = new DoubleCell(lowerBound);
upperBoundCell = new DoubleCell(upperBound);
}
domainCreator.setLowerBound(lowerBoundCell);
domainCreator.setUpperBound(upperBoundCell);
}
if (values != null && values.size() > 0) {
domainCreator.setValues(values);
}
final DataColumnSpecCreator specCreator = new DataColumnSpecCreator(columnName, type);
specCreator.setDomain(domainCreator.createDomain());
final DataColumnSpec spec = specCreator.createSpec();
return spec;
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class Coordinate method getDataColumnSpec.
/**
* Returns the underlying {@link DataColumnSpec}. If {@link MappingMethod}s
* are set, they will be applied to the domain. The domain must not be equal
* to the original {@link DataColumnSpec}.
*
* @return the underlying column spec of this coordinate
*/
DataColumnSpec getDataColumnSpec() {
DataColumnSpecCreator creator = new DataColumnSpecCreator(m_columnSpec);
DataCell newLowerBound = applyMappingMethod(m_columnSpec.getDomain().getLowerBound());
DataCell newUpperBound = applyMappingMethod(m_columnSpec.getDomain().getUpperBound());
creator.setDomain(new DataColumnDomainCreator(newLowerBound, newUpperBound).createDomain());
return creator.createSpec();
}
use of org.knime.core.data.DataColumnDomainCreator in project knime-core by knime.
the class AbstractPlotter method createXCoordinate.
/**
* Recalculates the domain of the x axis. If preserve is set to false the
* passed values are taken as min and max no matter was was set before. If
* preserve is set to true (default) the possibly already available min and
* max values are preserved.
*
* @param min the min value
* @param max the max value {@link AbstractPlotter#setPreserve(boolean)}
*/
public void createXCoordinate(final int min, final int max) {
DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
int actualMin = min;
int actualMax = max;
if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
return;
}
actualMin = (int) Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
actualMax = (int) Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
}
xDomainCreator.setLowerBound(new IntCell(actualMin));
xDomainCreator.setUpperBound(new IntCell(actualMax));
DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", IntCell.TYPE);
xSpecCreator.setDomain(xDomainCreator.createDomain());
Coordinate xCoordinate = Coordinate.createCoordinate(xSpecCreator.createSpec());
if (getXAxis() == null) {
Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
setXAxis(xAxis);
}
getXAxis().setCoordinate(xCoordinate);
}
Aggregations