mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
add return null option when time dimension is null
This commit is contained in:
parent
14dbf856f0
commit
fc56c2fee9
@ -21,6 +21,7 @@ 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.data.dimarray.Dimension;
|
||||
import org.meteoinfo.ndarray.InvalidRangeException;
|
||||
@ -157,6 +158,10 @@ import org.meteoinfo.projection.ProjectionInfo;
|
||||
* @return Times
|
||||
*/
|
||||
public List<LocalDateTime> getTimes() {
|
||||
if (tDim == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Array values = tDim.getDimValue();
|
||||
List<LocalDateTime> times = new ArrayList<>();
|
||||
for (int i = 0; i < values.getSize(); i++) {
|
||||
@ -173,6 +178,9 @@ import org.meteoinfo.projection.ProjectionInfo;
|
||||
* @return Time
|
||||
*/
|
||||
public LocalDateTime getTime(int timeIdx) {
|
||||
if (tDim == null)
|
||||
return null;
|
||||
|
||||
return JDateUtil.fromOADate(tDim.getDimValue().getDouble(timeIdx));
|
||||
}
|
||||
|
||||
@ -182,6 +190,9 @@ import org.meteoinfo.projection.ProjectionInfo;
|
||||
* @return Time double value
|
||||
*/
|
||||
public double getTimeValue(int timeIdx) {
|
||||
if (tDim == null)
|
||||
return Double.NaN;
|
||||
|
||||
return tDim.getDimValue().getDouble(timeIdx);
|
||||
}
|
||||
|
||||
@ -243,6 +254,11 @@ import org.meteoinfo.projection.ProjectionInfo;
|
||||
for (LocalDateTime t : value) {
|
||||
values.add(JDateUtil.toOADate(t));
|
||||
}
|
||||
|
||||
if (tDim == null) {
|
||||
tDim = new Dimension(DimensionType.T);
|
||||
}
|
||||
|
||||
tDim.setValues(values);
|
||||
}
|
||||
|
||||
@ -252,6 +268,9 @@ import org.meteoinfo.projection.ProjectionInfo;
|
||||
* @return Time number
|
||||
*/
|
||||
public int getTimeNum() {
|
||||
if (tDim == null)
|
||||
return 0;
|
||||
|
||||
return tDim.getLength();
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
|
||||
private List<ucar.nc2.Dimension> ncDimensions = new ArrayList<>();
|
||||
private List<Dimension> dimensions = new ArrayList<>();
|
||||
private List<ucar.nc2.Attribute> ncAttributes = new ArrayList<>();
|
||||
//private List<Attribute> attributes = new ArrayList<>();
|
||||
private ucar.nc2.Variable _xVar = null;
|
||||
private ucar.nc2.Variable _yVar = null;
|
||||
private ucar.nc2.Variable _levelVar = null;
|
||||
@ -275,9 +274,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
|
||||
try {
|
||||
_fileTypeStr = ncfile.getFileTypeDescription();
|
||||
_fileTypeId = ncfile.getFileTypeId();
|
||||
// if (_fileTypeId.equals("GRIB2")){
|
||||
// ncfile.getIosp().
|
||||
// }
|
||||
|
||||
//Read variables
|
||||
ncVariables = ncfile.getVariables();
|
||||
@ -305,16 +301,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
|
||||
dim.setShortName(dimName);
|
||||
}
|
||||
}
|
||||
// String newName;
|
||||
// //int idx = dim.getShortName().lastIndexOf("_");
|
||||
// int idx = dim.getShortName().indexOf("Data_Fields_");
|
||||
// if (idx >= 0) {
|
||||
// newName = dim.getShortName().substring(idx + 12);
|
||||
// } else {
|
||||
// idx = dim.getShortName().lastIndexOf("_");
|
||||
// newName = dim.getShortName().substring(idx + 1);
|
||||
// }
|
||||
// dim.setShortName(newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Temp\test">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
|
||||
@ -9,24 +9,26 @@
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface"/>
|
||||
<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\plot_types\3d\jogl\volume"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
|
||||
<RecentFolder Folder="D:\Temp\test"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\heart.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
|
||||
<OpenedFile File="D:\Temp\test\pm25_interp.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\radar_1.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\heart.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.py"/>
|
||||
<RecentFile File="D:\Temp\test\pm25_interp.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\radar_1.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -34,5 +36,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/>
|
||||
<Startup MainFormLocation="-7,0" MainFormSize="1367,795"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -256,22 +256,28 @@ class DimDataFile(object):
|
||||
return self.dataset.getDataInfo().getTimeNum()
|
||||
|
||||
def gettime(self, idx):
|
||||
'''
|
||||
"""
|
||||
Get time by index.
|
||||
|
||||
:param idx: (*int*) Time index.
|
||||
|
||||
:returns: (*datetime*) The time
|
||||
'''
|
||||
t = self.dataset.getDataInfo().getTimes().get(idx)
|
||||
"""
|
||||
t = self.dataset.getDataInfo().getTimes().get(idx)
|
||||
if t is None:
|
||||
return None
|
||||
|
||||
t = miutil.pydate(t)
|
||||
return t
|
||||
|
||||
def gettimes(self):
|
||||
'''
|
||||
"""
|
||||
Get time list.
|
||||
'''
|
||||
"""
|
||||
tt = self.dataset.getDataInfo().getTimes()
|
||||
if tt is None:
|
||||
return None
|
||||
|
||||
times = []
|
||||
for t in tt:
|
||||
times.append(miutil.pydate(t))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user