In [102]:
%matplotlib inline
from array import array
import matplotlib.pyplot as plt
import numpy as np
import dmdd
import pylab as pl
import matplotlib.patches as patches
import matplotlib.path as path

# having trouble because when overwriting a pre assigned KWARG in mainplotter() doesn't overwrite KWARGS in the 
# functions it calls
# the only way I can see how to make it do what I want is to make everything not a KWARG

In [92]:
def expectvalues(element, Qmin=5, Qmax=100, binsize=1, exposure=2000, sigma_name='sigma_si', sigma_val=200, efficiency= dmdd.eff.efficiency_unit, v_lag = 220):
    #auto pass efficiency function. sigma val is cross section, sigma name is theory
    bins = (Qmax - Qmin)/binsize #number of bins graph has
    #energylist = np.arange(Qmin, Qmax+binsize, binsize) #includes the last point
    energy_lower = np.arange(Qmin, Qmax, binsize)
    energy_upper = np.arange(Qmin+binsize, Qmax+binsize, binsize)
    #return energy_upper

    
    #pseudocode for what I want it to do
    result = []
    for qmin, qmax in zip(energy_lower,energy_upper):
        #print qmin,qmax
        n = dmdd.Nexpected(element, qmin, qmax, exposure, efficiency, sigma_name, sigma_val, v_lag)
        result.append(n)

    return result

In [93]:
data = expectvalues('xenon')
print data


[86.97772843091985, 79.06805682846979, 71.81493997964309, 65.17123784858238, 59.09226750956789, 53.53580887368531, 48.46208396936936, 43.83371487036432, 39.61566464702563, 35.77516508583126, 32.28163436820468, 29.106587414853724, 26.22354117819781, 23.607916796251057, 21.23694020033215, 19.08954248957183, 17.14625693068721, 15.389099706487121, 13.801496651302639, 12.36821335523105, 11.075262593764181, 9.909815367201626, 8.860116944471493, 7.915407723194259, 7.0658487398775245, 6.302451672666548, 5.617013179999097, 5.002053415617265, 4.450758555994095, 3.956927171757184, 3.514920270960307, 3.1196148394757977, 2.766360702556071, 2.450940531752358, 2.1695328228203783, 1.9186776728634494, 1.6952451886113131, 1.4964063622532842, 1.319606256477456, 1.1625393461626878, 1.02312687039684, 0.899496055018575, 0.7899610726031847, 0.6930056136336473, 0.6072669494364065, 0.5315213742527144, 0.46467092049831915, 0.40573124779569975, 0.35382061270438664, 0.30814983219676684, 0.26801315981138624, 0.23277999904145502, 0.20188738387984195, 0.17483316153136666, 0.15116981712088995, 0.13049888477043084, 0.1124658936947354, 0.09675580197806281, 0.08308887445229031, 0.07121696460721891, 0.060920163736622845, 0.052003783569420314, 0.04429564146422325, 0.037643619868736676, 0.03191347417418995, 0.026986865339644624, 0.02275959573329082, 0.01914002854747934, 0.016047672902463953, 0.013411918369810143, 0.011170904130517486, 0.009270509343715662, 0.007663452548505918, 0.006308489062220449, 0.0051696963810335585, 0.004215838540911073, 0.0034198012652766393, 0.002758090517114445, 0.0022103877936159085, 0.0017591561566793962, 0.0013892915879033948, 0.0010878147971753486, 0.0008435991041374228, 0.0006471304560115291, 0.0004902960474335174, 0.0003661983717438534, 0.0002689918619908147, 0.00019373957682365512, 0.0001362876543605309, 9.315549863070911e-05, 6.143988073425119e-05, 3.873133264432715e-05, 2.304138762677617e-05, 1.2739379422253678e-05, 6.4976543220733604e-06]

In [94]:
data = expectvalues('xenon', v_lag = 500) #this is a generator
data_list = list(data) #puts data into a list
data_array = np.asarray(data_list) #turns list into an array

#print data_array

In [95]:
energy_lower = np.arange(5., 100., 1)
energy_upper = np.arange(5+1, 100+1, 1)
qmid = np.zeros(len(energy_lower))
#for i in np.arange(len(energy_upper)):
    #qmid[i] = (energy_upper[i] + energy_lower[i])/2

In [96]:
def calc_xy(Qmin, Qmax, binsize, v_lag = 220): #combine calc_xy and expectvalues into one -> v_lag needs to pass into Nexpected!
    energy_lower = np.arange(Qmin, Qmax, binsize)
    energy_upper = np.arange(Qmin+binsize, Qmax+binsize, binsize)
    qmid = np.zeros(len(energy_lower))
    qmid = (energy_upper + energy_lower)/2
    for i in np.arange(len(energy_upper)): 
        qmid[i] = (energy_upper[i] + energy_lower[i])/2 

    data = expectvalues('xenon') #this is a generator
    data_list = list(data) #puts data into a list
    data_array = np.asarray(data_list) #turns list into an array
    

    #√ package these 2 into 1 2d list using list=[], list.append(qmid)
    #√ save qmid,data_array into 1 file; use np.savetxt(filename, 2d list);
    #√ then that file can be read using 2dlist=np.loadtxt(filename)
    
    datalist = []
    datalist.append(qmid)
    datalist.append(data_array)
    np.savetxt('xenondata.txt', datalist)#float argument required, not np.ndarray
    
    datalist=np.loadtxt('xenondata.txt') 

    return datalist

In [97]:
x,y = calc_xy(5., 100., 1.)

In [98]:
def plot_xy(x,y):
    #make plot look pretty!
    #√ write a seperate function that calls this and first function gets passed sigma, element, ect that will calculate and plot EVERYTHING
    #√ include in calculator function the argument v_lag= 220 km/s (in dmdd.Nexpected), make it a KWARG and pass to Nexpected/calc_xy
    plt.figure()
    plt.plot(x, y) #scatter makes dots, plot makes lines
    plt.title('Dark Matter-Nucleus Collisions', fontsize = 15)
    plt.xlabel('Energy [keV]', fontsize = 13)
    plt.ylabel('Number of Expected Recoil Events', fontsize = 13)
    plt.show()

    plt.savefig('/Users/katelynneese/dmdd/results/darkmattercollisions.png')

In [99]:
plot_xy(x,y)


<matplotlib.figure.Figure at 0x108587e90>

In [100]:
def mainplotter(element='xenon', Qmin=5, Qmax=100, binsize=1, exposure=2000, sigma_name='sigma_si', sigma_val=200, efficiency= dmdd.eff.efficiency_unit, v_lag = 500):
    expectvalues(element, Qmin, Qmax, binsize, exposure, sigma_name, sigma_val, efficiency, v_lag)
    x,y = calc_xy(Qmin, Qmax, binsize, v_lag)
    plot_xy(x,y)

In [101]:
mainplotter(element = 'xenon', v_lag = 220)


<matplotlib.figure.Figure at 0x10860a690>

In [ ]: