reaclib_example.py
Go to the documentation of this file.
1 # Example file for reaclib class
2 # Author: Moritz Reichert
3 # Date : 08.05.17
4 
5 # Import the reaclib class
6 from class_files.reaclib_class import reaclib
7 import matplotlib.pyplot as plt
8 import pandas as pd
9 
10 # The class is able to make several tests with a reaclib file. It is also able to plot rates of a reaclib.
11 # Furthermore, you can update the rates with other reaclibs, specifying what you want to update.
12 # This should be done carefully and always checked afterwards!!
13 
14 ################
15 # INITIALIZING #
16 ################
17 
18 # Create an instance of the reaclib class. If you want the class to be quiet, add quiet=True.
19 reaclib_file_path = " INSERT REACLIB FILE PATH "
20 reaclib_file_update_path = " INSERT MORE RECENT REACLIB FILE PATH "
21 
22 r_testclass = reaclib(reaclib_file_path)
23 # Read the file
24 r_testclass.read_reaclib()
25 
26 
27 #########
28 # TESTS #
29 #########
30 
31 # Make several tests with the file
32 # Tests are:
33 # 1. Test for rate being in the correct chapter
34 # 2. Test for consistency of weak rates
35 # 3. Test for mass consistency
36 # 4. Test for overflows of the rate
37 r_testclass.test_reaclib()
38 # Save the result to "reaclib_errors.html"
39 r_testclass.get_rate_error_html('reaclib_errors.html')
40 # Remove all reactions that contain errors
41 r_testclass.drop_errors()
42 
43 
44 ############
45 # PLOTTING #
46 ############
47 
48 reactants = ['he4','c12']
49 products = ['o16']
50 # Also kwargs for plotting are possible
51 # Plot it (optional values for this function are figure=None (give a figure object to plot to the same axes ),axlabel=True (label the x and y axis))
52 figure = r_testclass.plot_rate(reactants,products)
53 # Get the axes object
54 # you could change the range by e.g. ax.set_ylim(1e-50,1e10)
55 ax = figure.gca()
56 # Show it
57 plt.show()
58 
59 
60 #######################
61 # UPDATE AND ANALYSIS #
62 #######################
63 
64 # Get a brief overview of the reactions. How much n-gamma, gamma-n, alpha-n,... reactions are included. Return value is a pandas series
65 print('Overview of contained reactions:')
66 print((r_testclass.get_statistics()))
67 
68 # Update reaclib with other more recent one.
69 # Possible values are:
70 # reaclib_path - path of the reaclib that contains new rates
71 # dataframe - pandas dataframe that contains reactions. If this is given, you don't have to give a reaclib_path.
72 # reaction_type - Reaction type that will be updated (string or list of strings), for possible values see ".get_statistics()"
73 # possible reaction types are: 'n-gamma', 'gamma-n', 'p-gamma', 'gamma-p', 'a-gamma', 'gamma-a', 'n-p', 'p-n', 'n-a', 'a-n', 'p-a', 'a-p', 'weak', 'fission', 'other'
74 # chapter - Chapter that will be updated (list of integer or integer)
75 # ignore_label - ignore the label for updating and only look at the reactions itself
76 # ignore_reverse- ignore if the reaction is reverse
77 # ignore_type - ignore the type
78 # r_testclass.update('testfiles/20161205ReaclibV2.0no910',reaction_type=['n-gamma','gamma-n'])
79 r_testclass.update(reaclib_file_update_path,ignore_label=False)
80 print((r_testclass.get_statistics()))
81 # Save the reaclib again
82 r_testclass.save_reaclib('updated_reaclib.dat')
83 
84 # It's also possible to get all 'n-gamma' rates and play around with them to merge them in afterwards again
85 n_gamma = r_testclass.get_dataframe(reaction_type='n-gamma')
86 # You can also print them: (comment it in again)
87 # print(n_gamma)
88 # Or multiply factor 10 to all a0's in all n-gamma reactions
89 n_gamma['a0'] = n_gamma['a0'].apply(lambda x: x*10.)
90 # And merge it in again.
91 r_testclass.update(dataframe=n_gamma)
92 
93 # Or get critical low temperature rates:
94 # with min_temperature range of temperature
95 # amount_points - points for grid to look if the rate diverges
96 # max_rate - at which value is the rate critical?
97 crit_low_temp_dataframe = r_testclass.get_critical_low_temperature_rates(min_temperature=1e-3,amount_points=20,max_rate=1.e100)
98 # And do whatever you want with it e.g. save it or print the amount of rates
99 print(('Amount critical low temperature rates : ' + str(crit_low_temp_dataframe.count()[0])))
100 r_testclass.save_reaclib('crit_lowtemp.dat',dataframe = crit_low_temp_dataframe)
bin.class_files.reaclib_class.reaclib
Definition: reaclib_class.py:15