Binder Tutorial (hint: start here!)
This code is here to show the process of performing computations for benchmark plots.
Updated 7/2/20 to include better documentation.
Goal:
Get benchmark plots for website to appear in a more convenient way. This includes using a local flask app, which for now is all run locally.
The TODOs are at the bottom, and we must finish this before we can integrate automatic plot-creation on the website!
- Open your terminal, change to the directory you want to work in.
- Create or activate python 3.7 environment:
conda activate <envname>
- Clone this repository:
git clone https://github.com/sophiaandaloro/NESTplots/
- Install requirements:
pip install -r requirements.txt
open an issue if I am missing other requirements! - Check that the nestpy version installed is the one that you want to work with.
Next, there are three main python files for you to keep track of.
- This one should stay out of your way and you should be able to ignore it except when it makes your life easier.
- A great little tool that allows you to identify interaction types as the following (so that you don't have to memorize numbers used in the wrappers!)
- nr: Nuclear recoil
- wimp: WIMP
- b8: Boron-8
- And so on. They are straightforward if you look in this code, and you'll see what you want to make.
- Should make your life easier. Just any time you want to specify NEST interaction_type, just say
interaction_type='nr'
, or whatever.
- Makes plots using nestpy of various yields.
- This contains all of the functions that are used to make the plots which will be called via flask on main.py
The main components are: 1. Getting the yields for the interaction types of interest (done via numpy vectorized, rather than a loop) 2. Defining the plots for each of the yields (these aren't looped over because each of them slightly differs) 3. Making the plots via one function so that in main.py, you only have to call the one makeplots() function to make all plots.
Main ingredients for the above steps:
- np.vectorize, dictionary with yields, field array and energy array.
- Note: some of the yields will crash the plots at too high of energies (way above physical meaning) so np.nan is returned to keep things running.
- Plotting tools via matplotlib, but note that all plots are saved in an arbitrary "IMAGE_OBJECTS" object, which, rather than a file, will store the images in a dictionary when called in main.py
- (easier for using with flask.)
- You will call this once you have finished setup.
- This is the function for launching flask app which will display benchmark plots.
- All nestpy and NEST code is contained inside of the previous file,
benchmark_plots.py
. We only call it here. So, if you see something odd in nestpy, your issue isn't with here. - io, collections for storing the dictionary of objects locally rather than to disk.
- flask: Flask makes apps...
- send_file allows us to work with saved image dictionary in Flask;
- request processes arguments in url format.
- Returns: an app (!) hosted locally, by you.
So you've set up your environment and you're ready to make some benchmark plots. This should work, if you followed setup correctly. If it doesn't, open an issue please.
- Go into this directory on your machine if you aren't already.
- Run:
python main.py
. - You should see some warnings, ignore (as we always do!)
- You'll start to see messages from NEST, telling you you're using the default detector. Then you'll see messages from Flask, hopefully, telling you that you're running in debug mode, and give you a port number.
- That means you're ready. In your browser, type in
localhost:8080
and hit enter. You should see a welcome message with some instructions for seeing your plots. - Try going here: http://localhost:8080/get_image?interaction=gamma&yieldtype=LY. If your Flask app is working, you should see the Light yields benchmark plot for gamma-ray Electronic Recoils. You did it, take a break.
- Fork this repo, improve upon it, make a PR and help make this a much more useful tool.
The most important section. Listed in order of urgency/importance/feasibility
- Get the global data also on this local app.
- Update these plots to new nestpy version, confirm this app works, and update website accordingly.
- Ideally, make this not a local server running this app, but a remote app that is running with the plots at certain locations: accessible by the NEST website, so we don't have to always download new plots upon new NEST versions.
- Then, we would like a GitHub version to trigger the nestpy to be upgraded on our remote Flask app, then the plots to be remade. A physicist can dream.
v 0.1.0: Finalized July 2, 2020