Find all masked and/or non-finite points in a set of arguments, and return the arguments with only the unmasked points remaining. Arguments can be in any of 5 categories: 1) 1-D masked arrays 2) 1-D ndarrays 3) ndarrays with more than one dimension 4) other non-string
(*args)
| 971 | |
| 972 | |
| 973 | def delete_masked_points(*args): |
| 974 | """ |
| 975 | Find all masked and/or non-finite points in a set of arguments, |
| 976 | and return the arguments with only the unmasked points remaining. |
| 977 | |
| 978 | Arguments can be in any of 5 categories: |
| 979 | |
| 980 | 1) 1-D masked arrays |
| 981 | 2) 1-D ndarrays |
| 982 | 3) ndarrays with more than one dimension |
| 983 | 4) other non-string iterables |
| 984 | 5) anything else |
| 985 | |
| 986 | The first argument must be in one of the first four categories; |
| 987 | any argument with a length differing from that of the first |
| 988 | argument (and hence anything in category 5) then will be |
| 989 | passed through unchanged. |
| 990 | |
| 991 | Masks are obtained from all arguments of the correct length |
| 992 | in categories 1, 2, and 4; a point is bad if masked in a masked |
| 993 | array or if it is a nan or inf. No attempt is made to |
| 994 | extract a mask from categories 2, 3, and 4 if `numpy.isfinite` |
| 995 | does not yield a Boolean array. |
| 996 | |
| 997 | All input arguments that are not passed unchanged are returned |
| 998 | as ndarrays after removing the points or rows corresponding to |
| 999 | masks in any of the arguments. |
| 1000 | |
| 1001 | A vastly simpler version of this function was originally |
| 1002 | written as a helper for Axes.scatter(). |
| 1003 | |
| 1004 | """ |
| 1005 | if not len(args): |
| 1006 | return () |
| 1007 | if is_scalar_or_string(args[0]): |
| 1008 | raise ValueError("First argument must be a sequence") |
| 1009 | nrecs = len(args[0]) |
| 1010 | margs = [] |
| 1011 | seqlist = [False] * len(args) |
| 1012 | for i, x in enumerate(args): |
| 1013 | if not isinstance(x, str) and np.iterable(x) and len(x) == nrecs: |
| 1014 | seqlist[i] = True |
| 1015 | if isinstance(x, np.ma.MaskedArray): |
| 1016 | if x.ndim > 1: |
| 1017 | raise ValueError("Masked arrays must be 1-D") |
| 1018 | else: |
| 1019 | x = np.asarray(x) |
| 1020 | margs.append(x) |
| 1021 | masks = [] # List of masks that are True where good. |
| 1022 | for i, x in enumerate(margs): |
| 1023 | if seqlist[i]: |
| 1024 | if x.ndim > 1: |
| 1025 | continue # Don't try to get nan locations unless 1-D. |
| 1026 | if isinstance(x, np.ma.MaskedArray): |
| 1027 | masks.append(~np.ma.getmaskarray(x)) # invert the mask |
| 1028 | xd = x.data |
| 1029 | else: |
| 1030 | xd = x |
searching dependent graphs…