Python numpy.nanmin() Examples

The following are 30 code examples for showing how to use numpy.nanmin(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: neuropythy   Author: noahbenson   File: core.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def apply_cmap(zs, cmap, vmin=None, vmax=None, unit=None, logrescale=False):
    '''
    apply_cmap(z, cmap) applies the given cmap to the values in z; if vmin and/or vmax are passed,
      they are used to scale z.

    Note that this function can automatically rescale data into log-space if the colormap is a
    neuropythy log-space colormap such as log_eccentricity. To enable this behaviour use the
    optional argument logrescale=True.
    '''
    zs = pimms.mag(zs) if unit is None else pimms.mag(zs, unit)
    zs = np.asarray(zs, dtype='float')
    if pimms.is_str(cmap): cmap = matplotlib.cm.get_cmap(cmap)
    if logrescale:
        if vmin is None: vmin = np.log(np.nanmin(zs))
        if vmax is None: vmax = np.log(np.nanmax(zs))
        mn = np.exp(vmin)
        u = zdivide(nanlog(zs + mn) - vmin, vmax - vmin, null=np.nan)
    else:        
        if vmin is None: vmin = np.nanmin(zs)
        if vmax is None: vmax = np.nanmax(zs)
        u = zdivide(zs - vmin, vmax - vmin, null=np.nan)
    u[np.isnan(u)] = -np.inf
    return cmap(u) 
Example 2
Project: python-control   Author: python-control   File: grid.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __call__(self, transform_xy, x1, y1, x2, y2):
        x_, y_ = np.linspace(x1, x2, self.nx), np.linspace(y1, y2, self.ny)
        x, y = np.meshgrid(x_, y_)
        lon, lat = transform_xy(np.ravel(x), np.ravel(y))

        with np.errstate(invalid='ignore'):
            if self.lon_cycle is not None:
                lon0 = np.nanmin(lon)
                # Changed from 180 to 360 to be able to span only
                # 90-270 (left hand side)
                lon -= 360. * ((lon - lon0) > 360.)
            if self.lat_cycle is not None:
                lat0 = np.nanmin(lat)
                # Changed from 180 to 360 to be able to span only
                # 90-270 (left hand side)
                lat -= 360. * ((lat - lat0) > 360.)

        lon_min, lon_max = np.nanmin(lon), np.nanmax(lon)
        lat_min, lat_max = np.nanmin(lat), np.nanmax(lat)

        lon_min, lon_max, lat_min, lat_max = \
            self._adjust_extremes(lon_min, lon_max, lat_min, lat_max)

        return lon_min, lon_max, lat_min, lat_max 
Example 3
Project: pysat   Author: pysat   File: test_sw.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_calc_f107a_daily_missing(self):
        """ Test the calc_f107a routine with some daily data missing"""

        self.testInst.data = pds.DataFrame({'f107': np.linspace(70, 200, 160)},
                                           index=[pysat.datetime(2009, 1, 1)
                                                  + pds.DateOffset(days=2*i+1)
                                                  for i in range(160)])
        sw_f107.calc_f107a(self.testInst, f107_name='f107', f107a_name='f107a')

        # Assert that new data and metadata exist
        assert 'f107a' in self.testInst.data.columns
        assert 'f107a' in self.testInst.meta.keys()

        # Assert the finite values have realistic means
        assert(np.nanmin(self.testInst['f107a'])
               > np.nanmin(self.testInst['f107']))
        assert(np.nanmax(self.testInst['f107a'])
               < np.nanmax(self.testInst['f107']))

        # Assert the expected number of fill values
        assert(len(self.testInst['f107a'][np.isnan(self.testInst['f107a'])])
               == 40) 
Example 4
Project: recruit   Author: Frank-qlu   File: test_frame.py    License: Apache License 2.0 6 votes vote down vote up
def test_unsorted_index_lims(self):
        df = DataFrame({'y': [0., 1., 2., 3.]}, index=[1., 0., 3., 2.])
        ax = df.plot()
        xmin, xmax = ax.get_xlim()
        lines = ax.get_lines()
        assert xmin <= np.nanmin(lines[0].get_data()[0])
        assert xmax >= np.nanmax(lines[0].get_data()[0])

        df = DataFrame({'y': [0., 1., np.nan, 3., 4., 5., 6.]},
                       index=[1., 0., 3., 2., np.nan, 3., 2.])
        ax = df.plot()
        xmin, xmax = ax.get_xlim()
        lines = ax.get_lines()
        assert xmin <= np.nanmin(lines[0].get_data()[0])
        assert xmax >= np.nanmax(lines[0].get_data()[0])

        df = DataFrame({'y': [0., 1., 2., 3.], 'z': [91., 90., 93., 92.]})
        ax = df.plot(x='z', y='y')
        xmin, xmax = ax.get_xlim()
        lines = ax.get_lines()
        assert xmin <= np.nanmin(lines[0].get_data()[0])
        assert xmax >= np.nanmax(lines[0].get_data()[0]) 
Example 5
Project: basenji   Author: calico   File: bam_cov.py    License: Apache License 2.0 6 votes vote down vote up
def scatter_lims(vals1, vals2=None, buffer=.05):
  if vals2 is not None:
    vals = np.concatenate((vals1, vals2))
  else:
    vals = vals1
  vmin = np.nanmin(vals)
  vmax = np.nanmax(vals)

  buf = .05 * (vmax - vmin)

  if vmin == 0:
    vmin -= buf / 2
  else:
    vmin -= buf
  vmax += buf

  return vmin, vmax

################################################################################
# __main__
################################################################################ 
Example 6
Project: basenji   Author: calico   File: plots.py    License: Apache License 2.0 6 votes vote down vote up
def scatter_lims(vals1, vals2=None, buffer=.05):
  if vals2 is not None:
    vals = np.concatenate((vals1, vals2))
  else:
    vals = vals1
  vmin = np.nanmin(vals)
  vmax = np.nanmax(vals)

  buf = .05 * (vmax - vmin)

  if vmin == 0:
    vmin -= buf / 2
  else:
    vmin -= buf
  vmax += buf

  return vmin, vmax


################################################################################
# nucleotides

# Thanks to Anshul Kundaje, Avanti Shrikumar
# https://github.com/kundajelab/deeplift/tree/master/deeplift/visualization 
Example 7
Project: LSDMappingTools   Author: LSDtopotools   File: LSDMap_Subplots.py    License: MIT License 6 votes vote down vote up
def findminval_multirasters(FileList):
    """
    Loops through a list or array of rasters (np arrays)
    and finds the minimum single value in the set of arrays.
    """
    overall_min_val = 0

    for i in range (len(FileList)):

        raster_as_array = LSDMap_IO.ReadRasterArrayBlocks(FileList[i])
        this_min_val = np.nanmin(raster_as_array)

        if this_min_val > overall_min_val:
            overall_min_val = this_min_val
            print(overall_min_val)

    return overall_min_val 
Example 8
Project: tf-pose   Author: SrikanthVelpuri   File: ImageView.py    License: Apache License 2.0 6 votes vote down vote up
def quickMinMax(self, data):
        """
        Estimate the min/max values of *data* by subsampling.
        Returns [(min, max), ...] with one item per channel
        """
        while data.size > 1e6:
            ax = np.argmax(data.shape)
            sl = [slice(None)] * data.ndim
            sl[ax] = slice(None, None, 2)
            data = data[sl]
            
        cax = self.axes['c']
        if cax is None:
            return [(float(nanmin(data)), float(nanmax(data)))]
        else:
            return [(float(nanmin(data.take(i, axis=cax))), 
                     float(nanmax(data.take(i, axis=cax)))) for i in range(data.shape[-1])] 
Example 9
Project: geojsoncontour   Author: bartromgens   File: netcdfhelper.py    License: MIT License 6 votes vote down vote up
def netcdf_to_geojson(ncfile, var, fourth_dim=None):
    realpath = os.path.realpath(ncfile)
    name, ext = os.path.splitext(realpath)
    X, Y, Z, levels, unit = setup(ncfile, var)
    figure = plt.figure()
    ax = figure.add_subplot(111)
    for t in range(len(Z.time)):
        third = Z.isel(time=t)
        position = 0
        if len(third.dims) == 3:
            position = len(getattr(third, third.dims[0]))-1
            third = third[position, ]
        # local min max
        levels = np.linspace(start=np.nanmin(third),
                             stop=np.nanmax(third), num=20)
        contourf = ax.contourf(X, Y, third, levels=levels, cmap=plt.cm.viridis)
        geojsoncontour.contourf_to_geojson(
            contourf=contourf,
            geojson_filepath='{}_{}_t{}_{}.geojson'.format(name, var,
                                                           t, position),
            ndigits=3,
            min_angle_deg=None,
            unit=unit
        ) 
Example 10
Project: pyERA   Author: mpatacchiola   File: som.py    License: MIT License 6 votes vote down vote up
def return_normalized_distance_matrix(self, input_vector):
        """Return the min-max normalized euclidean-distance matrix between the input vector and the SOM weights.

        A value of 0.0 means that the input/weights are equal.
        @param input_vector the vector to use for the comparison.
        """
        output_matrix = np.zeros((self._matrix_size, self._matrix_size))
        it = np.nditer(output_matrix, flags=['multi_index'])
        while not it.finished:
            #print "%d <%s>" % (it[0], it.multi_index),
            dist = self.return_euclidean_distance(input_vector, self._weights_matrix[it.multi_index[0], it.multi_index[1], :])
            output_matrix[it.multi_index[0], it.multi_index[1]] = dist
            it.iternext()
        #min-max normalization
        max_value = np.nanmax(output_matrix)
        min_value = np.nanmin(output_matrix)
        output_matrix = (output_matrix - min_value) / (max_value - min_value)
        return output_matrix 
Example 11
Project: pyERA   Author: mpatacchiola   File: som.py    License: MIT License 6 votes vote down vote up
def return_similarity_matrix(self, input_vector):
        """Return a similarity matrix where a value is 1.0 if the distance input/weight is zero.

        @param input_vector the vector to use for the comparison.
        """
        output_matrix = np.zeros((self._matrix_size, self._matrix_size))
        it = np.nditer(output_matrix, flags=['multi_index'])
        while not it.finished:
            #print "%d <%s>" % (it[0], it.multi_index),
            dist = self.return_euclidean_distance(input_vector, self._weights_matrix[it.multi_index[0], it.multi_index[1], :])
            output_matrix[it.multi_index[0], it.multi_index[1]] = dist
            it.iternext()
        #min-max normalization
        max_value = np.nanmax(output_matrix)
        min_value = np.nanmin(output_matrix)
        output_matrix = (output_matrix - min_value) / (max_value - min_value)
        output_matrix = 1.0 - output_matrix
        return output_matrix 
Example 12
Project: fylearn   Author: sorend   File: rafpc.py    License: MIT License 6 votes vote down vote up
def fuzzify_partitions(p):
    def fuzzify_p(A):
        R = np.zeros((A.shape[0], A.shape[1] * p))

        cmin, cmax = np.nanmin(A, 0), np.nanmax(A, 0)
        psize = (cmax - cmin) / (p - 1)

        mus = []
        # iterate features
        for i in range(A.shape[1]):
            # iterate partitions
            mu_i = []
            offset = cmin[i]
            for j in range(p):
                f = fl.TriangularSet(offset - psize[i], offset, offset + psize[i])
                R[:, (i * p) + j] = f(A[:, i])
                mu_i.append(f)
                offset += psize[i]
            mus.append(mu_i)
        return p, R, mus
    return fuzzify_p 
Example 13
Project: fylearn   Author: sorend   File: rafpc.py    License: MIT License 6 votes vote down vote up
def fuzzify_mean(A):
    # output for fuzzified values
    R = np.zeros((A.shape[0], A.shape[1] * 3))

    cmin, cmax, cmean = np.nanmin(A, 0), np.nanmax(A, 0), np.nanmean(A, 0)
        
    left = np.array([cmin - (cmax - cmin), cmin, cmax]).T
    middle = np.array([cmin, cmean, cmax]).T
    right = np.array([cmin, cmax, cmax + (cmax - cmin)]).T

    mus = []

    for i in range(A.shape[1]):
        f_l = fl.TriangularSet(*left[i])
        f_m = fl.TriangularSet(*middle[i])
        f_r = fl.TriangularSet(*right[i])
        R[:,(i*3)] = f_l(A[:,i])
        R[:,(i*3)+1] = f_m(A[:,i])
        R[:,(i*3)+2] = f_r(A[:,i])
        mus.extend([(i, f_l), (i, f_m), (i, f_r)])

    return 3, R, mus 
Example 14
Project: neuropythy   Author: noahbenson   File: core.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def scale_for_cmap(cmap, x, vmin=Ellipsis, vmax=Ellipsis, unit=Ellipsis):
    '''
    scale_for_cmap(cmap, x) yields the values in x rescaled to be appropriate for the given
      colormap cmap. The cmap must be the name of a colormap or a colormap object.

    For a given cmap argument, if the object is a colormap itself, it is treated as cmap.name.
    If the cmap names a colormap known to neuropythy, neuropythy will rescale the values in x
    according to a heuristic.
    '''
    import matplotlib as mpl
    if isinstance(cmap, mpl.colors.Colormap): cmap = cmap.name
    (name, cm) = (None, None)
    if cmap not in colormaps:
        for (k,v) in six.iteritems(colormaps):
            if cmap in k:
                (name, cm) = (k, v)
                break
    else: (name, cm) = (cmap, colormaps[cmap])
    if cm is not None:
        cm = cm if len(cm) == 3 else (cm + (None,))
        (cm, (mn,mx), uu) = cm
        if vmin is Ellipsis: vmin = mn
        if vmax is Ellipsis: vmax = mx
        if unit is Ellipsis: unit = uu
    if vmin is Ellipsis: vmin = None
    if vmax is Ellipsis: vmax = None
    if unit is Ellipsis: unit = None
    x = pimms.mag(x) if unit is None else pimms.mag(x, unit)
    if name is not None and name.startswith('log_'):
        emn = np.exp(vmin)
        x = np.log(x + emn)
    vmin = np.nanmin(x) if vmin is None else vmin
    vmax = np.nanmax(x) if vmax is None else vmax
    return zdivide(x - vmin, vmax - vmin, null=np.nan) 
Example 15
Project: pymoo   Author: msu-coinlab   File: high_tradeoff.py    License: Apache License 2.0 5 votes vote down vote up
def _do(self, F, **kwargs):
        n, m = F.shape

        if self.normalize:
            F = normalize(F, self.ideal_point, self.nadir_point, estimate_bounds_if_none=True)

        neighbors_finder = NeighborFinder(F, epsilon=0.125, n_min_neigbors="auto", consider_2d=False)

        mu = np.full(n, - np.inf)

        # for each solution in the set calculate the least amount of improvement per unit deterioration
        for i in range(n):

            # for each neighbour in a specific radius of that solution
            neighbors = neighbors_finder.find(i)

            # calculate the trade-off to all neighbours
            diff = F[neighbors] - F[i]

            # calculate sacrifice and gain
            sacrifice = np.maximum(0, diff).sum(axis=1)
            gain = np.maximum(0, -diff).sum(axis=1)

            np.warnings.filterwarnings('ignore')
            tradeoff = sacrifice / gain

            # otherwise find the one with the smalled one
            mu[i] = np.nanmin(tradeoff)

        return find_outliers_upper_tail(mu) 
Example 16
Project: NeuroKit   Author: neuropsychology   File: signal_findpeaks.py    License: MIT License 5 votes vote down vote up
def _signal_findpeaks_distances(peaks):

    if len(peaks) <= 2:
        distances = np.full(len(peaks), np.nan)
    else:
        distances_next = np.concatenate([[np.nan], np.abs(np.diff(peaks))])
        distances_prev = np.concatenate([np.abs(np.diff(peaks[::-1])), [np.nan]])
        distances = np.array([np.nanmin(i) for i in list(zip(distances_next, distances_prev))])

    return distances 
Example 17
Project: NeuroKit   Author: neuropsychology   File: rescale.py    License: MIT License 5 votes vote down vote up
def _rescale(data, to=[0, 1]):
    return (to[1] - to[0]) / (np.nanmax(data) - np.nanmin(data)) * (data - np.nanmin(data)) + to[0] 
Example 18
Project: connecting_the_dots   Author: autonomousvision   File: plt.py    License: MIT License 5 votes vote down vote up
def color_map(im_, cmap='viridis', vmin=None, vmax=None):
  cm = plt.get_cmap(cmap)
  im = im_.copy()
  if vmin is None:
    vmin = np.nanmin(im)
  if vmax is None:
    vmax = np.nanmax(im)
  mask = np.logical_not(np.isfinite(im))
  im[mask] = vmin
  im = (im.clip(vmin, vmax) - vmin) / (vmax - vmin)
  im = cm(im)
  im = im[...,:3]
  for c in range(3):
    im[mask, c] = 1
  return im 
Example 19
Project: connecting_the_dots   Author: autonomousvision   File: exp_synphge.py    License: MIT License 5 votes vote down vote up
def write_img(self, out_path, es, gt, im, ma):
    logging.info(f'write img {out_path}')
    u_pos, _ = np.meshgrid(range(es.shape[1]), range(es.shape[0]))

    diff = np.abs(es - gt)

    vmin, vmax = np.nanmin(gt), np.nanmax(gt)
    vmin = vmin - 0.2*(vmax-vmin)
    vmax = vmax + 0.2*(vmax-vmin)

    pattern_proj = self.pattern_proj.to('cpu').numpy()[0,0]
    im_orig = self.data['im0'].detach().to('cpu').numpy()[0,0,0]
    pattern_diff = np.abs(im_orig - pattern_proj)

    fig = plt.figure(figsize=(16,16))
    es0 = co.cmap.color_depth_map(es[0], scale=vmax)
    gt0 = co.cmap.color_depth_map(gt[0], scale=vmax)
    diff0 = co.cmap.color_error_image(diff[0], BGR=True)

    # plot disparities, ground truth disparity is shown only for reference
    ax = plt.subplot(3,3,1); plt.imshow(es0[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F0 Disparity Est. {es0.min():.4f}/{es0.max():.4f}')
    ax = plt.subplot(3,3,2); plt.imshow(gt0[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F0 Disparity GT {np.nanmin(gt0):.4f}/{np.nanmax(gt0):.4f}')
    ax = plt.subplot(3,3,3); plt.imshow(diff0[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F0 Disparity Err. {diff0.mean():.5f}')

    # plot disparities of the second frame in the track if exists
    if es.shape[0]>=2:
      es1 = co.cmap.color_depth_map(es[1], scale=vmax)
      gt1 = co.cmap.color_depth_map(gt[1], scale=vmax)
      diff1 = co.cmap.color_error_image(diff[1], BGR=True)
      ax = plt.subplot(3,3,4); plt.imshow(es1[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F1 Disparity Est. {es1.min():.4f}/{es1.max():.4f}')
      ax = plt.subplot(3,3,5); plt.imshow(gt1[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F1 Disparity GT {np.nanmin(gt1):.4f}/{np.nanmax(gt1):.4f}')
      ax = plt.subplot(3,3,6); plt.imshow(diff1[...,[2,1,0]]); plt.xticks([]); plt.yticks([]); ax.set_title(f'F1 Disparity Err. {diff1.mean():.5f}')

    # plot normalized IR inputs
    ax = plt.subplot(3,3,7); plt.imshow(im[0], vmin=im.min(), vmax=im.max(), cmap='gray'); plt.xticks([]); plt.yticks([]); ax.set_title(f'F0 IR input {im[0].mean():.5f}/{im[0].std():.5f}')
    if es.shape[0]>=2:
      ax = plt.subplot(3,3,8); plt.imshow(im[1], vmin=im.min(), vmax=im.max(), cmap='gray'); plt.xticks([]); plt.yticks([]); ax.set_title(f'F1 IR input {im[1].mean():.5f}/{im[1].std():.5f}')
    
    plt.tight_layout()
    plt.savefig(str(out_path))
    plt.close(fig) 
Example 20
Project: yatsm   Author: ceholden   File: longtermmean.py    License: MIT License 5 votes vote down vote up
def halfmax(x):
    """ Return index of the observation closest to the half of some data

    Assumes that data are scaled between [0, 1] and half-max is 0.5

    Args:
        x (np.ndarray): a one dimensional vector

    Returns:
        int: the index of the observation closest to the half-max of the data

    """
    return np.argmin(np.abs(
        (x - np.nanmin(x)) /
        (np.nanmax(x) - np.nanmin(x)) - 0.5)) 
Example 21
Project: recruit   Author: Frank-qlu   File: test_interaction.py    License: Apache License 2.0 5 votes vote down vote up
def test_nanfunctions_matrices():
    # Check that it works and that type and
    # shape are preserved
    # 2018-04-29: moved here from core.tests.test_nanfunctions
    mat = np.matrix(np.eye(3))
    for f in [np.nanmin, np.nanmax]:
        res = f(mat, axis=0)
        assert_(isinstance(res, np.matrix))
        assert_(res.shape == (1, 3))
        res = f(mat, axis=1)
        assert_(isinstance(res, np.matrix))
        assert_(res.shape == (3, 1))
        res = f(mat)
        assert_(np.isscalar(res))
    # check that rows of nan are dealt with for subclasses (#4628)
    mat[1] = np.nan
    for f in [np.nanmin, np.nanmax]:
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            res = f(mat, axis=0)
            assert_(isinstance(res, np.matrix))
            assert_(not np.any(np.isnan(res)))
            assert_(len(w) == 0)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            res = f(mat, axis=1)
            assert_(isinstance(res, np.matrix))
            assert_(np.isnan(res[1, 0]) and not np.isnan(res[0, 0])
                    and not np.isnan(res[2, 0]))
            assert_(len(w) == 1, 'no warning raised')
            assert_(issubclass(w[0].category, RuntimeWarning))

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            res = f(mat)
            assert_(np.isscalar(res))
            assert_(res != np.nan)
            assert_(len(w) == 0) 
Example 22
Project: recruit   Author: Frank-qlu   File: test_nanfunctions.py    License: Apache License 2.0 5 votes vote down vote up
def test_masked(self):
        mat = np.ma.fix_invalid(_ndat)
        msk = mat._mask.copy()
        for f in [np.nanmin]:
            res = f(mat, axis=1)
            tgt = f(_ndat, axis=1)
            assert_equal(res, tgt)
            assert_equal(mat._mask, msk)
            assert_(not np.isinf(mat).any()) 
Example 23
Project: recruit   Author: Frank-qlu   File: test_nanfunctions.py    License: Apache License 2.0 5 votes vote down vote up
def test_object_array(self):
        arr = np.array([[1.0, 2.0], [np.nan, 4.0], [np.nan, np.nan]], dtype=object)
        assert_equal(np.nanmin(arr), 1.0)
        assert_equal(np.nanmin(arr, axis=0), [1.0, 2.0])

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            # assert_equal does not work on object arrays of nan
            assert_equal(list(np.nanmin(arr, axis=1)), [1.0, 4.0, np.nan])
            assert_(len(w) == 1, 'no warning raised')
            assert_(issubclass(w[0].category, RuntimeWarning)) 
Example 24
Project: recruit   Author: Frank-qlu   File: test_nanfunctions.py    License: Apache License 2.0 5 votes vote down vote up
def test_nanmin(self):
        tgt = np.min(self.mat)
        for mat in self.integer_arrays():
            assert_equal(np.nanmin(mat), tgt) 
Example 25
Project: recruit   Author: Frank-qlu   File: _core.py    License: Apache License 2.0 5 votes vote down vote up
def _get_ind(self, y):
        if self.ind is None:
            # np.nanmax() and np.nanmin() ignores the missing values
            sample_range = np.nanmax(y) - np.nanmin(y)
            ind = np.linspace(np.nanmin(y) - 0.5 * sample_range,
                              np.nanmax(y) + 0.5 * sample_range, 1000)
        elif is_integer(self.ind):
            sample_range = np.nanmax(y) - np.nanmin(y)
            ind = np.linspace(np.nanmin(y) - 0.5 * sample_range,
                              np.nanmax(y) + 0.5 * sample_range, self.ind)
        else:
            ind = self.ind
        return ind 
Example 26
Project: recruit   Author: Frank-qlu   File: test_series.py    License: Apache License 2.0 5 votes vote down vote up
def test_unsorted_index_xlim(self):
        ser = Series([0., 1., np.nan, 3., 4., 5., 6.],
                     index=[1., 0., 3., 2., np.nan, 3., 2.])
        _, ax = self.plt.subplots()
        ax = ser.plot(ax=ax)
        xmin, xmax = ax.get_xlim()
        lines = ax.get_lines()
        assert xmin <= np.nanmin(lines[0].get_data(orig=False)[0])
        assert xmax >= np.nanmax(lines[0].get_data(orig=False)[0]) 
Example 27
Project: recruit   Author: Frank-qlu   File: test_nanops.py    License: Apache License 2.0 5 votes vote down vote up
def test_nanmin(self):
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("ignore", RuntimeWarning)
            func = partial(self._minmax_wrap, func=np.min)
            self.check_funs(nanops.nanmin, func,
                            allow_str=False, allow_obj=False) 
Example 28
Project: recruit   Author: Frank-qlu   File: base.py    License: Apache License 2.0 5 votes vote down vote up
def min(self, axis=None, skipna=True):
        """
        Return the minimum value of the Index.

        Parameters
        ----------
        axis : {None}
            Dummy argument for consistency with Series
        skipna : bool, default True

        Returns
        -------
        scalar
            Minimum value.

        See Also
        --------
        Index.max : Return the maximum value of the object.
        Series.min : Return the minimum value in a Series.
        DataFrame.min : Return the minimum values in a DataFrame.

        Examples
        --------
        >>> idx = pd.Index([3, 2, 1])
        >>> idx.min()
        1

        >>> idx = pd.Index(['c', 'b', 'a'])
        >>> idx.min()
        'a'

        For a MultiIndex, the minimum is determined lexicographically.

        >>> idx = pd.MultiIndex.from_product([('a', 'b'), (2, 1)])
        >>> idx.min()
        ('a', 1)
        """
        nv.validate_minmax_axis(axis)
        return nanops.nanmin(self._values, skipna=skipna) 
Example 29
Project: cgpm   Author: probcomp   File: render.py    License: Apache License 2.0 5 votes vote down vote up
def nanptp(array, axis=0):
    """Returns peak-to-peak distance of an array ignoring nan values."""
    ptp = np.nanmax(array, axis=axis) - np.nanmin(array, axis=0)
    ptp_without_null = [i if i != 0 else 1. for i in ptp]
    return ptp_without_null 
Example 30
Project: cgpm   Author: probcomp   File: render.py    License: Apache License 2.0 5 votes vote down vote up
def nannormalize(data):
    """Normalizes data across the columns, ignoring nan values."""
    return (data - np.nanmin(data, axis=0)) / nanptp(data, axis=0)