How to use the pymedphys._imports.numpy.abs function in pymedphys

To help you get started, we’ve selected a few pymedphys 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 pymedphys / pymedphys / pymedphys / _dicom / delivery / core.py View on Github external
filtered = self._filter_cps()
        dicom_metersets = get_fraction_group_beam_sequence_and_meterset(
            dicom_dataset, fraction_number
        )[1]

        dicom_fraction = convert_to_one_fraction_group(dicom_dataset, fraction_number)

        gantry_angles = get_gantry_angles_from_dicom(dicom_fraction)

        delivery_metersets = filtered._metersets(  # pylint: disable = protected-access
            gantry_angles, gantry_tol
        )

        try:
            maximmum_diff = np.max(
                np.abs(np.array(dicom_metersets) - np.array(delivery_metersets))
            )
        except ValueError:
            maximmum_diff = np.inf

        return maximmum_diff <= meterset_tol
github pymedphys / pymedphys / pymedphys / labs / managelogfiles / bygantry.py View on Github external
def assert_array_agreement(
    unique_logfile_gantry_angles, mosaiq_gantry_angles, allowed_deviation
):
    difference_matrix = np.abs(
        unique_logfile_gantry_angles[:, None] - mosaiq_gantry_angles[None, :]
    )
    agreement_matrix = difference_matrix <= allowed_deviation
    row_agreement = np.any(agreement_matrix, axis=1)
    at_least_one_agreement = np.all(row_agreement)

    assert at_least_one_agreement, (
        "There is a logfile gantry angle that deviates by more than {} degrees"
        " from the Mosaiq control points. Unsure how to handle this.\n\n"
        "Logfile: {}\nMosaiq: {}\nDifference Matrix:\n{}\n"
        "Agreement Matrix:\n{}".format(
            allowed_deviation,
            unique_logfile_gantry_angles,
            mosaiq_gantry_angles,
            difference_matrix,
            agreement_matrix,
github pymedphys / pymedphys / pymedphys / labs / pedromartinez / qc-jaws.py View on Github external
inc = 1
                for i in range(0, inc * 80, inc * 1):
                    x = np.linspace(
                        0, 0 + (len(amp_base_res) * dx), len(amplitude), endpoint=False
                    )  # definition of the distance axis
                    amp_overlay_res_roll = np.roll(amp_overlay_res, i)

                    # amplitude is the vector to analyze +-500 samples from the center
                    amp_tot = (
                        amp_base_res[peaks[j] - 1000 : peaks[j] + 1000]
                        + amp_overlay_res_roll[peaks[j] - 1000 : peaks[j] + 1000]
                    )  # divided by 2 to normalize
                    xsel = x[peaks[j] - 1000 : peaks[j] + 1000]

                    amp_filt = running_mean(amp_tot, 281)
                    cumsum = np.sum(np.abs(amp_tot - amp_filt))

                    if cumsum > cumsum_prev:  # then we went too far
                        ax = fig.add_subplot(amplitude.shape[1] - 1, 1, kk)
                        ax.plot(amp_prev)
                        ax.plot(amp_filt_prev)
                        if kk == 1:
                            ax.set_title("Minimization result", fontsize=16)
                        if (
                            kk == amplitude.shape[1] - 1
                        ):  # if we reach the final plot the add the x axis label
                            ax.set_xlabel("distance [mm]")

                        ax.set_ylabel("amplitude")
                        ax.annotate(
                            "delta=" + str(abs(i - inc * 1) * dx) + " mm",
                            xy=(2, 1),
github pymedphys / pymedphys / pymedphys / _base / delivery.py View on Github external
def _gantry_angle_mask(self, gantry_angle, gantry_angle_tol):
        near_angle = np.abs(np.array(self.gantry) - gantry_angle) <= gantry_angle_tol
        assert np.all(np.diff(np.where(near_angle)[0]) == 1)

        return near_angle
github pymedphys / pymedphys / pymedphys / labs / managelogfiles / analyse.py View on Github external
def find_consecutive_logfiles(field_id_key_map, field_id, filehash, index):
    keys = np.array(field_id_key_map[field_id])

    times = np.array([index[key]["local_time"] for key in keys]).astype(np.datetime64)

    sort_reference = np.argsort(times)
    keys = keys[sort_reference]
    times = times[sort_reference]

    hours_4 = np.array(60 * 60 * 4).astype(np.timedelta64)

    delivery_time = np.array(index[filehash]["local_time"]).astype(np.datetime64)
    within_4_hours_reference = np.abs(delivery_time - times) < hours_4
    within_4_hours = keys[within_4_hours_reference].tolist()

    return within_4_hours
github pymedphys / pymedphys / pymedphys / _wlutz / interppoints.py View on Github external
def define_rotation_field_points_at_origin(edge_lengths, penumbra):
    x_half_range = edge_lengths[0] / 2 + penumbra / 2
    y_half_range = edge_lengths[1] / 2 + penumbra / 2

    num_x = np.ceil(x_half_range * 2 * 8) + 1
    num_y = np.ceil(y_half_range * 2 * 8) + 1

    x = np.linspace(-x_half_range, x_half_range, int(num_x))
    y = np.linspace(-y_half_range, y_half_range, int(num_y))

    xx, yy = np.meshgrid(x, y)
    xx_flat = np.ravel(xx)
    yy_flat = np.ravel(yy)

    inside = np.logical_and(
        (np.abs(xx_flat) < x_half_range), (np.abs(yy_flat) < y_half_range)
    )

    xx_flat = xx_flat[np.invert(inside)]
    yy_flat = yy_flat[np.invert(inside)]

    return xx_flat, yy_flat
github pymedphys / pymedphys / pymedphys / labs / managelogfiles / analyse.py View on Github external
def calc_comparison(logfile_mu_density, mosaiq_mu_density, normalisation=None):
    if normalisation is None:
        normalisation = np.sum(mosaiq_mu_density)

    comparison = np.sum(np.abs(logfile_mu_density - mosaiq_mu_density)) / normalisation

    return comparison
github pymedphys / pymedphys / pymedphys / _utilities / transforms / bipolar.py View on Github external
angle = np.copy(angle)
    if np.all(angle == 180):
        return angle

    angle[angle > 180] = angle[angle > 180] - 360

    is_180 = np.where(angle == 180)[0]
    not_180 = np.where(np.invert(angle == 180))[0]

    where_closest_left_leaning = np.argmin(
        np.abs(is_180[:, None] - not_180[None, :]), axis=1
    )
    where_closest_right_leaning = (
        len(not_180)
        - 1
        - np.argmin(np.abs(is_180[::-1, None] - not_180[None, ::-1]), axis=1)[::-1]
    )

    closest_left_leaning = not_180[where_closest_left_leaning]
    closest_right_leaning = not_180[where_closest_right_leaning]

    assert np.all(
        np.sign(angle[closest_left_leaning]) == np.sign(angle[closest_right_leaning])
    ), "Unable to automatically determine whether angle is 180 or -180"

    angle[is_180] = np.sign(angle[closest_left_leaning]) * angle[is_180]

    return angle