move DimArray to the dataset package

This commit is contained in:
wyq 2025-10-23 14:57:14 +08:00
parent cd03155677
commit eba0fd101c
61 changed files with 421 additions and 578 deletions

View File

@ -18,6 +18,7 @@ import org.meteoinfo.ndarray.math.ArrayMath;
import org.meteoinfo.ndarray.math.ArrayUtil;
import org.meteoinfo.ndarray.util.BigDecimalUtil;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -101,6 +102,17 @@ public class Dimension {
this(name, dimValue, DimensionType.OTHER);
}
/**
* Constructor
*
* @param name Name
* @param dimType Dimension type
*/
public Dimension(String name, DimensionType dimType) {
this.name = name;
this.dimType = dimType;
}
/**
* Constructor
*
@ -415,6 +427,15 @@ public class Dimension {
dimValue = ArrayUtil.array(values);
}
/**
* Set dimension value
* @param v Dimension value
*/
public void setValue(LocalDateTime v) {
dimValue = Array.factory(DataType.DATE, new int[]{1});
dimValue.setDate(0, v);
}
/**
* Set dimension value
* @param v Dimension value
@ -527,29 +548,33 @@ public class Dimension {
dim.setStagger(this.stagger);
//dim.setReverse(this.reverse);
if (this.dimValue.getSize() > last) {
List<Double> values = new ArrayList<>();
List values = new ArrayList<>();
if (first <= last) {
if (stride > 0) {
for (int i = first; i <= last; i += stride) {
values.add(this.dimValue.getDouble(i));
values.add(this.dimValue.getObject(i));
}
} else {
for (int i = last; i >= first; i += stride) {
values.add(this.dimValue.getDouble(i));
values.add(this.dimValue.getObject(i));
}
}
} else {
if (stride > 0) {
for (int i = last; i <= first; i += stride) {
values.add(this.dimValue.getDouble(i));
values.add(this.dimValue.getObject(i));
}
} else {
for (int i = first; i >= last; i += stride) {
values.add(this.dimValue.getDouble(i));
values.add(this.dimValue.getObject(i));
}
}
}
dim.setValues(values);
Array array = Array.factory(this.dimValue.getDataType(), new int[]{values.size()});
for (int i = 0; i < values.size(); i++) {
array.setObject(i, values.get(i));
}
dim.setDimValue(array);
}
return dim;
@ -568,13 +593,17 @@ public class Dimension {
dim.setDimId(this.dimId);
dim.setUnit(this.unit);
dim.setStagger(this.stagger);
List<Double> values = new ArrayList<>();
List values = new ArrayList<>();
int idx;
for (double v = first; v <= last; v += stride) {
idx = this.getValueIndex(v);
values.add(this.dimValue.getDouble(idx));
values.add(this.dimValue.getObject(idx));
}
dim.setValues(values);
Array array = Array.factory(this.dimValue.getDataType(), new int[]{values.size()});
for (int i = 0; i < values.size(); i++) {
array.setObject(i, values.get(i));
}
dim.setDimValue(array);
return dim;
}
@ -590,12 +619,11 @@ public class Dimension {
dim.setDimId(this.dimId);
dim.setUnit(this.unit);
dim.setStagger(this.stagger);
//dim.setReverse(this.reverse);
List<Double> values = new ArrayList<>();
Array array = Array.factory(this.dimValue.getDataType(), new int[]{index.size()});
for (int i = 0; i < index.size(); i++) {
values.add(this.dimValue.getDouble(index.get(i)));
array.setObject(i, this.dimValue.getObject(index.get(i)));
}
dim.setValues(values);
dim.setDimValue(array);
return dim;
}
@ -611,12 +639,13 @@ public class Dimension {
dim.setDimId(this.dimId);
dim.setUnit(this.unit);
dim.setStagger(this.stagger);
List<Double> values = new ArrayList<>();
Array values = Array.factory(this.dimValue.getDataType(), new int[]{(int) index.getSize()});
IndexIterator iter = index.getIndexIterator();
IndexIterator iterV = values.getIndexIterator();
while (iter.hasNext()) {
values.add(this.dimValue.getDouble(iter.getIntNext()));
iterV.setObjectNext(this.dimValue.getObject(iter.getIntNext()));
}
dim.setValues(values);
dim.setDimValue(values);
return dim;
}

View File

@ -0,0 +1,23 @@
package org.meteoinfo.data.meteodata;
import org.meteoinfo.data.dimarray.Dimension;
public class Coordinate extends Variable {
/**
* Get dimension
* @return The dimension
*/
public Dimension getDimension() {
return this.dimensions.get(0);
}
/**
* Set dimension
* @param value The dimension
*/
public void setDimension(Dimension value) {
this.dimensions.clear();
this.dimensions.add(value);
}
}

View File

