|
30 | 30 | """ |
31 | 31 | import re |
32 | 32 |
|
33 | | -from numerix import array, arange, take, put, Float, Int, where, \ |
| 33 | +from numerix import array, arange, take, put, Float, Int, putmask, \ |
34 | 34 | zeros, asarray, sort, searchsorted, sometrue, ravel, divide,\ |
35 | | - ones, typecode, typecodes, alltrue |
| 35 | + ones, typecode, typecodes, alltrue, clip |
36 | 36 | from numerix.mlab import amin, amax |
37 | 37 | import numerix.ma as ma |
38 | 38 | import numerix as nx |
@@ -536,8 +536,9 @@ def makeMappingArray(N, data): |
536 | 536 | lut[0] = y1[0] |
537 | 537 | lut[-1] = y0[-1] |
538 | 538 | # ensure that the lut is confined to values between 0 and 1 by clipping it |
539 | | - lut = where(lut > 1., 1., lut) |
540 | | - lut = where(lut < 0., 0., lut) |
| 539 | + clip(lut, 0.0, 1.0) |
| 540 | + #lut = where(lut > 1., 1., lut) |
| 541 | + #lut = where(lut < 0., 0., lut) |
541 | 542 | return lut |
542 | 543 |
|
543 | 544 |
|
@@ -588,16 +589,16 @@ def __call__(self, X, alpha=1.0): |
588 | 589 | vtype = 'array' |
589 | 590 | xma = ma.asarray(X) |
590 | 591 | xa = xma.filled(0) |
591 | | - mask_bad = ma.getmaskorNone(xma) |
| 592 | + mask_bad = ma.getmask(xma) |
592 | 593 | if typecode(xa) in typecodes['Float']: |
593 | | - xa = where(xa == 1.0, 0.9999999, xa) # Tweak so 1.0 is in range. |
| 594 | + putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1. |
594 | 595 | xa = (xa * self.N).astype(Int) |
595 | | - mask_under = xa < 0 |
596 | | - mask_over = xa > self.N-1 |
597 | | - xa = where(mask_under, self._i_under, xa) |
598 | | - xa = where(mask_over, self._i_over, xa) |
599 | | - if mask_bad is not None: # and sometrue(mask_bad): |
600 | | - xa = where(mask_bad, self._i_bad, xa) |
| 596 | + # Set the over-range indices before the under-range; |
| 597 | + # otherwise the under-range values get converted to over-range. |
| 598 | + putmask(xa, xa>self.N-1, self._i_over) |
| 599 | + putmask(xa, xa<0, self._i_under) |
| 600 | + if mask_bad is not None and mask_bad.shape == xa.shape: |
| 601 | + putmask(xa, mask_bad, self._i_bad) |
601 | 602 | rgba = take(self._lut, xa) |
602 | 603 | if vtype == 'scalar': |
603 | 604 | rgba = tuple(rgba[0,:]) |
@@ -752,7 +753,7 @@ def __call__(self, value, clip=None): |
752 | 753 | return 0.*value |
753 | 754 | else: |
754 | 755 | if clip: |
755 | | - mask = ma.getmaskorNone(val) |
| 756 | + mask = ma.getmask(val) |
756 | 757 | val = ma.array(nx.clip(val.filled(vmax), vmin, vmax), |
757 | 758 | mask=mask) |
758 | 759 | result = (val-vmin)/float(vmax-vmin) |
@@ -804,7 +805,7 @@ def __call__(self, value, clip=None): |
804 | 805 | return 0.*value |
805 | 806 | else: |
806 | 807 | if clip: |
807 | | - mask = ma.getmaskorNone(val) |
| 808 | + mask = ma.getmask(val) |
808 | 809 | val = ma.array(nx.clip(val.filled(vmax), vmin, vmax), |
809 | 810 | mask=mask) |
810 | 811 | result = (ma.log(val)-nx.log(vmin))/(nx.log(vmax)-nx.log(vmin)) |
|
0 commit comments