mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
format NDArray iter behaviours and add nditer class
This commit is contained in:
parent
ca3d08c841
commit
d9da7e4f73
@ -1,30 +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\imshow">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\scatter"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\micaps"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\scatter"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\test">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\bar"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\json"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\imshow"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
|
||||
<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\test"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\imshow\plot_fy_rgb_reproj.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\satellite\FY\FY4A_AGRI_L1_rgb_lonlat_3d.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\flower_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\meteo\calc\frontogenesis.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\test\iter_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\test\iter_2.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\imshow\plot_fy_rgb_reproj.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\satellite\FY\FY4A_AGRI_L1_rgb_lonlat_3d.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\flower_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\meteo\calc\frontogenesis.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\test\iter_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\test\iter_2.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
|
||||
Binary file not shown.
@ -2,6 +2,7 @@ from ._ndarray import NDArray
|
||||
from . import multiarray
|
||||
from .multiarray import *
|
||||
from .dimarray import DimArray, dimension, dim_array
|
||||
from ._base import nditer
|
||||
from .mitable import PyTableData
|
||||
from ._dtype import dtype
|
||||
from . import numeric
|
||||
@ -14,7 +15,7 @@ from . import umath
|
||||
from umath import *
|
||||
from .shape_base import *
|
||||
|
||||
__all__ = ['NDArray','DimArray','PyTableData','dtype','dimension','dim_array']
|
||||
__all__ = ['NDArray','DimArray','PyTableData','dtype','dimension','dim_array','nditer']
|
||||
__all__ += multiarray.__all__
|
||||
__all__ += numeric.__all__
|
||||
__all__ += fromnumeric.__all__
|
||||
|
||||
@ -1,6 +1,26 @@
|
||||
from org.meteoinfo.ndarray import FlatIndex
|
||||
from org.meteoinfo.ndarray.math import ArrayUtil
|
||||
|
||||
|
||||
class nditer(object):
|
||||
|
||||
def __init__(self, array):
|
||||
self.array = array
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
provide iteration over the values of the array
|
||||
"""
|
||||
self.iterator = self.array._array.getIndexIterator()
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if self.iterator.hasNext():
|
||||
return self.iterator.getObjectNext()
|
||||
else:
|
||||
raise StopIteration()
|
||||
|
||||
|
||||
class flatiter(object):
|
||||
|
||||
def __init__(self, array):
|
||||
|
||||
@ -20,16 +20,12 @@ class NDArray(object):
|
||||
if not isinstance(array, Array):
|
||||
array = ArrayUtil.array(array, None)
|
||||
|
||||
# if array.getRank() == 0 and array.getDataType() != DataType.STRUCTURE:
|
||||
# array = ArrayUtil.array([array.getIndexIterator().getObjectNext()])
|
||||
|
||||
self._array = array
|
||||
self.ndim = array.getRank()
|
||||
s = array.getShape()
|
||||
self._shape = tuple(s)
|
||||
self.dtype = _dtype.dtype.fromjava(array.getDataType())
|
||||
self.size = int(self._array.getSize())
|
||||
self.iterator = array.getIndexIterator()
|
||||
self.base = None
|
||||
if self.ndim > 0:
|
||||
self.sizestr = str(self.shape[0])
|
||||
@ -337,7 +333,6 @@ class NDArray(object):
|
||||
else:
|
||||
r = ArrayMath.setSection_Mix(self._array, ranges, value)
|
||||
self._array = r
|
||||
self.iterator = self._array.getIndexIterator()
|
||||
|
||||
def __value_other(self, other):
|
||||
if isinstance(other, NDArray):
|
||||
@ -514,14 +509,16 @@ class NDArray(object):
|
||||
"""
|
||||
provide iteration over the values of the array
|
||||
"""
|
||||
self.iterator = self._array.getIndexIterator()
|
||||
self._idx = 0
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if self.iterator.hasNext():
|
||||
return self.iterator.getObjectNext()
|
||||
else:
|
||||
if self._idx >= self.shape[0]:
|
||||
raise StopIteration()
|
||||
else:
|
||||
value = self.__getitem__(self._idx)
|
||||
self._idx += 1
|
||||
return value
|
||||
|
||||
def item(self, *args):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user