@ -23,10 +23,8 @@ import java.util.List;
import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.dimarray.DimArray;
import org.meteoinfo.data.dimarray.DimensionType;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.*;
import org.meteoinfo.data.dimarray.Dimension;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.Range;
import org.meteoinfo.ndarray.math.ArrayMath;
import org.meteoinfo.projection.KnownCoordinateSystems;
import org.meteoinfo.projection.ProjectionInfo;
@ -158,17 +156,29 @@ import org.meteoinfo.projection.ProjectionInfo;
*
* @return Times
*/
public List<LocalDateTime> getTimes() {
public Array getTimes() {
if (tDim == null) {
return null;
}
Array values = tDim.getDimValue();
List<LocalDateTime> times = new ArrayList<>();
for (int i = 0; i < values.getSize(); i++) {
times.add(JDateUtil.fromOADate(values.getDouble(i)));
return tDim.getDimValue();
}
/**
* Get times
*
* @return Times
*/
public List<LocalDateTime> getTimeList() {
if (tDim == null) {
return null;
}
List<LocalDateTime> times = new ArrayList<>();
IndexIterator iter = tDim.getDimValue().getIndexIterator();
while (iter.hasNext()) {
times.add(iter.getDateNext());
}
return times;
}
@ -182,7 +192,7 @@ import org.meteoinfo.projection.ProjectionInfo;
if (tDim == null)
return null;
return JDateUtil.fromOADate(tDim.getDimValue().getDouble(timeIdx));
return tDim.getDimValue().getDate(timeIdx);
}
/**
@ -194,7 +204,7 @@ import org.meteoinfo.projection.ProjectionInfo;
if (tDim == null)
return Double.NaN;
return tDim.getDimValue().getDouble(timeIdx);
return JDateUtil.toOADate(tDim.getDimValue().getDate(timeIdx));
}
/**
@ -232,9 +242,11 @@ import org.meteoinfo.projection.ProjectionInfo;
* @return Time values
*/
public List<Integer> getTimeValues(LocalDateTime baseDate, String tDelta) {
List<LocalDateTime> times = this.getTimes();
Array times = this.getTimes();
List<Integer> values = new ArrayList<>();
for (LocalDateTime time : times) {
IndexIterator iter = times.getIndexIterator();
while (iter.hasNext()){
LocalDateTime time = iter.getDateNext();
if (tDelta.equalsIgnoreCase("hours")) {
values.add((int)Duration.between(baseDate, time).toHours());
} else if (tDelta.equalsIgnoreCase("days")) {
@ -251,16 +263,25 @@ import org.meteoinfo.projection.ProjectionInfo;
* @param value Times
*/
public void setTimes(List<LocalDateTime> value) {
List<Double> values = new ArrayList<>();
Array times = Array.factory(DataType.DATE, new int[]{value.size()});
IndexIterator iter = times.getIndexIterator();
for (LocalDateTime t : value) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
if (tDim == null) {
tDim = new Dimension(DimensionType.T);
}
tDim.setValues(values);
tDim.setDimValue(times);
}
/**
* Set times array
* @param value Times array
*/
public void setTimes(Array value) {
tDim.setDimValue(value);
}
/**

View File

@ -1264,7 +1264,7 @@ public class MeteoDataInfo {
tData = tData.setValue(tData.getDoubleMissingValue());
int xnum = gData.getXNum();
int ynum = gData.getYNum();
LocalDateTime date = this.getDataInfo().getTimes().get(0);
LocalDateTime date = this.getDataInfo().getTimes().getDate(0);
List<Integer> hours = this.getDataInfo().getTimeValues(date, "hours");
for (int t = 0; t < tnum; t++) {
int hour = hours.get(t);
@ -1297,24 +1297,24 @@ public class MeteoDataInfo {
* @return Interpolated value
*/
public double toStation(String varName, double x, double y, double z, LocalDateTime t) {
List<LocalDateTime> times = this.getDataInfo().getTimes();
int tnum = times.size();
if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
Array times = this.getDataInfo().getTimes();
int tnum = (int) times.getSize();
if (t.isBefore(times.getDate(0)) || t.isAfter(times.getDate(tnum - 1))) {
return this.getDataInfo().getMissingValue();
}
double ivalue = this.getDataInfo().getMissingValue();
double v_t1, v_t2;
for (int i = 0; i < tnum; i++) {
if (t.equals(times.get(i))) {
if (t.equals(times.getDate(i))) {
ivalue = this.toStation(varName, x, y, z, i);
break;
}
if (t.isBefore(times.get(i))) {
if (t.isBefore(times.getDate(i))) {
v_t1 = this.toStation(varName, x, y, z, i - 1);
v_t2 = this.toStation(varName, x, y, z, i);
int h = (int)Duration.between(times.get(i - 1), t).toHours();
int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours();
int h = (int)Duration.between(times.getDate(i - 1), t).toHours();
int th = (int)Duration.between(times.getDate(i - 1), times.getDate(i)).toHours();
ivalue = (v_t2 - v_t1) * h / th + v_t1;
break;
}
@ -1333,24 +1333,24 @@ public class MeteoDataInfo {
* @return Interpolated value
*/
public double toStation(String varName, double x, double y, LocalDateTime t) {
List<LocalDateTime> times = this.getDataInfo().getTimes();
int tnum = times.size();
if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
Array times = this.getDataInfo().getTimes();
int tnum = (int) times.getSize();
if (t.isBefore(times.getDate(0)) || t.isAfter(times.getDate(tnum - 1))) {
return this.getDataInfo().getMissingValue();
}
double ivalue = this.getDataInfo().getMissingValue();
double v_t1, v_t2;
for (int i = 0; i < tnum; i++) {
if (t.equals(times.get(i))) {
if (t.equals(times.getDate(i))) {
ivalue = this.toStation(varName, x, y, i);
break;
}
if (t.isBefore(times.get(i))) {
if (t.isBefore(times.getDate(i))) {
v_t1 = this.toStation(varName, x, y, i - 1);
v_t2 = this.toStation(varName, x, y, i);
int h = (int)Duration.between(times.get(i - 1), t).toHours();
int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours();
int h = (int)Duration.between(times.getDate(i - 1), t).toHours();
int th = (int)Duration.between(times.getDate(i - 1), times.getDate(i)).toHours();
ivalue = (v_t2 - v_t1) * h / th + v_t1;
break;
}
@ -1370,7 +1370,7 @@ public class MeteoDataInfo {
* @return Interpolated values
*/
public List<Double> toStation(List<String> varNames, double x, double y, double z, LocalDateTime t) {
List<LocalDateTime> times = this.getDataInfo().getTimes();
List<LocalDateTime> times = this.getDataInfo().getTimeList();
int tnum = times.size();
if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
return null;

View File

@ -32,9 +32,9 @@ public class Variable {
// <editor-fold desc="Variables">
public int Number;
private String name;
private String shortName;
private DataType dataType;
protected String name;
protected String shortName;
protected DataType dataType;
protected int[] shape = new int[0];
protected List<Dimension> dimensions = new ArrayList<>();
protected List<Attribute> attributes = new ArrayList<>();
@ -43,8 +43,8 @@ public class Variable {
protected double fillValue = Double.NaN;
private int levelType;
private List<Double> levels;
private String units;
private String description;
protected String units;
protected String description;
private String hdfPath;
private boolean isStation = false;
private boolean isSwath = false;
@ -53,7 +53,7 @@ public class Variable {
private boolean memberOfStructure = false;
private List<Integer> levelIdxs = new ArrayList<>();
private List<Integer> varInLevelIdxs = new ArrayList<>();
private Array cachedData;
protected Array cachedData;
// </editor-fold>
// <editor-fold desc="Constructor">
@ -153,7 +153,7 @@ public class Variable {
/**
* Get dimensions by section
* @param section The section
* @return Result dimesions
* @return Result dimensions
*/
public List<Dimension> getDimensions(Section section) {
List<Dimension> dims = new ArrayList<>();

View File

@ -470,12 +470,13 @@ public class ARLDataInfo extends DataInfo implements IGridDataInfo {
}*/
//Set dimensions
List<Double> values = new ArrayList<>();
Array values = Array.factory(DataType.DATE, new int[]{times.size()});
IndexIterator iter = values.getIndexIterator();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setValues(values);
tDim.setDimValue(values);
this.setTimeDimension(tDim);
this.addDimension(tDim);
@ -954,7 +955,7 @@ public class ARLDataInfo extends DataInfo implements IGridDataInfo {
double[] yArray = new double[tNum];
for (int i = 0; i < tNum; i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(newGridData, Y, yArray, this.missingValue);
@ -1009,7 +1010,7 @@ public class ARLDataInfo extends DataInfo implements IGridDataInfo {
double[] yArray = new double[tNum];
for (int i = 0; i < tNum; i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(newGridData, X, yArray, this.missingValue);
@ -1175,7 +1176,7 @@ public class ARLDataInfo extends DataInfo implements IGridDataInfo {
double[] xArray = new double[tNum];
for (int i = 0; i < tNum; i++) {
xArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
xArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
double[] yArray = new double[lNum];
for (int i = 0; i < lNum; i++) {
@ -1232,7 +1233,7 @@ public class ARLDataInfo extends DataInfo implements IGridDataInfo {
gridData = unpackARLGridData(dataBytes, xNum, yNum, aDL);
aValue = gridData[latIdx][lonIdx];
xArray[t] = JDateUtil.toOADate(this.getTimes().get(t));
xArray[t] = JDateUtil.toOADate(this.getTimes().getDate(t));
data[0][t] = aValue;
}

View File

@ -244,8 +244,13 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
* @return Times
*/
@Override
public List<LocalDateTime> getTimes() {
return TDEF.times;
public Array getTimes() {
Array times = Array.factory(DataType.DATE, new int[]{TDEF.times.size()});
IndexIterator iter = times.getIndexIterator();
for (LocalDateTime dt : TDEF.times) {
iter.setDateNext(dt);
}
return times;
}
/**
@ -808,13 +813,14 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
default:
break;
}
values = new ArrayList<>();
Array tArray = Array.factory(DataType.DATE, new int[]{TDEF.times.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : TDEF.times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setShortName("T");
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
this.addDimension(tDim);
} else {
@ -835,17 +841,17 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
//goto ERROR;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm ddMMMyyyy", Locale.ENGLISH);
values = new ArrayList<>();
Array tArray = Array.factory(DataType.DATE, new int[]{tnum});
for (i = 0; i < tnum; i++) {
String dStr = dataArray[3 + i];
dStr = dStr.replace("Z", " ");
LocalDateTime t = LocalDateTime.parse(dStr, formatter);
TDEF.times.add(t);
values.add(JDateUtil.toOADate(t));
tArray.setDate(i, t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setShortName("T");
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
this.addDimension(tDim);
}
@ -1232,7 +1238,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
return new Object[] {filePath, 0};
}
LocalDateTime time = this.getTimes().get(timeIdx);
LocalDateTime time = this.getTimes().getDate(timeIdx);
DateTimeFormatter format;
String tStr = "year";
if (fn.contains("%y4")) {
@ -1732,7 +1738,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
double[] yArray = new double[this.getTimeNum()];
for (i = 0; i < this.getTimeNum(); i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(gridData, Y, yArray, this.missingValue);
@ -1822,7 +1828,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
double[] yArray = new double[this.getTimeNum()];
for (i = 0; i < this.getTimeNum(); i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(gridData, X, yArray, this.missingValue);
@ -2041,7 +2047,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
double[] xArray = new double[this.getTimeNum()];
for (i = 0; i < this.getTimeNum(); i++) {
xArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
xArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
double[] levels = new double[VARDEF.getVars().get(varIdx).getLevelNum()];
for (i = 0; i < levels.length; i++) {
@ -2325,7 +2331,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
double[] xArray = new double[this.getTimeNum()];
for (i = 0; i < this.getTimeNum(); i++) {
xArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
xArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
double[] yArray = new double[aVar.getLevelNum()];
@ -2391,7 +2397,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
} else //End of time seriel
{
stNum = 0;
if (tNum == getTimes().size() - 1) {
if (tNum == getTimes().getSize() - 1) {
break;
}
tNum += 1;

View File

@ -343,13 +343,14 @@ public class HYSPLITConcDataInfo extends DataInfo implements IGridDataInfo {
}
} while (true);
List<Double> values = new ArrayList<>();
Array tArray = Array.factory(DataType.DATE, new int[]{sample_start.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : sample_start) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setShortName("time");
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
this.addDimension(tDim);

View File

@ -39,6 +39,7 @@ import java.util.logging.Logger;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.ndarray.IndexIterator;
/**
*
@ -169,12 +170,13 @@ public class HYSPLITPartDataInfo extends DataInfo implements IStationDataInfo {
br.close();
List<Double> values = new ArrayList<Double>();
Array tArray = Array.factory(DataType.DATE, new int[]{times.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
this.addDimension(tDim);

View File

@ -29,15 +29,10 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.meteoinfo.data.XYListDataset;
import org.meteoinfo.ndarray.*;
import org.meteoinfo.table.ColumnData;
import org.meteoinfo.table.DataColumn;
import org.meteoinfo.table.DataTable;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.Index;
import org.meteoinfo.ndarray.InvalidRangeException;
import org.meteoinfo.ndarray.Range;
import org.meteoinfo.ndarray.Section;
/**
*
@ -145,7 +140,7 @@ public class HYSPLITTrajDataInfo extends DataInfo implements ITrajDataInfo {
String[] dataArray;
int i;
initVariables();
List<Double> times = new ArrayList<>();
List<LocalDateTime> times = new ArrayList<>();
sr = new BufferedReader(new FileReader(new File(fileName)));
//Record #1
aLine = sr.readLine().trim();
@ -178,7 +173,7 @@ public class HYSPLITTrajDataInfo extends DataInfo implements ITrajDataInfo {
Integer.parseInt(dataArray[2]), Integer.parseInt(dataArray[3]), 0, 0);
if (times.isEmpty()) {
times.add(JDateUtil.toOADate(tt));
times.add(tt);
}
aTrajInfo = new TrajectoryInfo();
aTrajInfo.startTime = tt;
@ -187,8 +182,13 @@ public class HYSPLITTrajDataInfo extends DataInfo implements ITrajDataInfo {
aTrajInfo.startHeight = Float.parseFloat(dataArray[6]);
trajInfoList.add(aTrajInfo);
}
Array tArray = Array.factory(DataType.DATE, new int[]{times.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : times) {
iter.setDateNext(t);
}
Dimension tdim = new Dimension(DimensionType.T);
tdim.setValues(times);
tdim.setDimValue(tArray);
//Record #5
aLine = sr.readLine().trim();
dataArray = aLine.split("\\s+");

View File

@ -37,6 +37,7 @@ import java.util.logging.Logger;
import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.ndarray.DataType;
/**
*
@ -169,9 +170,9 @@ public class METARDataInfo extends DataInfo implements IStationDataInfo {
DataList = disDataList;
Dimension tdim = new Dimension(DimensionType.T);
double[] values = new double[1];
values[0] = JDateUtil.toOADate(date);
tdim.setValues(values);
Array tArray = Array.factory(DataType.DATE, new int[]{1});
tArray.setDate(0, date);
tdim.setDimValue(tArray);
this.setTimeDimension(tdim);
List<Variable> vars = new ArrayList<>();
for (String vName : varList) {
@ -211,7 +212,7 @@ public class METARDataInfo extends DataInfo implements IStationDataInfo {
String dataInfo;
dataInfo = "File Name: " + this.getFileName();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + "Station Number: " + String.valueOf(this.stationNum);
dataInfo += System.getProperty("line.separator") + "Number of Variables = " + String.valueOf(this.getVariableNum());
for (int i = 0; i < this.getVariableNum(); i++) {

View File

@ -127,7 +127,7 @@ public class MDFSDataInfo extends DataInfo implements IGridDataInfo, IStationDat
LocalDateTime dt = LocalDateTime.of(year, month, day, hour, 0);
Dimension tDim = new Dimension(DimensionType.T);
tDim.setName("time");
tDim.setValue(JDateUtil.toOADate(dt));
tDim.setValue(dt);
this.setTimeDimension(tDim);
this.addDimension(tDim);
Dimension zDim = new Dimension(DimensionType.Z);
@ -258,7 +258,7 @@ public class MDFSDataInfo extends DataInfo implements IGridDataInfo, IStationDat
dt = LocalDateTime.of(year, month, day, hour, 0);
tDim = new Dimension(DimensionType.T);
tDim.setName("time");
tDim.setValue(JDateUtil.toOADate(dt));
tDim.setValue(dt);
this.setTimeDimension(tDim);
this.addDimension(tDim);
zDim = new Dimension(DimensionType.Z);

View File

@ -166,9 +166,7 @@ public class MICAPS11DataInfo extends DataInfo implements IGridDataInfo {
this.addAttribute(new Attribute("data_format", "MICAPS 11"));
Dimension tdim = new Dimension(DimensionType.T);
tdim.setShortName("time");
double[] values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
this.addDimension(tdim);
Dimension zdim = new Dimension(DimensionType.Z);
@ -220,7 +218,7 @@ public class MICAPS11DataInfo extends DataInfo implements IGridDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -96,9 +96,7 @@ public class MICAPS120DataInfo extends DataInfo implements IStationDataInfo {
//Set dimension and variables
Dimension tdim = new Dimension(DimensionType.T);
double[] values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
String[] dataArray;
@ -124,7 +122,7 @@ public class MICAPS120DataInfo extends DataInfo implements IStationDataInfo {
Dimension stdim = new Dimension(DimensionType.OTHER);
stdim.setShortName("station");
values = new double[stNum];
double[] values = new double[stNum];
for (int i = 0; i < stNum; i++){
values[i] = i;
}
@ -174,7 +172,7 @@ public class MICAPS120DataInfo extends DataInfo implements IStationDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -213,7 +213,7 @@ public class MICAPS131DataInfo extends DataInfo implements IGridDataInfo {
br.close();
Dimension tdim = new Dimension(DimensionType.T);
tdim.setValue(JDateUtil.toOADate(time));
tdim.setValue(time);
this.setTimeDimension(tdim);
this.addDimension(tdim);
Dimension zdim = new Dimension(DimensionType.Z);

View File

@ -136,7 +136,7 @@ public class MICAPS13DataInfo extends DataInfo implements IGridDataInfo {
br.close();
Dimension tdim = new Dimension(DimensionType.T);
tdim.setValue(JDateUtil.toOADate(_time));
tdim.setValue(_time);
this.setTimeDimension(tdim);
this.addDimension(tdim);
Dimension ydim = new Dimension(DimensionType.Y);

View File

@ -124,9 +124,7 @@ public class MICAPS1DataInfo extends DataInfo implements IStationDataInfo {
Integer.parseInt(dataArray[2]), Integer.parseInt(dataArray[3]), 0, 0);
Dimension tdim = new Dimension(DimensionType.T);
tdim.setName("time");
double[] values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
this.addDimension(tdim);
@ -144,7 +142,7 @@ public class MICAPS1DataInfo extends DataInfo implements IStationDataInfo {
}
Dimension stdim = new Dimension(DimensionType.OTHER);
stdim.setShortName("station");
values = new double[_stNum];
double[] values = new double[_stNum];
for (int i = 0; i < _stNum; i++) {
values[i] = i;
}
@ -339,7 +337,7 @@ public class MICAPS1DataInfo extends DataInfo implements IStationDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -123,16 +123,14 @@ public class MICAPS2DataInfo extends DataInfo implements IStationDataInfo {
}
Dimension tdim = new Dimension(DimensionType.T);
double[] values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
Dimension zdim = new Dimension(DimensionType.Z);
zdim.setValues(new double[]{level});
this.setZDimension(zdim);
Dimension stdim = new Dimension(DimensionType.OTHER);
stdim.setShortName("station");
values = new double[stNum];
double[] values = new double[stNum];
for (i = 0; i < stNum; i++){
values[i] = i;
}
@ -178,7 +176,7 @@ public class MICAPS2DataInfo extends DataInfo implements IStationDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -155,9 +155,7 @@ public class MICAPS3DataInfo extends DataInfo implements IStationDataInfo {
stdim.setValues(values);
this.addDimension(stdim);
Dimension tdim = new Dimension(DimensionType.T);
values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
Dimension zdim = new Dimension(DimensionType.Z);
zdim.setValues(new double[]{level});
@ -204,7 +202,7 @@ public class MICAPS3DataInfo extends DataInfo implements IStationDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -181,9 +181,7 @@ public class MICAPS4DataInfo extends DataInfo implements IGridDataInfo {
this.addAttribute(new Attribute("data_format", "MICAPS 4"));
Dimension tdim = new Dimension(DimensionType.T);
double[] values = new double[1];
values[0] = JDateUtil.toOADate(time);
tdim.setValues(values);
tdim.setValue(time);
this.setTimeDimension(tdim);
this.addDimension(tdim);
Dimension zdim = new Dimension(DimensionType.Z);
@ -227,7 +225,7 @@ public class MICAPS4DataInfo extends DataInfo implements IGridDataInfo {
String dataInfo;
dataInfo = "Description: " + _description;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + super.generateInfoText();
return dataInfo;

View File

@ -285,13 +285,14 @@ public class MM5DataInfo extends DataInfo implements IGridDataInfo {
}
}
List<Double> values = new ArrayList<>();
Array tArray = Array.factory(DataType.DATE, new int[]{times.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setShortName("time");
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
this.addDimension(tDim);
@ -907,7 +908,7 @@ public class MM5DataInfo extends DataInfo implements IGridDataInfo {
double[] yArray = new double[tNum];
for (i = 0; i < tNum; i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(theData, ydim.getValues(), yArray, this.missingValue);
@ -959,7 +960,7 @@ public class MM5DataInfo extends DataInfo implements IGridDataInfo {
double[] yArray = new double[tNum];
for (i = 0; i < tNum; i++) {
yArray[i] = JDateUtil.toOADate(this.getTimes().get(i));
yArray[i] = JDateUtil.toOADate(this.getTimes().getDate(i));
}
return new GridData(theData, xdim.getValues(), yArray, this.missingValue);

View File

@ -31,6 +31,8 @@ import org.meteoinfo.data.meteodata.MeteoDataType;
import org.meteoinfo.data.meteodata.Variable;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.meteodata.Attribute;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
/**
* MM5 regrid intermediate data info
@ -118,13 +120,14 @@ public class MM5IMDataInfo extends DataInfo implements IGridDataInfo {
}
}
}
List<Double> values = new ArrayList<>();
Array tArray = Array.factory(DataType.DATE, new int[]{times.size()});
IndexIterator iter = tArray.getIndexIterator();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
Dimension tDim = new Dimension(DimensionType.T);
tDim.setValues(values);
tDim.setDimValue(tArray);
this.setTimeDimension(tDim);
for (Variable var : variables){
var.updateZDimension();

View File

@ -982,17 +982,18 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
return attStr;
}
private List<LocalDateTime> getTimes(ucar.nc2.Variable aVar, Array values) {
private Array getTimes(ucar.nc2.Variable aVar, Array values) {
//Get start time
String unitsStr;
int i;
List<LocalDateTime> times = new ArrayList<>();
Array times = Array.factory(org.meteoinfo.ndarray.DataType.DATE, values.getShape());
IndexIterator iterT = times.getIndexIterator();
ucar.nc2.Attribute unitAtt = aVar.findAttribute("units");
if (unitAtt == null) {
LocalDateTime sTime = LocalDateTime.of(1985, 1, 1, 0, 0);
IndexIterator ii = values.getIndexIterator();
while (ii.hasNext()) {
times.add(sTime.plusHours(ii.getIntNext()));
iterT.setDateNext(sTime.plusHours(ii.getIntNext()));
}
return times;
}
@ -1009,7 +1010,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
if (md.length() <= 3) {
md = "0" + md;
}
times.add(LocalDateTime.parse(md, format));
iterT.setDateNext(LocalDateTime.parse(md, format));
}
} else {
TimeUnit aTU;
@ -1027,7 +1028,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
for (i = 0; i < values.getSize(); i++) {
switch (aTU) {
case Year:
times.add(sTime.plusYears(values.getLong(i)));
iterT.setDateNext(sTime.plusYears(values.getLong(i)));
break;
case Month:
// if (unitsStr.equalsIgnoreCase("month")) {
@ -1035,24 +1036,24 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
// } else {
// cal.add(Calendar.MONTH, values.getInt(i));
// }
times.add(sTime.plusMonths(values.getLong(i)));
iterT.setDateNext(sTime.plusMonths(values.getLong(i)));
break;
case Day:
times.add(sTime.plusDays(values.getLong(i)));
iterT.setDateNext(sTime.plusDays(values.getLong(i)));
break;
case Hour:
if (sTime.getYear() == 1 && sTime.getMonthValue() == 1
&& sTime.getDayOfMonth() == 1 && values.getInt(i) > 48) {
times.add(sTime.plusHours(values.getLong(i) - 48));
iterT.setDateNext(sTime.plusHours(values.getLong(i) - 48));
} else {
times.add(sTime.plusHours(values.getLong(i)));
iterT.setDateNext(sTime.plusHours(values.getLong(i)));
}
break;
case Minute:
times.add(sTime.plusMinutes(values.getLong(i)));
iterT.setDateNext(sTime.plusMinutes(values.getLong(i)));
break;
case Second:
times.add(sTime.plusSeconds(values.getLong(i)));
iterT.setDateNext(sTime.plusSeconds(values.getLong(i)));
break;
}
}
@ -1109,16 +1110,11 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
var = this.findNCVariable("Time");
if (var != null && var.getDimensions().size() == 1) {
Array darray = NCUtil.convertArray(var.read());
List<LocalDateTime> times = this.getTimes(var, darray);
List<Double> ts = new ArrayList<>();
for (LocalDateTime t : times) {
ts.add(JDateUtil.toOADate(t));
}
Array times = this.getTimes(var, darray);
Dimension tDim = this.findDimension(var.getDimension(0).getShortName());
if (tDim != null) {
tDim.setDimType(DimensionType.T);
tDim.setValues(ts);
tDim.setDimValue(times);
this.setTimeDimension(tDim);
}
}
@ -1213,13 +1209,9 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
this.setZDimension(dim);
break;
case T:
List<LocalDateTime> times = this.getTimes(var, values);
Array times = this.getTimes(var, values);
if (times != null) {
List<Double> ts = new ArrayList<>();
for (LocalDateTime t : times) {
ts.add(JDateUtil.toOADate(t));
}
dim.setValues(ts);
dim.setDimValue(times);
}
this.setTimeDimension(dim);
break;
@ -1260,8 +1252,8 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
int tNum = getDimensionLength("TSTEP");
sTimeStr = getGlobalAttStr("TSTEP");
len = sTimeStr.length();
List<LocalDateTime> times = new ArrayList<>();
times.add(tt);
Array times = Array.factory(org.meteoinfo.ndarray.DataType.DATE, new int[]{tNum});
times.setDate(0, tt);
for (i = 1; i < tNum; i++) {
if (sTimeStr.length() <= 2) {
tt = tt.plusSeconds(Integer.parseInt(sTimeStr));
@ -1273,16 +1265,13 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
tt = tt.plusMinutes(Integer.parseInt(sTimeStr.substring(len - 4, len - 2)));
tt = tt.plusSeconds(Integer.parseInt(sTimeStr.substring(len - 2)));
}
times.add(tt);
}
List<Double> values = new ArrayList<>();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
times.setDate(i, tt);
}
Dimension tDim = this.findDimension("TSTEP");
if (tDim != null) {
tDim.setDimType(DimensionType.T);
tDim.setValues(values);
tDim.setDimValue(times);
this.setTimeDimension(tDim);
}
@ -1575,13 +1564,14 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
times.add(LocalDateTime.parse(tStr, format));
}
}
List<Double> values = new ArrayList<>();
Array ta = Array.factory(org.meteoinfo.ndarray.DataType.DATE, new int[]{times.size()});
IndexIterator iter = ta.getIndexIterator();
for (LocalDateTime t : times) {
values.add(JDateUtil.toOADate(t));
iter.setDateNext(t);
}
tDim.setDimType(DimensionType.T);
//tDim.setDimName("times");
tDim.setValues(values);
tDim.setDimValue(ta);
this.setTimeDimension(tDim);
break;
}
@ -1922,7 +1912,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
+ String.valueOf(ncDimensions.get(i).getLength()) + ";";
}
/*Dimension xdim = this.getXDimension();
Dimension xdim = this.getXDimension();
if (xdim != null) {
dataInfo += System.getProperty("line.separator") + "X Dimension: Xmin = " + String.valueOf(xdim.getMinValue())
+ "; Xmax = " + String.valueOf(xdim.getMaxValue()) + "; Xsize = "
@ -1933,7 +1923,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
dataInfo += System.getProperty("line.separator") + "Y Dimension: Ymin = " + String.valueOf(ydim.getMinValue())
+ "; Ymax = " + String.valueOf(ydim.getMaxValue()) + "; Ysize = "
+ String.valueOf(ydim.getLength()) + "; Ydelta = " + String.valueOf(ydim.getDeltaValue());
}*/
}
dataInfo += System.getProperty("line.separator") + "Global Attributes: ";
for (i = 0; i < ncAttributes.size(); i++) {

View File

@ -253,9 +253,7 @@ import org.meteoinfo.data.meteodata.Attribute;
DataList = disDataList;
Dimension tdim = new Dimension(DimensionType.T);
double[] values = new double[1];
values[0] = JDateUtil.toOADate(date);
tdim.setValues(values);
tdim.setValue(date);
this.setTimeDimension(tdim);
List<Variable> vars = new ArrayList<>();
for (String vName : varList) {
@ -294,7 +292,7 @@ import org.meteoinfo.data.meteodata.Attribute;
String dataInfo;
dataInfo = "File Name: " + this.getFileName();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00");
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().get(0));
dataInfo += System.getProperty("line.separator") + "Time: " + format.format(this.getTimes().getDate(0));
dataInfo += System.getProperty("line.separator") + "Station Number: " + String.valueOf(this.stationNum);
dataInfo += System.getProperty("line.separator") + "Number of Variables = " + String.valueOf(this.getVariableNum());
for (int i = 0; i < this.getVariableNum(); i++) {

View File

@ -3537,13 +3537,13 @@ public class DataFrame implements Iterable {
*/
public DataFrame isIn(List values) {
if (this.array2D) {
Array a = ArrayMath.inValues((Array) this.data, values);
Array a = ArrayMath.isIn((Array) this.data, values);
return new DataFrame(a, (Index) this.index.clone(), this.columns.copyAsBoolean());
} else {
List<Array> arrays = (List<Array>) this.data;
List<Array> r = new ArrayList<>();
for (Array arr : arrays) {
Array a = ArrayMath.inValues(arr, values);
Array a = ArrayMath.isIn(arr, values);
r.add(a);
}
return new DataFrame(r, (Index) this.index.clone(), this.columns.copyAsBoolean());

View File

@ -9,6 +9,7 @@ import org.meteoinfo.common.MIMath;
import org.meteoinfo.ndarray.math.ArrayMath;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.math.ArrayUtil;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -20,7 +21,6 @@ import java.util.stream.Collectors;
/**
*
* @author Yaqiang Wang
* @param <V> Index data type
*/
public class Index<V> implements Iterable<V>{
// <editor-fold desc="Variables">

View File

@ -556,7 +556,7 @@ public class Series implements Iterable {
* @return Series of booleans indicating if each element is in values
*/
public Series isIn(List values) {
Array rdata = ArrayMath.inValues(data, values);
Array rdata = ArrayMath.isIn(data, values);
Series r = new Series(rdata, index, name);
return r;
}

View File

@ -4,12 +4,17 @@ import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.Complex;
import org.meteoinfo.ndarray.DataType;
import org.meteoinfo.ndarray.IndexIterator;
import org.python.core.Py;
import org.python.core.PyComplex;
import org.python.core.PyObject;
import org.python.modules.time.PyTimeTuple;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class JythonUtil {
@ -82,4 +87,57 @@ public class JythonUtil {
}
}
/**
* Convert Jython datetime to Java LocalDateTime
*
* @param dt Jython datetime object
* @return Java LocalDateTime object
*/
public static LocalDateTime toDateTime(PyObject dt) {
Calendar calendar = (Calendar) dt.__tojava__(Calendar.class);
LocalDateTime localDateTime = LocalDateTime.ofInstant(calendar.toInstant(), calendar.getTimeZone().toZoneId());
return localDateTime;
}
/**
* Convert Java LocalDateTime object to Jython datetime object
*
* @param dt Java LocalDatetime object
* @return Jython datetime object
*/
public static PyObject toDateTime(LocalDateTime dt) {
Timestamp timestamp = Timestamp.valueOf(dt);
return Py.newDatetime(timestamp);
}
/**
* Convert Java LocalDateTime array to Jython datetime array or verse vise
*
* @param a Java LocalDateTime array or Jython datetime array
* @return Jython datatime array or Java LocalDateTime array
*/
public static Array toDateTime(Array a) {
IndexIterator iterA = a.getIndexIterator();
if (a.getDataType() == DataType.DATE) {
Array r = Array.factory(DataType.OBJECT, a.getShape());
IndexIterator interR = r.getIndexIterator();
while (interR.hasNext()) {
interR.setObjectNext(toDateTime(iterA.getDateNext()));
}
return r;
} else {
Array r = Array.factory(DataType.DATE, a.getShape());
IndexIterator interR = r.getIndexIterator();
while (interR.hasNext()) {
interR.setDateNext(toDateTime((PyObject) iterA.getObjectNext()));
}
return r;
}
}
}

View File

@ -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\common_math\fft">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\netcdf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\binary"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\matlab"/>
<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\common_math\stats"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\fft"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grads"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe\series"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\wrf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\fft\fftn_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\fft\ifftn_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\fft\ifftn_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\typhoon_path_trace.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\netcdf\era5_blh.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\fft\fftn_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\fft\ifftn_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\fft\ifftn_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\typhoon_path_trace.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\io\netcdf\era5_blh.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -1,9 +1,11 @@
import midata
from .dataarray import *
#import midata
from .midata import *
from .util import ncutil
from .dimvariable import DimVariable
from .util import *
__all__ = ['DimVariable']
__all__ += dataarray.__all__
__all__ += midata.__all__
__all__ += util.__all__

View File

@ -0,0 +1,5 @@
from dimarray import dimension, DimArray, dim_array
__all__ = ['dim_array','dimension','DimArray']

View File

@ -12,7 +12,7 @@ from org.meteoinfo.common import ResampleMethods
from org.meteoinfo.common import PointD
from org.meteoinfo.ndarray import Array, Range, MAMath, DataType
from org.meteoinfo.data.dimarray import Dimension, DimensionType
from ._ndarray import NDArray
from mipylib.numeric.core._ndarray import NDArray
import math
import datetime
import numbers

View File

@ -7,9 +7,11 @@
from org.meteoinfo.data.meteodata import MeteoDataType
from org.meteoinfo.data.meteodata.netcdf import NCUtil
from org.meteoinfo.data.dimarray import DimensionType, Dimension
from org.meteoinfo.jython import JythonUtil
from ucar.ma2 import DataType as NCDataType
from ucar.nc2 import Attribute as NCAttribute
from ucar.nc2 import Variable as NCVariable
from dimvariable import DimVariable, TDimVariable
from mipylib.geolib.milayer import MILayer, MIXYListData
from mipylib.dataframe.dataframe import DataFrame
@ -316,12 +318,13 @@ class DimDataFile(object):
:returns: (*datetime*) The time
"""
t = self.dataset.getDataInfo().getTimes().get(idx)
t = self.dataset.getDataInfo().getTimes().getDate(idx)
if t is None:
return None
t = miutil.pydate(t)
return t
def gettimes(self):
"""
@ -331,10 +334,10 @@ class DimDataFile(object):
if tt is None:
return None
times = []
for t in tt:
times.append(miutil.pydate(t))
return times
#tt = JythonUtil.toDateTime(tt)
return np.NDArray(tt)
def bigendian(self, big_endian):
"""

View File

@ -17,6 +17,7 @@ from org.meteoinfo.data.meteodata.netcdf import NCUtil
from org.meteoinfo.ndarray import DataType
import mipylib.numeric as np
from .dataarray import DimArray
import mipylib.miutil as miutil
import datetime
import numbers
@ -340,7 +341,7 @@ class DimVariable(object):
array = np.array(rrr)
else:
array = np.array(rr)
data = np.DimArray(array, dims, self.dataset.proj)
data = DimArray(array, dims, self.dataset.proj)
return data
def read(self):
@ -935,11 +936,11 @@ class TDimVariable(object):
nindices = tuple(nindices)
aa = var.__getitem__(nindices)
if si == ei:
if isinstance(aa, np.DimArray):
if isinstance(aa, DimArray):
aa.addtdim(self.dataset.gettime(si))
else:
aa = np.array([aa])
aa = np.DimArray(aa)
aa = DimArray(aa)
aa.addtdim(self.dataset.gettime(si))
if data is None:
data = aa
@ -960,11 +961,11 @@ class TDimVariable(object):
nindices = tuple(nindices)
aa = var.__getitem__(nindices)
if si == ei and eidx != sidx:
if isinstance(aa, np.DimArray):
if isinstance(aa, DimArray):
aa.addtdim(self.dataset.gettime(si))
else:
aa = np.array([aa])
aa = np.DimArray(aa)
aa = DimArray(aa)
aa.addtdim(self.dataset.gettime(si))
if data is None:
data = aa
@ -997,7 +998,7 @@ class TDimVariable(object):
else:
data = np.concatenate([data, aa])
if isinstance(data, np.DimArray):
if isinstance(data, DimArray):
return data
else:
if isinstance(aa, numbers.Number):
@ -1005,5 +1006,5 @@ class TDimVariable(object):
dims = aa.dims
dims[0].setDimValues(times)
r = np.DimArray(data, dims, aa.proj)
r = DimArray(data, dims, aa.proj)
return r

View File

@ -22,7 +22,8 @@ from ucar.nc2.iosp.bufr.tables import BufrTables
import mipylib.numeric as np
import mipylib.miutil as miutil
from mipylib.numeric.core import NDArray, DimArray, PyTableData
from mipylib.numeric.core import NDArray, PyTableData
from .dataarray import DimArray
from dimdatafile import DimDataFile, DimDataFiles
from arldatafile import ARLDataFile
@ -852,6 +853,7 @@ def grads2nc(infn, outfn, big_endian=None, largefile=False):
#Close netCDF file
ncfile.close()
print('Convert finished!')
def dimension(dimvalue, dimname='null', dimtype=None):
"""
@ -861,10 +863,11 @@ def dimension(dimvalue, dimname='null', dimtype=None):
:param dimname: (*string*) Dimension name.
:param dimtype: (*DimensionType*) Dimension type ['X' | 'Y' | 'Z' | 'T'].
"""
if isinstance(dimvalue, (NDArray, DimArray)):
dimvalue = dimvalue.aslist()
dtype = DimensionType.Other
if not dimtype is None:
dimvalue = np.asarray(dimvalue)
if dimtype is None:
dtype = DimensionType.Other
else:
if dimtype.upper() == 'X':
dtype = DimensionType.X
elif dimtype.upper() == 'Y':
@ -873,10 +876,12 @@ def dimension(dimvalue, dimname='null', dimtype=None):
dtype = DimensionType.Z
elif dimtype.upper() == 'T':
dtype = DimensionType.T
dim = Dimension(dtype)
dim.setDimValues(dimvalue)
dim.setDimValue(dimvalue)
dim.setShortName(dimname)
return dim
def ncwrite(fn, data, varname, dims=None, attrs=None, gattrs=None, proj=None, largefile=False,
version='netcdf3', time_units='hours', start_time=datetime.datetime(1900,1,1)):

View File

@ -1,345 +0,0 @@
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2016-7-4
# Purpose: MeteoInfo io module
# Note: Jython
#-----------------------------------------------------
import datetime
import mipylib.numeric as np
import mipylib.miutil as miutil
from mipylib.numeric.core import NDArray, DimArray
import midata as midata
from dimdatafile import DimDataFile
from org.meteoinfo.data.dimarray import Dimension, DimensionType
__all__ = [
'convert2nc','dimension','grads2nc','ncwrite'
]
def convert2nc(infn, outfn, version='netcdf3', writedimvar=False, largefile=False):
"""
Convert data file (Grib, HDF...) to netCDF data file.
:param infn: (*string or DimDataFile*) Input data file (or file name).
:param outfn: (*string*) Output netCDF data file name.
:param writedimvar: (*boolean*) Write dimension variables or not.
:param largefile: (*boolean*) Create netCDF as large file or not.
"""
if isinstance(infn, DimDataFile):
f = infn
else:
#Open input data file
f = midata.addfile(infn)
#New netCDF file
ncfile = midata.addfile(outfn, 'c', version=version, largefile=largefile)
#Add dimensions
dims = []
for dim in f.dimensions:
dims.append(ncfile.adddim(dim.getShortName(), dim.getLength()))
#Add global attributes
for attr in f.attributes():
ncfile.addgroupattr(attr.getName(), attr.getValues())
#Add dimension variables
tvar = None
if writedimvar:
dimvars = []
for i in range(len(f.dimensions)):
dim = f.dimensions[i]
dname = dim.getShortName()
if dim.getDimType() == DimensionType.T:
var = ncfile.addvar(dname, 'int', [dims[i]])
var.addattr('units', 'hours since 1900-01-01 00:00:0.0')
var.addattr('long_name', 'Time')
var.addattr('standard_name', 'time')
var.addattr('axis', 'T')
tvar = var
elif dim.getDimType() == DimensionType.Z:
var = ncfile.addvar(dname, 'float', [dims[i]])
var.addattr('long_name', 'Level')
var.addattr('axis', 'Z')
elif dim.getDimType() == DimensionType.Y:
var = ncfile.addvar(dname, 'float', [dims[i]])
var.addattr('long_name', dname)
var.addattr('axis', 'Y')
elif dim.getDimType() == DimensionType.X:
var = ncfile.addvar(dname, 'float', [dims[i]])
var.addattr('long_name', dname)
var.addattr('axis', 'X')
else:
var = ncfile.addvar(dname, 'float', [dims[i]])
var.addattr('long_name', dname)
var.addattr('axis', dname)
dimvars.append(var)
#Add variables
variables = []
for var in f.variables:
#print 'Variable: ' + var.getShortName()
if var.hasNullDimension():
continue
vdims = []
missdim = False
for vdim in var.getDimensions():
isvalid = False
for dim in dims:
if dim.getShortName() == vdim.getShortName():
vdims.append(dim)
isvalid = True
break
if not isvalid:
missdim = True
break
if missdim:
continue
nvar = ncfile.addvar(var.getShortName(), var.getDataType(), vdims)
for attr in var.getAttributes():
nvar.addattr(attr.getName(), attr.getValues())
variables.append(nvar)
#Create netCDF file
ncfile.create()
#Write dimension variable data
if writedimvar:
for dimvar, dim in zip(dimvars, f.dimensions):
if dim.getDimType() != DimensionType.T:
ncfile.write(dimvar, np.array(dim.getDimValue()))
#Write time dimension variable data
if writedimvar and not tvar is None:
sst = datetime.datetime(1900,1,1)
tnum = f.timenum()
hours = []
for t in range(0, tnum):
st = f.gettime(t)
hs = (st - sst).total_seconds() // 3600
hours.append(hs)
ncfile.write(tvar, np.array(hours))
#Write variable data
for var in variables:
print 'Variable: ' + var.name
data = f[str(var.name)].read()
ncfile.write(var, data)
#Close netCDF file
ncfile.close()
print 'Convert finished!'
def grads2nc(infn, outfn, big_endian=None, largefile=False):
"""
Convert GrADS data file to netCDF data file.
:param infn: (*string*) Input GrADS data file name.
:param outfn: (*string*) Output netCDF data file name.
:param big_endian: (*boolean*) Is GrADS data big_endian or not.
:param largefile: (*boolean*) Create netCDF as large file or not.
"""
#Open GrADS file
f = midata.addfile_grads(infn)
if not big_endian is None:
f.bigendian(big_endian)
#New netCDF file
ncfile = midata.addfile(outfn, 'c')
#Add dimensions
dims = []
for dim in f.dimensions:
dims.append(ncfile.adddim(dim.getShortName(), dim.getLength()))
xdim = f.finddim('X')
ydim = f.finddim('Y')
tdim = f.finddim('T')
xnum = xdim.getLength()
ynum = ydim.getLength()
tnum = tdim.getLength()
#Add global attributes
ncfile.addgroupattr('Conventions', 'CF-1.6')
for attr in f.attributes():
ncfile.addgroupattr(attr.getName(), attr.getValues())
#Add dimension variables
dimvars = []
for dim in dims:
dname = dim.getShortName()
if dname == 'T':
var = ncfile.addvar('time', 'int', [dim])
var.addattr('units', 'hours since 1900-01-01 00:00:0.0')
var.addattr('long_name', 'Time')
var.addattr('standard_name', 'time')
var.addattr('axis', dname)
tvar = var
elif dname == 'Z':
var = ncfile.addvar('level', 'float', [dim])
var.addattr('axis', dname)
else:
var = ncfile.addvar(dim.getShortName(), 'float', [dim])
if 'Z' in dname:
var.addattr('axis', 'Z')
else:
var.addattr('axis', dname)
dimvars.append(var)
#Add variables
variables = []
for var in f.variables:
print 'Variable: ' + var.getShortName()
vdims = []
for vdim in var.getDimensions():
for dim in dims:
if vdim.getShortName() == dim.getShortName():
vdims.append(dim)
#print vdims
nvar = ncfile.addvar(var.getShortName(), var.getDataType(), vdims)
nvar.addattr('fill_value', -9999.0)
for attr in var.getAttributes():
nvar.addattr(attr.getName(), attr.getValues())
variables.append(nvar)
#Create netCDF file
ncfile.create()
#Write variable data
for dimvar, dim in zip(dimvars, f.dimensions):
if dim.getShortName() != 'T':
ncfile.write(dimvar, np.array(dim.getDimValue()))
sst = datetime.datetime(1900,1,1)
for t in range(0, tnum):
st = f.gettime(t)
print st.strftime('%Y-%m-%d %H:00')
hours = (st - sst).total_seconds() // 3600
origin = [t]
ncfile.write(tvar, np.array([hours]), origin=origin)
for var in variables:
print 'Variable: ' + var.name
if var.ndim == 3:
data = f[str(var.name)][t,:,:]
data[data==np.nan] = -9999.0
origin = [t, 0, 0]
shape = [1, ynum, xnum]
data = data.reshape(shape)
ncfile.write(var, data, origin=origin)
else:
znum = var.dims[1].getLength()
for z in range(0, znum):
data = f[str(var.name)][t,z,:,:]
data[data==np.nan] = -9999.0
origin = [t, z, 0, 0]
shape = [1, 1, ynum, xnum]
data = data.reshape(shape)
ncfile.write(var, data, origin=origin)
#Close netCDF file
ncfile.close()
print 'Convert finished!'
def dimension(dimvalue, dimname='null', dimtype=None):
"""
Create a new Dimension.
:param dimvalue: (*array_like*) Dimension value.
:param dimname: (*string*) Dimension name.
:param dimtype: (*DimensionType*) Dimension type.
"""
if isinstance(dimvalue, (NDArray, DimArray)):
dimvalue = dimvalue.aslist()
dtype = DimensionType.Other
if not dimtype is None:
if dimtype.upper() == 'X':
dtype = DimensionType.X
elif dimtype.upper() == 'Y':
dtype = DimensionType.Y
elif dimtype.upper() == 'Z':
dtype = DimensionType.Z
elif dimtype.upper() == 'T':
dtype = DimensionType.T
dim = Dimension(dtype)
dim.setDimValues(dimvalue)
dim.setShortName(dimname)
return dim
def ncwrite(fn, data, varname, dims=None, attrs=None, largefile=False):
"""
Write a netCDF data file.
:param: fn: (*string*) netCDF data file path.
:param data: (*array_like*) A numeric array variable of any dimensionality.
:param varname: (*string*) Variable name.
:param dims: (*list of dimensions*) Dimension list.
:param attrs: (*list of attributes*) Attribute list.
:param largefile: (*boolean*) Create netCDF as large file or not.
"""
if dims is None:
if isinstance(data, NDArray):
dims = []
for s in data.shape:
dimvalue = np.arange(s)
dimname = 'dim' + str(len(dims))
dims.append(dimension(dimvalue, dimname))
else:
dims = data.dims
#New netCDF file
ncfile = midata.addfile(fn, 'c')
#Add dimensions
ncdims = []
for dim in dims:
ncdims.append(ncfile.adddim(dim.getShortName(), dim.getLength()))
#Add global attributes
ncfile.addgroupattr('Conventions', 'CF-1.6')
ncfile.addgroupattr('Tools', 'Created using MeteoInfo')
#Add dimension variables
dimvars = []
for dim,midim in zip(ncdims,dims):
dimtype = midim.getDimType()
dimname = dim.getShortName()
if dimtype == DimensionType.T:
var = ncfile.addvar(dimname, 'int', [dim])
var.addattr('units', 'hours since 1900-01-01 00:00:0.0')
var.addattr('long_name', 'Time')
var.addattr('standard_name', 'time')
var.addattr('axis', 'T')
tvar = var
elif dimtype == DimensionType.Z:
var = ncfile.addvar(dimname, 'float', [dim])
var.addattr('axis', 'Z')
elif dimtype == DimensionType.Y:
var = ncfile.addvar(dimname, 'float', [dim])
var.addattr('axis', 'Y')
elif dimtype == DimensionType.X:
var = ncfile.addvar(dimname, 'float', [dim])
var.addattr('axis', 'X')
else:
var = ncfile.addvar(dim.getShortName(), 'float', [dim])
var.addattr('axis', 'null')
dimvars.append(var)
#Add variable
var = ncfile.addvar(varname, data.dtype, ncdims)
if attrs is None:
var.addattr('name', varname)
else:
for key in attrs:
var.addattr(key, attr[key])
#Create netCDF file
ncfile.create()
#Write variable data
for dimvar, dim in zip(dimvars, dims):
if dim.getDimType() == DimensionType.T:
sst = datetime.datetime(1900,1,1)
tt = miutil.nums2dates(dim.getDimValue())
hours = []
for t in tt:
hours.append((t - sst).total_seconds() // 3600)
ncfile.write(dimvar, np.array(hours))
else:
ncfile.write(dimvar, np.array(dim.getDimValue()))
ncfile.write(var, data)
#Close netCDF file
ncfile.close()

View File

@ -26,7 +26,8 @@ from org.meteoinfo.common import ResampleMethods
from .milayer import MILayer
from ._graphic import GeoGraphicCollection
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
import mipylib.migl as migl
import mipylib.numeric as np

View File

@ -8,7 +8,8 @@
from org.meteoinfo.math.meteo import MeteoMath
import mipylib.numeric as np
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
import constants as constants
from .calc.thermo import saturation_vapor_pressure, saturation_mixing_ratio

View File

@ -1,5 +1,6 @@
from org.meteoinfo.math.meteo import WRF
import mipylib.numeric as np
from mipylib.dataset import DimArray
from .. import constants
from ..calc.thermo import temperature_from_potential_temperature
@ -63,4 +64,4 @@ def get_dbz(wrfin, timeidx=0, use_varint=False, use_liqskin=False):
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)
return DimArray(dbz, dims=t.dims)

View File

@ -1,5 +1,5 @@
from org.meteoinfo.math.meteo import MeteoMath
from mipylib.numeric.core import DimArray
from mipylib.dataset import DimArray
from .. import constants
from ..calc.thermo import temperature_from_potential_temperature
from destag import destagger

View File

@ -6,7 +6,8 @@
#-----------------------------------------------------
from org.meteoinfo.math.meteo import MeteoMath
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
import constants as constants
from pylib.mipylib.meteolib.calc.thermo import relative_humidity_from_specific_humidity, temperature_from_potential_temperature

View File

@ -1,7 +1,6 @@
from ._ndarray import NDArray
from . import multiarray
from .multiarray import *
from .dimarray import DimArray, dimension, dim_array
from ._base import nditer
from .mitable import PyTableData
from ._dtype import dtype
@ -16,7 +15,7 @@ from umath import *
from .shape_base import *
from .stride_tricks import *
__all__ = ['NDArray','DimArray','PyTableData','dtype','dimension','dim_array','nditer']
__all__ = ['NDArray','PyTableData','dtype','nditer']
__all__ += multiarray.__all__
__all__ += numeric.__all__
__all__ += fromnumeric.__all__

View File

@ -7,11 +7,13 @@ from org.meteoinfo.data import GridArray
from org.meteoinfo.ndarray.math import ArrayMath, ArrayUtil
from org.meteoinfo.math.linalg import LinalgUtil
from org.meteoinfo.ndarray import Array, Range, MAMath, Complex, DataType
from java.time import LocalDateTime
import datetime
import _dtype
from ._base import flatiter
from ... import miutil
# The encapsulate class of Array
class NDArray(object):
@ -132,6 +134,8 @@ class NDArray(object):
r = self._array.getObject(aindex)
if isinstance(r, Complex):
return complex(r.getReal(), r.getImaginary())
elif isinstance(r, LocalDateTime):
return miutil.pydate(r)
else:
return r
@ -617,7 +621,17 @@ class NDArray(object):
else:
return None
def in_values(self, other):
def index(self, other):
"""
Return index of the other in this array.
:param other: (*object*) The value to be indexed.
:return: (*int*) The index
"""
return ArrayMath.isIn(self._array, other)
def isin(self, other):
"""
Return the array with the value of 1 when the element value
in the list other, otherwise set value as 0.
@ -628,7 +642,7 @@ class NDArray(object):
"""
if not isinstance(other, (list, tuple)):
other = other.aslist()
return self.array_wrap(ArrayMath.inValues(self._array, other))
return self.array_wrap(ArrayMath.isIn(self._array, other))
def squeeze(self):
"""

View File

@ -29,7 +29,8 @@ import datetime
import math
import mipylib.numeric as np
from mipylib.numeric.core import DimArray, NDArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
from mipylib.geolib.milayer import MILayer, MIXYListData
import plotutil
import colors

View File

@ -19,7 +19,8 @@ from org.meteoinfo.geo.layer import LayerTypes
from org.meteoinfo.common import Extent3D
from ._axes import Axes
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
import mipylib.numeric as np
import plotutil
import mipylib.miutil as miutil

View File

@ -29,7 +29,8 @@ import warnings
import plotutil
import colors
from ._axes3d import Axes3D
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
import mipylib.numeric as np
from mipylib import migl
from mipylib.geolib import migeo

View File

@ -30,7 +30,8 @@ from java.awt import Font, Color
from ._axes import Axes
from .graphic import Point2DCollection, Line2D, LineCollection
import mipylib.numeric as np
from mipylib.numeric.core import NDArray, DimArray
from mipylib.numeric.core import NDArray
from mipylib.dataset import DimArray
from mipylib.geolib.milayer import MILayer
from mipylib.geolib._graphic import GeoGraphicCollection
import mipylib.geolib.migeo as migeo

View File

@ -5009,6 +5009,35 @@ public class ArrayMath {
return r;
}
/**
* Return the index of the object in the array.
*
* @param a Array a
* @param o The object
* @return Object index
*/
public static int indexOf(Array a, Object o) {
Array r = Array.factory(DataType.BOOLEAN, a.getShape());
if (a.getIndexPrivate().isFastIterator()) {
for (int i = 0; i < a.getSize(); i++) {
if (a.getObject(i) == o) {
return i;
}
}
} else {
IndexIterator iterA = a.getIndexIterator();
int i = 0;
while (iterA.hasNext()) {
if (iterA.getObjectNext() == o) {
return i;
}
i += 1;
}
}
return -1;
}
/**
* Return the array with the value of 1 when the input array element value
* in the list b, otherwise set value as 0.
@ -5017,7 +5046,7 @@ public class ArrayMath {
* @param b List b
* @return Result array
*/
public static Array inValues(Array a, List b) {
public static Array isIn(Array a, List b) {
Array r = Array.factory(DataType.BOOLEAN, a.getShape());
if (a.getIndexPrivate().isFastIterator()) {
for (int i = 0; i < a.getSize(); i++) {