diff --git a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_4_0_SNAPSHOT.xml b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_4_0_SNAPSHOT.xml index 867e4dbb..5e48bd23 100644 --- a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_4_0_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_4_0_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_core_4_0_SNAPSHOT.xml b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_core_4_0_SNAPSHOT.xml index 209b23fb..d397b347 100644 --- a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_core_4_0_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_core_4_0_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_exception_4_0_SNAPSHOT.xml b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_exception_4_0_SNAPSHOT.xml index 8e7f2e45..b172e846 100644 --- a/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_exception_4_0_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_apache_commons_commons_math4_legacy_exception_4_0_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_statistics_distribution_1_0_SNAPSHOT.xml b/.idea/libraries/Maven__org_apache_commons_commons_statistics_distribution_1_0_SNAPSHOT.xml index 48d52414..dc25306e 100644 --- a/.idea/libraries/Maven__org_apache_commons_commons_statistics_distribution_1_0_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_apache_commons_commons_statistics_distribution_1_0_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_locationtech_proj4j_proj4j_1_1_6_SNAPSHOT.xml b/.idea/libraries/Maven__org_locationtech_proj4j_proj4j_1_1_6_SNAPSHOT.xml index 8d2ba86b..599ba0fc 100644 --- a/.idea/libraries/Maven__org_locationtech_proj4j_proj4j_1_1_6_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_locationtech_proj4j_proj4j_1_1_6_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLPlot.java index ec191552..5dcb1277 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLPlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/GLPlot.java @@ -2499,13 +2499,17 @@ public class GLPlot extends Plot { } else { boolean isDraw = true; if (graphic instanceof GraphicCollection3D) { - GraphicCollection3D gg = (GraphicCollection3D) graphic; - if (gg.isAllQuads()) { - this.drawQuadsPolygons(gl, gg); - isDraw = false; - } else if (gg.isAllTriangle()) { - this.drawTrianglePolygons(gl, gg); + if (graphic.getNumGraphics() == 0) { isDraw = false; + } else { + GraphicCollection3D gg = (GraphicCollection3D) graphic; + if (gg.isAllQuads()) { + this.drawQuadsPolygons(gl, gg); + isDraw = false; + } else if (gg.isAllTriangle()) { + this.drawTrianglePolygons(gl, gg); + isDraw = false; + } } } if (isDraw) { diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java index 88a99c3d..ac0a48ec 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/MapGLPlot.java @@ -3,6 +3,7 @@ package org.meteoinfo.chart.jogl; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; import org.meteoinfo.chart.ChartText; +import org.meteoinfo.chart.graphic.GraphicCollection3D; import org.meteoinfo.chart.graphic.GraphicProjectionUtil; import org.meteoinfo.chart.plot.MapGridLine; import org.meteoinfo.chart.plot.MapGridLine3D; @@ -64,6 +65,9 @@ public class MapGLPlot extends GLPlot { super.addGraphic(graphic); } else { Graphic nGraphic = GraphicProjectionUtil.projectClipGraphic(graphic, proj, this.projInfo); + if (nGraphic instanceof GraphicCollection3D) { + ((GraphicCollection3D) nGraphic).setUsingLight(((GraphicCollection3D) graphic).isUsingLight()); + } super.addGraphic(nGraphic); } } diff --git a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/mapview/MapView.java b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/mapview/MapView.java index ca067906..5d292761 100644 --- a/meteoinfo-geo/src/main/java/org/meteoinfo/geo/mapview/MapView.java +++ b/meteoinfo-geo/src/main/java/org/meteoinfo/geo/mapview/MapView.java @@ -7848,9 +7848,6 @@ public class MapView extends JPanel implements IWebMapPanel { this._scaleX = scale; this._scaleY = scale; PointD center = (PointD)this._drawExtent.getCenterPoint().clone(); - //PointD center = (PointD) this._viewExtent.getCenterPoint().clone(); - //center.X -= g.getTransform().getTranslateX(); - //center.Y -= g.getTransform().getTranslateY(); double xlen = width / scale * 0.5; double ylen = height / scale * 0.5; this._drawExtent.minX = center.X - xlen; diff --git a/meteoinfo-lab/milconfig.xml b/meteoinfo-lab/milconfig.xml index 385b8d4e..d8cf59bc 100644 --- a/meteoinfo-lab/milconfig.xml +++ b/meteoinfo-lab/milconfig.xml @@ -1,33 +1,32 @@ - - - - - - - - - - - + + + + + + + + + + + + - - + + - - - - + + + - - - - + + + diff --git a/meteoinfo-lab/pylib/mipylib/meteolib/wrf/__init__.py b/meteoinfo-lab/pylib/mipylib/meteolib/wrf/__init__.py index 74bb9851..043a1696 100644 --- a/meteoinfo-lab/pylib/mipylib/meteolib/wrf/__init__.py +++ b/meteoinfo-lab/pylib/mipylib/meteolib/wrf/__init__.py @@ -3,9 +3,11 @@ from g_slp import * from g_rh import * from g_pressure import * from g_geoht import * +from g_dbz import * __all__ = destag.__all__ __all__ += g_slp.__all__ __all__ += g_rh.__all__ __all__ += g_pressure.__all__ -__all__ += g_geoht.__all__ \ No newline at end of file +__all__ += g_geoht.__all__ +__all__ += g_dbz.__all__ \ No newline at end of file diff --git a/meteoinfo-lab/pylib/mipylib/meteolib/wrf/g_dbz.py b/meteoinfo-lab/pylib/mipylib/meteolib/wrf/g_dbz.py new file mode 100644 index 00000000..15443ace --- /dev/null +++ b/meteoinfo-lab/pylib/mipylib/meteolib/wrf/g_dbz.py @@ -0,0 +1,66 @@ +from org.meteoinfo.math.meteo import WRF +import mipylib.numeric as np +from .. import constants +from ..calc.thermo import temperature_from_potential_temperature + +__all__ = ['get_dbz'] + +def get_dbz(wrfin, timeidx=0, use_varint=False, use_liqskin=False): + """Return the simulated radar reflectivity. + This functions extracts the necessary variables from the NetCDF file + object in order to perform the calculation. + Args: + wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ + iterable): WRF-ARW NetCDF + data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` + or an iterable sequence of the aforementioned types. + timeidx (:obj:`int` or :data:`wrf.ALL_TIMES`, optional): The + desired time index. This value can be a positive integer, + negative integer, or + :data:`wrf.ALL_TIMES` (an alias for None) to return + all times in the file or sequence. The default is 0. + use_varint (:obj:`bool`, optional): When set to False, + the intercept parameters are assumed constant + (as in MM5's Reisner-2 bulk microphysical scheme). + When set to True, the variable intercept + parameters are used as in the more recent version of Reisner-2 + (based on Thompson, Rasmussen, and Manning, 2004, Monthly weather + Review, Vol. 132, No. 2, pp. 519-542.). + use_liqskin (:obj:`bool`, optional): When set to True, frozen particles + that are at a temperature above freezing are assumed to scatter + as a liquid particle. Set to False to disable. + Returns: + :class:`xarray.DataArray` or :class:`numpy.ndarray`: The simulated + radar reflectivity. + If xarray is enabled and the *meta* parameter is True, then the result + will be a :class:`xarray.DataArray` object. Otherwise, the result will + be a :class:`numpy.ndarray` object with no metadata. + """ + t = wrfin["T"][timeidx] + p = wrfin["P"][timeidx] + pb = wrfin["PB"][timeidx] + qv = wrfin["QVAPOR"][timeidx] + qr = wrfin["QRAIN"][timeidx] + + if wrfin.varnames.contains("QSNOW"): + qs = wrfin["QSNOW"][timeidx] + else: + qs = np.zeros(qv.shape, qv.dtype) + + if wrfin.varnames.contains("QGRAUP"): + qg = wrfin["QGRAUP"][timeidx] + else: + qg = np.zeros(qv.shape, qv.dtype) + + full_t = t + constants.T_BASE + full_p = p + pb + tk = temperature_from_potential_temperature(full_p * 0.01, full_t) + + # If qsnow is not all 0, set sn0 to 1 + sn0 = 1 if qs.any() else 0 + ivarint = 1 if use_varint else 0 + iliqskin = 1 if use_liqskin else 0 + + dbz = WRF.calcDBZ(full_p._array, tk._array, qv._array, qr._array, qs._array, qg._array, + sn0, ivarint, iliqskin) + return np.DimArray(dbz, dims=t.dims) \ No newline at end of file diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py b/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py index bec60957..c2706185 100644 --- a/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py +++ b/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py @@ -574,6 +574,23 @@ class NDArray(object): r = NDArray(ArrayMath.inValues(self._array, other)) return r + def any(self, axis=None): + """ + Test whether any array element along a given axis evaluates to True. + + :param axis: (*int*) Axis along which a logical OR reduction is performed. + The default (axis = None) is to perform a logical OR over all the + dimensions of the input array. + + :returns: (*array_like*) Any result + """ + if axis is None: + return ArrayMath.any(self._array) + else: + if axis < 0: + axis += self.ndim + return NDArray(ArrayMath.any(self._array, axis)) + def contains_nan(self): """ Check if the array contains nan value. diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/numeric$py.class b/meteoinfo-lab/pylib/mipylib/numeric/core/numeric$py.class index 11336b1b..48e11989 100644 Binary files a/meteoinfo-lab/pylib/mipylib/numeric/core/numeric$py.class and b/meteoinfo-lab/pylib/mipylib/numeric/core/numeric$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/numeric.py b/meteoinfo-lab/pylib/mipylib/numeric/core/numeric.py index 4bd053fa..1d133260 100644 --- a/meteoinfo-lab/pylib/mipylib/numeric/core/numeric.py +++ b/meteoinfo-lab/pylib/mipylib/numeric/core/numeric.py @@ -1166,12 +1166,7 @@ def any(x, axis=None): if isinstance(x, list): x = array(x) - if axis is None: - return ArrayMath.any(x._array) - else: - if axis < 0: - axis += x.ndim - return NDArray(ArrayMath.any(x._array, axis)) + return x.any(axis) def all(x, axis=None): """ diff --git a/meteoinfo-lab/pylib/mipylib/numeric/stats/stats$py.class b/meteoinfo-lab/pylib/mipylib/numeric/stats/stats$py.class index 2a227d40..c6125756 100644 Binary files a/meteoinfo-lab/pylib/mipylib/numeric/stats/stats$py.class and b/meteoinfo-lab/pylib/mipylib/numeric/stats/stats$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/numeric/stats/stats.py b/meteoinfo-lab/pylib/mipylib/numeric/stats/stats.py index b69a5c14..34348f65 100644 --- a/meteoinfo-lab/pylib/mipylib/numeric/stats/stats.py +++ b/meteoinfo-lab/pylib/mipylib/numeric/stats/stats.py @@ -10,7 +10,7 @@ from org.meteoinfo.math.stats import StatsUtil from org.meteoinfo.ndarray.math import ArrayMath from org.meteoinfo.ndarray import Array -from ..core import numeric as np +from .. import core as np from collections import namedtuple import warnings diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_figure$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/_figure$py.class index 237bd57e..d8d9766b 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/_figure$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/_figure$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/_figure.py b/meteoinfo-lab/pylib/mipylib/plotlib/_figure.py index 00976fd3..72273e16 100644 --- a/meteoinfo-lab/pylib/mipylib/plotlib/_figure.py +++ b/meteoinfo-lab/pylib/mipylib/plotlib/_figure.py @@ -504,7 +504,7 @@ class Figure(GLChartPanel): """ Set MouseMode. - :param mm: (*string*) MouseMode string [zoom_in | zoom_out | pan | identifer + :param mm: (*string*) MouseMode string [zoom_in | zoom_out | pan | identifier | rotate | select]. """ mm = MouseMode.valueOf(mm.upper()) diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class b/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class index 3a08a90b..7baa6fbf 100644 Binary files a/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class and b/meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py b/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py index 64228ad1..4d68dd57 100644 --- a/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py +++ b/meteoinfo-lab/pylib/mipylib/plotlib/miplot.py @@ -846,7 +846,7 @@ def axes3dgl(*args, **kwargs): def axes3d_map(*args, **kwargs): """ - Add an map 3d axes with JOGL to the figure. + Add a map 3d axes with JOGL to the figure. :returns: The axes. """ diff --git a/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmAppsManager.java b/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmAppsManager.java index beab0e08..75d431d7 100644 --- a/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmAppsManager.java +++ b/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmAppsManager.java @@ -8,6 +8,8 @@ import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -204,9 +206,12 @@ public class FrmAppsManager extends javax.swing.JDialog { File fs[] = f.listFiles(); for (File ff : fs) { if (ff.isDirectory()) { - Application plugin = this.readPyApp(ff.getName(), "loadApp.py"); - if (plugin != null) { - plugins.add(plugin); + Path loadApp = Paths.get(ff.getPath(), "loadApp.py"); + if (loadApp.toFile().isFile()) { + Application plugin = this.readPyApp(ff.getName(), "loadApp.py"); + if (plugin != null) { + plugins.add(plugin); + } } } } diff --git a/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmMain.java b/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmMain.java index 21d88c64..84aebc61 100644 --- a/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmMain.java +++ b/meteoinfo-lab/src/main/java/org/meteoinfo/lab/gui/FrmMain.java @@ -157,8 +157,12 @@ public class FrmMain extends javax.swing.JFrame implements IApplication { if (this.startupPath.endsWith("meteoinfo-lab")) { Path path = new File(this.startupPath).toPath(); path = path.getParent(); - path = path.resolve(Paths.get("auxdata", "toolbox")); - toolboxPath = path.toString(); + Path toolPath = path.getParent(); + toolPath = toolPath.resolve(Paths.get("toolbox")); + if (!toolPath.toFile().isDirectory()) { + toolPath = path.resolve(Paths.get("auxdata", "toolbox")); + } + toolboxPath = toolPath.toString(); } String appConfFn = toolboxPath + File.separator + "apps.xml"; if (new File(appConfFn).exists()) { diff --git a/meteoinfo-math/src/main/java/org/meteoinfo/math/meteo/WRF.java b/meteoinfo-math/src/main/java/org/meteoinfo/math/meteo/WRF.java new file mode 100644 index 00000000..a427f61f --- /dev/null +++ b/meteoinfo-math/src/main/java/org/meteoinfo/math/meteo/WRF.java @@ -0,0 +1,163 @@ +/* + * Calculation algorithm for WRF model output + */ +package org.meteoinfo.math.meteo; + +import org.meteoinfo.ndarray.Array; +import org.meteoinfo.ndarray.Index3D; + +public class WRF { + //constants + public static final double GAMMA_SEVEN = 720.; + public static final double RHOWAT = 1000.; + public static final double RHO_R = RHOWAT; + public static final double RHO_S = 100.; + public static final double RHO_G = 400.; + public static final double ALPHA = 0.224; + public static final double CELKEL = 273.15; + public static final double PI = 3.141592653589793; + public static final double RD = 287.04; + + /** + * Computes equivalent reflectivity factor (in dBZ) at + * each model grid point. + * + * @param prs Pressure + * @param tmk Temperature + * @param qvp Water vapor mixing ratio + * @param qra Rain water mixing ratio + * @param qsn Snow mixing ratio + * @param qgr Graupel mixing ratio + * @param sn0 Whether snow mixing ratio is not all 0 + * @param ivarint The variable intercept parameter + * @param iliqskin The frozen particles parameter + * @return Calculated dBZ array + */ + public static Array calcDBZ(Array prs, Array tmk, Array qvp, Array qra, Array qsn, Array qgr, + int sn0, int ivarint, int iliqskin) { + int[] shape = prs.getShape(); + int nz = shape[0]; int ny = shape[1]; int nx = shape[2]; + int i, j, k; + double temp_c, virtual_t, gonv, ronv, sonv, factor_g, factor_r, factor_s, + factorb_g, factorb_s, rhoair, z_e; + + //Constants used to calculate variable intercepts + double R1 = 1.E-15; + double RON = 8.E6; + double RON2 = 1.E10; + double SON = 2.E7; + double GON = 5.E7; + double RON_MIN = 8.E6; + double RON_QR0 = 0.00010; + double RON_DELQR0 = 0.25 * RON_QR0; + double RON_CONST1R = (RON2-RON_MIN)*0.5; + double RON_CONST2R = (RON2+RON_MIN)*0.5; + + //Constant intercepts + double RN0_R = 8.E6; + double RN0_S = 2.E7; + double RN0_G = 4.E6; + + //Force all Q arrays to be 0.0 or greater. + Index3D index = (Index3D) Index3D.factory(shape); + for (k = 0; k < nz; k++) { + for (j = 0; j < ny; j++) { + for (i = 0; i < nx; i++) { + index.set(k, j, i); + if (qvp.getDouble(index) < 0.0) { + qvp.setDouble(index, 0.0); + } + if (qra.getDouble(index) < 0.0) { + qra.setDouble(index, 0.0); + } + if (qsn.getDouble(index) < 0.0) { + qsn.setDouble(index, 0.0); + } + if (qgr.getDouble(index) < 0.0) { + qgr.setDouble(index, 0.0); + } + } + } + } + + //Input pressure is Pa, but we need hPa in calculations + if (sn0 == 0) { + for (k = 0; k < nz; k++) { + for (j = 0; j < ny; j++) { + for (i = 0; i < nx; i++) { + index.set(k, j, i); + if (tmk.getDouble(index) < CELKEL) { + qsn.setDouble(index, qra.getDouble(index)); + qra.setDouble(index, 0.); + } + } + } + } + } + + factor_r = GAMMA_SEVEN * 1.E18 * Math.pow((1.0 / (PI * RHO_R)), 1.75); + factor_s = GAMMA_SEVEN * 1.E18 * Math.pow((1.0 / (PI * RHO_S)), 1.75) * + Math.pow((RHO_S / RHOWAT), 2) * ALPHA; + factor_g = GAMMA_SEVEN * 1.E18 * Math.pow((1.0 / (PI * RHO_G)), 1.75) * + Math.pow((RHO_G / RHOWAT), 2) * ALPHA; + + Array dbz = Array.factory(prs.getDataType(), shape); + for (k = 0; k < nz; k++) { + for (j = 0; j < ny; j++) { + for (i = 0; i < nx; i++) { + index.set(k, j, i); + virtual_t = tmk.getDouble(index) * (0.622 + qvp.getDouble(index)) / + (0.622 * (1. + qvp.getDouble(index))); + rhoair = prs.getDouble(index) / (RD * virtual_t); + + //Adjust factor for brightband, where snow or graupel particle + //scatters like liquid water (alpha=1.0) because it is assumed to + //have a liquid skin. + if (iliqskin == 1 && tmk.getDouble(index) > CELKEL) { + factorb_s = factor_s / ALPHA; + factorb_g = factor_g / ALPHA; + } else { + factorb_s = factor_s; + factorb_g = factor_g; + } + + //Calculate variable intercept parameters + if (ivarint == 1) { + temp_c = Math.min(-0.001, tmk.getDouble(index) - CELKEL); + sonv = Math.min(2.0E8, 2.0E6 * Math.exp(-0.12 * temp_c)); + + gonv = GON; + if (qgr.getDouble(index) > R1) { + gonv = 2.38 * Math.pow(PI * RHO_G / (rhoair * qgr.getDouble(index)), 0.92); + gonv = Math.max(1.E4, Math.min(gonv, GON)); + } + + ronv = RON2; + if (qra.getDouble(index) > R1) { + ronv = RON_CONST1R * Math.tanh((RON_QR0 - qra.getDouble(index)) / RON_DELQR0) + RON_CONST2R; + } + + } else { + ronv = RN0_R; + sonv = RN0_S; + gonv = RN0_G; + } + + //Total equivalent reflectivity factor (z_e, in mm^6 m^-3) is + //the sum of z_e for each hydrometeor species: + z_e = factor_r * Math.pow(rhoair * qra.getDouble(index), 1.75) / Math.pow(ronv, .75) + + factorb_s * Math.pow(rhoair * qsn.getDouble(index), 1.75) / Math.pow(sonv, .75) + + factorb_g * Math.pow(rhoair * qgr.getDouble(index), 1.75) / Math.pow(gonv, .75); + + //Adjust small values of Z_e so that dBZ is no lower than -30 + z_e = Math.max(z_e, .001); + + //Convert to dBZ + dbz.setDouble(index, 10. * Math.log10(z_e)); + } + } + } + + return dbz; + } +} diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java index 546d7f96..9262c99d 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java @@ -228,14 +228,14 @@ public class ArrayDouble extends Array { * not legal, throw ForbiddenConversionException */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return storageD[i.currentElement()] != 0; } /** * not legal, throw ForbiddenConversionException */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storageD[i.currentElement()] = value ? 1 : 0; } /** @@ -336,11 +336,11 @@ public class ArrayDouble extends Array { } public boolean getBoolean(int index) { - throw new ForbiddenConversionException(); + return storageD[index] != 0; } public void setBoolean(int index, boolean value) { - throw new ForbiddenConversionException(); + storageD[index] = value ? 1 : 0; } public String getString(int index) { diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayFloat.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayFloat.java index 53adb578..fc941d29 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayFloat.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayFloat.java @@ -233,14 +233,14 @@ public class ArrayFloat extends Array { * not legal, throw ForbiddenConversionException */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return storage[i.currentElement()] != 0; } /** * not legal, throw ForbiddenConversionException */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = value ? 1 : 0; } /** @@ -341,11 +341,11 @@ public class ArrayFloat extends Array { } public boolean getBoolean(int index) { - throw new ForbiddenConversionException(); + return storage[index] != 0; } public void setBoolean(int index, boolean value) { - throw new ForbiddenConversionException(); + storage[index] = value ? 1 : 0; } public String getString(int index) { diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayInt.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayInt.java index 4b4d9cfb..294778f1 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayInt.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayInt.java @@ -248,14 +248,14 @@ public class ArrayInt extends Array { * not legal, throw ForbiddenConversionException */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return storage[i.currentElement()] != 0; } /** * not legal, throw ForbiddenConversionException */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = value ? 1 : 0; } /** diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayLong.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayLong.java index a2530261..7e47c5e1 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayLong.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayLong.java @@ -238,14 +238,14 @@ public class ArrayLong extends Array { * not legal, throw ForbiddenConversionException */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return storage[i.currentElement()] != 0; } /** * not legal, throw ForbiddenConversionException */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = value ? 1 : 0; } /** @@ -348,11 +348,11 @@ public class ArrayLong extends Array { } public boolean getBoolean(int index) { - throw new ForbiddenConversionException(); + return storage[index] != 0; } public void setBoolean(int index, boolean value) { - throw new ForbiddenConversionException(); + storage[index] = value ? 1 : 0; } public String getString(int index) { diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayShort.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayShort.java index 860542e4..a2478e4a 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayShort.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayShort.java @@ -243,18 +243,12 @@ public class ArrayShort extends Array { storage[i.currentElement()] = (short) value; } - /** - * not legal, throw ForbiddenConversionException - */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return storage[i.currentElement()] != 0; } - /** - * not legal, throw ForbiddenConversionException - */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = value ? (short) 1 : 0; } /** @@ -362,11 +356,11 @@ public class ArrayShort extends Array { } public boolean getBoolean(int index) { - throw new ForbiddenConversionException(); + return storage[index] != 0; } public void setBoolean(int index, boolean value) { - throw new ForbiddenConversionException(); + storage[index] = value ? (short)1 : 0; } public String getString(int index) {