Code Monkey home page Code Monkey logo

pybragg's Introduction

pybragg

An adaption of the Bortfeld bragg curve fit in python with scipy and numpy, strongly influenced by the original author.

Installation

You can install pybragg using pip install <optional: '--user'> git+https://github.com/flome/pybragg.git.

Usage

Please note that z needs to be passed in cm.

Bragg peak fit

If you have a data set (z, D) with two arrays, z being the depth in mm in a phantom and Dbeing the deposited dose at that depth, you can fit the curve using the bortfeld fit with

from pybragg import fitBP
bortfeld_fit_params = fitBP(z, D)

The fit returns characteristic values like D100 (max. Dose) or the proton beam range R80D (distal side of the beam, 80% maximum dose).

The bortfeld fit result (parameters: bortfeld_fit_params['bortfeld_fit_p'], covariance matrix: bortfeld_fit_params['bortfeld_fit_cov']) can be plotted using the fit results:

from pybragg import bortfeld
z = np.linspace(0, 20, 500) # depth in cm
curve = bortfeld(z, *bortfeld_fit_params['bortfeld_fit_p'])
plt.plot(z, curve)

The bortfeld equation

You can use the bortfeld equation for your own fit routine or to generate bragg peaks:

import numpy
from pybragg import bortfeld

z = np.linspace(0, 20, 500) # depth in cm
D = bortfeld(z, D100=600, R0=130, sigma=1.3)

import matplotlib.pyplot as plt

plt.plot(z, D, label='bortfeld function')
plt.xlabel('$z$ in mm')
plt.ylabel('$D$ in a.u.')
plt.legend(loc='best')
plt.tight_layout()

plt.show()

pybragg's People

Contributors

flome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.