Skip to content

Commit

Permalink
add meshc and surfc plot functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaqiang committed Jun 1, 2023
1 parent 6214af5 commit 62ff9c0
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1075,18 +1075,13 @@ public void setMinMaxValue(double minValue, double maxValue) {
}

updateTickValues();
// if (this.timeAxis) {
// this.updateTimeLabels();
// } else {
// tickValues = MIMath.getIntervalValues(minValue, maxValue);
// }
}

/**
* Update tick values
*/
public void updateTickValues() {
List<Object> r = MIMath.getIntervalValues1(minValue, maxValue);
List<Object> r = MIMath.getIntervalValuesAxis(minValue, maxValue);
this.tickValues = (double[]) r.get(0);
this.tickDeltaValue = (Double) r.get(1);
}
Expand Down
113 changes: 97 additions & 16 deletions meteoinfo-common/src/main/java/org/meteoinfo/common/MIMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,103 @@ public static List<Object> getIntervalValues1(double min, double max) {
return getIntervalValues(min, max, false);
}

/**
* Create contour values by minimum and maximum values
*
* @param min Minimum value
* @param max Maximum value
* @return Contour values
*/
public static List<Object> getIntervalValuesAxis(double min, double max) {
return getIntervalValuesAxis(min, max, false);
}

/**
* Create contour values by minimum and maximum values
*
* @param min Minimum value
* @param max Maximum value
* @param isExtend If extend values
* @return Contour values
*/
public static List<Object> getIntervalValuesAxis(double min, double max, boolean isExtend) {
int i, cNum, aD, aE;
double cDelt, range, newMin;
String eStr;
List<Object> r = new ArrayList<>();

range = BigDecimalUtil.sub(max, min);
if (range == 0.0) {
r.add(new double[]{min});
r.add(0.0);
return r;
} else if (range < 0) {
range = -range;
double temp = min;
min = max;
max = temp;
}

eStr = String.format("%1$E", range);
aD = Integer.parseInt(eStr.substring(0, 1));
aE = (int) Math.floor(Math.log10(range));
int nMin = 4;
if (aD >= nMin) {
cDelt = BigDecimalUtil.pow(10, aE);
cNum = aD;
} else {
double cd = BigDecimalUtil.pow(10, aE - 1);
i = 5;
cDelt = BigDecimalUtil.mul(i, cd);
cNum = (int) (range / cDelt);
while (cNum < nMin && i > 1) {
i--;
cDelt = BigDecimalUtil.mul(i, cd);
cNum = (int) (range / cDelt);
}
}
int temp = (int) (min / cDelt + 1);
newMin = BigDecimalUtil.mul(temp, cDelt);
if (newMin - min >= cDelt) {
newMin = BigDecimalUtil.sub(newMin, cDelt);
cNum += 1;
}

if (newMin + (cNum - 1) * cDelt > max) {
cNum -= 1;
} else if (newMin + (cNum - 1) * cDelt + cDelt < max) {
cNum += 1;
}

//Get values
List<Double> values = new ArrayList<>();
double v;
for (i = 0; i < cNum; i++) {
v = BigDecimalUtil.add(newMin, BigDecimalUtil.mul(i, cDelt));
if (v >= min && v <= max)
values.add(v);
}

//Extend values
if (isExtend) {
if (values.get(0) > min) {
values.add(0, BigDecimalUtil.sub(newMin, cDelt));
}
if (values.get(values.size() - 1) < max) {
values.add(BigDecimalUtil.add(values.get(values.size() - 1), cDelt));
}
}

double[] cValues = new double[values.size()];
for (i = 0; i < values.size(); i++) {
cValues[i] = values.get(i);
}

r.add(cValues);
r.add(cDelt);
return r;
}

