Exemple #1
0
def body():
    dh = 0.0001
    dt = 0.0001
    time = 100
    t_finish = int(time / dt)
    grid = PipeGrid(dh)
    X = int(grid.shape[0] / 2)
    Y = grid.shape[1] - 2
    T_Tot = []
    file = open('stats.csv', 'w')
    file.write('Time (s), Temperature (K)\n')

    T_Tot.append(grid)
    file.write('{0}, {1:.2f}\n'.format(0, grid[X, Y]))
    for t in np.arange(1, t_finish):
        print("----{}----".format(t * dt))
        z = v * dt * t

        if z < L:
            heated = int(z / dh)
            grid[:heated, 1] = T_g

            if t % reco_step == 0:
                T_Tot.append(grid)
                file.write('{0:.2f}, {1:.2f}\n'.format(t * dt, grid[X, Y]))
        else:
            grid[:, 1] = T_g
            break

        run(grid, T_g, k_s, rho_s, T_Tot, dh, dt)

    t_start = t

    for t in np.arange(t_start, t_finish):
        print("----{}----".format(t * dt))
        if t % reco_step == 0:
            T_Tot.append(grid)
            file.write('{0:.2f}, {1:.2f}\n'.format(t * dt, grid[X, Y]))

        run(grid, T_g, k_s, rho_s, T_Tot, dh, dt)

    t_list = np.arange(len(T_Tot)) * dt
    T_plot = []
    for T in T_Tot:
        T_plot.append(T[X, Y])

    file.close()
    return t_list, T_plot
Exemple #2
0
def test(cmd, smpl_paths, tmpl_paths, patterns, out_dir, demo):
    # run the main process to obtain a synthesized model
    #no_sketch()
    res = main(cmd, smpl_paths, tmpl_paths, patterns, out_dir)
    if res: return res

    # simulate
    log_fname = os.path.join(out_dir, "simulated.txt")
    res = simulate.run(cmd, demo, patterns, out_dir, log_fname)
    if res: return res

    # compare logs
    smpl_path = os.path.join(smpl_dir, cmd, demo)
    for smpl in util.get_files_from_path(smpl_path, "txt"):
        res = compare.compare(smpl, log_fname)
        if res:
            logging.error("conflict with " + os.path.normpath(smpl))
            return res
        logging.info("compared with " + os.path.normpath(smpl))

    logging.info("test done")
    return 0
Exemple #3
0
def test(cmd, smpl_paths, tmpl_paths, patterns, out_dir, demo):
  # run the main process to obtain a synthesized model
  #no_sketch()
  res = main(cmd, smpl_paths, tmpl_paths, patterns, out_dir)
  if res: return res

  # simulate
  log_fname = os.path.join(out_dir, "simulated.txt")
  res = simulate.run(cmd, demo, patterns, out_dir, log_fname)
  if res: return res

  # compare logs
  smpl_path = os.path.join(smpl_dir, cmd, demo)
  for smpl in util.get_files_from_path(smpl_path, "txt"):
    res = compare.compare(smpl, log_fname)
    if res:
      logging.error("conflict with " + os.path.normpath(smpl))
      return res
    logging.info("compared with " + os.path.normpath(smpl))

  logging.info("test done")
  return 0

detectedflux = float(flux) * float(area) * float(solidangle) * float(selectionefficiency)
rateperhour = detectedflux * 60 * 60
n = int(rateperhour * float(numberofhours))
print time.asctime(
    time.localtime()
), "Cosmic Ray Iron Flux is", flux, "Simulated Area is", area, "Field of View is", solidangle, "Detected Flux is", detectedflux
print time.asctime(
    time.localtime()
), "Rate per hour", rateperhour, "Simulated Hours", numberofhours, "Simulated Events", n

with open(
    "/afs/desy.de/user/s/steinrob/Documents/DESY/positioning/orientations/" + orientation + ".csv", "rb"
) as csvfile:
    reader = csv.reader(csvfile, delimiter=",", quotechar="|")
    rowcount = 0
    for row in reader:
        rowcount += 1

