List of usage examples for java.lang Float isNaN
public static boolean isNaN(float v)
From source file:eu.itesla_project.modules.histo.IIDM2DB.java
public static CimValuesMap extractCimValues(Network n, Config config) { CimValuesMap valuesMap = new CimValuesMap(); for (Substation ss : n.getSubstations()) { if (config.getCountryFilter() != null && !config.getCountryFilter().contains(ss.getCountry())) { continue; }/*from ww w . ja v a2 s .c om*/ for (VoltageLevel vl : ss.getVoltageLevels()) { if (vl.getNominalV() < config.getMinBaseVoltageFilter()) { continue; } String horizon = n.getForecastDistance() > 0 ? "DACF" : "SN"; // for backward compatibility final LinkedHashMap<HistoDbAttributeId, Object> valueMap = valuesMap .getValueMap(new HorizonKey(n.getForecastDistance(), horizon)); if (config.getCimName() != null && !valueMap.containsKey(HistoDbMetaAttributeId.cimName)) valueMap.put(HistoDbMetaAttributeId.cimName, config.getCimName()); if (config.isExtractTemporalFields()) { if (!valueMap.containsKey(HistoDbMetaAttributeId.datetime)) valueMap.put(HistoDbMetaAttributeId.datetime, n.getCaseDate().toDate()); if (!valueMap.containsKey(HistoDbMetaAttributeId.daytime)) valueMap.put(HistoDbMetaAttributeId.daytime, n.getCaseDate().getMillisOfDay()); if (!valueMap.containsKey(HistoDbMetaAttributeId.month)) valueMap.put(HistoDbMetaAttributeId.month, n.getCaseDate().getMonthOfYear()); if (!valueMap.containsKey(HistoDbMetaAttributeId.forecastTime)) valueMap.put(HistoDbMetaAttributeId.forecastTime, n.getForecastDistance()); if (!valueMap.containsKey(HistoDbMetaAttributeId.horizon)) valueMap.put(HistoDbMetaAttributeId.horizon, horizon); } vl.visitEquipments(new AbstractTopologyVisitor() { private void visitInjection(SingleTerminalConnectable inj) { visitInjection(inj, new TerminalContext()); } private void visitInjection(SingleTerminalConnectable inj, TerminalContext context) { Terminal t = inj.getTerminal(); context.update(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } if (Float.isNaN(context.v)) { context.v = 0f; // TODO is there a better value? } if (Float.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.I), context.i); } private void visitBranch(TwoTerminalsConnectable branch, TwoTerminalsConnectable.Side side, float r, float x, float g1, float b1, float g2, float b2, float ratio) { Terminal t = side == TwoTerminalsConnectable.Side.ONE ? branch.getTerminal1() : branch.getTerminal2(); TerminalContext context = TerminalContext.create(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { Terminal otherT = t == branch.getTerminal1() ? branch.getTerminal2() : branch.getTerminal1(); Bus otherBus = otherT.getBusView().getBus(); if (otherBus != null && !Float.isNaN(otherBus.getV())) { // compute the voltage from the other side physical values // TODO approx we do not consider voltage drop due to branch impedance if (t == branch.getTerminal1()) { // we are on side 1 disconnected and side 2 is connected context.v = otherBus.getV() / ratio; } else if (t == branch.getTerminal2()) { // we are on side 2 disconnected and side 1 is connected context.v = otherBus.getV() * ratio; } else { throw new AssertionError(); } } else { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } } if (Float.isNaN(context.v)) { context.v = 0; // TODO is there a better value? } if (Float.isNaN(context.i)) { context.i = 0; } } valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.I), context.i); } @Override public void visitGenerator(Generator g) { TerminalContext context = new TerminalContext(); visitInjection(g, context); // reactive limit float qmax = g.getReactiveLimits().getMaxQ(context.p); valueMap.put(new HistoDbNetworkAttributeId(g.getId(), HistoDbAttr.QR), Math.abs(qmax - context.q)); } @Override public void visitLoad(Load l) { if (l.getLoadType() != LoadType.FICTITIOUS) { visitInjection(l); } } @Override public void visitShuntCompensator(ShuntCompensator sc) { visitInjection(sc); } @Override public void visitDanglingLine(DanglingLine dl) { visitInjection(dl); valueMap.put(new HistoDbNetworkAttributeId(dl.getId(), HistoDbAttr.P0), dl.getP0()); valueMap.put(new HistoDbNetworkAttributeId(dl.getId(), HistoDbAttr.Q0), dl.getQ0()); } @Override public void visitLine(Line l, Line.Side side) { visitBranch(l, side, l.getR(), l.getX(), l.getG1(), l.getB1(), l.getG2(), l.getB2(), 1); } @Override public void visitTwoWindingsTransformer(TwoWindingsTransformer twt, TwoWindingsTransformer.Side side) { visitBranch(twt, side, twt.getR(), twt.getX(), twt.getG(), twt.getB(), 0, 0, SV.getRatio(twt)); } @Override public void visitThreeWindingsTransformer(ThreeWindingsTransformer twt, ThreeWindingsTransformer.Side side) { Terminal t; switch (side) { case ONE: t = twt.getLeg1().getTerminal(); break; case TWO: t = twt.getLeg2().getTerminal(); break; case THREE: t = twt.getLeg3().getTerminal(); break; default: throw new AssertionError(); } TerminalContext context = TerminalContext.create(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { context.v = 0; // TODO is possible to find a better replacement value? } if (Float.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.I), context.i); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.Q), context.q); } }); // taps for (TwoWindingsTransformer twt : ss.getTwoWindingsTransformers()) { if (twt.getPhaseTapChanger() != null) { valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), HistoDbAttr.PTC), twt.getPhaseTapChanger().getTapPosition()); } if (twt.getRatioTapChanger() != null) { valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), HistoDbAttr.RTC), twt.getRatioTapChanger().getTapPosition()); } } for (ThreeWindingsTransformer twt : ss.getThreeWindingsTransformers()) { valueMap.put( new HistoDbNetworkAttributeId(twt.getId(), twt.getLeg2().getTerminal().getVoltageLevel().getId(), HistoDbAttr.RTC), twt.getLeg2().getRatioTapChanger().getTapPosition()); valueMap.put( new HistoDbNetworkAttributeId(twt.getId(), twt.getLeg3().getTerminal().getVoltageLevel().getId(), HistoDbAttr.RTC), twt.getLeg3().getRatioTapChanger().getTapPosition()); } /** * Extract topologies and mean tension */ try { JSONArray toposArray = toTopoSet(vl); String jsonRep = toposArray.toString(); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.TOPO), jsonRep); String base64hash = computeTopoHash(jsonRep); valuesMap.addTopology(vl.getId(), base64hash, toposArray); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.TOPOHASH), base64hash); } catch (JSONException e) { throw new RuntimeException("Failed to gather topologies", e); } float pgen = 0; float qgen = 0; float pload = 0; float qload = 0; float qshunt = 0; for (Generator g : vl.getGenerators()) { Terminal t = g.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getP())) { pgen += t.getP(); } if (!Float.isNaN(t.getQ())) { qgen += t.getQ(); } } } for (Load l : vl.getLoads()) { Terminal t = l.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getP())) { pload += t.getP(); } if (!Float.isNaN(t.getQ())) { qload += t.getQ(); } } } for (ShuntCompensator s : vl.getShunts()) { Terminal t = s.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getQ())) { qshunt += t.getQ(); } } } float vSum = 0; int validBusCount = 0; int busCount = 0; float vMin = Float.NaN; float vMax = Float.NaN; for (Bus b : vl.getBusView().getBuses()) { if (!Float.isNaN(b.getV())) { vSum += b.getV(); validBusCount++; vMin = Float.isNaN(vMin) ? b.getV() : Math.min(vMin, b.getV()); vMax = Float.isNaN(vMax) ? b.getV() : Math.max(vMax, b.getV()); } busCount++; } float meanV = Float.NaN; if (validBusCount > 0) { meanV = vSum / validBusCount; } if (config.isReplaceMissingValues()) { if (Float.isNaN(meanV)) { meanV = 0; // TODO is there a better value? } if (Float.isNaN(vMin)) { vMin = 0; // TODO is there a better value? } if (Float.isNaN(vMax)) { vMax = 0; // TODO is there a better value? } } valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.PGEN), pgen); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QGEN), qgen); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.PLOAD), pload); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QLOAD), qload); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QSHUNT), qshunt); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.V), meanV); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.VMIN), vMin); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.VMAX), vMax); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.BC), busCount); } } return valuesMap; }
From source file:com.numenta.taurus.instance.InstanceDetailPageFragment.java
void updateServerHeader() { if (_chartData == null) { return;/*from w w w. ja v a2s . c o m*/ } if (_instanceChartFrag == null) { return; } // Update server header _instanceChartFrag.setChartData(_chartData); // Update time slider Date endDate = _chartData.getEndDate(); long endTime; if (endDate == null) { endTime = System.currentTimeMillis(); } else { endTime = endDate.getTime(); } _timeView.setAggregation(_chartData.getAggregation()); _timeView.setEndDate(endTime); // Check if need to collapse to market hours if (_collapseAfterHours) { EnumSet<MetricType> anomalousMetrics = _chartData.getAnomalousMetrics(); if (anomalousMetrics.contains(MetricType.TwitterVolume)) { // Collapse to market hours if twitter anomalies occurred during market hours MarketCalendar marketCalendar = TaurusApplication.getMarketCalendar(); boolean collapsed = true; // Check if is there any twitter anomaly on the last visible bars List<Pair<Long, Float>> data = _chartData.getData(); ListIterator<Pair<Long, Float>> iterator = data.listIterator(data.size()); for (int i = 0; i < TaurusApplication.getTotalBarsOnChart() && iterator.hasPrevious(); i++) { Pair<Long, Float> value = iterator.previous(); if (value != null && value.second != null && !Float.isNaN(value.second)) { double scaled = DataUtils.logScale(value.second); if (scaled >= TaurusApplication.getYellowBarFloor() && !marketCalendar.isOpen(value.first)) { // Found anomaly, don't collapse collapsed = false; break; } } } _marketHoursCheckbox.setChecked(collapsed); } else { // Collapse to market hours if we only have stock anomalies _marketHoursCheckbox.setChecked(true); } // Prevent collapsing during scroll _collapseAfterHours = false; } }
From source file:org.caleydo.core.util.impute.KNNImpute.java
/** * split the neighbor hood in two groups based on 2 k-means * * @param neighborhood/* w w w . j av a 2s . c om*/ * @return */ private Pair<List<Gene>, List<Gene>> twoMeanClusterSplit(List<Gene> neighborhood) { final int n = neighborhood.size(); final int maxit = desc.getMaxit(); final double eps = desc.getEps(); int a_start = r.nextInt(n); int b_start = r.nextInt(n); Gene a_center = new Gene(1, -1, Arrays.copyOf(neighborhood.get(a_start).data, samples)); Gene b_center = new Gene(1, -1, Arrays.copyOf(neighborhood.get(b_start).data, samples)); float[] a_center_pong = new float[samples]; Arrays.fill(a_center_pong, Float.NaN); float[] b_center_pong = new float[samples]; Arrays.fill(b_center_pong, Float.NaN); float[] tmp; BitSet partOf_a = new BitSet(n); double d_old = 0; for (int i = 0; i < maxit; ++i) { int j = 0; int changed = 0; double d_new = 0; for (Gene gene : neighborhood) { final double a_distance = distance(a_center, gene); final double b_distance = distance(b_center, gene); final boolean in_a = a_distance < b_distance; if (partOf_a.get(j) != in_a) { changed++; partOf_a.set(j, in_a); } d_new += in_a ? a_distance : b_distance; tmp = in_a ? a_center_pong : b_center_pong; // shift new center for (int k = 0; k < samples; ++k) { if (!gene.isNaN(k)) { if (Float.isNaN(tmp[k])) tmp[k] = gene.get(k); else tmp[k] += gene.get(k); } } j++; } if (changed == 0 || d_new == 0) break; final double ratio = Math.abs(d_new - d_old) / d_old; if (i > 0 && ratio < eps) break; d_old = d_new; int a_n = partOf_a.cardinality(); int b_n = n - a_n; if (a_n == 0 || b_n == 0) { // FIXME } updateCenter(a_center, a_center_pong, a_n); updateCenter(b_center, b_center_pong, b_n); } return split(neighborhood, partOf_a); }
From source file:model.scenario.CompetitiveScenarioTest.java
@Test public void rightPriceAndQuantityLearningInventory() { for (int competitors = 4; competitors <= 7; competitors++) { System.out.println("FORCED COMPETITIVE FIRMS: " + (competitors + 1)); for (int i = 0; i < 5; i++) { final MacroII macroII = new MacroII(System.currentTimeMillis()); final TripolistScenario scenario1 = new TripolistScenario(macroII); scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class); scenario1.setAskPricingStrategy(SalesControlWithFixedInventoryAndPID.class); scenario1.setControlType(//w ww . j a v a 2 s . c o m MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL); scenario1.setAdditionalCompetitors(competitors); scenario1.setWorkersToBeRehiredEveryDay(true); scenario1.setDemandIntercept(102); //assign scenario macroII.setScenario(scenario1); macroII.start(); while (macroII.schedule.getTime() < 8000) { macroII.schedule.step(macroII); /* System.out.println("sales: " + scenario1.getCompetitors().get(0).getSalesDepartment(GoodType.GENERIC). getLatestObservation(SalesDataType.OUTFLOW) +"," + scenario1.getCompetitors().get(1).getSalesDepartment(GoodType.GENERIC). getLatestObservation(SalesDataType.OUTFLOW)); */ } SummaryStatistics prices = new SummaryStatistics(); SummaryStatistics quantities = new SummaryStatistics(); SummaryStatistics target = new SummaryStatistics(); for (int j = 0; j < 500; j++) { macroII.schedule.step(macroII); assert !Float.isNaN(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); prices.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); quantities.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume()); for (EconomicAgent agent : macroII.getMarket(UndifferentiatedGoodType.GENERIC).getSellers()) { SalesDepartment department = ((Firm) agent) .getSalesDepartment(UndifferentiatedGoodType.GENERIC); target.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume()); } } System.out.println(prices.getMean() + " - " + quantities.getMean() + "/" + target.getMean() + "----" + macroII.seed() + " | " + macroII.getMarket(UndifferentiatedGoodType.GENERIC).getLastDaysAveragePrice()); System.out.println("standard deviations: price : " + prices.getStandardDeviation() + " , quantity: " + quantities.getStandardDeviation()); OneSectorStatics.printSlopes(scenario1); if (competitors >= 4) { assertEquals(prices.getMean(), 58, 5); // assertTrue(prices.getStandardDeviation() < 5.5); assertEquals(quantities.getMean(), 44, 5); // assertTrue(quantities.getStandardDeviation() < 5.5); } macroII.finish(); } } }
From source file:savant.data.DataTableModel.java
public void setData(List<Record> dataInRange) { if (dataInRange == null) { data = null;//from w w w .j a va2 s .c o m } else { if (dataSource.getDataFormat() == DataFormat.CONTINUOUS) { // Continuous tracks now use NaNs for missing values. Filter them out. data = new ArrayList<Record>(); for (Record r : dataInRange) { if (!Float.isNaN(((ContinuousRecord) r).getValue())) { data.add(r); if (data.size() >= maxRows) { break; } } } } else { data = dataInRange; } } }
From source file:com.bstek.dorado.view.output.JsonBuilder.java
/** * //w ww . j a v a 2 s.c om */ public JsonBuilder value(Object o) { if (o == null) { outputValue("null", false); } else if (o instanceof Number || o instanceof Boolean) { if (o instanceof Float && (Float.isNaN((Float) o))) { outputValue("undefined", false); } if (o instanceof Double && (Double.isNaN((Double) o))) { outputValue("undefined", false); } else { outputValue(o.toString(), false); } } else if (o.getClass().isArray()) { array(); int len = Array.getLength(o); for (int i = 0; i < len; i++) { value(Array.get(o, i)); } endArray(); } else { String s = o.toString(); if (s.length() == 0) { outputValue("\"\"", false); } else { outputValue(StringEscapeUtils.escapeJavaScript(s), true); } } return this; }
From source file:com.saylor.harrison.opustestround2.audio.WebSocketUploader.java
private void sendSpeechHeader() { JSONObject obj = new JSONObject(); try {/* w w w . j a v a 2 s . com*/ obj.put("action", "start"); obj.put("content-type", this.sConfig.audioFormat); obj.put("interim_results", this.sConfig.returnInterimResults); obj.put("continuous", this.sConfig.continuous); obj.put("inactivity_timeout", this.sConfig.inactivityTimeout); if (this.sConfig.maxAlternatives > 1) { obj.put("max_alternatives", this.sConfig.maxAlternatives); } if (!(Float.isNaN(this.sConfig.wordAlternativesThreshold))) { obj.put("word_alternatives_threshold", this.sConfig.wordAlternativesThreshold); } } catch (JSONException e) { e.printStackTrace(); } String startHeader = obj.toString(); this.upload(startHeader); this.encoder.onStart(); Log.d(TAG, "Sending init message: " + startHeader); }
From source file:org.mrgeo.rasterops.GeoTiffExporter.java
public static void export(final RenderedImage image, final Bounds bounds, final OutputStream os, final boolean replaceNan, final String xmp, final Number nodata) throws IOException { OpImageRegistrar.registerMrGeoOps(); final TIFFEncodeParam param = new TIFFEncodeParam(); // The version of GDAL that Legion is using requires a tile size > 1 param.setTileSize(image.getTileWidth(), image.getTileHeight()); param.setWriteTiled(true);//from www. j ava2 s . co m // if the image only has 1 pixel, the value of this pixel changes after compressing (especially // if this pixel is no data value. e.g -9999 changes to -8192 when read the image back). // So don't do compress if the image has only 1 pixel. if (image.getWidth() > 1 && image.getHeight() > 1) { // Deflate lossless compression (also known as "Zip-in-TIFF") param.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE); param.setDeflateLevel(Deflater.BEST_COMPRESSION); } final GeoTIFFDirectory dir = new GeoTIFFDirectory(); // GTModelTypeGeoKey : using geographic coordinate system. dir.addGeoKey(new XTIFFField(1024, XTIFFField.TIFF_SHORT, 1, new char[] { 2 })); // GTRasterTypeGeoKey : pixel is point dir.addGeoKey(new XTIFFField(1025, XTIFFField.TIFF_SHORT, 1, new char[] { 1 })); // GeographicTypeGeoKey : 4326 WGS84 dir.addGeoKey(new XTIFFField(2048, XTIFFField.TIFF_SHORT, 1, new char[] { 4326 })); dir.addGeoKey(new XTIFFField(2049, XTIFFField.TIFF_ASCII, 7, new String[] { "WGS 84" })); // GeogAngularUnitsGeoKey : Angular Degree dir.addGeoKey(new XTIFFField(2054, XTIFFField.TIFF_SHORT, 1, new char[] { 9102 })); if (xmp != null) { final byte[] b = xmp.getBytes("UTF8"); dir.addField(new XTIFFField(700, XTIFFField.TIFF_BYTE, b.length, b)); } dir.getFields(); final double[] tiePoints = new double[6]; tiePoints[0] = 0.0; tiePoints[1] = 0.0; tiePoints[2] = 0.0; tiePoints[3] = bounds.getMinX(); tiePoints[4] = bounds.getMaxY(); tiePoints[5] = 0.0; dir.setTiepoints(tiePoints); final double[] pixelScale = new double[3]; pixelScale[0] = bounds.getWidth() / image.getWidth(); pixelScale[1] = bounds.getHeight() / image.getHeight(); pixelScale[2] = 0; dir.setPixelScale(pixelScale); final Vector<TIFFField> fields = toTiffField(dir.getFields()); RenderedImage output = image; final String[] nullValues = new String[1]; switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_DOUBLE: nullValues[0] = Double.toString(nodata.doubleValue()); if (replaceNan) { output = ReplaceNanDescriptor.create(image, nodata.doubleValue()); } // Tiff exporter doesn't handle doubles. Yuck! output = ConvertToFloatDescriptor.create(output); // Double.NaN (our default nodata on ingest) should not be written out as nodata on export // (i.e. GeoTiffs imported without NODATA metadata field should be exported as such) if (!Double.isNaN(nodata.doubleValue())) { fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues)); } break; case DataBuffer.TYPE_FLOAT: nullValues[0] = Double.toString(nodata.floatValue()); if (replaceNan) { output = ReplaceNanDescriptor.create(image, nodata.floatValue()); } // Float.NaN (our default nodata on ingest) should not be written out as nodata on export // (i.e. GeoTiffs imported without NODATA metadata field should be exported as such) if (!Float.isNaN(nodata.floatValue())) { fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues)); } break; case DataBuffer.TYPE_INT: case DataBuffer.TYPE_USHORT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_BYTE: nullValues[0] = Integer.toString(nodata.intValue()); fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues)); break; } param.setExtraFields(fields.toArray(new TIFFField[0])); EncodeDescriptor.create(output, os, "TIFF", param, null); }
From source file:ExposedFloat.java
void updateNumberFields() { int intBits = Float.floatToIntBits(value); if (Float.isNaN(value)) { base10Field.setText(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity base10Field.setText(negativeInfinityString); } else {// w w w . j ava2s . c o m // This is a positive infinity base10Field.setText(positiveInfinityString); } } else if (intBits == (int) 0x80000000) { base10Field.setText("-0"); } else { base10Field.setText(Float.toString(value)); } int v = intBits; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0: buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = intBits; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); if (intBits < 0) { signField.setText("1"); } else { signField.setText("0"); } v = intBits >> 23; buf.setLength(0); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } exponentField.setText(buf.toString()); // Do the mantissa v = intBits; buf.setLength(0); for (int i = 0; i < 23; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } if (((intBits >> 23) & 0xff) == 0) { // This is a denormalized number, first bit is 0 buf.insert(0, "0"); } else { // This is a normalized number, first bit is 1 buf.insert(0, "1"); } mantissaField.setText(buf.toString()); // Print out a denormalized base 2 version. buf.setLength(0); if (Float.isNaN(value)) { buf.append(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity buf.append(negativeInfinityString); } else { // This is a positive infinity buf.append(positiveInfinityString); } } else { if ((intBits >>> 31) == 1) { // This is a negative number buf.append("-"); } // Convert mantissa to int. v = (intBits & 0x007fffff); if (((intBits >> 23) & 0xff) != 0) { // Set bit 23 if the number is normalized v |= 0x00800000; } buf.append(v); // print out the exponent v = (intBits >> 23) & 0xff; if (v != 150 && intBits != 0 && intBits != (int) 0x80000000) { if (v != 0) { // regular normalized number buf.append("e" + (v - 150)); } else { // denormalized number buf.append("e-149"); } } } base2Field.setText(buf.toString()); }