add return null option when time dimension is null

This commit is contained in:
wyq 2022-05-30 15:13:33 +08:00
parent 14dbf856f0
commit fc56c2fee9
5 changed files with 35 additions and 22 deletions

View File

@ -21,6 +21,7 @@ import java.util.List;
import org.meteoinfo.common.util.JDateUtil; import org.meteoinfo.common.util.JDateUtil;
import org.meteoinfo.data.dimarray.DimArray; import org.meteoinfo.data.dimarray.DimArray;
import org.meteoinfo.data.dimarray.DimensionType;
import org.meteoinfo.ndarray.Array; import org.meteoinfo.ndarray.Array;
import org.meteoinfo.data.dimarray.Dimension; import org.meteoinfo.data.dimarray.Dimension;
import org.meteoinfo.ndarray.InvalidRangeException; import org.meteoinfo.ndarray.InvalidRangeException;
@ -157,6 +158,10 @@ import org.meteoinfo.projection.ProjectionInfo;
* @return Times * @return Times
*/ */
public List<LocalDateTime> getTimes() { public List<LocalDateTime> getTimes() {
if (tDim == null) {
return null;
}
Array values = tDim.getDimValue(); Array values = tDim.getDimValue();
List<LocalDateTime> times = new ArrayList<>(); List<LocalDateTime> times = new ArrayList<>();
for (int i = 0; i < values.getSize(); i++) { for (int i = 0; i < values.getSize(); i++) {
@ -173,6 +178,9 @@ import org.meteoinfo.projection.ProjectionInfo;
* @return Time * @return Time
*/ */
public LocalDateTime getTime(int timeIdx) { public LocalDateTime getTime(int timeIdx) {
if (tDim == null)
return null;
return JDateUtil.fromOADate(tDim.getDimValue().getDouble(timeIdx)); return JDateUtil.fromOADate(tDim.getDimValue().getDouble(timeIdx));
} }
@ -182,6 +190,9 @@ import org.meteoinfo.projection.ProjectionInfo;
* @return Time double value * @return Time double value
*/ */
public double getTimeValue(int timeIdx) { public double getTimeValue(int timeIdx) {
if (tDim == null)
return Double.NaN;
return tDim.getDimValue().getDouble(timeIdx); return tDim.getDimValue().getDouble(timeIdx);
} }
@ -243,6 +254,11 @@ import org.meteoinfo.projection.ProjectionInfo;
for (LocalDateTime t : value) { for (LocalDateTime t : value) {
values.add(JDateUtil.toOADate(t)); values.add(JDateUtil.toOADate(t));
} }
if (tDim == null) {
tDim = new Dimension(DimensionType.T);
}
tDim.setValues(values); tDim.setValues(values);
} }
@ -252,6 +268,9 @@ import org.meteoinfo.projection.ProjectionInfo;
* @return Time number * @return Time number
*/ */
public int getTimeNum() { public int getTimeNum() {
if (tDim == null)
return 0;
return tDim.getLength(); return tDim.getLength();
} }

View File

@ -73,7 +73,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
private List<ucar.nc2.Dimension> ncDimensions = new ArrayList<>(); private List<ucar.nc2.Dimension> ncDimensions = new ArrayList<>();
private List<Dimension> dimensions = new ArrayList<>(); private List<Dimension> dimensions = new ArrayList<>();
private List<ucar.nc2.Attribute> ncAttributes = 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 _xVar = null;
private ucar.nc2.Variable _yVar = null; private ucar.nc2.Variable _yVar = null;
private ucar.nc2.Variable _levelVar = null; private ucar.nc2.Variable _levelVar = null;
@ -275,9 +274,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
try { try {
_fileTypeStr = ncfile.getFileTypeDescription(); _fileTypeStr = ncfile.getFileTypeDescription();
_fileTypeId = ncfile.getFileTypeId(); _fileTypeId = ncfile.getFileTypeId();
// if (_fileTypeId.equals("GRIB2")){
// ncfile.getIosp().
// }
//Read variables //Read variables
ncVariables = ncfile.getVariables(); ncVariables = ncfile.getVariables();
@ -305,16 +301,6 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
dim.setShortName(dimName); 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);
} }
} }
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile"> <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"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/> <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\jogl\isosurface"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/> <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\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"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/> <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"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
<RecentFolder Folder="D:\Temp\test"/> <RecentFolder Folder="D:\Temp\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
</Path> </Path>
<File> <File>
<OpenedFiles> <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\heart.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.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:\Temp\test\pm25_interp.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\radar_1.py"/>
</OpenedFiles> </OpenedFiles>
<RecentFiles> <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\heart.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\isosurface\isosurface_2.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:\Temp\test\pm25_interp.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume\radar_1.py"/>
</RecentFiles> </RecentFiles>
</File> </File>
<Font> <Font>
@ -34,5 +36,5 @@
</Font> </Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/> <LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/> <Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/> <Startup MainFormLocation="-7,0" MainFormSize="1367,795"/>
</MeteoInfo> </MeteoInfo>

View File

@ -256,22 +256,28 @@ class DimDataFile(object):
return self.dataset.getDataInfo().getTimeNum() return self.dataset.getDataInfo().getTimeNum()
def gettime(self, idx): def gettime(self, idx):
''' """
Get time by index. Get time by index.
:param idx: (*int*) Time index. :param idx: (*int*) Time index.
:returns: (*datetime*) The time :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) t = miutil.pydate(t)
return t return t
def gettimes(self): def gettimes(self):
''' """
Get time list. Get time list.
''' """
tt = self.dataset.getDataInfo().getTimes() tt = self.dataset.getDataInfo().getTimes()
if tt is None:
return None
times = [] times = []
for t in tt: for t in tt:
times.append(miutil.pydate(t)) times.append(miutil.pydate(t))