示例#1
0
def draw_by_diff(dx, dy, transform):
    draw_x = np.cumsum(dx)
    draw_y = np.cumsum(dy)

    draw_x, draw_y = interppoints.apply_transform(draw_x, draw_y, transform)

    return draw_x, draw_y
示例#2
0
def delivery_from_tel_plan_contents(tel_contents):
    pattern = get_control_point_pattern()
    all_controlpoint_results = re.findall(pattern, tel_contents)

    mu = np.cumsum([float(result[3]) for result in all_controlpoint_results])

    iec_gantry_angle = [float(result[1]) for result in all_controlpoint_results]
    bipolar_gantry_angle = pymedphys._utilities.transforms.convert_IEC_angle_to_bipolar(  # pylint: disable = protected-access
        iec_gantry_angle
    )

    iec_coll_angle = [float(result[2]) for result in all_controlpoint_results]
    bipolar_coll_angle = pymedphys._utilities.transforms.convert_IEC_angle_to_bipolar(  # pylint: disable = protected-access
        iec_coll_angle
    )

    mlcs = [convert_mlc_string(result[0]) for result in all_controlpoint_results]

    jaw_gap = np.array([float(result[4]) for result in all_controlpoint_results])
    jaw_field_centre = np.array(
        [float(result[5]) for result in all_controlpoint_results]
    )
    jaw_a = jaw_field_centre + jaw_gap / 2
    jaw_b = -(jaw_field_centre - jaw_gap / 2)
    jaws = np.vstack([jaw_a, jaw_b]).T

    return mu, bipolar_gantry_angle, bipolar_coll_angle, mlcs, jaws
示例#3
0
def delivery_from_tel_plan_contents(tel_contents):
    pattern = get_control_point_pattern()
    all_controlpoint_results = re.findall(pattern, tel_contents)

    mu = np.cumsum([float(result[4])
                    for result in all_controlpoint_results]).tolist()

    iec_gantry_angle = [
        float(result[2]) for result in all_controlpoint_results
    ]
    bipolar_gantry_angle = pymedphys._utilities.transforms.convert_IEC_angle_to_bipolar(  # pylint: disable = protected-access
        iec_gantry_angle).tolist()

    iec_coll_angle = [float(result[3]) for result in all_controlpoint_results]
    bipolar_coll_angle = pymedphys._utilities.transforms.convert_IEC_angle_to_bipolar(  # pylint: disable = protected-access
        iec_coll_angle).tolist()

    mlcs = [
        convert_mlc_string(result[0]) for result in all_controlpoint_results
    ]

    jaw_gap = np.array(
        [float(result[5]) for result in all_controlpoint_results])
    jaw_field_centre = np.array(
        [float(result[6]) for result in all_controlpoint_results])
    jaw_a = jaw_field_centre + jaw_gap / 2
    jaw_b = -(jaw_field_centre - jaw_gap / 2)
    jaws = np.vstack([jaw_a, jaw_b]).T.tolist()

    for i in range(len(mu) - 1, -1, -1):
        result = all_controlpoint_results[i]
        if result[
                1] == "2,2":  #  A nasty hack to attempt to find static fields
            if i == 0:
                mu = [0] + mu
            else:
                mu = mu[0:i] + [mu[i - 1]] + mu[i::]

            bipolar_gantry_angle = (bipolar_gantry_angle[0:i] +
                                    [bipolar_gantry_angle[i]] +
                                    bipolar_gantry_angle[i::])

            bipolar_coll_angle = (bipolar_coll_angle[0:i] +
                                  [bipolar_coll_angle[i]] +
                                  bipolar_coll_angle[i::])

            mlcs = mlcs[0:i] + [mlcs[i]] + mlcs[i::]
            jaws = jaws[0:i] + [jaws[i]] + jaws[i::]
        elif result[1] != "1,1":
            raise ValueError(
                "Detection for static or dynamic control points has fallen down"
            )

    return mu, bipolar_gantry_angle, bipolar_coll_angle, mlcs, jaws
示例#4
0
def _determine_leaf_centres(leaf_pair_widths):
    total_leaf_widths = np.sum(leaf_pair_widths)
    leaf_centres = (np.cumsum(leaf_pair_widths) - leaf_pair_widths / 2 -
                    total_leaf_widths / 2)

    reference_leaf_index = len(leaf_centres) // 2

    top_of_reference_leaf = (leaf_centres[reference_leaf_index] +
                             leaf_pair_widths[reference_leaf_index] / 2)

    return leaf_centres, top_of_reference_leaf
示例#5
0
def delivery_from_icom_stream(icom_stream):
    icom_stream_points = extract.get_data_points(icom_stream)
    delivery_raw = [
        get_delivery_data_items(single_icom_stream)
        for single_icom_stream in icom_stream_points
    ]

    mu = np.array([item[0] for item in delivery_raw])
    diff_mu = np.concatenate([[0], np.diff(mu)])
    diff_mu[diff_mu < 0] = 0
    mu = np.cumsum(diff_mu)

    gantry = np.array([item[1] for item in delivery_raw])
    collimator = np.array([item[2] for item in delivery_raw])
    mlc = np.array([item[3] for item in delivery_raw])
    jaw = np.array([item[4] for item in delivery_raw])

    return mu, gantry, collimator, mlc, jaw