s.run(eff, rowcount, mincount=mincount, text=False, graph=False, output=sourcedata, layout=orientation, number=n)
bp.run(sourcedata, processdata, int(mincount), rowcount, text=False)
br.run(processdata, reconstructdata, rowcount, reconstructiongridwidth, eff)

message = str(time.asctime(time.localtime())) + " Completed simulation of " + str(n) + " events!"
import os, sys
import sendemail as se

name = os.path.basename(__file__)
se.send(name, message, False)
print time.asctime(
    time.localtime()
), "Rate per hour", rateperhour, "Simulated Hours", numberofhours, "Simulated Events", n

with open(
        "/afs/desy.de/user/s/steinrob/Documents/DESY/positioning/orientations/"
        + orientation + ".csv", 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='|')
    rowcount = 0
    for row in reader:
        rowcount += 1

s.run(eff,
      rowcount,
      mincount=mincount,
      text=False,
      graph=False,
      output=sourcedata,
      layout=orientation,
      number=n)
bp.run(sourcedata, processdata, int(mincount), rowcount, text=False)
br.run(processdata, reconstructdata, rowcount, reconstructiongridwidth, eff)

message = str(time.asctime(
    time.localtime())) + " Completed simulation of " + str(n) + " events!"
import os, sys
import sendemail as se

name = os.path.basename(__file__)
se.send(name, message, False)
	
else:
	sourcedata= str(cfg.data) + "simulated" + str(cfg.mincount)
	processdata = str(cfg.data) + "processed"+ str(cfg.mincount)
	reconstructdata = str(cfg.data) + "reconstructed"+ str(cfg.mincount)

with open("orientations/"+ cfg.orientation +".csv", 'rb') as csvfile:
	reader = csv.reader(csvfile, delimiter=',', quotechar='|')
	rowcount = 0
	for row in reader:
		rowcount +=1
		
if cfg.simulate:
	print time.asctime(time.localtime()),"Cosmic Ray Iron Flux is", flux, "Simulated Area is", area, "Field of View is", solidangle, "Detected Flux is", detectedflux
	print time.asctime(time.localtime()),"Rate per hour", rateperhour, "Simulated Hours", cfg.numberofhours, "Simulated Events", n 
	s.run(eff, rowcount, mincount=cfg.mincount, text=cfg.text, graph=cfg.graph, output=sourcedata, layout=cfg.orientation, number = n)
	bp.run(sourcedata, processdata, int(cfg.mincount), rowcount, text=cfg.text)
	br.run(processdata, reconstructdata, rowcount, cfg.reconstructiongridwidth, eff)
	message = str(time.asctime(time.localtime())) + " Completed simulation of " + str(n) + " events!"
	print message
	import os, sys
	import sendemail as se
	name = os.path.basename(__file__)
	se.send(name, message)
	
if cfg.plotcut:
	allcounts = cc.run(reconstructdata, rowcount, int(cfg.mincount))
	
	sys.path.append('/d6/rstein/Hamburg-Cosmic-Rays/BDT')
	import BDT
	BDT.run(reconstructdata, rowcount, int(cfg.mincount), allcounts)
Exemple #7
0
    reader = csv.reader(csvfile, delimiter=',', quotechar='|')
    rowcount = 0
    for row in reader:
        rowcount += 1

if cfg.simulate:
    print time.asctime(
        time.localtime()
    ), "Cosmic Ray Iron Flux is", flux, "Simulated Area is", area, "Field of View is", solidangle, "Detected Flux is", detectedflux
    print time.asctime(
        time.localtime()
    ), "Rate per hour", rateperhour, "Simulated Hours", cfg.numberofhours, "Simulated Events", n
    s.run(eff,
          rowcount,
          mincount=cfg.mincount,
          text=cfg.text,
          graph=cfg.graph,
          output=sourcedata,
          layout=cfg.orientation,
          number=n)
    bp.run(sourcedata, processdata, int(cfg.mincount), rowcount, text=cfg.text)
    br.run(processdata, reconstructdata, rowcount, cfg.reconstructiongridwidth,
           eff)
    message = str(time.asctime(
        time.localtime())) + " Completed simulation of " + str(n) + " events!"
    print message
    import os, sys
    import sendemail as se
    name = os.path.basename(__file__)
    se.send(name, message)

