add fill plot function

This commit is contained in:
wyq 2022-04-09 14:35:16 +08:00
parent 546ce06f90
commit 36508193b6
11 changed files with 129 additions and 82 deletions

View File

@ -50,6 +50,7 @@ public class Plot2D extends AbstractPlot2D {
// <editor-fold desc="Variables">
private GraphicCollection graphics;
private float barsWidth = 0.8f;
private boolean fixDrawExtent = false;
// </editor-fold>
// <editor-fold desc="Constructor">
@ -102,6 +103,22 @@ public class Plot2D extends AbstractPlot2D {
this.barsWidth = value;
}
/**
* Get whether fix draw extent
* @return Whether fix draw extent
*/
public boolean isFixDrawExtent() {
return this.fixDrawExtent;
}
/**
* Set whether fix draw extent
* @param value Whether fix draw extent
*/
public void setFixDrawExtent(boolean value) {
this.fixDrawExtent = value;
}
// </editor-fold>
// <editor-fold desc="Methods">
/**
@ -1277,7 +1294,8 @@ public class Plot2D extends AbstractPlot2D {
@Override
public void setAutoExtent() {
Extent extent = this.getAutoExtent();
this.setDrawExtent(extent);
if (!this.fixDrawExtent)
this.setDrawExtent(extent);
this.setExtent((Extent) extent.clone());
}

View File

@ -65,7 +65,7 @@ import java.util.zip.ZipInputStream;
public static String getVersion(){
String version = GlobalUtil.class.getPackage().getImplementationVersion();
if (version == null || version.equals("")) {
version = "3.3.7";
version = "3.3.8";
}
return version;
}

View File

@ -450,7 +450,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
String pStr = PDEF.PDEF_Type;
switch (pStr) {
case "LCC":
case "LCCR": {
case "LCCR":
PDEF_LCC aPLCC = new PDEF_LCC();
aPLCC.isize = Integer.parseInt(dataArray[1]);
aPLCC.jsize = Integer.parseInt(dataArray[2]);
@ -483,18 +483,19 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
aPLCC.latref, X, Y);
Dimension xdim = new Dimension(DimensionType.X);
xdim.setShortName("X");
xdim.setUnit("m");
xdim.setValues(X);
this.setXDimension(xdim);
this.addDimension(xdim);
Dimension ydim = new Dimension(DimensionType.Y);
ydim.setShortName("Y");
ydim.setUnit("m");
ydim.setValues(Y);
this.setYDimension(ydim);
this.addDimension(ydim);
break;
}
case "NPS":
case "SPS": {
case "SPS":
int iSize = Integer.parseInt(dataArray[1]);
int jSize = Integer.parseInt(dataArray[2]);
float iPole = Float.parseFloat(dataArray[3]);
@ -516,18 +517,19 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
X = new double[iSize];
Y = new double[jSize];
getProjectedXY_NPS(dx, dy, iPole, jPole, X, Y);
Dimension xdim = new Dimension(DimensionType.X);
xdim = new Dimension(DimensionType.X);
xdim.setShortName("X");
xdim.setUnit("m");
xdim.setValues(X);
this.setXDimension(xdim);
this.addDimension(xdim);
Dimension ydim = new Dimension(DimensionType.Y);
ydim = new Dimension(DimensionType.Y);
ydim.setShortName("Y");
ydim.setUnit("m");
ydim.setValues(Y);
this.setYDimension(ydim);
this.addDimension(ydim);
break;
}
default:
errorStr = "The PDEF type is not supported at present!" + System.getProperty("line.separator")
+ "Please send your data to the author to improve MeteoInfo!";
@ -577,6 +579,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
}
Dimension xDim = new Dimension(DimensionType.X);
xDim.setShortName("X");
xDim.setUnit("degree east");
xDim.setValues(values);
this.setXDimension(xDim);
this.addDimension(xDim);
@ -623,6 +626,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
Dimension yDim = new Dimension(DimensionType.Y);
yDim.setShortName("Y");
yDim.setUnit("degree north");
yDim.setValues(values);
this.setYDimension(yDim);
this.addDimension(yDim);
@ -632,6 +636,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
ZDEF.ZNum = Integer.parseInt(dataArray[1]);
ZDEF.Type = dataArray[2];
ZDEF.ZLevels = new float[ZDEF.ZNum];
String unit = "hpa";
List<Double> values = new ArrayList<>();
if (ZDEF.Type.toUpperCase().equals("LINEAR")) {
ZDEF.SLevel = Float.parseFloat(dataArray[3]);
@ -640,52 +645,44 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
ZDEF.ZLevels[i] = ZDEF.SLevel + i * ZDEF.ZDelt;
values.add(Double.valueOf(ZDEF.ZLevels[i]));
}
} else if (dataArray.length < ZDEF.ZNum + 3) {
while (true) {
String line = sr.readLine().trim();
if (line.isEmpty()) {
continue;
}
dataArray = line.split("\\s+|,");
if (this.isKeyWord(dataArray[0])) {
dataArray = aLine.split("\\s+|,");
// if (dataArray.length > ZDEF.ZNum + 3) {
// errorStr = "ZDEF is wrong! Please check the ctl file!";
// //goto ERROR;
// }
// for (i = 0; i < ZDEF.ZNum; i++) {
// ZDEF.ZLevels[i] = Float.parseFloat(dataArray[3 + i]);
// values.add(Double.parseDouble(dataArray[3 + i]));
// }
ZDEF.ZNum = dataArray.length - 3;
ZDEF.ZLevels = new float[ZDEF.ZNum];
for (i = 0; i < ZDEF.ZNum; i++) {
ZDEF.ZLevels[i] = Float.parseFloat(dataArray[3 + i]);
values.add(Double.parseDouble(dataArray[3 + i]));
}
aLine = line;
isReadLine = false;
break;
}
aLine = aLine + " " + line;
// dataArray = aLine.split("\\s+");
// if (dataArray.length >= ZDEF.ZNum + 3) {
// break;
// }
}
unit = "m";
} else {
ZDEF.ZNum = dataArray.length - 3;
ZDEF.ZLevels = new float[ZDEF.ZNum];
String v;
for (i = 0; i < ZDEF.ZNum; i++) {
v = dataArray[3 + i].trim();
ZDEF.ZLevels[i] = Float.parseFloat(dataArray[3 + i]);
values.add(Double.parseDouble(dataArray[3 + i]));
if (dataArray.length < ZDEF.ZNum + 3) {
while (true) {
String line = sr.readLine().trim();
if (line.isEmpty()) {
continue;
}
dataArray = line.split("\\s+|,");
if (this.isKeyWord(dataArray[0])) {
dataArray = aLine.split("\\s+|,");
ZDEF.ZNum = dataArray.length - 3;
ZDEF.ZLevels = new float[ZDEF.ZNum];
for (i = 0; i < ZDEF.ZNum; i++) {
ZDEF.ZLevels[i] = Float.parseFloat(dataArray[3 + i]);
values.add(Double.parseDouble(dataArray[3 + i]));
}
aLine = line;
isReadLine = false;
break;
}
aLine = aLine + " " + line;
}
} else {
ZDEF.ZNum = dataArray.length - 3;
ZDEF.ZLevels = new float[ZDEF.ZNum];
String v;
for (i = 0; i < ZDEF.ZNum; i++) {
v = dataArray[3 + i].trim();
ZDEF.ZLevels[i] = Float.parseFloat(dataArray[3 + i]);
values.add(Double.parseDouble(dataArray[3 + i]));
}
}
}
zDim = new Dimension(DimensionType.Z);
zDim.setShortName("Z");
zDim.setUnit(unit);
zDim.setValues(values);
this.setZDimension(zDim);
this.addDimension(zDim);
@ -869,6 +866,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
break;
case "VARS":
int vNum = Integer.parseInt(dataArray[1]);
zDim = this.getZDimension();
for (i = 0; i < vNum; i++) {
aLine = sr.readLine().trim();
if (aLine.isEmpty()) {
@ -916,6 +914,7 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
}
Dimension dim = new Dimension(DimensionType.Z);
dim.setShortName("Z_" + String.valueOf(lNum));
dim.setUnit(zDim.getUnit());
dim.setValues(levs);
aVar.setDimension(dim);
this.addDimension(dim);

View File

@ -66,7 +66,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
private String _fileTypeStr;
private String _fileTypeId;
private Conventions _convention = Conventions.CF;
private Conventions convention = Conventions.CF;
private NetcdfFile ncfile = null;
private boolean keepOpen = false;
private List<ucar.nc2.Variable> ncVariables = new ArrayList<>();
@ -171,6 +171,14 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
}
}
/**
* Get convention
* @return Convention
*/
public Conventions getConvention() {
return this.convention;
}
// </editor-fold>
// <editor-fold desc="Methods">
// <editor-fold desc="Read Data">
@ -335,7 +343,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
}
//Get convention
_convention = this.getConvention();
this.convention = this.readConvention();
//Get projection
this.getProjection();
@ -504,11 +512,10 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
}
}
private Conventions getConvention() {
Conventions convention = _convention;
private Conventions readConvention() {
Conventions convention = Conventions.CF;
boolean isIOAPI = false;
boolean isWRFOUT = false;
//List<String> WRFStrings = new ArrayList<String>();
for (ucar.nc2.Attribute aAtts : ncAttributes) {
if (aAtts.getShortName().toLowerCase().equals("ioapi_version")) {
@ -552,7 +559,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
private void getProjection() {
ProjectionInfo projInfo = this.getProjectionInfo();
switch (_convention) {
switch (convention) {
case CF:
projInfo = getProjection_CF();
break;
@ -1079,7 +1086,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
}
private boolean getDimensionValues(NetcdfFile ncfile) throws IOException, ParseException {
switch (_convention) {
switch (convention) {
case CF:
if (this._isHDFEOS) {
getDimValues_HDFEOS_SWATH();
@ -2121,7 +2128,7 @@ public class NetCDFDataInfo extends DataInfo implements IGridDataInfo, IStationD
GridData aGridData = new GridData(gridData, nvar.getXDimension().getValues(),
nvar.getYDimension().getValues(), missingValue);
if (this._convention == Conventions.WRFOUT) {
if (this.convention == Conventions.WRFOUT) {
if (nvar.getName().equals("U")) {
aGridData.setXStagger(true);
}

View File

@ -1,32 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\meteo\wrf">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\quiver"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\fitting"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\common_math\linalg">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\maskout"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\volume"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\turtle"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\wrf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\grads"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\others"/>
<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\linalg"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth\CALIPSO_L1_3d_axis.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\typhoon_volume_w_specular.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\wrf\wrf_interp_press.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\others\bindundun_animation.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth\CALIPSO_L1_3d_axis.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\typhoon_volume_w_specular.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\wrf\wrf_interp_press.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\others\bindundun_animation.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -742,7 +742,7 @@ def grads2nc(infn, outfn, big_endian=None, largefile=False):
#Add dimension variables
dimvars = []
for dim in dims:
for dim, mdim in zip(dims, f.dimensions()):
dname = dim.getShortName()
if dname == 'T':
var = ncfile.addvar('time', 'int', [dim])
@ -754,27 +754,29 @@ def grads2nc(infn, outfn, big_endian=None, largefile=False):
elif dname == 'Z':
var = ncfile.addvar('level', 'float', [dim])
var.addattr('axis', dname)
var.addattr('units', mdim.getUnit())
else:
var = ncfile.addvar(dim.getShortName(), 'float', [dim])
if 'Z' in dname:
var.addattr('axis', 'Z')
else:
var.addattr('axis', dname)
var.addattr('units', mdim.getUnit())
dimvars.append(var)
#Add variables
variables = []
for var in f.variables():
print 'Variable: ' + var.getShortName()
print('Variable: ' + var.name)
vdims = []
for vdim in var.getDimensions():
for vdim in var.dims:
for dim in dims:
if vdim.getShortName() == dim.getShortName():
vdims.append(dim)
#print vdims
nvar = ncfile.addvar(var.getShortName(), var.getDataType(), vdims)
nvar = ncfile.addvar(var.name, var.dtype, vdims)
nvar.addattr('fill_value', -9999.0)
for attr in var.getAttributes():
for attr in var.attributes:
nvar.addattr(attr.getName(), attr.getValues())
variables.append(nvar)
@ -789,14 +791,14 @@ def grads2nc(infn, outfn, big_endian=None, largefile=False):
sst = datetime.datetime(1900,1,1)
for t in range(0, tnum):
st = f.gettime(t)
print st.strftime('%Y-%m-%d %H:00')
print(st.strftime('%Y-%m-%d %H:00'))
hours = (st - sst).total_seconds() // 3600
origin = [t]
ncfile.write(tvar, np.array([hours]), origin=origin)
for var in variables:
print 'Variable: ' + var.name
print('Variable: ' + var.name)
if var.ndim == 3:
data = f[str(var.name)][t,:,:]
data = f[var.name][t,:,:]
data[data==np.nan] = -9999.0
origin = [t, 0, 0]
shape = [1, ynum, xnum]
@ -814,7 +816,7 @@ def grads2nc(infn, outfn, big_endian=None, largefile=False):
#Close netCDF file
ncfile.close()
print 'Convert finished!'
print('Convert finished!')
def dimension(dimvalue, dimname='null', dimtype=None):
"""

View File

@ -616,9 +616,10 @@ class Axes(object):
extent = Extent(xmin, xmax, ymin, ymax)
self.axes.setDrawExtent(extent)
self.axes.setExtent(extent.clone())
self.axes.setFixDrawExtent(True)
return True
else:
print 'The limits parameter must be a list with 4 elements: xmin, xmax, ymin, ymax!'
print('The limits parameter must be a list with 4 elements: xmin, xmax, ymin, ymax!')
return None
def get_xlim(self):
@ -646,7 +647,8 @@ class Axes(object):
extent.minX = xmin
extent.maxX = xmax
self.axes.setDrawExtent(extent)
self.axes.setExtent(extent.clone())
self.axes.setExtent(extent.clone())
self.axes.setFixDrawExtent(True)
def get_ylim(self):
"""
@ -673,7 +675,8 @@ class Axes(object):
extent.minY = ymin
extent.maxY = ymax
self.axes.setDrawExtent(extent)
self.axes.setExtent(extent.clone())
self.axes.setExtent(extent.clone())
self.axes.setFixDrawExtent(True)
def twinx(self):
"""

View File

@ -42,7 +42,7 @@ __all__ = [
'axism','bar','bar3','barh','barbs','barbsm','bgcolor','box',
'boxplot','windrose','cla','clabel','clc','clear','clf','cll','cloudspec','colorbar','contour','contourf',
'contourfm','contourm','contourfslice','contourslice','delfig','draw','draw_if_interactive','errorbar',
'figure','glfigure','figsize','patch','rectangle','fill_between','fill_betweenx','webmap','gc_collect','geoshow',
'figure','glfigure','figsize','patch','rectangle','fill','fill_between','fill_betweenx','webmap','gc_collect','geoshow',
'get_figure','gifaddframe','gifanimation','giffinish',
'grid','gridshow','gridshowm','hist','imshow','imshowm','isosurface','legend','left_title','lighting','loglog','makecolors',
'makelegend','makesymbolspec','masklayer','mesh','particles','pcolor','pcolorm','pie','plot','plot3','plotm','quiver','quiver3',
@ -829,6 +829,26 @@ def annotate(s, xy, *args, **kwargs):
draw_if_interactive()
return r
def fill(x, y=None, **kwargs):
"""
Create one or more filled polygons.
:param x: (*array_like*) X coordinates for each vertex. X should be PolygonShape if y
is None.
:param y: (*array_like*) Y coordinates for each vertex.
"""
global g_axes
if g_figure is None:
figure()
if g_axes is None:
g_axes = axes()
r = g_axes.patch(x, y, **kwargs)
if not r is None:
draw_if_interactive()
return r
def patch(x, y=None, **kwargs):
'''
Create one or more filled polygons.