mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update reprojectImage function
This commit is contained in:
parent
8627374c9a
commit
cb6f683a24
@ -67,7 +67,7 @@ import java.util.zip.ZipInputStream;
|
||||
public static String getVersion(){
|
||||
String version = GlobalUtil.class.getPackage().getImplementationVersion();
|
||||
if (version == null || version.equals("")) {
|
||||
version = "3.4.5";
|
||||
version = "3.4.6";
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@ -1,32 +1,34 @@
|
||||
<?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\mesh">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\savefig"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\projection">
|
||||
<RecentFolder Folder="D:\Run\emips\run_cams"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\airship"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\geotiff"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\sounding.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\radar_bz2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_peaks.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\projection\robinson_proj_image.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\sounding.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\airship\radar_bz2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh\mesh_peaks.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\map\projection\robinson_proj_image.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
|
||||
Binary file not shown.
@ -629,7 +629,7 @@ def reproject(a, x=None, y=None, fromproj=None, xp=None, yp=None, toproj=None, m
|
||||
r = Reproject.reproject(a.asarray(), x.aslist(), y.aslist(), xp, yp, fromproj, toproj, method)
|
||||
return NDArray(r)
|
||||
|
||||
def reproject_image(a, x, y, fromproj=None, xp=None, yp=None, toproj=None):
|
||||
def reproject_image(a, x=None, y=None, fromproj=None, xp=None, yp=None, toproj=None):
|
||||
"""
|
||||
Project image data array
|
||||
|
||||
@ -643,6 +643,13 @@ def reproject_image(a, x, y, fromproj=None, xp=None, yp=None, toproj=None):
|
||||
|
||||
:returns: (*NDArray*) Projected array
|
||||
"""
|
||||
if x is None or y is None:
|
||||
if isinstance(a, DimArray):
|
||||
y = a.dimvalue(a.ndim - 2)
|
||||
x = a.dimvalue(a.ndim - 1)
|
||||
else:
|
||||
raise ValueError('Input x/y coordinates are None')
|
||||
|
||||
if fromproj is None:
|
||||
fromproj = KnownCoordinateSystems.geographic.world.WGS1984
|
||||
|
||||
|
||||
@ -744,7 +744,12 @@ public class Reproject {
|
||||
int[] shape = rx.getShape();
|
||||
int ny = shape[0];
|
||||
int nx = shape[1];
|
||||
int[] newShape = new int[]{ny, nx, data.getShape()[2]};
|
||||
int[] newShape;
|
||||
if (data.getRank() == 2) {
|
||||
newShape = new int[]{ny, nx};
|
||||
} else {
|
||||
newShape = new int[]{ny, nx, data.getShape()[2]};
|
||||
}
|
||||
Array r = Array.factory(data.getDataType(), newShape);
|
||||
|
||||
int n = ny * nx;
|
||||
@ -765,38 +770,64 @@ public class Reproject {
|
||||
double xx, yy;
|
||||
int xi, yi, ii;
|
||||
int idx = 0;
|
||||
Index3D index = (Index3D) data.getIndex();
|
||||
for (int i = 0; i < ny; i++) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
ii = i * nx + j;
|
||||
xx = points[ii][0];
|
||||
yy = points[ii][1];
|
||||
if (xx < minX || xx > maxX)
|
||||
xi = -1;
|
||||
else
|
||||
xi = (int)((xx - minX) / dx);
|
||||
if (yy < minY || yy > maxY)
|
||||
yi = -1;
|
||||
else
|
||||
yi = (int)((yy - minY) / dy);
|
||||
if (data.getRank() == 2) {
|
||||
Index2D index = (Index2D) data.getIndex();
|
||||
for (int i = 0; i < ny; i++) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
ii = i * nx + j;
|
||||
xx = points[ii][0];
|
||||
yy = points[ii][1];
|
||||
if (xx < minX || xx > maxX)
|
||||
xi = -1;
|
||||
else
|
||||
xi = (int) ((xx - minX) / dx);
|
||||
if (yy < minY || yy > maxY)
|
||||
yi = -1;
|
||||
else
|
||||
yi = (int) ((yy - minY) / dy);
|
||||
|
||||
if (xi >= 0 && yi >= 0) {
|
||||
index.set(yi, xi, 0);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
index.set2(1);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
index.set2(2);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
} else {
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
if (xi >= 0 && yi >= 0) {
|
||||
index.set(yi, xi);
|
||||
r.setObject(ii, data.getObject(index));
|
||||
} else {
|
||||
r.setObject(ii, Double.NaN);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Index3D index = (Index3D) data.getIndex();
|
||||
for (int i = 0; i < ny; i++) {
|
||||
for (int j = 0; j < nx; j++) {
|
||||
ii = i * nx + j;
|
||||
xx = points[ii][0];
|
||||
yy = points[ii][1];
|
||||
if (xx < minX || xx > maxX)
|
||||
xi = -1;
|
||||
else
|
||||
xi = (int) ((xx - minX) / dx);
|
||||
if (yy < minY || yy > maxY)
|
||||
yi = -1;
|
||||
else
|
||||
yi = (int) ((yy - minY) / dy);
|
||||
|
||||
if (xi >= 0 && yi >= 0) {
|
||||
index.set(yi, xi, 0);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
index.set2(1);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
index.set2(2);
|
||||
r.setObject(idx, data.getObject(index));
|
||||
idx += 1;
|
||||
} else {
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
r.setObject(idx, 255);
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user