示例#6
0
def create_dvh(structure, dcm_struct, dcm_dose):
    structure_dose_values = find_dose_within_structure(structure, dcm_struct,
                                                       dcm_dose)
    hist = np.histogram(structure_dose_values, 100)
    freq = hist[0]
    bin_edge = hist[1]
    bin_mid = (bin_edge[1::] + bin_edge[:-1:]) / 2

    cumulative = np.cumsum(freq[::-1])
    cumulative = cumulative[::-1]
    bin_mid = np.append([0], bin_mid)

    cumulative = np.append(cumulative[0], cumulative)
    percent_cumulative = cumulative / cumulative[0] * 100

    plt.plot(bin_mid, percent_cumulative, label=structure)
    plt.title("DVH")
    plt.xlabel("Dose (Gy)")
    plt.ylabel("Relative Volume (%)")
示例#7
0
    def _from_pandas(cls: Type[DeliveryGeneric], table) -> DeliveryGeneric:
        raw_monitor_units = table["Step Dose/Actual Value (Mu)"]

        diff = np.append([0], np.diff(raw_monitor_units))
        diff[diff < 0] = 0

        monitor_units = np.cumsum(diff)

        gantry = table[GANTRY_NAME]
        collimator = table[COLLIMATOR_NAME]

        y1_bank = [table[name] for name in Y1_LEAF_BANK_NAMES]

        y2_bank = [table[name] for name in Y2_LEAF_BANK_NAMES]

        mlc = [y1_bank, y2_bank]
        mlc = np.swapaxes(mlc, 0, 2)

        jaw = [table[name] for name in JAW_NAMES]
        jaw = np.swapaxes(jaw, 0, 1)

        return cls(monitor_units, gantry, collimator, mlc, jaw)
示例#8
0
    def _from_mosaiq_base(cls, cursor, field_id):
        txfield_results, txfieldpoint_results = fetch_and_verify_mosaiq_sql(
            cursor, field_id)

        total_mu = np.array(txfield_results[0]).astype(float)
        cumulative_percentage_mu = txfieldpoint_results[:, 0].astype(float)

        if np.shape(cumulative_percentage_mu) == ():
            mu_per_control_point = [0, total_mu]
        else:
            cumulative_mu = cumulative_percentage_mu * total_mu / 100
            mu_per_control_point = np.concatenate([[0],
                                                   np.diff(cumulative_mu)])

        monitor_units = np.cumsum(mu_per_control_point).tolist()

        mlc_a = np.squeeze(
            decode_msq_mlc(txfieldpoint_results[:, 1].astype(bytes))).T
        mlc_b = np.squeeze(
            decode_msq_mlc(txfieldpoint_results[:, 2].astype(bytes))).T

        msq_gantry_angle = txfieldpoint_results[:, 3].astype(float)
        msq_collimator_angle = txfieldpoint_results[:, 4].astype(float)

        coll_y1 = txfieldpoint_results[:, 5].astype(float)
        coll_y2 = txfieldpoint_results[:, 6].astype(float)

        mlc, jaw = collimation_to_bipolar_mm(mlc_a, mlc_b, coll_y1, coll_y2)
        gantry = convert_IEC_angle_to_bipolar(msq_gantry_angle)
        collimator = convert_IEC_angle_to_bipolar(msq_collimator_angle)

        # TODO Tidy up this axis swap
        mlc = np.swapaxes(mlc, 0, 2)
        jaw = np.swapaxes(jaw, 0, 1)

        mosaiq_delivery_data = cls(monitor_units, gantry, collimator, mlc, jaw)

        return mosaiq_delivery_data
示例#9
0
    def merge(self: DeliveryGeneric,
              *args: DeliveryGeneric) -> DeliveryGeneric:
        cls = type(self)
        separate: List[DeliveryGeneric] = [self] + [*args]
        collection: Dict[str, Tuple] = {}

        for delivery_data in separate:
            for field in delivery_data._fields:  # pylint: disable=no-member
                try:
                    collection[field] = np.concatenate(
                        [collection[field],
                         getattr(delivery_data, field)],
                        axis=0)
                except KeyError:
                    collection[field] = getattr(delivery_data, field)

        mu = np.concatenate([[0], np.diff(collection["monitor_units"])])
        mu[mu < 0] = 0
        collection["monitor_units"] = np.cumsum(mu)

        merged = cls(**collection)

        return merged
示例#10
0
def get_mosaiq_delivery_data_bygantry(mosaiq_delivery_data):
    mu = np.array(mosaiq_delivery_data.monitor_units)
    mlc = np.array(mosaiq_delivery_data.mlc)
    jaw = np.array(mosaiq_delivery_data.jaw)
    gantry_angles = np.array(mosaiq_delivery_data.gantry)
    unique_mosaiq_gantry_angles = np.unique(gantry_angles)

    mosaiq_delivery_data_bygantry = dict()

    for mosaiq_gantry_angle in unique_mosaiq_gantry_angles:
        gantry_angle_matches = gantry_angles == mosaiq_gantry_angle

        diff_mu = np.concatenate([[0], np.diff(mu)])[gantry_angle_matches]
        gantry_angle_specific_mu = np.cumsum(diff_mu)

        mosaiq_delivery_data_bygantry[mosaiq_gantry_angle] = dict()
        mosaiq_delivery_data_bygantry[mosaiq_gantry_angle][
            "mu"] = gantry_angle_specific_mu
        mosaiq_delivery_data_bygantry[mosaiq_gantry_angle]["mlc"] = mlc[
            gantry_angle_matches]
        mosaiq_delivery_data_bygantry[mosaiq_gantry_angle]["jaw"] = jaw[
            gantry_angle_matches]

    return mosaiq_delivery_data_bygantry