mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
update __getitem__ function in MemberVariable class
This commit is contained in:
parent
27ff2934b2
commit
fc22eea6eb
@ -654,6 +654,7 @@ public class JConsole extends JScrollPane
|
||||
private void append(String string) {
|
||||
if (string.length() > 10000) {
|
||||
string = string.substring(0, 10000);
|
||||
string = string + "\n...";
|
||||
}
|
||||
string = StringUtil.unicodeToString(string);
|
||||
int slen = textLength();
|
||||
|
||||
@ -94,7 +94,7 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert unicode string to character string
|
||||
* Convert Unicode string to character string
|
||||
*
|
||||
* @param unicodeString Unicode string
|
||||
* @return Character string
|
||||
|
||||
@ -148,6 +148,7 @@ public class JIntrospect implements NameCompletion {
|
||||
String name;
|
||||
for (int i = 0; i < plist.__len__(); i++) {
|
||||
name = plist.get(i).toString();
|
||||
//list.add(name);
|
||||
if (!name.contains("__")) {
|
||||
list.add(name);
|
||||
}
|
||||
|
||||
@ -376,10 +376,10 @@ public class NCUtil {
|
||||
*
|
||||
* @param parentArray The ucar ArrayObject with ArraySequence elements
|
||||
* @param memberName Member name
|
||||
* @param index Station index
|
||||
* @param index Sequence index
|
||||
* @return Read data array
|
||||
*/
|
||||
public static Array readSequenceStation(ucar.ma2.ArrayObject parentArray, String memberName,
|
||||
public static Array readSequence(ucar.ma2.ArrayObject parentArray, String memberName,
|
||||
int index) throws IOException {
|
||||
int n = (int) parentArray.getSize();
|
||||
ucar.ma2.ArrayStructure sArray = (ucar.ma2.ArrayStructure) parentArray.getObject(index);
|
||||
|
||||
@ -21,10 +21,12 @@
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\radar\radar_x_phase_2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\burf\bufr_cma_rsd.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\burf\bufr_cma_rsd_1.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\radar\radar_x_phase_2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\burf\bufr_cma_rsd.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\burf\bufr_cma_rsd_1.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -32,5 +34,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-6,0" MainFormSize="1357,849"/>
|
||||
<Startup MainFormLocation="-6,-6" MainFormSize="1292,764"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -668,21 +668,32 @@ class MemberVariable(DimVariable):
|
||||
self._ncfile = datainfo.getFile()
|
||||
self._ncvar = self._ncfile.findVariable(self.name)
|
||||
|
||||
def __getitem__(self, key=0, station=None):
|
||||
def __getitem__(self, key):
|
||||
"""
|
||||
Read array data from the variable.
|
||||
|
||||
:param key: (*int, complex or slice*) For `int`, key means record index. For `complex`, the image
|
||||
of the complex is the sequence index. For `slice`, `:` to read all data, otherwise the start
|
||||
of the slice is the sequence index.
|
||||
|
||||
:return: (*NDArray*) Data array.
|
||||
"""
|
||||
if isinstance(key, int):
|
||||
return self.read_array(record=key)
|
||||
elif isinstance(key, complex):
|
||||
return self.read_array(seq=int(key.imag))
|
||||
elif isinstance(key, slice):
|
||||
if key == slice(None):
|
||||
return self.read()
|
||||
else:
|
||||
return self.read_array(station=key.start)
|
||||
return self.read_array(seq=key.start)
|
||||
|
||||
def read_array(self, record=0, station=None):
|
||||
def read_array(self, record=0, seq=None):
|
||||
"""
|
||||
Read data array.
|
||||
|
||||
:param record: (*int*) Record index. Default is 0.
|
||||
:param station: (*int*) station index. Default is `None`, means all stations.
|
||||
:param seq: (*int*) Sequence index. Default is `None`, means all sequences.
|
||||
:return: (*array*) Data array.
|
||||
"""
|
||||
a = self._parent_variable.read()
|
||||
@ -692,10 +703,10 @@ class MemberVariable(DimVariable):
|
||||
if is_structure:
|
||||
r = NCUtil.readSequence(a, self.short_name)
|
||||
else:
|
||||
if station is None:
|
||||
if seq is None:
|
||||
r = NCUtil.readSequenceRecord(a, self.short_name, record, missing_value)
|
||||
else:
|
||||
r = NCUtil.readSequenceStation(a, self.short_name, station)
|
||||
r = NCUtil.readSequence(a, self.short_name, seq)
|
||||
|
||||
if r is None:
|
||||
return None
|
||||
|
||||
Binary file not shown.
@ -183,6 +183,15 @@ class DataType(object):
|
||||
else:
|
||||
return DataType('object')
|
||||
|
||||
def is_numeric(self):
|
||||
"""
|
||||
Is numeric data type or not.
|
||||
|
||||
:return: (*bool*) Is numeric data type or not.
|
||||
"""
|
||||
return self._dtype.isNumeric()
|
||||
|
||||
|
||||
class dtype(DataType):
|
||||
byte = DataType('byte')
|
||||
char = DataType('char')
|
||||
|
||||
@ -496,6 +496,10 @@ class NDArray(object):
|
||||
other = NDArray.__value_other(self, other)
|
||||
return self.array_wrap(ArrayMath.rightShift(self._array, other))
|
||||
|
||||
def __contains__(self, other):
|
||||
other = NDArray.__value_other(self, other)
|
||||
return self.array_wrap(ArrayMath.contains(self._array, other))
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
provide iteration over the values of the array
|
||||
|
||||
@ -4801,6 +4801,50 @@ public class ArrayMath {
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the array contains a given value
|
||||
*
|
||||
* @param a Input array
|
||||
* @param v The give value
|
||||
* @return Boolean
|
||||
*/
|
||||
public static boolean contains(Array a, Object v) {
|
||||
if (a.getDataType().isNumeric()) {
|
||||
double dv = ((Number) v).doubleValue();
|
||||
if (a.getIndexPrivate().isFastIterator()) {
|
||||
for (int i = 0; i < a.getSize(); i++) {
|
||||
if (a.getDouble(i) == dv) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IndexIterator iterA = a.getIndexIterator();
|
||||
while (iterA.hasNext()) {
|
||||
if (iterA.getDoubleNext() == dv) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (a.getIndexPrivate().isFastIterator()) {
|
||||
for (int i = 0; i < a.getSize(); i++) {
|
||||
if (a.getObject(i) == v) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IndexIterator iterA = a.getIndexIterator();
|
||||
while (iterA.hasNext()) {
|
||||
if (iterA.getObjectNext() == v) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the array contains NaN value
|
||||
*
|
||||
|
||||
@ -2360,7 +2360,7 @@ public class ArrayUtil {
|
||||
* @return Output array
|
||||
*/
|
||||
public static Array unPack(Array a, double missingValue, double scaleFactor, double addOffset) {
|
||||
if (!Double.isNaN(missingValue)) {
|
||||
if (!Double.isNaN(missingValue) && ArrayMath.contains(a, missingValue)) {
|
||||
a = ArrayUtil.convertToDataType(a, DataType.DOUBLE);
|
||||
ArrayMath.replaceValue(a, missingValue, Double.NaN);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user