List of usage examples for java.lang Double isNaN
public boolean isNaN()
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
@Override public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {//w ww . j a va2 s . co m try { g2D.setColor(UI.colorBlack2); g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); g2D.setColor(barColorNormal); g2D.setStroke(UI.stroke1_5); //This is the //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue)); //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight)); if (rowNode.isSingleNode() && columnNode.isSingleNode()) { double value = (v - _minValue) / (_maxValue - _minValue); if (v >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * value), (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * value)); } else { // double min = percentile.evaluate(valueArray, 0); // double max = percentile.evaluate(valueArray, 100) double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode); if (fiveVal == null) { g2D.setColor(UI.colorBlack1); g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); } double range = _maxValue - _minValue; double minP = (fiveVal[0] - _minValue) / range; double maxP = (fiveVal[4] - _minValue) / range; double medianP = (fiveVal[2] - _minValue) / range; double q1P = (fiveVal[1] - _minValue) / range; double q3P = (fiveVal[3] - _minValue) / range; try { // if (cellWidth >= 2 && cellHeight >= 2) { g2D.drawLine((int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2), (int) (anchorY + cellHeight - cellHeight * minP)); if (fiveVal[2] >= disectBound) { g2D.setColor(UI.colorLightGreen4); } else { g2D.setColor(UI.colorOrange2); } g2D.fillRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); if (fiveVal[2] >= disectBound) { g2D.setColor(barColorNormal); } else { g2D.setColor(barColorBelow); } // g2D.setColor(barColorNormal); //g2D.drawRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P))); g2D.drawLine((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * medianP), (int) (anchorX + cellWidth), (int) (anchorY + cellHeight - cellHeight * medianP)); // } else { // // if (fiveVal[2] >= medianP) { // g2D.setColor(barColorNormal); // } else { // g2D.setColor(barColorBelow); // } // //// System.out.println("painted rect"); //// System.out.println((int) cellWidth + " " + ((int) cellHeight)); // g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); // } } catch (Exception e) { System.err.println("Boxplot render exception"); } } // if(cellWidth>=4 && cellHeight >=){ // g2D.setColor(UI.colorBlack1); // g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight)); // } } catch (Exception e) { } } }
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
public FolderType getLinkFolder(String transportMode, Map<Id, BasicLocation> locations, Map<Id, Double> evacuationTimes) throws IOException { calcMaxEvacuationTime(evacuationTimes); /*//from w w w . jav a 2 s.co m * create Folders and connect them */ FolderType mainFolder = this.kmlObjectFactory.createFolderType(); FolderType linkFolder = this.kmlObjectFactory.createFolderType(); FolderType facilityFolder = this.kmlObjectFactory.createFolderType(); FolderType linkFolderA = this.kmlObjectFactory.createFolderType(); // 0 .. 10 valid Trips FolderType linkFolderB = this.kmlObjectFactory.createFolderType(); // 10 .. 100 valid Trips FolderType linkFolderC = this.kmlObjectFactory.createFolderType(); // 100 .. 1000 valid Trips FolderType linkFolderD = this.kmlObjectFactory.createFolderType(); // 1000 and more valid Trips FolderType facilityFolderA = this.kmlObjectFactory.createFolderType(); // 0 .. 10 valid Trips FolderType facilityFolderB = this.kmlObjectFactory.createFolderType(); // 10 .. 100 valid Trips FolderType facilityFolderC = this.kmlObjectFactory.createFolderType(); // 100 .. 1000 valid Trips FolderType facilityFolderD = this.kmlObjectFactory.createFolderType(); // 1000 and more valid Trips mainFolder.setName("Evacuation Times " + transportMode); linkFolder.setName("Links"); facilityFolder.setName("Facilities"); linkFolderA.setName("Links with 0..9 valid Trips"); linkFolderB.setName("Links with 10..99 valid Trips"); linkFolderC.setName("Links with 100..9 valid Trips"); linkFolderD.setName("Links with 1000 and more valid Trips"); facilityFolderA.setName("Facilities with 0..9 valid Trips"); facilityFolderB.setName("Facilities with 10..99 valid Trips"); facilityFolderC.setName("Facilities with 100..9 valid Trips"); facilityFolderD.setName("Facilities with 1000 and more valid Trips"); mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolder)); mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolder)); linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderA)); linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderB)); linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderC)); linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderD)); facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderA)); facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderB)); facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderC)); facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderD)); /* * create overall histogram and add it to the kmz file */ ScreenOverlayType histogram = createHistogram(transportMode, evacuationTimes); mainFolder.getAbstractFeatureGroup().add(kmlObjectFactory.createScreenOverlay(histogram)); /* * create legend and add it to the kmz file */ ScreenOverlayType legend = createLegend(transportMode); mainFolder.getAbstractFeatureGroup().add(kmlObjectFactory.createScreenOverlay(legend)); Map<BasicLocation, List<Double>> locationMap = new HashMap<BasicLocation, List<Double>>(); for (Entry<Id, BasicLocation> entry : locations.entrySet()) { Id id = entry.getKey(); BasicLocation location = entry.getValue(); List<Double> list = locationMap.get(location); if (list == null) { list = new ArrayList<Double>(); locationMap.put(location, list); } Double value = evacuationTimes.get(id); if (value == null) value = Double.NaN; list.add(value); } log.info("Number of different start locations found: " + locationMap.size()); if (doClustering) { EvacuationTimeClusterer clusterer = new EvacuationTimeClusterer(scenario.getNetwork(), locationMap, scenario.getConfig().global().getNumberOfThreads()); int numClusters = (int) Math.ceil(locationMap.size() / clusterFactor); locationMap = clusterer.buildCluster(numClusters, clusterIterations); } for (Entry<BasicLocation, List<Double>> entry : locationMap.entrySet()) { BasicLocation location = entry.getKey(); List<Double> list = entry.getValue(); int valid = 0; int invalid = 0; /* * Remove NaN entries from the List */ List<Double> listWithoutNaN = new ArrayList<Double>(); for (Double d : list) { if (d.isNaN()) { invalid++; } else listWithoutNaN.add(d); } /* * If trip with significant to high evacuation times should be cut off */ if (limitMaxEvacuationTime) { double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor; ListIterator<Double> iter = listWithoutNaN.listIterator(); while (iter.hasNext()) { double value = iter.next(); if (value > cutOffValue) { iter.remove(); invalid++; } } } valid = list.size() - invalid; double mean = 0.0; for (Double d : list) { mean = mean + d; } mean = mean / list.size(); // if at least one valid entry found - otherwise it would result in a divide by zero error if (listWithoutNaN.size() == 0) continue; // if (invalid < list.size()) mean = mean / (list.size() - invalid); // else continue; int index = getColorIndex(mean); StyleType styleType = colorBarStyles[index]; PlacemarkType placemark = createPlacemark(transportMode, location, mean, valid, invalid); placemark.setStyleUrl(styleType.getId()); if (location instanceof Facility) { if (valid < 10) facilityFolderA.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else if (valid < 100) facilityFolderB.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else if (valid < 1000) facilityFolderC.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else facilityFolderD.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); } else if (location instanceof Link) { if (valid < 10) linkFolderA.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else if (valid < 100) linkFolderB.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else if (valid < 1000) linkFolderC.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); else linkFolderD.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); } else { mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark)); } histogramToKMZ(transportMode, location, listWithoutNaN); boxplotToKMZ(transportMode, location, listWithoutNaN); } return mainFolder; }
From source file:net.solarnetwork.node.support.XmlServiceSupport.java
/** * Extract a tracking ID from an XML string. * /* w w w . ja va 2s. c o m*/ * @param xml * the XML to extract from * @param xp * the XPath to use that returns a number * @param xpath * the XPath as a string (for debugging) * @return the tracking ID, or <em>null</em> if not found */ protected Long extractTrackingId(InputSource xml, XPathExpression xp, String xpath) { Double tid; try { tid = (Double) xp.evaluate(xml, XPathConstants.NUMBER); } catch (XPathExpressionException e) { throw new RuntimeException(e); } if (tid.isNaN()) { log.warn("Unable to extract tracking ID via XPath [{}]", xpath); return null; } return tid.longValue(); }
From source file:de.bund.bfr.knime.pmm.common.chart.Plotable.java
private boolean isValidValue(Double value) { return value != null && !value.isNaN() && !value.isInfinite(); }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private boolean isValid(Double value) { return value != null && !value.isInfinite() && !value.isNaN(); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override protected void initialize() { // System.out.println("===Number to color initialized==="); CoolMapObject obj = getCoolMapObject(); if (!canRender(obj.getViewClass())) { return;//from ww w. ja va2s.c om } double minValue = Double.MAX_VALUE; double maxValue = -Double.MAX_VALUE; for (int i = 0; i < obj.getViewNumRows(); i++) { for (int j = 0; j < obj.getViewNumColumns(); j++) { try { Double v = (Double) obj.getViewValue(i, j); if (v == null || v.isNaN()) { continue; } else { if (v < minValue) { minValue = v; } if (v > maxValue) { maxValue = v; } } } catch (Exception e) { } } } minValueField.setText(minValue + ""); maxValueField.setText(maxValue + ""); editor.clearColors(); editor.setStart(DEFAULT_MIN_COLOR); editor.addColor(Color.BLACK, 0.5f); editor.setEnd(DEFAULT_MAX_COLOR); // System.err.println("Number to color initialized"); updateRenderer(); }
From source file:com.ibm.bi.dml.test.utils.TestUtils.java
/** * Compares two double values regarding tolerance t. If one or both of them * is null it is converted to 0.0.// w w w .ja v a 2 s . co m * * @param v1 * @param v2 * @param t * Tolerance * @return */ public static boolean compareCellValue(Double v1, Double v2, double t, boolean ignoreNaN) { if (v1 == null) v1 = 0.0; if (v2 == null) v2 = 0.0; if (ignoreNaN && (v1.isNaN() || v1.isInfinite() || v2.isNaN() || v2.isInfinite())) return true; if (v1.equals(v2)) return true; return Math.abs(v1 - v2) <= t; }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { // renderCellSD(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/*from w w w .ja v a2 s.c o m*/ try { int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } Color c = _gradientColors[index]; //System.out.println(c); g2D.setColor(c); // System.out.println((int) cellWidth + " " + ((int) cellHeight)) ; g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); } catch (Exception e) { } } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override public void renderCellSD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {/*from w w w .j a va2s. c o m*/ try { int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } Color c = _gradientColors[index]; //System.out.println(c); g2D.setColor(c); // System.out.println((int) cellWidth + " " + ((int) cellHeight)) ; g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight); // System.out.println("WH:" + cellWidth + " " + cellHeight); if (drawSubMap.isSelected()) { //paint the sub heatmap block // System.out.println("draw submap"); if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return; } else { //need to determine the number of cMatrices CoolMapObject object = getCoolMapObject(); List<CMatrix> matrices = object.getBaseCMatrices(); Double value; //row and column indices Integer[] rowIndices; Integer[] colIndices; //whether they are group node or node if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfColName(columnNode.getName()) }; } //then determine the width int subMatrixWidth = Math.round(cellWidth * 1.0f / matrices.size()); int subAnchorX = anchorX; int subCellHeight = Math.round(cellHeight * 1.0f / rowIndices.length); int subCellWidth = Math.round(subMatrixWidth * 1.0f / colIndices.length); // System.out.println("CW:" + cellWidth + " " + colIndices.length + " " + subCellWidth); // System.out.println("CH:" + cellHeight + " " + rowIndices.length + " " + subCellHeight); if (subCellHeight < 1) { subCellHeight = 1; } if (subCellWidth < 1) { subCellWidth = 1; } for (CMatrix matrix : matrices) { int rowIndex = 0; for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } int columnIndex = 0; for (Integer j : colIndices) { if (j == null || j < 0) { continue; } try { value = (Double) matrix.getValue(i, j); index = (int) ((value - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } c = _gradientColors[index]; g2D.setColor(c); int subCellX = Math .round(subMatrixWidth * 1.0f * columnIndex / colIndices.length) + subAnchorX; int subCellY = Math.round(cellHeight * 1.0f * rowIndex / rowIndices.length) + anchorY; // System.out.println("WTF:" + columnIndex + " " + rowIndex + "----" + subCellX + " " + subCellY + " " + subCellWidth + " " + subCellHeight); g2D.fillRect(subCellX, subCellY, subCellWidth, subCellHeight); } catch (Exception e) { //draw it here e.printStackTrace(); } columnIndex++; } //end of column loop rowIndex++; } //end of row loop subAnchorX += subMatrixWidth; } //end of matrix loop g2D.setStroke(UI.stroke1); g2D.setColor(Color.BLACK); g2D.drawRect(anchorX, anchorY, cellWidth, cellHeight); } } } catch (Exception e) { // System.out.println("Null pointer exception:" + v + "," + _minValue + "," + _maxValue + "," + _gradientColors + " " + getName() + "" + this); //e.printStackTrace(); } } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override public void renderCellHD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {// w ww . j a v a2s. c o m try { int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } Color c = _gradientColors[index]; //System.out.println(c); g2D.setColor(c); // System.out.println((int) cellWidth + " " + ((int) cellHeight)) ; g2D.fillRoundRect((int) anchorX + 1, (int) anchorY + 1, (int) cellWidth - 2, (int) cellHeight - 2, 4, 4); if (drawSubMap.isSelected()) { //paint the sub heatmap block // System.out.println("draw submap"); if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return; } else { g2D.setStroke(UI.strokeDash1_5); //need to determine the number of cMatrices CoolMapObject object = getCoolMapObject(); List<CMatrix> matrices = object.getBaseCMatrices(); Double value; //row and column indices Integer[] rowIndices; Integer[] colIndices; //whether they are group node or node if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfColName(columnNode.getName()) }; } //then determine the width int subMatrixWidth = Math.round(cellWidth * 1.0f / matrices.size()); int subAnchorX = anchorX; int subCellHeight = Math.round(cellHeight * 1.0f / rowIndices.length); int subCellWidth = Math.round(subMatrixWidth * 1.0f / colIndices.length); // System.out.println("CW:" + cellWidth + " " + colIndices.length + " " + subCellWidth); // System.out.println("CH:" + cellHeight + " " + rowIndices.length + " " + subCellHeight); if (subCellHeight < 1) { subCellHeight = 1; } if (subCellWidth < 1) { subCellWidth = 1; } int matrixIndex = 0; for (CMatrix matrix : matrices) { int rowIndex = 0; for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } int columnIndex = 0; for (Integer j : colIndices) { if (j == null || j < 0) { continue; } try { value = (Double) matrix.getValue(i, j); index = (int) ((value - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } c = _gradientColors[index]; g2D.setColor(c); int subCellX = Math .round(subMatrixWidth * 1.0f * columnIndex / colIndices.length) + subAnchorX; int subCellY = Math.round(cellHeight * 1.0f * rowIndex / rowIndices.length) + anchorY; // System.out.println("WTF:" + columnIndex + " " + rowIndex + "----" + subCellX + " " + subCellY + " " + subCellWidth + " " + subCellHeight); g2D.fillRect(subCellX, subCellY, subCellWidth, subCellHeight); } catch (Exception e) { //draw it here e.printStackTrace(); } columnIndex++; } //end of column loop rowIndex++; } //end of row loop g2D.setColor(UI.colorBlack1); g2D.drawRect(subAnchorX, anchorY, subMatrixWidth, cellHeight); // // subAnchorX += subMatrixWidth; matrixIndex++; subAnchorX = anchorX + Math.round(cellWidth * 1.0f * matrixIndex / matrices.size()); } //end of matrix loop g2D.setStroke(UI.stroke2); g2D.setColor(Color.BLACK); g2D.drawRect(anchorX, anchorY, cellWidth, cellHeight); } } } catch (Exception e) { // System.out.println("Null pointer exception:" + v + "," + _minValue + "," + _maxValue + "," + _gradientColors + " " + getName() + "" + this); //e.printStackTrace(); } } }