if cfg.plotcut:
Exemple #8
0
        exit(1)

    # Spawn a CASA process to work with and put the config_file variable to
    # the CASA variable list.
    #casa = drivecasa.Casapy(working_dir=os.path.curdir,
    #casa_logfile=False,
    #echo_to_stdout=True)
    #casa.run_script(["config_file = '{}'".format(args.config)])

    # Top level simulation output directory.
    # TODO-BM use the filename of the settings file as the path?
    sim_dir = settings['path']

    # Create a copy of the settings file.
    if not os.path.isdir(sim_dir):
        os.makedirs(sim_dir)
    copyfile(args.config, join(sim_dir, args.config))

    # Simulation.
    simulate.run(settings)

    # Average.
    #casa.run_script_from_file('average_ms.py')

    # Image.
    #casa.run_script_from_file('image.py')

    # Plot results.
    #plot.run(settings)
    # Record time taken.
from simulate import run

if __name__ == "__main__":
    import sys
    fileToRead = sys.argv[1]
    run(fileToRead)
Exemple #10
0
def output(bdt=0.96, probk=-2.0, probmu=2.0, probe=2.0, countoutput=False, text=False, dynamic=False, graph =False, random=False):
    #Fit to find expected background count and exponential distribution parameter
    
    expcount, aval = f.run(file1, t1, CommonSelection, lower, upper, lowercut, uppercut, bdt, probk, probmu, probe, text=text, graph=graph)
    count = 17
    significance = False
    
    maxrandomcount = 100
    
    if random:
        randomcount=0
    
    else:
        randomcount = maxrandomcount - 1
        
    ratioarray = []
    errorarray = []
    
    if expcount != None:
        
        #Calculates the Branmching Ratio 100 times, and calculates a mean
        
        while randomcount != maxrandomcount:
            
            #iteratively add counts to the signal peak until it has a 5 sigma significance
            
            while significance != True:
                sig, entries, significance, peak, sigma, selection = s.run(file2, t2, CommonSelection, var, lower, upper, lowercut, uppercut, bdt, expcount, aval, count, probk, probmu, probe, text=text, graph=graph)
                if (dynamic == True) & (peak < 3.0):
                    if sigma < (expcount * 0.2):
                        count += (int(sigma) +1)
                    else:
                        count +=20
                elif significance != True:
                    count += int(sigma*0.01) +1
            
            ratio, error = br.run(sig, entries, file2, t2, selection)
            randomcount += 1    
            
            ratioarray.append(ratio)
            errorarray.append(error)
            significance = False
            count += -5
        
        averageratio = np.mean(ratioarray)
        
        if random:
            averageerror = np.mean(errorarray)/math.sqrt(float(randomcount))
            print time.asctime(time.localtime()), "Final Branching Ratio is", ufloat(averageratio, averageerror)
            
            
        else:
            averageerror = np.mean(errorarray)
            
                    
        #return ratio and error for the purpose of a csv output and graph
        if countoutput == True:
            return averageratio, averageerror
        #return just the ratio, for the purpose of minimisation
        else:
            return averageratio
    #If the fit has not converged, or expected count is 0, return error
    else:
        return float('nan')
        exit(1)

    # Spawn a CASA process to work with and put the config_file variable to
    # the CASA variable list.
    casa = drivecasa.Casapy(working_dir=os.path.curdir,
                            casa_logfile=False,
                            echo_to_stdout=True)
    casa.run_script(["config_file = '{}'".format(args.config)])

    # Top level simulation output directory.
    # TODO-BM use the filename of the settings file as the path?
    sim_dir = settings['path']

    # Create a copy of the settings file.
    if not os.path.isdir(sim_dir):
        os.makedirs(sim_dir)
    copyfile(args.config, join(sim_dir, args.config))

    # Simulation.
    simulate.run(settings)

    # Average.
    casa.run_script_from_file('average_ms.py')

    # Image.
    casa.run_script_from_file('image.py')

    # Plot results.
    plot.run(settings)