Skip to content

Commit

Permalink
update array's astype function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaqiang committed Jul 24, 2024
1 parent 4de1cef commit ee78df3
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 83 deletions.
14 changes: 5 additions & 9 deletions meteoinfo-chart/src/main/java/org/meteoinfo/chart/axis/Axis.java
Original file line number Diff line number Diff line change
Expand Up @@ -1624,31 +1624,27 @@ void drawXAxis(Graphics2D g, Rectangle2D area, AbstractPlot2D plot) {
}
//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);
Expand Down
16 changes: 8 additions & 8 deletions meteoinfo-lab/milconfig.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\contour">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\axis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\topology"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\traj">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\eof"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\subplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\scatter"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conout_negtive_value.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm_clabel_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\array\astype_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\traj\plot_traj_bd.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_3.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conout_negtive_value.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\contour\conoutm_clabel_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\array\astype_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\traj\plot_traj_bd.py"/>
</RecentFiles>
</File>
<Font>
Expand Down
Binary file modified meteoinfo-lab/pylib/mipylib/numeric/core/_dtype$py.class
Binary file not shown.
9 changes: 9 additions & 0 deletions meteoinfo-lab/pylib/mipylib/numeric/core/_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@

_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):
Expand Down
23 changes: 12 additions & 11 deletions meteoinfo-lab/pylib/mipylib/numeric/core/_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,18 @@ def astype(self, dtype):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,9 +268,13 @@ public void setComplex(Index i, Complex value) {
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()];
Expand Down Expand Up @@ -363,9 +369,13 @@ public void setComplex(int index, Complex value) {
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);
Expand Down
Loading

0 comments on commit ee78df3

Please sign in to comment.