Python numpy.ma.min() Examples
The following are 30
code examples of numpy.ma.min().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.ma
, or try the search function
.
Example #1
Source File: colors.py From neural-network-animation with MIT License | 6 votes |
def shade(self, data, cmap, norm=None): """ Take the input data array, convert to HSV values in the given colormap, then adjust those color values to give the impression of a shaded relief map with a specified light source. RGBA values are returned, which can then be used to plot the shaded image with imshow. """ if norm is None: norm = Normalize(vmin=data.min(), vmax=data.max()) rgb0 = cmap(norm(data)) rgb1 = self.shade_rgb(rgb0, elevation=data) rgb0[:, :, 0:3] = rgb1 return rgb0
Example #2
Source File: contour.py From coffeegrindsize with MIT License | 6 votes |
def _contour_args(self, args, kwargs): if self.filled: fn = 'contourf' else: fn = 'contour' Nargs = len(args) if Nargs <= 2: z = ma.asarray(args[0], dtype=np.float64) x, y = self._initialize_x_y(z) args = args[1:] elif Nargs <= 4: x, y, z = self._check_xyz(args[:3], kwargs) args = args[3:] else: raise TypeError("Too many arguments to %s; see help(%s)" % (fn, fn)) z = ma.masked_invalid(z, copy=False) self.zmax = float(z.max()) self.zmin = float(z.min()) if self.logscale and self.zmin <= 0: z = ma.masked_where(z <= 0, z) warnings.warn('Log scale: values of z <= 0 have been masked') self.zmin = float(z.min()) self._contour_level_args(z, args) return (x, y, z)
Example #3
Source File: virtualOS.py From PCR-GLOBWB_model with GNU General Public License v3.0 | 6 votes |
def regridToCoarse(fine,fac,mode,missValue): nr,nc = np.shape(fine) coarse = np.zeros(nr/fac * nc / fac).reshape(nr/fac,nc/fac) + MV nr,nc = np.shape(coarse) for r in range(0,nr): for c in range(0,nc): ar = fine[r * fac : fac * (r+1),c * fac: fac * (c+1)] m = np.ma.masked_values(ar,missValue) if ma.count(m) == 0: coarse[r,c] = MV else: if mode == 'average': coarse [r,c] = ma.average(m) elif mode == 'median': coarse [r,c] = ma.median(m) elif mode == 'sum': coarse [r,c] = ma.sum(m) elif mode =='min': coarse [r,c] = ma.min(m) elif mode == 'max': coarse [r,c] = ma.max(m) return coarse
Example #4
Source File: virtualOS.py From PCR-GLOBWB_model with GNU General Public License v3.0 | 6 votes |
def regridToCoarse(fine,fac,mode,missValue): nr,nc = np.shape(fine) coarse = np.zeros(nr/fac * nc / fac).reshape(nr/fac,nc/fac) + MV nr,nc = np.shape(coarse) for r in range(0,nr): for c in range(0,nc): ar = fine[r * fac : fac * (r+1),c * fac: fac * (c+1)] m = np.ma.masked_values(ar,missValue) if ma.count(m) == 0: coarse[r,c] = MV else: if mode == 'average': coarse [r,c] = ma.average(m) elif mode == 'median': coarse [r,c] = ma.median(m) elif mode == 'sum': coarse [r,c] = ma.sum(m) elif mode =='min': coarse [r,c] = ma.min(m) elif mode == 'max': coarse [r,c] = ma.max(m) return coarse
Example #5
Source File: contour.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _contour_args(self, args, kwargs): if self.filled: fn = 'contourf' else: fn = 'contour' Nargs = len(args) if Nargs <= 2: z = ma.asarray(args[0], dtype=np.float64) x, y = self._initialize_x_y(z) args = args[1:] elif Nargs <= 4: x, y, z = self._check_xyz(args[:3], kwargs) args = args[3:] else: raise TypeError("Too many arguments to %s; see help(%s)" % (fn, fn)) z = ma.masked_invalid(z, copy=False) self.zmax = float(z.max()) self.zmin = float(z.min()) if self.logscale and self.zmin <= 0: z = ma.masked_where(z <= 0, z) warnings.warn('Log scale: values of z <= 0 have been masked') self.zmin = float(z.min()) self._contour_level_args(z, args) return (x, y, z)
Example #6
Source File: contour.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _contour_args(self, args, kwargs): if self.filled: fn = 'contourf' else: fn = 'contour' Nargs = len(args) if Nargs <= 2: z = ma.asarray(args[0], dtype=np.float64) x, y = self._initialize_x_y(z) args = args[1:] elif Nargs <= 4: x, y, z = self._check_xyz(args[:3], kwargs) args = args[3:] else: raise TypeError("Too many arguments to %s; see help(%s)" % (fn, fn)) z = ma.masked_invalid(z, copy=False) self.zmax = float(z.max()) self.zmin = float(z.min()) if self.logscale and self.zmin <= 0: z = ma.masked_where(z <= 0, z) warnings.warn('Log scale: values of z <= 0 have been masked') self.zmin = float(z.min()) self._contour_level_args(z, args) return (x, y, z)
Example #7
Source File: contour.py From CogAlg with MIT License | 5 votes |
def _contour_args(self, args, kwargs): if self.filled: fn = 'contourf' else: fn = 'contour' Nargs = len(args) if Nargs <= 2: z = ma.asarray(args[0], dtype=np.float64) x, y = self._initialize_x_y(z) args = args[1:] elif Nargs <= 4: x, y, z = self._check_xyz(args[:3], kwargs) args = args[3:] else: raise TypeError("Too many arguments to %s; see help(%s)" % (fn, fn)) z = ma.masked_invalid(z, copy=False) self.zmax = float(z.max()) self.zmin = float(z.min()) if self.logscale and self.zmin <= 0: z = ma.masked_where(z <= 0, z) cbook._warn_external('Log scale: values of z <= 0 have been ' 'masked') self.zmin = float(z.min()) self._contour_level_args(z, args) return (x, y, z)
Example #8
Source File: contour.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _process_args(self, *args, **kwargs): """ Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update axes limits. """ self.levels = args[0] self.allsegs = args[1] self.allkinds = len(args) > 2 and args[2] or None self.zmax = np.max(self.levels) self.zmin = np.min(self.levels) self._auto = False # Check lengths of levels and allsegs. if self.filled: if len(self.allsegs) != len(self.levels) - 1: raise ValueError('must be one less number of segments as ' 'levels') else: if len(self.allsegs) != len(self.levels): raise ValueError('must be same number of segments as levels') # Check length of allkinds. if (self.allkinds is not None and len(self.allkinds) != len(self.allsegs)): raise ValueError('allkinds has different length to allsegs') # Determine x,y bounds and update axes data limits. flatseglist = [s for seg in self.allsegs for s in seg] points = np.concatenate(flatseglist, axis=0) self._mins = points.min(axis=0) self._maxs = points.max(axis=0) return kwargs
Example #9
Source File: contour.py From twitter-stock-recommendation with MIT License | 5 votes |
def _contour_level_args(self, z, args): """ Determine the contour levels and store in self.levels. """ if self.filled: fn = 'contourf' else: fn = 'contour' self._auto = False if self.levels is None: if len(args) == 0: lev = self._autolev(7) else: level_arg = args[0] try: if type(level_arg) == int: lev = self._autolev(level_arg) else: lev = np.asarray(level_arg).astype(np.float64) except: raise TypeError( "Last {0} arg must give levels; see help({0})" .format(fn)) self.levels = lev else: self.levels = np.asarray(self.levels).astype(np.float64) if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) self.levels = self.levels[inside] if len(self.levels) == 0: self.levels = [self.zmin] warnings.warn("No contour levels were found" " within the data range.") if self.filled and len(self.levels) < 2: raise ValueError("Filled contours require at least 2 levels.") if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0: raise ValueError("Contour levels must be increasing")
Example #10
Source File: contour.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _contour_level_args(self, z, args): """ Determine the contour levels and store in self.levels. """ if self.filled: fn = 'contourf' else: fn = 'contour' self._auto = False if self.levels is None: if len(args) == 0: levels_arg = 7 # Default, hard-wired. else: levels_arg = args[0] else: levels_arg = self.levels if isinstance(levels_arg, Integral): self.levels = self._autolev(levels_arg) else: self.levels = np.asarray(levels_arg).astype(np.float64) if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) levels_in = self.levels[inside] if len(levels_in) == 0: self.levels = [self.zmin] warnings.warn("No contour levels were found" " within the data range.") if self.filled and len(self.levels) < 2: raise ValueError("Filled contours require at least 2 levels.") if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0: raise ValueError("Contour levels must be increasing")
Example #11
Source File: contour.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, adding extended layers as needed if contours are filled. For line contours, layers simply coincide with levels; a line is a thin layer. No extended levels are needed with line contours. """ # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. # (Colorbar needs this even for line contours.) self._levels = list(self.levels) if self.logscale: lower, upper = 1e-250, 1e250 else: lower, upper = -1e250, 1e250 if self.extend in ('both', 'min'): self._levels.insert(0, lower) if self.extend in ('both', 'max'): self._levels.append(upper) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return # Layer values are mid-way between levels in screen space. if self.logscale: # Avoid overflow by taking sqrt before multiplying. self.layers = (np.sqrt(self._levels[:-1]) * np.sqrt(self._levels[1:])) else: self.layers = 0.5 * (self._levels[:-1] + self._levels[1:])
Example #12
Source File: contour.py From twitter-stock-recommendation with MIT License | 5 votes |
def _process_args(self, *args, **kwargs): """ Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update axes limits. """ self.levels = args[0] self.allsegs = args[1] self.allkinds = len(args) > 2 and args[2] or None self.zmax = np.max(self.levels) self.zmin = np.min(self.levels) self._auto = False # Check lengths of levels and allsegs. if self.filled: if len(self.allsegs) != len(self.levels) - 1: raise ValueError('must be one less number of segments as ' 'levels') else: if len(self.allsegs) != len(self.levels): raise ValueError('must be same number of segments as levels') # Check length of allkinds. if (self.allkinds is not None and len(self.allkinds) != len(self.allsegs)): raise ValueError('allkinds has different length to allsegs') # Determine x,y bounds and update axes data limits. flatseglist = [s for seg in self.allsegs for s in seg] points = np.concatenate(flatseglist, axis=0) self._mins = points.min(axis=0) self._maxs = points.max(axis=0) return kwargs
Example #13
Source File: contour.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _process_args(self, *args, **kwargs): """ Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update axes limits. """ self.levels = args[0] self.allsegs = args[1] self.allkinds = len(args) > 2 and args[2] or None self.zmax = np.max(self.levels) self.zmin = np.min(self.levels) self._auto = False # Check lengths of levels and allsegs. if self.filled: if len(self.allsegs) != len(self.levels) - 1: raise ValueError('must be one less number of segments as ' 'levels') else: if len(self.allsegs) != len(self.levels): raise ValueError('must be same number of segments as levels') # Check length of allkinds. if (self.allkinds is not None and len(self.allkinds) != len(self.allsegs)): raise ValueError('allkinds has different length to allsegs') # Determine x,y bounds and update axes data limits. flatseglist = [s for seg in self.allsegs for s in seg] points = np.concatenate(flatseglist, axis=0) self._mins = points.min(axis=0) self._maxs = points.max(axis=0) return kwargs
Example #14
Source File: contour.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _contour_level_args(self, z, args): """ Determine the contour levels and store in self.levels. """ if self.filled: fn = 'contourf' else: fn = 'contour' self._auto = False if self.levels is None: if len(args) == 0: levels_arg = 7 # Default, hard-wired. else: levels_arg = args[0] else: levels_arg = self.levels if isinstance(levels_arg, Integral): self.levels = self._autolev(levels_arg) else: self.levels = np.asarray(levels_arg).astype(np.float64) if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) levels_in = self.levels[inside] if len(levels_in) == 0: self.levels = [self.zmin] warnings.warn("No contour levels were found" " within the data range.") if self.filled and len(self.levels) < 2: raise ValueError("Filled contours require at least 2 levels.") if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0: raise ValueError("Contour levels must be increasing")
Example #15
Source File: contour.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, adding extended layers as needed if contours are filled. For line contours, layers simply coincide with levels; a line is a thin layer. No extended levels are needed with line contours. """ # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. # (Colorbar needs this even for line contours.) self._levels = list(self.levels) if self.logscale: lower, upper = 1e-250, 1e250 else: lower, upper = -1e250, 1e250 if self.extend in ('both', 'min'): self._levels.insert(0, lower) if self.extend in ('both', 'max'): self._levels.append(upper) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return # Layer values are mid-way between levels in screen space. if self.logscale: # Avoid overflow by taking sqrt before multiplying. self.layers = (np.sqrt(self._levels[:-1]) * np.sqrt(self._levels[1:])) else: self.layers = 0.5 * (self._levels[:-1] + self._levels[1:])
Example #16
Source File: contour.py From twitter-stock-recommendation with MIT License | 5 votes |
def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, adding extended layers as needed if contours are filled. For line contours, layers simply coincide with levels; a line is a thin layer. No extended levels are needed with line contours. """ # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. # (Colorbar needs this even for line contours.) self._levels = list(self.levels) if self.extend in ('both', 'min'): self._levels.insert(0, min(self.levels[0], self.zmin) - 1) if self.extend in ('both', 'max'): self._levels.append(max(self.levels[-1], self.zmax) + 1) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return # layer values are mid-way between levels self.layers = 0.5 * (self._levels[:-1] + self._levels[1:]) # ...except that extended layers must be outside the # normed range: if self.extend in ('both', 'min'): self.layers[0] = -1e150 if self.extend in ('both', 'max'): self.layers[-1] = 1e150
Example #17
Source File: contour.py From coffeegrindsize with MIT License | 5 votes |
def _process_args(self, *args, **kwargs): """ Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update axes limits. """ self.levels = args[0] self.allsegs = args[1] self.allkinds = len(args) > 2 and args[2] or None self.zmax = np.max(self.levels) self.zmin = np.min(self.levels) self._auto = False # Check lengths of levels and allsegs. if self.filled: if len(self.allsegs) != len(self.levels) - 1: raise ValueError('must be one less number of segments as ' 'levels') else: if len(self.allsegs) != len(self.levels): raise ValueError('must be same number of segments as levels') # Check length of allkinds. if (self.allkinds is not None and len(self.allkinds) != len(self.allsegs)): raise ValueError('allkinds has different length to allsegs') # Determine x,y bounds and update axes data limits. flatseglist = [s for seg in self.allsegs for s in seg] points = np.concatenate(flatseglist, axis=0) self._mins = points.min(axis=0) self._maxs = points.max(axis=0) return kwargs
Example #18
Source File: contour.py From coffeegrindsize with MIT License | 5 votes |
def _contour_level_args(self, z, args): """ Determine the contour levels and store in self.levels. """ if self.filled: fn = 'contourf' else: fn = 'contour' self._auto = False if self.levels is None: if len(args) == 0: levels_arg = 7 # Default, hard-wired. else: levels_arg = args[0] else: levels_arg = self.levels if isinstance(levels_arg, Integral): self.levels = self._autolev(levels_arg) else: self.levels = np.asarray(levels_arg).astype(np.float64) if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) levels_in = self.levels[inside] if len(levels_in) == 0: self.levels = [self.zmin] warnings.warn("No contour levels were found" " within the data range.") if self.filled and len(self.levels) < 2: raise ValueError("Filled contours require at least 2 levels.") if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0: raise ValueError("Contour levels must be increasing")
Example #19
Source File: contour.py From coffeegrindsize with MIT License | 5 votes |
def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, adding extended layers as needed if contours are filled. For line contours, layers simply coincide with levels; a line is a thin layer. No extended levels are needed with line contours. """ # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. # (Colorbar needs this even for line contours.) self._levels = list(self.levels) if self.logscale: lower, upper = 1e-250, 1e250 else: lower, upper = -1e250, 1e250 if self.extend in ('both', 'min'): self._levels.insert(0, lower) if self.extend in ('both', 'max'): self._levels.append(upper) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return # Layer values are mid-way between levels in screen space. if self.logscale: # Avoid overflow by taking sqrt before multiplying. self.layers = (np.sqrt(self._levels[:-1]) * np.sqrt(self._levels[1:])) else: self.layers = 0.5 * (self._levels[:-1] + self._levels[1:])
Example #20
Source File: contour.py From CogAlg with MIT License | 5 votes |
def _process_levels(self): """ Assign values to :attr:`layers` based on :attr:`levels`, adding extended layers as needed if contours are filled. For line contours, layers simply coincide with levels; a line is a thin layer. No extended levels are needed with line contours. """ # Make a private _levels to include extended regions; we # want to leave the original levels attribute unchanged. # (Colorbar needs this even for line contours.) self._levels = list(self.levels) if self.logscale: lower, upper = 1e-250, 1e250 else: lower, upper = -1e250, 1e250 if self.extend in ('both', 'min'): self._levels.insert(0, lower) if self.extend in ('both', 'max'): self._levels.append(upper) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return # Layer values are mid-way between levels in screen space. if self.logscale: # Avoid overflow by taking sqrt before multiplying. self.layers = (np.sqrt(self._levels[:-1]) * np.sqrt(self._levels[1:])) else: self.layers = 0.5 * (self._levels[:-1] + self._levels[1:])
Example #21
Source File: contour.py From CogAlg with MIT License | 5 votes |
def _process_args(self, *args, **kwargs): """ Process *args* and *kwargs*; override in derived classes. Must set self.levels, self.zmin and self.zmax, and update axes limits. """ self.levels = args[0] self.allsegs = args[1] self.allkinds = len(args) > 2 and args[2] or None self.zmax = np.max(self.levels) self.zmin = np.min(self.levels) # Check lengths of levels and allsegs. if self.filled: if len(self.allsegs) != len(self.levels) - 1: raise ValueError('must be one less number of segments as ' 'levels') else: if len(self.allsegs) != len(self.levels): raise ValueError('must be same number of segments as levels') # Check length of allkinds. if (self.allkinds is not None and len(self.allkinds) != len(self.allsegs)): raise ValueError('allkinds has different length to allsegs') # Determine x,y bounds and update axes data limits. flatseglist = [s for seg in self.allsegs for s in seg] points = np.concatenate(flatseglist, axis=0) self._mins = points.min(axis=0) self._maxs = points.max(axis=0) return kwargs
Example #22
Source File: contour.py From CogAlg with MIT License | 5 votes |
def _contour_level_args(self, z, args): """ Determine the contour levels and store in self.levels. """ if self.levels is None: if len(args) == 0: levels_arg = 7 # Default, hard-wired. else: levels_arg = args[0] else: levels_arg = self.levels if isinstance(levels_arg, Integral): self.levels = self._autolev(levels_arg) else: self.levels = np.asarray(levels_arg).astype(np.float64) if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) levels_in = self.levels[inside] if len(levels_in) == 0: self.levels = [self.zmin] cbook._warn_external( "No contour levels were found within the data range.") if self.filled and len(self.levels) < 2: raise ValueError("Filled contours require at least 2 levels.") if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0: raise ValueError("Contour levels must be increasing")
Example #23
Source File: colors.py From matplotlib-4-abaqus with MIT License | 5 votes |
def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ self.vmin = ma.min(A) self.vmax = ma.max(A) self._transform_vmin_vmax()
Example #24
Source File: colors.py From Computable with MIT License | 5 votes |
def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' if self.vmin is None and np.size(A) > 0: self.vmin = ma.min(A) if self.vmax is None and np.size(A) > 0: self.vmax = ma.max(A)
Example #25
Source File: colors.py From Computable with MIT License | 5 votes |
def autoscale(self, A): ''' Set *vmin*, *vmax* to min, max of *A*. ''' A = ma.masked_less_equal(A, 0, copy=False) self.vmin = ma.min(A) self.vmax = ma.max(A)
Example #26
Source File: colors.py From Computable with MIT License | 5 votes |
def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' if self.vmin is not None and self.vmax is not None: return A = ma.masked_less_equal(A, 0, copy=False) if self.vmin is None: self.vmin = ma.min(A) if self.vmax is None: self.vmax = ma.max(A)
Example #27
Source File: colors.py From Computable with MIT License | 5 votes |
def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ self.vmin = ma.min(A) self.vmax = ma.max(A) self._transform_vmin_vmax()
Example #28
Source File: colors.py From Computable with MIT License | 5 votes |
def shade(self, data, cmap): """ Take the input data array, convert to HSV values in the given colormap, then adjust those color values to given the impression of a shaded relief map with a specified light source. RGBA values are returned, which can then be used to plot the shaded image with imshow. """ rgb0 = cmap((data - data.min()) / (data.max() - data.min())) rgb1 = self.shade_rgb(rgb0, elevation=data) rgb0[:, :, 0:3] = rgb1 return rgb0
Example #29
Source File: colors.py From Computable with MIT License | 5 votes |
def autoscale(self, A): ''' Set *vmin*, *vmax* to min, max of *A*. ''' self.vmin = ma.min(A) self.vmax = ma.max(A)
Example #30
Source File: colors.py From matplotlib-4-abaqus with MIT License | 5 votes |
def autoscale(self, A): ''' Set *vmin*, *vmax* to min, max of *A*. ''' self.vmin = ma.min(A) self.vmax = ma.max(A)