Simple command-line tool to extract mean energies and yields from CPS scans.
It's just a couple of python scripts and some CSVs; all you need to do is download the repo.
There are some dependencies. Most of them are on PyPI and can be installed with one command if you don't already have them:
pip install matplotlib numpy pandas scipy xarray
This program also requires Peter Heuer’s CR39py libary. It’s not on PyPI last I checked, but you can pip-install it using
pip install git+https://github.com/pheuer/CR39py.git
Random troubleshooting note just in case it’s relevant: if pip complains about fcntl, that’s because you foolishly installed py2app. Only Macs are allowed to install py2app. Get it off of your computer you disgusting whelp because it’s basically a virus if you install it on Windows I guess?
To run the basic spectrum inference, simply navigate to the root directory in a command line and call
python analyze_cps.py {particle} --directory={path/to/files/}
where {particle}
stands for the particle being measured or the A/Z^2 of the particle being measured (for example “d” or “2.0”)
and {path/to/files/}
stands for the directory, absolute or relative, that contains the .cpsa
files.
The directory may be omitted if the files are somewhere in the current working directory.
You may also optionally set the max contrast with --max_contrast=X
.
You will first be prompted to click on the plot to highlight the background region. This will generally be somewhere in the empty space above the indicated data region. You may specify any two diagonal corners of the rectangle in either order. At any time, you may right-click to delete the most recently placed corner. When both points are set, the rectangle will be displayed for confirmation. Close the plot at this point to continue.
You will then be prompted to click on the plot to select the diameter limits. Each time you click, it will place a new point on the plot. To use diagonal diameter cuts, you’ll want to click multiple times from left to right, drawing a line either above or below the signal region. Once you get all the way to the right, start clicking from the left again to place the limit on the other side. Pay attention to how the lines appear to make sure it’s understanding you correctly. As before, you can right-click at any point to undo an action. Close the plot when the diameter cuts are satisfactory. If you only draw one line, it will be taken as the maximum diameter and the minimum diameter will be set to zero.
It will repeat this for every scan file in the given directory, outputing a CSV containing the spectrum for each one.
To extract yields, mean energies, and plots from the analyzed spectra, call
python analyze_spectra.py --directory={path/to/files/}
where {path/to/files/}
stands for the directory, absolute or relative, that contains the .csv
files.
The directory may be omitted if the files are somewhere in the current working directory.
You will be prompted to click on the plot to select the upper and lower limits for the peak fit. As before, you can right-click at any time to undo an action. Close the plot when the peak limits are satisfactory.
It will repeat this for every spectrum file in the given directory, outputting a plot of each spectrum as a PNG, with the yield, mean energy, and width written on the side. Lmk if you want the output as EPS or something for whatever reason; it's not that difficult a thing to add.
This program isn’t as powerful as Fredrick’s AnalyzeCR39. If you have a use case that doesn’t seem to be covered by the choices you’re given, I encourage you to code it up here, but acknowledge that it’s probably easiest to use AnalyzeCR39 instead. Nevertheless, I hope that this already covers most use cases in a more convenient format.
The main limitation is that this script doesn’t make it very easy for the user to go back and forth on their limits. Once you set a cut or highlight a region, it will automatically move onto the next question/piece. I hope that the fact that this program makes the data much easier to visualize than AnalyzeCR39 mitigates this shortcoming.
This analysis also currently assumes a slit width of 2mm. You will need to modify the script or ask me to add an option if you want to use it for 1mm.
The broadening due to the finite slit width is not accounted for when the peak width is calculated, so be wary of that if you care about the peak width.
I don't currently allow the user to set the data region, so if part of the scan is bad there's no way to remove it. I probably could make it so clicking after you set the background would do it... but I haven't.
Lastly, there is no provision for ramped background subtraction, so users will have to make do with flat background for now.
In the future, I would really like to have this also automatically compute ρR with error bars using the fit mean energy and particle species. But I haven't done that yet.