Ejemplo n.º 1
0
    def get_x(self, y):
        """ tuple of x-values at intensity y

        Return distance values based on interpolation of source data for a
        supplied y value.

        Parameters
        ----------
        y : float

        Returns
        -------
        tuple : (x1, x2, ...)

         """

        dose_step = (max(self.y) - min(self.y)) / 100
        x_ = self.resample_y(dose_step).x
        y_ = self.resample_y(dose_step).y
        dists = []
        for i in range(1, len(x_)):
            val = None
            if (y_[i] - y) * (y_[i - 1] - y) < 0:
                val = x_[i] - ((y_[i] - y) /
                               (y_[i] - y_[i - 1])) * (x_[i] - x_[i - 1])
            elif np.isclose(y_[i], y):
                val = x_[i]
            if val and (val not in dists):
                dists.append(val)
        return tuple(dists)
Ejemplo n.º 2
0
def is_anonymised_dataset(ds, ignore_private_tags=False):
    r"""Check whether a DICOM dataset has been (fully) anonymised.

    This function specifically checks whether the dataset has been
    anonymised using a PyMedPhys anonymiser. It is very likely that it
    will return ``False`` for an anonymous dataset that was anonymised
    using a different tool.

    Parameters
    ----------
    ds : ``pydicom.dataset.Dataset``
        The DICOM dataset to check for anonymity

    ignore_private_tags : ``bool``, optional
        If set to ``False``, ``is_anonymised_dataset()`` will return
        ``False`` if any private (non-standard) DICOM tags exist in
        ``ds``. Set to ``True`` to ignore private tags when checking for
        anonymity. Do so with caution, since private tags may contain
        identifying information. Defaults to ``False``.

    Returns
    -------
    is_anonymised : ``bool``
        `True` if `ds` has been anonymised, `False` otherwise.
    """
    for elem in ds:
        if elem.keyword in get_default_identifying_keywords():
            dummy_value = get_anonymous_replacement_value(elem.keyword)
            if not elem.value in ("", [], dummy_value, None):
                if elem.VR == "DS" and np.isclose(float(elem.value),
                                                  float(dummy_value)):
                    continue
                logging.info("%s is not considered to be anonymised",
                             elem.name)
                return False

        elif elem.tag.is_private and not ignore_private_tags:
            logging.info(
                "%s is private and private tags are not being ignored",
                elem.tag)
            return False
        elif elem.VR == "SQ":
            contents_are_anonymous = True
            for seq in elem.value:
                contents_are_anonymous = is_anonymised_dataset(
                    seq, ignore_private_tags)
                if not contents_are_anonymous:
                    logging.info(
                        "%s contained an element not considered to be anonymised",
                        elem.name,
                    )
                    return False

    return True
Ejemplo n.º 3
0
    def get_increment(self):
        """ minimum step-size increment

        Returns
        -------
        increment : float

        """
        steps = np.diff(self.x)
        if np.isclose(steps.min(), steps.mean()):
            return steps.mean()
        else:
            return steps.min()