mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
add magic function
This commit is contained in:
parent
221fca14f2
commit
ec4e09f946
@ -123,9 +123,9 @@ public class GraphicFactory {
|
||||
PolylineShape pls;
|
||||
List<PointD> points = new ArrayList<>();
|
||||
double x, y;
|
||||
IndexIterator xIter = xdata.getIndexIterator();
|
||||
IndexIterator yIter = ydata.getIndexIterator();
|
||||
if (xdata.getRank() == 1) {
|
||||
IndexIterator xIter = xdata.getIndexIterator();
|
||||
IndexIterator yIter = ydata.getIndexIterator();
|
||||
while (xIter.hasNext()) {
|
||||
x = xIter.getDoubleNext();
|
||||
y = yIter.getDoubleNext();
|
||||
@ -164,13 +164,15 @@ public class GraphicFactory {
|
||||
int[] shape = xdata.getShape();
|
||||
int yn = shape[0];
|
||||
int xn = shape[1];
|
||||
for (int j = 0; j < yn; j++) {
|
||||
Index2D xIndex = (Index2D) xdata.getIndex();
|
||||
Index2D yIndex = (Index2D) ydata.getIndex();
|
||||
for (int i = 0; i < xn; i++) {
|
||||
points = new ArrayList<>();
|
||||
for (int i = 0; i < xn; i++) {
|
||||
x = xIter.getDoubleNext();
|
||||
y = yIter.getDoubleNext();
|
||||
//x = xdata.getDouble(j * xn + i);
|
||||
//y = ydata.getDouble(j * xn + i);
|
||||
for (int j = 0; j < yn; j++) {
|
||||
xIndex.set(j, i);
|
||||
yIndex.set(j, i);
|
||||
x = xdata.getDouble(xIndex);
|
||||
y = ydata.getDouble(yIndex);
|
||||
if (Double.isNaN(y) || Double.isNaN(x)) {
|
||||
if (points.isEmpty()) {
|
||||
continue;
|
||||
|
||||
@ -43,7 +43,6 @@ import org.meteoinfo.data.meteodata.numpy.NumpyDataInfo;
|
||||
import org.meteoinfo.data.meteodata.radar.CMARadarBaseDataInfo;
|
||||
import org.meteoinfo.data.meteodata.radar.RadarDataType;
|
||||
import org.meteoinfo.data.meteodata.radar.RadarDataUtil;
|
||||
import org.meteoinfo.data.meteodata.radar.cinrad.CinradDataInfo;
|
||||
import org.meteoinfo.ndarray.math.ArrayMath;
|
||||
import org.meteoinfo.projection.ProjectionInfo;
|
||||
import java.util.List;
|
||||
|
||||
@ -77,6 +77,15 @@ public class RadarDataUtil {
|
||||
return RadarDataType.STANDARD;
|
||||
}
|
||||
|
||||
String radarT = new String(bytes);
|
||||
if (radarT.contains("CINRAD/SC") || radarT.contains("CINRAD/CD")) {
|
||||
return RadarDataType.SC;
|
||||
} else if (radarT.contains("CINRADC")) {
|
||||
return RadarDataType.CC;
|
||||
} else if (!radarT.contains("CINRADC") && radarT.contains("CINRAD/CC")) {
|
||||
return RadarDataType.CC20;
|
||||
}
|
||||
|
||||
magicBytes = Arrays.copyOfRange(bytes, 14, 16);
|
||||
if (Arrays.equals(magicBytes, new byte[]{1, 0})) {
|
||||
return RadarDataType.SAB;
|
||||
@ -87,14 +96,6 @@ public class RadarDataUtil {
|
||||
return RadarDataType.PA;
|
||||
}
|
||||
|
||||
String radarT = new String(bytes);
|
||||
if (radarT.contains("CINRAD/SC") || radarT.contains("CINRAD/CD")) {
|
||||
return RadarDataType.SC;
|
||||
} else if (radarT.contains("CINRADC")) {
|
||||
return RadarDataType.CC;
|
||||
} else if (!radarT.contains("CINRADC") && radarT.contains("CINRAD/CC")) {
|
||||
return RadarDataType.CC20;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1,28 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\radar\cinrad">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\bar"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\plot">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe\series"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||
<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\contour"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar\cinrad"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\image"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\calc"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\imshow"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\gridshow"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\radar\cinrad\test_read_SC.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\radar\cinrad\radar_cc_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_2darray_1.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\radar\cinrad\test_read_SC.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\radar\cinrad\radar_cc_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_2darray_1.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -30,5 +34,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-7,-7" MainFormSize="1293,765"/>
|
||||
<Startup MainFormLocation="-7,0" MainFormSize="1415,864"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -44,7 +44,7 @@ __all__ = [
|
||||
'datatable','dot','empty','empty_like','exp','eye','flatnonzero','floor',
|
||||
'fmax','fmin','full','hcurl','hdivg','hstack','hypot','identity','indices','interp2d','interpn','isarray',
|
||||
'isclose','isfinite','isinf','isnan','isscalar','linspace','log','log10','logical_not','logspace',
|
||||
'magnitude','max','maximum','mean','median','meshgrid','min','minimum','monthname',
|
||||
'magic','magnitude','max','maximum','mean','median','meshgrid','min','minimum','monthname',
|
||||
'moveaxis','newaxis','ones','ones_like','outer','peaks','pol2cart','power','radians','reciprocal','reshape',
|
||||
'repeat','roll','rolling_mean','rot90','round','sec','sign','sin','sinh','shape','smooth5','smooth9','sort',
|
||||
'spacing','sphere','squeeze','split','sqrt','square','std','swapaxes','take','tan','tanh','tile',
|
||||
@ -490,6 +490,15 @@ def diag(v, k=0):
|
||||
if isinstance(v, (list, tuple)):
|
||||
v = array(v)
|
||||
return NDArray(ArrayUtil.diag(v.asarray(), k))
|
||||
|
||||
def magic(n):
|
||||
"""
|
||||
Generate a magic 2D array.
|
||||
|
||||
:param n: (*int*) Dimension length.
|
||||
:return: Magic 2D array.
|
||||
"""
|
||||
return NDArray(ArrayUtil.magic(n))
|
||||
|
||||
def repeat(a, repeats, axis=None):
|
||||
"""
|
||||
|
||||
Binary file not shown.
@ -1294,16 +1294,11 @@ class Axes(object):
|
||||
if isinstance(ydata, DimArray):
|
||||
xdata = ydata.dimvalue(0)
|
||||
if ydata.ndim == 2:
|
||||
xdata = ydata.dimvalue(1)
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
xdata = xdata[:,np.newaxis].repeat(ydata.shape[1], axis=1)
|
||||
else:
|
||||
xdata = np.arange(ydata.shape[-1])
|
||||
xdata = np.arange(ydata.shape[0])
|
||||
if ydata.ndim == 2:
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
xdata = xdata[:,np.newaxis].repeat(ydata.shape[1], axis=1)
|
||||
xdatalist.append(xdata)
|
||||
ydatalist.append(ydata)
|
||||
elif len(args) == 2:
|
||||
@ -1312,16 +1307,11 @@ class Axes(object):
|
||||
if isinstance(ydata, DimArray):
|
||||
xdata = ydata.dimvalue(0)
|
||||
if ydata.ndim == 2:
|
||||
xdata = ydata.dimvalue(1)
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
xdata = xdata[:,np.newaxis].repeat(ydata.shape[1], axis=1)
|
||||
else:
|
||||
xdata = np.arange(ydata.shape[-1])
|
||||
xdata = np.arange(ydata.shape[0])
|
||||
if ydata.ndim == 2:
|
||||
xx = np.zeros(ydata.shape)
|
||||
xx[:, :] = xdata
|
||||
xdata = xx
|
||||
xdata = xdata[:,np.newaxis].repeat(ydata.shape[1], axis=1)
|
||||
styles.append(args[1])
|
||||
else:
|
||||
xdata = args[0]
|
||||
@ -1442,7 +1432,12 @@ class Axes(object):
|
||||
lines.append(ncb)
|
||||
graphic = GraphicFactory.createLineString(xdata._array, ydata._array, lines, iscurve)
|
||||
else:
|
||||
graphic = Line2D(xdata, ydata, legend=lines[0], curve=iscurve)
|
||||
if ydata.ndim == 1:
|
||||
graphic = Line2D(xdata, ydata, legend=lines[0], curve=iscurve)
|
||||
else:
|
||||
if xdata.ndim == 1:
|
||||
xdata = xdata[:,np.newaxis].repeat(ydata.shape[1], axis=1)
|
||||
graphic = GraphicFactory.createLineString(xdata._array, ydata._array, lines[0], iscurve)
|
||||
else: # >1
|
||||
graphic = GraphicFactory.createLineString(xdata._array, ydata._array, lines, iscurve)
|
||||
self.add_graphic(graphic, zorder=zorder)
|
||||
|
||||
Binary file not shown.
@ -1109,7 +1109,7 @@ class MapAxes(Axes):
|
||||
if has_colors:
|
||||
ls = LegendManage.createImageLegend(arr._array, cmap)
|
||||
else:
|
||||
ls = plotutil.getlegendscheme(args, vmin, vmax, cmap, **kwargs)
|
||||
ls = plotutil.getlegendscheme(args, vmin, vmax, **kwargs)
|
||||
norm = kwargs.pop('norm', colors.Normalize(vmin, vmax))
|
||||
ls.setNormalize(norm._norm)
|
||||
ls.setColorMap(cmap)
|
||||
|
||||
Binary file not shown.
@ -1252,6 +1252,66 @@ public class ArrayUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate magic 2D array
|
||||
*
|
||||
* @param n Dimension length
|
||||
* @return Magic 2D array
|
||||
*/
|
||||
public static Array magic(int n) {
|
||||
int[] M = new int[n * n];
|
||||
|
||||
// Odd order
|
||||
if ((n % 2) == 1) {
|
||||
int a = (n+1)/2;
|
||||
int b = (n+1);
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
M[i * n + j] = n * ((i + j + a) % n) + ((i + 2 * j + b) % n) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Doubly Even Order
|
||||
} else if ((n % 4) == 0) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (((i+1)/2)%2 == ((j+1)/2)%2) {
|
||||
M[i * n + j] = n * n - n * i - j;
|
||||
} else {
|
||||
M[i * n + j] = n * i + j + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Singly Even Order
|
||||
} else {
|
||||
int p = n/2;
|
||||
int k = (n-2)/4;
|
||||
Array A = magic(p);
|
||||
for (int j = 0; j < p; j++) {
|
||||
for (int i = 0; i < p; i++) {
|
||||
int aij = A.getInt(i * p + j);
|
||||
M[i * n + j] = aij;
|
||||
M[i * n + j+p] = aij + 2 * p * p;
|
||||
M[(i + p) * n + j] = aij + 3 * p * p;
|
||||
M[(i + p) * n + j + p] = aij + p * p;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < p; i++) {
|
||||
for (int j = 0; j < k; j++) {
|
||||
int t = M[i * n + j]; M[i * n + j] = M[(i + p) * n + j]; M[(i + p) * n + j] = t;
|
||||
}
|
||||
for (int j = n-k+1; j < n; j++) {
|
||||
int t = M[i * n + j]; M[i * n + j] = M[(i + p) * n + j]; M[(i + p) * n + j] = t;
|
||||
}
|
||||
}
|
||||
int t = M[k * n]; M[k * n] = M[(k + p) * n]; M[(k + p) * n] = t;
|
||||
t = M[k * n + k]; M[k * n + k] = M[(k + p) * n + k]; M[(k + p) * n + k] = t;
|
||||
}
|
||||
|
||||
return Array.factory(DataType.INT, new int[]{n, n}, M);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeat a value n times
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user