From 1b442681d4c014fac28fe89d3a7d942e8405e4b3 Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Tue, 29 Jul 2014 10:27:32 -0500 Subject: [PATCH] Omaha #3463 grid lightning uses sparse data source Change-Id: I243b3a662bf1f3ab320ef5fee7637fd5245e8ad3 Former-commit-id: e755fc88a7b53e6ef501b4ebbc1f85e25d88eb41 [formerly e755fc88a7b53e6ef501b4ebbc1f85e25d88eb41 [formerly 00b60fd6ed95f3df30b1f477619ace9145d17f45]] Former-commit-id: c1f5fe0d3a4bf0419ca63c118683f34be4b97462 Former-commit-id: 82b33b67253a836b1baf3dadb56a0df87f956fa4 --- .../META-INF/MANIFEST.MF | 1 + .../viz/lightning/GridLightningResource.java | 37 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cave/com.raytheon.viz.lightning/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.lightning/META-INF/MANIFEST.MF index 30167a4d8e..9bc1b492cf 100644 --- a/cave/com.raytheon.viz.lightning/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.lightning/META-INF/MANIFEST.MF @@ -16,4 +16,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: com.raytheon.uf.common.numeric.buffer, com.raytheon.uf.common.numeric.filter, com.raytheon.uf.common.numeric.source, + com.raytheon.uf.common.numeric.sparse, com.raytheon.uf.viz.productbrowser diff --git a/cave/com.raytheon.viz.lightning/src/com/raytheon/viz/lightning/GridLightningResource.java b/cave/com.raytheon.viz.lightning/src/com/raytheon/viz/lightning/GridLightningResource.java index a85a73e1c0..2b91d10a94 100644 --- a/cave/com.raytheon.viz.lightning/src/com/raytheon/viz/lightning/GridLightningResource.java +++ b/cave/com.raytheon.viz.lightning/src/com/raytheon/viz/lightning/GridLightningResource.java @@ -45,9 +45,11 @@ import com.raytheon.uf.common.colormap.prefs.ColorMapParameters; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.binlightning.BinLightningRecord; import com.raytheon.uf.common.geospatial.MapUtil; -import com.raytheon.uf.common.numeric.buffer.ShortBufferWrapper; -import com.raytheon.uf.common.numeric.filter.UnsignedFilter; +import com.raytheon.uf.common.numeric.sparse.SparseArray; +import com.raytheon.uf.common.numeric.sparse.SparseShortArray; import com.raytheon.uf.common.style.ParamLevelMatchCriteria; +import com.raytheon.uf.common.style.StyleException; +import com.raytheon.uf.common.style.image.ColorMapParameterFactory; import com.raytheon.uf.common.style.image.DataScale; import com.raytheon.uf.common.style.image.ImagePreferences; import com.raytheon.uf.common.time.DataTime; @@ -72,6 +74,7 @@ import com.raytheon.viz.lightning.cache.LightningFrameRetriever; * Jul 07, 2014 3333 bclement Initial creation * Jul 22, 2014 3333 bclement ignores strikes that aren't on map * Jul 28, 2014 3451 bclement uses intended range min + * Jul 29, 2014 3463 bclement uses sparse data source * * * @@ -127,18 +130,32 @@ public class GridLightningResource extends * style preferences and restore it in the colormap parameters */ float minRange = Float.NaN; + ColorMapParameters rval; if (stylePreferences != null && stylePreferences instanceof ImagePreferences) { - DataScale dataScale = ((ImagePreferences) stylePreferences) - .getDataScale(); + ImagePreferences imgPrefs = (ImagePreferences) stylePreferences; + DataScale dataScale = imgPrefs.getDataScale(); if (dataScale != null) { Double minValue = dataScale.getMinValue(); if (minValue != null) { minRange = minValue.floatValue(); } } + try { + /* + * avoid calling super since it calls DataUtilities.getMinMax() + * which is slow for sparse data and not used for lightning + */ + rval = ColorMapParameterFactory.build(imgPrefs, Unit.ONE); + } catch (StyleException e) { + throw new VizException( +"Problem building lightning colormap" + + " parameters from image preferences", e); + } + } else { + /* call super as a fallback */ + rval = super.createColorMapParameters(data); } - ColorMapParameters rval = super.createColorMapParameters(data); rval.setNoDataValue(0); if (!Double.isNaN(minRange)) { rval.setColorMapMin(minRange); @@ -198,8 +215,7 @@ public class GridLightningResource extends * use shorts to save space, a grid cell is unlikely to contain over 64K * strikes */ - short[] data = new short[nx * ny]; - + SparseArray data = new SparseShortArray(nx, ny); LightningFrame frame = getFrame(time, pdos); List> iterators = new ArrayList<>(4); @@ -231,15 +247,12 @@ public class GridLightningResource extends int gridY = (int) Math.round(dest.y); /* ignore strikes that aren't on the map */ if (gridX >= 0 && gridX < nx && gridY >= 0 && gridY < ny) { - int index = (nx * gridY) + gridX; - data[index] += 1; + data.add(gridX, gridY, 1); } } } - - ShortBufferWrapper source = new ShortBufferWrapper(data, nx, ny); GeneralGridData gridData = GeneralGridData.createScalarData( - imageGeometry, UnsignedFilter.apply(source), Unit.ONE); + imageGeometry, data, Unit.ONE); return Arrays.asList(gridData); }