diff --git a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java index d94473bd..ef70ac1c 100644 --- a/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java +++ b/meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java @@ -1624,31 +1624,27 @@ public class Axis extends Artist implements Cloneable { } //Time label - left if (this.drawTickLabel) { - DateTimeFormatter format; if (this instanceof TimeAxis) { TimeAxis tAxis = (TimeAxis) this; if (tAxis.isVarFormat()) { - drawStr = null; + int idx = this.inverse ? this.getTickValues().length - 1 : 0; + LocalDateTime cDate = JDateUtil.fromOADate(this.getTickValues()[idx]); + DateTimeFormatter format = null; switch (tAxis.getTimeUnit()) { case MONTH: format = DateTimeFormatter.ofPattern("yyyy"); - LocalDateTime cdate = JDateUtil.fromOADate(this.getTickValues()[0]); - drawStr = format.format(cdate); break; case DAY: format = DateTimeFormatter.ofPattern("yyyy-MM"); - cdate = JDateUtil.fromOADate(this.getTickValues()[0]); - drawStr = format.format(cdate); break; case HOUR: case MINUTE: case SECOND: format = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - cdate = JDateUtil.fromOADate(this.getTickValues()[0]); - drawStr = format.format(cdate); break; } - if (drawStr != null) { + if (format != null) { + drawStr = format.format(cDate); labx = (float) minx; laby = laby + this.tickSpace; Draw.drawString(g, labx, laby, drawStr, XAlign.LEFT, YAlign.TOP, true); diff --git a/meteoinfo-lab/milconfig.xml b/meteoinfo-lab/milconfig.xml index 1bf2b597..a1700e12 100644 --- a/meteoinfo-lab/milconfig.xml +++ b/meteoinfo-lab/milconfig.xml @@ -1,14 +1,11 @@ - - - + - @@ -16,17 +13,20 @@ + + + - - + + - - + + diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype$py.class b/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype$py.class index 0987351d..25df6918 100644 Binary files a/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype$py.class and b/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype$py.class differ diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype.py b/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype.py index b8a66647..1c8ed457 100644 --- a/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype.py +++ b/meteoinfo-lab/pylib/mipylib/numeric/core/_dtype.py @@ -7,16 +7,25 @@ __all__ = [ _dtype_dict = dict(byte = JDataType.BYTE, char = JDataType.CHAR, + bool = JDataType.BOOLEAN, boolean = JDataType.BOOLEAN, int = JDataType.INT, + int32 = JDataType.INT, + integer = JDataType.INT, uint = JDataType.UINT, short = JDataType.SHORT, + int16 = JDataType.SHORT, long = JDataType.LONG, + int64 = JDataType.LONG, float = JDataType.FLOAT, + float32 = JDataType.FLOAT, double = JDataType.DOUBLE, + float64 = JDataType.DOUBLE, + str = JDataType.STRING, string = JDataType.STRING, complex = JDataType.COMPLEX, date = JDataType.DATE, + datetime = JDataType.DATE, object = JDataType.OBJECT) class DataType(object): diff --git a/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py b/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py index 97d95ef5..d32e10c9 100644 --- a/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py +++ b/meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py @@ -717,17 +717,18 @@ class NDArray(object): if self.dtype == dtype: return self.copy() - if dtype.kind == 'i': - r = NDArray(ArrayUtil.toInteger(self._array)) - elif dtype.kind == 'f': - if dtype.name == 'float': - r = NDArray(ArrayUtil.toFloat(self._array)) - else: - r = NDArray(ArrayUtil.toDouble(self._array)) - elif dtype.kind == 'b': - r = NDArray(ArrayUtil.toBoolean(self._array)) - else: - r = self + # if dtype.kind == 'i': + # r = NDArray(ArrayUtil.toInteger(self._array)) + # elif dtype.kind == 'f': + # if dtype.name == 'float': + # r = NDArray(ArrayUtil.toFloat(self._array)) + # else: + # r = NDArray(ArrayUtil.toDouble(self._array)) + # elif dtype.kind == 'b': + # r = NDArray(ArrayUtil.toBoolean(self._array)) + # else: + # r = self + r = NDArray(ArrayUtil.convertToDataType(self._array, dtype._dtype)) return r @property 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 a21c5a8d..7c8c1e17 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayDouble.java @@ -32,6 +32,8 @@ */ package org.meteoinfo.ndarray; +import org.meteoinfo.common.util.JDateUtil; + import java.nio.ByteBuffer; import java.nio.DoubleBuffer; import java.time.LocalDateTime; @@ -266,9 +268,13 @@ public class ArrayDouble extends Array { throw new ForbiddenConversionException(); } - public LocalDateTime getDate(Index i) { throw new ForbiddenConversionException(); } + public LocalDateTime getDate(Index i) { + return JDateUtil.fromOADate(storageD[i.currentElement()]); + } - public void setDate(Index i, LocalDateTime value) { throw new ForbiddenConversionException(); } + public void setDate(Index i, LocalDateTime value) { + storageD[i.currentElement()] = JDateUtil.toOADate(value); + } public Object getObject(Index i) { return storageD[i.currentElement()]; @@ -363,9 +369,13 @@ public class ArrayDouble extends Array { throw new ForbiddenConversionException(); } - public LocalDateTime getDate(int index) { throw new ForbiddenConversionException(); } + public LocalDateTime getDate(int index) { + return JDateUtil.fromOADate(storageD[index]); + } - public void setDate(int index, LocalDateTime value) { throw new ForbiddenConversionException(); } + public void setDate(int index, LocalDateTime value) { + storageD[index] = JDateUtil.toOADate(value); + } public Object getObject(int index) { return getDouble(index); diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayString.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayString.java index ba9722a9..e2ba3373 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayString.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/ArrayString.java @@ -191,122 +191,122 @@ public class ArrayString extends Array { } /** - * set the value at the sepcified index. + * set the value at the specified index. */ public void set(Index i, String value) { storage[i.currentElement()] = value; } /** - * not legal, throw ForbiddenConversionException + * get the double value at the specified index. */ public double getDouble(Index i) { - throw new ForbiddenConversionException(); + return Double.parseDouble(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setDouble(Index i, double value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the float value at the specified index. */ public float getFloat(Index i) { - throw new ForbiddenConversionException(); + return Float.parseFloat(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setFloat(Index i, float value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the long value at the specified index. */ public long getLong(Index i) { - throw new ForbiddenConversionException(); + return Long.parseLong(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setLong(Index i, long value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the integer value at the specified index. */ public int getInt(Index i) { - throw new ForbiddenConversionException(); + return Integer.parseInt(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setInt(Index i, int value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the short value at the specified index. */ public short getShort(Index i) { - throw new ForbiddenConversionException(); + return Short.parseShort(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setShort(Index i, short value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the byte value at the specified index. */ public byte getByte(Index i) { - throw new ForbiddenConversionException(); + return Byte.parseByte(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setByte(Index i, byte value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the boolean value at the specified index. */ public boolean getBoolean(Index i) { - throw new ForbiddenConversionException(); + return Boolean.parseBoolean(storage[i.currentElement()]); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setBoolean(Index i, boolean value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } /** - * not legal, throw ForbiddenConversionException + * get the char value at the specified index. */ public char getChar(Index i) { - throw new ForbiddenConversionException(); + return storage[i.currentElement()].charAt(0); } /** - * not legal, throw ForbiddenConversionException + * set the value at the specified index. */ public void setChar(Index i, char value) { - throw new ForbiddenConversionException(); + storage[i.currentElement()] = String.valueOf(value); } public String getString(Index i) { @@ -339,67 +339,67 @@ public class ArrayString extends Array { // package private : mostly for iterators public double getDouble(int index) { - throw new ForbiddenConversionException(); + return Double.parseDouble(storage[index]); } public void setDouble(int index, double value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public float getFloat(int index) { - throw new ForbiddenConversionException(); + return Float.parseFloat(storage[index]); } public void setFloat(int index, float value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public long getLong(int index) { - throw new ForbiddenConversionException(); + return Long.parseLong(storage[index]); } public void setLong(int index, long value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public int getInt(int index) { - throw new ForbiddenConversionException(); + return Integer.parseInt(storage[index]); } public void setInt(int index, int value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public short getShort(int index) { - throw new ForbiddenConversionException(); + return Short.parseShort(storage[index]); } public void setShort(int index, short value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value);; } public byte getByte(int index) { - throw new ForbiddenConversionException(); + return Byte.parseByte(storage[index]); } public void setByte(int index, byte value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public char getChar(int index) { - throw new ForbiddenConversionException(); + return storage[index].charAt(0); } public void setChar(int index, char value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public boolean getBoolean(int index) { - throw new ForbiddenConversionException(); + return Boolean.parseBoolean(storage[index]); } public void setBoolean(int index, boolean value) { - throw new ForbiddenConversionException(); + storage[index] = String.valueOf(value); } public String getString(int index) { @@ -411,11 +411,11 @@ public class ArrayString extends Array { } public Complex getComplex(int index) { - throw new ForbiddenConversionException(); + return Complex.parse(storage[index]); } public void setComplex(int index, Complex value) { - throw new ForbiddenConversionException(); + storage[index] = value.toString(); } public LocalDateTime getDate(int index) { throw new ForbiddenConversionException(); } diff --git a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/math/ArrayUtil.java b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/math/ArrayUtil.java index b9ae9cab..aa756411 100644 --- a/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/math/ArrayUtil.java +++ b/meteoinfo-ndarray/src/main/java/org/meteoinfo/ndarray/math/ArrayUtil.java @@ -1900,6 +1900,76 @@ public class ArrayUtil { } } + /** + * Convert array to another data type + * @param a The input array + * @param dataType The data type to be converted + * @return Converted array + */ + public static Array convertToDataType(Array a, DataType dataType) { + if (a.getDataType() == dataType) { + return a; + } else { + Array r = Array.factory(dataType, a.getShape()); + IndexIterator iterA = a.getIndexIterator(); + IndexIterator iterR = r.getIndexIterator(); + switch (dataType) { + case BYTE: + while (iterR.hasNext()) { + iterR.setByteNext(iterA.getByteNext()); + } + break; + case BOOLEAN: + while (iterR.hasNext()) { + iterR.setBooleanNext(iterA.getBooleanNext()); + } + break; + case SHORT: + while (iterR.hasNext()) { + iterR.setShortNext(iterA.getShortNext()); + } + break; + case INT: + while (iterR.hasNext()) { + iterR.setIntNext(iterA.getIntNext()); + } + break; + case LONG: + while (iterR.hasNext()) { + iterR.setLongNext(iterA.getLongNext()); + } + break; + case FLOAT: + while (iterR.hasNext()) { + iterR.setFloatNext(iterA.getFloatNext()); + } + break; + case DOUBLE: + while (iterR.hasNext()) { + iterR.setDoubleNext(iterA.getDoubleNext()); + } + break; + case COMPLEX: + while (iterR.hasNext()) { + iterR.setComplexNext(iterA.getComplexNext()); + } + break; + case STRING: + while (iterR.hasNext()) { + iterR.setStringNext(iterA.getStringNext()); + } + break; + case DATE: + while (iterR.hasNext()) { + iterR.setDateNext(iterA.getDateNext()); + } + break; + } + + return r; + } + } + /** * Convert array to integer type *