/**
* Create contour values by minimum and maximum values
*
Expand Down Expand Up @@ -993,29 +1090,15 @@ public static List<Object> getIntervalValues(double min, double max, boolean isE
eStr = String.format("%1$E", range);
aD = Integer.parseInt(eStr.substring(0, 1));
aE = (int) Math.floor(Math.log10(range));
// int idx = eStr.indexOf("E");
// if (idx < 0) {
// aE = 0;
// } else {
// aE = Integer.parseInt(eStr.substring(eStr.indexOf("E") + 1));
// }
if (aD > 5) {
//cDelt = Math.pow(10, aE);
cDelt = BigDecimalUtil.pow(10, aE);
cNum = aD;
//newMin = Convert.ToInt32((min + cDelt) / Math.Pow(10, aE)) * Math.Pow(10, aE);
//newMin = (int) (min / cDelt + 1) * cDelt;
} else if (aD == 5) {
//cDelt = aD * Math.pow(10, aE - 1);
cDelt = aD * BigDecimalUtil.pow(10, aE - 1);
cNum = 10;
//newMin = Convert.ToInt32((min + cDelt) / Math.Pow(10, aE)) * Math.Pow(10, aE);
//newMin = (int) (min / cDelt + 1) * cDelt;
cNum++;
} else {
//cDelt = aD * Math.pow(10, aE - 1);
double cd = BigDecimalUtil.pow(10, aE - 1);
//cDelt = BigDecimalUtil.mul(aD, cDelt);
cDelt = BigDecimalUtil.mul(5, cd);
cNum = (int) (range / cDelt);
if (cNum < 5) {
Expand All @@ -1026,8 +1109,6 @@ public static List<Object> getIntervalValues(double min, double max, boolean isE
cNum = (int) (range / cDelt);
}
}
//newMin = Convert.ToInt32((min + cDelt) / Math.Pow(10, aE - 1)) * Math.Pow(10, aE - 1);
//newMin = (int) (min / cDelt + 1) * cDelt;
}
int temp = (int) (min / cDelt + 1);
newMin = BigDecimalUtil.mul(temp, cDelt);
Expand Down
20 changes: 11 additions & 9 deletions meteoinfo-lab/milconfig.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\awx"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<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\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour\contour_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour\contourf_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surfc_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\meshc_peaks.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour\contour_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\contour\contourf_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf\surfc_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\meshc_peaks.py"/>
</RecentFiles>
</File>
<Font>
<TextFont FontName="YaHei Consolas Hybrid" FontSize="14"/>
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,0" MainFormSize="1354,809"/>
<Startup MainFormLocation="-7,0" MainFormSize="1429,860"/>
</MeteoInfo>
Binary file modified meteoinfo-lab/pylib/mipylib/plotlib/_axes3d$py.class
Binary file not shown.
16 changes: 14 additions & 2 deletions meteoinfo-lab/pylib/mipylib/plotlib/_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,17 @@ def contour(self, *args, **kwargs):
x = np.arange(a.shape[1])
y = np.arange(a.shape[0])
args = args[1:]
elif n <=4:
else:
x = args[0]
y = args[1]
a = args[2]
args = args[3:]

if x.ndim == 2:
x = x[0]
if y.ndim == 2:
y = y[:,0]

if len(args) > 0:
level_arg = args[0]
if isinstance(level_arg, int):
Expand Down Expand Up @@ -1214,11 +1220,17 @@ def contourf(self, *args, **kwargs):
x = np.arange(a.shape[1])
y = np.arange(a.shape[0])
args = args[1:]
elif n <=4:
else:
x = args[0]
y = args[1]
a = args[2]
args = args[3:]

if x.ndim == 2:
x = x[0]
if y.ndim == 2:
y = y[:,0]

if len(args) > 0:
level_arg = args[0]
if isinstance(level_arg, int):
Expand Down
Binary file modified meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl$py.class
Binary file not shown.
69 changes: 69 additions & 0 deletions meteoinfo-lab/pylib/mipylib/plotlib/_axes3dgl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,40 @@ def mesh(self, *args, **kwargs):
self.add_graphic(graphics)
return graphics

def meshc(self, *args, **kwargs):
"""
Contour plot under mesh surface plot.
:param x: (*array_like*) Optional. X coordinate array.
:param y: (*array_like*) Optional. Y coordinate array.
:param z: (*array_like*) 2-D z value array.
:param cmap: (*string*) Color map string.
:returns: 3D mesh and contour graphics.
"""
if len(args) <= 2:
z = args[0]
if isinstance(z, DimArray):
x = args[0].dimvalue(1)
y = args[0].dimvalue(0)
else:
ny, nx = z.shape
x = np.arange(nx)
y = np.arange(ny)
x, y = np.meshgrid(x, y)
args1 = [x, y, z] + args[1:]
else:
args1 = args

gmesh = self.mesh(*args1, **kwargs)
zmin = args1[2].min()

kwargs['offset'] = zmin
args1 = args1[:3]
gcontour = self.contour(*args1, **kwargs)

return gmesh, gcontour

def surf(self, *args, **kwargs):
"""
creates a three-dimensional surface plot
Expand Down Expand Up @@ -1253,6 +1287,41 @@ def surf(self, *args, **kwargs):
self.add_graphic(graphics)
return graphics

def surfc(self, *args, **kwargs):
"""
Contour plot under surface plot.
:param x: (*array_like*) Optional. X coordinate array.
:param y: (*array_like*) Optional. Y coordinate array.
:param z: (*array_like*) 2-D z value array.
:param cmap: (*string*) Color map string.
:param lighting: (*bool*) Using light or not.
:returns: 3D surface and contour graphics.
"""
if len(args) <= 2:
z = args[0]
if isinstance(z, DimArray):
x = args[0].dimvalue(1)
y = args[0].dimvalue(0)
else:
ny, nx = z.shape
x = np.arange(nx)
y = np.arange(ny)
x, y = np.meshgrid(x, y)
args1 = [x, y, z] + args[1:]
else:
args1 = args

gsurf = self.surf(*args1, **kwargs)
zmin = args1[2].min()

kwargs['offset'] = zmin
args1 = args1[:3]
gcontour = self.contour(*args1, **kwargs)

return gsurf, gcontour

def plot_surface(self, *args, **kwargs):
"""
creates a three-dimensional surface plot
Expand Down
Binary file modified meteoinfo-lab/pylib/mipylib/plotlib/miplot$py.class
Binary file not shown.
Loading

0 comments on commit 62ff9c0

Please sign in to comment.