How to use the plottr.utils.num.is_invalid function in plottr

To help you get started, we’ve selected a few plottr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github data-plottr / plottr / plottr / plot / mpl.py View on Github external
cmap = kw.get('cmap', cm.viridis)

    x = x.astype(float)
    y = y.astype(float)
    z = z.astype(float)

    # first check if we need to fill some masked values in
    if np.ma.is_masked(x):
        x = x.filled(np.nan)
    if np.ma.is_masked(y):
        y = y.filled(np.nan)
    if np.ma.is_masked(z):
        z = z.filled(np.nan)

    # next: try some surgery, if possible
    if np.all(num.is_invalid(x)) or np.all(num.is_invalid(y)):
        return
    if np.any(np.isnan(x)) or np.any(np.isnan(y)):
        x, y = interp_meshgrid_2d(x, y)
    if np.any(num.is_invalid(x)) or np.any(num.is_invalid(y)):
        x, y, z = num.crop2d(x, y, z)

    # next, check if the resulting grids are even still plotable
    for g in x, y, z:
        if g.size == 0:
            return
        elif len(g.shape) < 2:
            return

        # special case: if we have a single line, a pcolor-type plot won't work.
        elif min(g.shape) < 2:
            im = ax.scatter(x, y, c=z)
github data-plottr / plottr / plottr / plot / mpl.py View on Github external
z = z.astype(float)

    # first check if we need to fill some masked values in
    if np.ma.is_masked(x):
        x = x.filled(np.nan)
    if np.ma.is_masked(y):
        y = y.filled(np.nan)
    if np.ma.is_masked(z):
        z = z.filled(np.nan)

    # next: try some surgery, if possible
    if np.all(num.is_invalid(x)) or np.all(num.is_invalid(y)):
        return
    if np.any(np.isnan(x)) or np.any(np.isnan(y)):
        x, y = interp_meshgrid_2d(x, y)
    if np.any(num.is_invalid(x)) or np.any(num.is_invalid(y)):
        x, y, z = num.crop2d(x, y, z)

    # next, check if the resulting grids are even still plotable
    for g in x, y, z:
        if g.size == 0:
            return
        elif len(g.shape) < 2:
            return

        # special case: if we have a single line, a pcolor-type plot won't work.
        elif min(g.shape) < 2:
            im = ax.scatter(x, y, c=z)
            return im

    # and finally: the meshgrid we have describes coordinates, but for plotting
    # with pcolormesh we need vertices.
github data-plottr / plottr / plottr / data / datadict.py View on Github external
def mask_invalid(self) -> 'DataDictBase':
        """
        Mask all invalid data in all values.
        :return: copy of the dataset with invalid entries (nan/None) masked.
        """
        ret = self.copy()
        for d, _ in self.data_items():
            arr = self.data_vals(d)
            vals = np.ma.masked_where(num.is_invalid(arr), arr, copy=True)
            try:
                vals.fill_value = np.nan
            except TypeError:
                vals.fill_value = -9999
            ret[d]['values'] = vals

        return ret