update savefig function for better supporting sleep argument to wait webmap loading

This commit is contained in:
wyq 2023-06-29 15:50:44 +08:00
parent 7efed43099
commit 2b01be155d
12 changed files with 278 additions and 31 deletions

View File

@ -1298,6 +1298,11 @@ public class ChartPanel extends JPanel implements IChartPanel{
DocPrintJob job = service.createPrintJob(); DocPrintJob job = service.createPrintJob();
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
job.print(doc, attributes); job.print(doc, attributes);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
out.close(); out.close();
} }
} else if (aFile.endsWith(".eps")) { } else if (aFile.endsWith(".eps")) {
@ -1308,6 +1313,11 @@ public class ChartPanel extends JPanel implements IChartPanel{
g.startExport(); g.startExport();
//this.paintGraphics(g); //this.paintGraphics(g);
this.paintGraphics(g, width, height); this.paintGraphics(g, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g.endExport(); g.endExport();
g.dispose(); g.dispose();
} else if (aFile.endsWith(".pdf")) { } else if (aFile.endsWith(".pdf")) {
@ -1319,6 +1329,11 @@ public class ChartPanel extends JPanel implements IChartPanel{
PdfTemplate pdfTemp = cb.createTemplate(width, height); PdfTemplate pdfTemp = cb.createTemplate(width, height);
Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true); Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true);
this.paintGraphics(g2, width, height); this.paintGraphics(g2, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g2.dispose(); g2.dispose();
cb.addTemplate(pdfTemp, 0, 0); cb.addTemplate(pdfTemp, 0, 0);
document.close(); document.close();
@ -1331,6 +1346,11 @@ public class ChartPanel extends JPanel implements IChartPanel{
g.startExport(); g.startExport();
//this.paintGraphics(g); //this.paintGraphics(g);
this.paintGraphics(g, width, height); this.paintGraphics(g, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g.endExport(); g.endExport();
g.dispose(); g.dispose();
} else { } else {

View File

@ -1345,6 +1345,11 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
DocPrintJob job = service.createPrintJob(); DocPrintJob job = service.createPrintJob();
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
job.print(doc, attributes); job.print(doc, attributes);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
out.close(); out.close();
} }
} else if (aFile.endsWith(".eps")) { } else if (aFile.endsWith(".eps")) {
@ -1355,6 +1360,11 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
g.startExport(); g.startExport();
//this.paintGraphics(g); //this.paintGraphics(g);
this.paintGraphics(g, width, height); this.paintGraphics(g, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g.endExport(); g.endExport();
g.dispose(); g.dispose();
} else if (aFile.endsWith(".pdf")) { } else if (aFile.endsWith(".pdf")) {
@ -1366,6 +1376,11 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
PdfTemplate pdfTemp = cb.createTemplate(width, height); PdfTemplate pdfTemp = cb.createTemplate(width, height);
Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true); Graphics2D g2 = new PdfGraphics2D(pdfTemp, width, height, true);
this.paintGraphics(g2, width, height); this.paintGraphics(g2, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g2.dispose(); g2.dispose();
cb.addTemplate(pdfTemp, 0, 0); cb.addTemplate(pdfTemp, 0, 0);
document.close(); document.close();
@ -1378,6 +1393,11 @@ public class GLChartPanel extends GLJPanel implements IChartPanel{
g.startExport(); g.startExport();
//this.paintGraphics(g); //this.paintGraphics(g);
this.paintGraphics(g, width, height); this.paintGraphics(g, width, height);
if (sleep != null) {
Thread.sleep(sleep * 1000);
}
g.endExport(); g.endExport();
g.dispose(); g.dispose();
} else { } else {

View File

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

View File

@ -39,6 +39,46 @@ public class CMARadarBaseDataInfo extends DataInfo implements IGridDataInfo {
}).collect(Collectors.toMap(data -> (Integer) data[0], data -> (String) data[1])); }).collect(Collectors.toMap(data -> (Integer) data[0], data -> (String) data[1]));
private Map<String, RadialRecord> recordMap = new HashMap<>(); private Map<String, RadialRecord> recordMap = new HashMap<>();
/**
* Get generic header
* @return Generic header
*/
public GenericHeader getGenericHeader() {
return this.genericHeader;
}
/**
* Get site config
* @return Site config
*/
public SiteConfig getSiteConfig() {
return this.siteConfig;
}
/**
* Get task config
* @return Task config
*/
public TaskConfig getTaskConfig() {
return this.taskConfig;
}
/**
* Get cut config list
* @return Cut config list
*/
public List<CutConfig> getCutConfigs() {
return this.cutConfigs;
}
/**
* Get record map
* @return Record map
*/
public Map<String, RadialRecord> getRecordMap() {
return this.recordMap;
}
@Override @Override
public GridArray getGridArray(String varName) { public GridArray getGridArray(String varName) {
return null; return null;
@ -184,7 +224,7 @@ public class CMARadarBaseDataInfo extends DataInfo implements IGridDataInfo {
} else { } else {
record = new RadialRecord(product); record = new RadialRecord(product);
record.setBinLength(momentHeader.binLength); record.setBinLength(momentHeader.binLength);
record.scale = momentHeader.scale;; record.scale = momentHeader.scale;
record.offset = momentHeader.offset; record.offset = momentHeader.offset;
this.recordMap.put(product, record); this.recordMap.put(product, record);
} }
@ -232,6 +272,7 @@ public class CMARadarBaseDataInfo extends DataInfo implements IGridDataInfo {
this.addAttribute(new Attribute("StationLongitude", siteConfig.longitude)); this.addAttribute(new Attribute("StationLongitude", siteConfig.longitude));
this.addAttribute(new Attribute("AntennaHeight", siteConfig.antennaHeight)); this.addAttribute(new Attribute("AntennaHeight", siteConfig.antennaHeight));
this.addAttribute(new Attribute("GroundHeight", siteConfig.groundHeight)); this.addAttribute(new Attribute("GroundHeight", siteConfig.groundHeight));
this.addAttribute(new Attribute("RadarType", siteConfig.getRadarType()));
//Read radial data //Read radial data
taskConfig = new TaskConfig(raf); taskConfig = new TaskConfig(raf);

View File

@ -111,4 +111,51 @@ public class SiteConfig {
reserved = new byte[46]; reserved = new byte[46];
raf.read(reserved); raf.read(reserved);
} }
/**
* Get radar type string
* @return Radar type string
*/
public String getRadarType() {
switch (radarType) {
case 1:
return "SA";
case 2:
return "SB";
case 3:
return "SC";
case 4:
return "SAD";
case 5:
return "SBD";
case 6:
return "SCD";
case 33:
return "CA";
case 34:
return "CB";
case 35:
return "CC";
case 36:
return "CCJ";
case 37:
return "CD";
case 38:
return "CAD";
case 39:
return "CBD";
case 40:
return "CCD";
case 41:
return "CCJD";
case 42:
return "CDD";
case 65:
return "XA";
case 66:
return "XAD";
default:
return "UNDEFINE";
}
}
} }

View File

@ -1,36 +1,34 @@
<?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:\Working\MIScript\Jython\mis\common_math\linalg"> <Path OpenPath="D:\Temp\test\webmap">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\topology"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\projection"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<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"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<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\city"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city"/>
<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\array\complex"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\linalg"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou"/>
<RecentFolder Folder="D:\Temp\test\webmap"/>
</Path> </Path>
<File> <File>
<OpenedFiles> <OpenedFiles>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/> <OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/> <OpenedFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\svd.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou\radar_bz2_3d.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\cond.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou\radar_bz2_3d_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\norm_1.py"/>
</OpenedFiles> </OpenedFiles>
<RecentFiles> <RecentFiles>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/> <RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\_reload.py"/>
<RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/> <RecentFile File="D:\MyProgram\java\MeteoInfoDev\toolbox\meteoview3d\mainGUI.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\svd.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou\radar_bz2_3d.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\cond.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\LaSW\ZhengZhou\radar_bz2_3d_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\linalg\norm_1.py"/>
</RecentFiles> </RecentFiles>
</File> </File>
<Font> <Font>
@ -38,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="1393,844"/>
</MeteoInfo> </MeteoInfo>

View File

@ -0,0 +1,117 @@
from .dimdatafile import DimDataFile
class ARLDataFile(DimDataFile):
def __init__(self, dataset=None, access='r', arldata=None):
self.dataset = dataset
self.access = access
self._variables = []
if not dataset is None:
self.filename = dataset.getFileName()
for v in dataset.getDataInfo().getVariables():
self._variables.append(DimVariable(v))
self.nvar = dataset.getDataInfo().getVariableNum()
self.fill_value = dataset.getMissingValue()
self.proj = dataset.getProjectionInfo()
self.arldata = arldata
# Write ARL data
def setx(self, x):
"""
Set x (longitude) dimension value.
:param x: (*array_like*) X dimension value.
"""
self.arldata.setX(x.aslist())
def sety(self, y):
"""
Set y (latitude) dimension value.
:param y: (*array_like*) Y dimension value.
"""
self.arldata.setY(y.aslist())
def setlevels(self, levels, add_ground=True):
"""
Set vertical levels.
:param levels: (*list*) Vertical levels.
:param add_ground: (*bool*) Whether add ground level. Default is `True`.
"""
if isinstance(levels, np.NDArray):
levels = levels.aslist()
if add_ground:
levels.insert(0, 1)
self.arldata.levels = levels
def set2dvar(self, vnames):
"""
Set surface variables (2 dimensions ignore time dimension).
:param vnames: (*list*) Variable names.
"""
self.arldata.LevelVarList.add(vnames)
def set3dvar(self, vnames):
"""
Set level variables (3 dimensions ignore time dimension).
:param vnames: (*list*) Variable names.
"""
self.arldata.LevelVarList.add(vnames)
def getdatahead(self, proj, model, vertical, icx=0, mn=0):
"""
Get data head.
:param proj: (*ProjectionInfo*) Projection information.
:param model: (*string*) Model name with 4 characters.
:param vertical: (*int*) Vertical coordinate system flag. 1-sigma (fraction);
2-pressure (mb); 3-terrain (fraction); 4-hybrid (mb: offset.fraction)
:param icx: (*int*) Forecast hour (>99 the header forecast hr = 99)
:param mn: (*int*) Minutes associated with data time.
"""
return self.arldata.getDataHead(proj, model, vertical, icx, mn)
def diff_origin_pack(self, data):
"""
Get difference between the original data and the packed data.
:param data: (*array*) The original data.
:return: (*array*) Difference.
"""
r = self.arldata.diffOriginPack(data._array)
return np.NDArray(r)
def writeindexrec(self, t, datahead, ksums=None):
"""
Write index record.
:param t: (*datatime*) The time of the data.
:param datahead: (*DataHeader') Data header of the record.
:param ksums: (*list*) Check sum list.
"""
t = miutil.jdate(t)
self.arldata.writeIndexRecord(t, datahead, ksums)
def writedatarec(self, t, lidx, vname, fhour, grid, data):
"""
Write data record.
:param t: (*datetime*) The time of the data.
:param lidx: (*int*) Level index.
:param vname: (*string*) Variable name.
:param fhour: (*int*) Forecasting hour.
:param grid: (*int*) Grid id to check if the data grid is bigger than 999. Header
record does not support grids of more than 999, therefore in those situations
the grid number is converted to character to represent the 1000s digit,
e.g. @(64)=<1000, A(65)=1000, B(66)=2000, etc.
:param data: (*array_like*) Data array.
:returns: (*int*) Check sum of the record data.
"""
t = miutil.jdate(t)
ksum = self.arldata.writeGridData(t, lidx, vname, fhour, grid, data.asarray())
return ksum

View File

@ -5,7 +5,8 @@ from ._ndarray import NDArray
from .dimarray import DimArray from .dimarray import DimArray
from org.meteoinfo.ndarray.math import ArrayUtil, ArrayMath from org.meteoinfo.ndarray.math import ArrayUtil, ArrayMath
__all__ = ['cumprod', 'cumsum', 'ndim', 'nonzero', 'prod', 'ravel', 'searchsorted', 'sum'] __all__ = ['cumprod', 'cumsum', 'ndim', 'nonzero', 'prod', 'ravel', 'searchsorted', 'sum',
'where']
def ndim(a): def ndim(a):
@ -80,6 +81,19 @@ def nonzero(a):
return tuple(r) return tuple(r)
def where(condition):
"""
Return elements, either from x or y, depending on condition.
If only condition is given, return condition.nonzero().
:param condition: (*array_like*) Input array.
:returns: (*tuple*) Indices of elements that are non-zero.
"""
return nonzero(condition)
def searchsorted(a, v, side='left', sorter=None): def searchsorted(a, v, side='left', sorter=None):
""" """
Find indices where elements should be inserted to maintain order. Find indices where elements should be inserted to maintain order.

View File

@ -5,10 +5,9 @@ multiarray module
from org.meteoinfo.ndarray.math import ArrayMath from org.meteoinfo.ndarray.math import ArrayMath
from ._ndarray import NDArray from ._ndarray import NDArray
from .fromnumeric import nonzero
from ._exceptions import AxisError from ._exceptions import AxisError
__all__ = ['normalize_axis_index','where','bincount'] __all__ = ['normalize_axis_index','bincount']
def normalize_axis_index(axis, ndim, msg_prefix=None): def normalize_axis_index(axis, ndim, msg_prefix=None):
""" """
@ -33,18 +32,6 @@ def normalize_axis_index(axis, ndim, msg_prefix=None):
else: else:
raise AxisError(axis, ndim, msg_prefix) raise AxisError(axis, ndim, msg_prefix)
def where(condition):
"""
Return elements, either from x or y, depending on condition.
If only condition is given, return condition.nonzero().
:param condition: (*array_like*) Input array.
:returns: (*tuple*) Indices of elements that are non-zero.
"""
return nonzero(condition)
def bincount(x, weights=None, minlength=0): def bincount(x, weights=None, minlength=0):
""" """
Count number of occurrences of each value in array of non-negative ints. Count number of occurrences of each value in array of non-negative ints.

View File

@ -27,13 +27,16 @@ def _check_version(version):
def magic(major, minor): def magic(major, minor):
""" Return the magic string for the given file format version. """ Return the magic string for the given file format version.
Parameters Parameters
---------- ----------
major : int in [0, 255] major : int in [0, 255]
minor : int in [0, 255] minor : int in [0, 255]
Returns Returns
------- -------
magic : str magic : str
Raises Raises
------ ------
ValueError if the version cannot be formatted. ValueError if the version cannot be formatted.