update nc file writing functions

This commit is contained in:
wyq 2021-08-04 21:38:21 +08:00
parent a0c0fc86b3
commit 81756e9dce
11 changed files with 31 additions and 21 deletions

View File

@ -84,6 +84,7 @@ public class NCUtil {
ncArray = (ucar.ma2.Array)((ArrayStructure)array).getArrayObject();
break;
default:
array = array.copyIfView();
ncArray = ucar.ma2.Array.factory(convertDataType(array.getDataType()), array.getShape(), array.getStorage());
break;
}

View File

@ -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\scatter">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
<RecentFolder Folder="D:\Temp\script"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\interpolate"/>
<Path OpenPath="D:\Working\MIScript\cuace_dust\py\mm5">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\data_process"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\grads"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\math"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\meteo\interpolation"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\calipso"/>
<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\scatter"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\ascii"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\cuace_dust\py\mm5"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\cluster\dbscan_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\convolution\mnist_cnn.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\scatter\scatter_density.py"/>
<OpenedFile File="D:\Working\MIScript\cuace_dust\py\mm5\mm5tonc_lcc.py"/>
<OpenedFile File="D:\Working\MIScript\cuace_dust\py\mm5\test_nc-2.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\cluster\dbscan_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\convolution\mnist_cnn.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\scatter\scatter_density.py"/>
<RecentFile File="D:\Working\MIScript\cuace_dust\py\mm5\mm5tonc_lcc.py"/>
<RecentFile File="D:\Working\MIScript\cuace_dust\py\mm5\test_nc-2.py"/>
</RecentFiles>
</File>
<Font>
@ -34,5 +36,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,0" MainFormSize="1442,851"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,693"/>
</MeteoInfo>

View File

@ -363,13 +363,17 @@ class DimDataFile(object):
:param attrs: (*dict*) Attributes.
'''
dt = self.__getdatatype(datatype)
if isinstance(dims[0], Dimension):
ncdims = []
for dim in dims:
ncdims.append(self.ncfile.findDimension(dim.getName()))
var = DimVariable(ncvariable=self.ncfile.addVariable(group, varname, dt, ncdims))
if len(dims) > 0:
if isinstance(dims[0], Dimension):
ncdims = []
for dim in dims:
ncdims.append(self.ncfile.findDimension(dim.getName()))
var = DimVariable(ncvariable=self.ncfile.addVariable(group, varname, dt, ncdims))
else:
var = DimVariable(ncvariable=self.ncfile.addVariable(group, varname, dt, dims))
else:
var = DimVariable(ncvariable=self.ncfile.addVariable(group, varname, dt, dims))
if not attrs is None:
for key in attrs:
var.addattr(key, attrs[key])

View File

@ -60,7 +60,10 @@ class DimVariable(object):
def __str__(self):
if self.variable is None:
return 'None'
if self.ncvariable is None:
return 'None'
else:
return self.ncvariable.toString()
r = str(self.dtype) + ' ' + self.name + '('
for dim in self.dims:

View File

@ -485,7 +485,8 @@ def readtable(filename, **kwargs):
:param headerlines: (*int*) Lines to skip at beginning of the file. Default is ``0``. The line
after the skip lines will be read as variable names of the table. the ``headerlines`` should set
as ``-1`` if there is no field name line at beginning of the file.
:param encoding: (*string*) Character encoding scheme associated with the file. Default is ``UTF8``.
:param encoding: (*string*) Character encoding scheme associated with the file. Default is ``None`` that the function
will check the encoding automatically.
:param varnames: (*string*) Specified variable names for the readed table. Default is ``None``, means
the variable names should be read from the file.
:param readvarnames: (*boolean*) Read variable names or not. Default is ``True``.
@ -500,7 +501,7 @@ def readtable(filename, **kwargs):
delimiter = kwargs.pop('delimiter', None)
format = kwargs.pop('format', None)
headerlines = kwargs.pop('headerlines', 0)
encoding = kwargs.pop('encoding', 'UTF8')
encoding = kwargs.pop('encoding', None)
readvarnames = kwargs.pop('readvarnames', True)
readrownames = kwargs.pop('readrownames', False)
usecols = kwargs.pop('usecols', None)

View File

@ -483,6 +483,7 @@ class NDArray(object):
"""
provide iteration over the values of the array
"""
self.iterator = self._array.getIndexIterator()
return self
def next(self):

View File

@ -366,7 +366,7 @@ public class Index implements Cloneable {
Index reshape(int[] shape) {
boolean canReshape = true;
for (int s : this.stride) {
if (s > 1) {
if (s != 1) {
canReshape = false;
}
}

View File

@ -1516,20 +1516,18 @@ public class ArrayUtil {
for (int i = 0; i < ndim; i++) {
r.add(new ArrayList<Integer>());
}
Index index = a.getIndex();
IndexIterator iterA = a.getIndexIterator();
int[] counter;
double v;
while (iterA.hasNext()) {
v = iterA.getDoubleNext();
if (!Double.isNaN(v) && v != 0) {
counter = index.getCurrentCounter();
counter = iterA.getCurrentCounter();
for (int j = 0; j < ndim; j++) {
r.get(j).add(counter[j]);
}
}
index.incr();
//iterA.next();
}
if (r.get(0).isEmpty()) {