Пример #1
0
def test_readPreferences_values():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    preferences = Analysis.readPreferences()
    number_of_values = list(preferences.values())
    print(preferences)
    assert len(number_of_values) == 11
Пример #2
0
def test_extract_fuzzParam_from_single_run2():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    simulationFile = os.path.join(
        fileDir, "resources", "100simulations_psf0.0.sim.phs")
    returns = Analysis.extract_fuzzParam_from_single_run(simulationFile)
    assert len(returns.values()) == 14
Пример #3
0
def test_get_point_spread_function():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    simulationFile = os.path.join(
        fileDir, "resources", "100simulations_psf0.0.sim.phs")
    psf = Analysis.get_point_spread_function(simulationFile)
    assert psf == 0
Пример #4
0
def main(output_dir, scoop_hosts, preferencesFile, steps, maximum_PSF):
    oa_outDir = os.path.join(output_dir, "acceptance_vs_openingAngle")
    if not os.path.isdir(oa_outDir):
        os.makedirs(oa_outDir)
    fuzz_outDir = os.path.join(output_dir, "psf_fuzz_analysis")
    if not os.path.isdir(fuzz_outDir):
        os.makedirs(fuzz_outDir)
    extMethod_dir = os.path.join(output_dir, "extractionMethod_evaluation")
    if not os.path.isdir(extMethod_dir):
        os.makedirs(extMethod_dir)
    detectionMethod_dir = os.path.join(output_dir,
                                       "detectionMethod_evaluation")
    if not os.path.isdir(detectionMethod_dir):
        os.makedirs(detectionMethod_dir)
    simulationFileDir = os.path.join(fuzz_outDir, "simulations", "iterStep_0")
    simulationTruth_path = os.path.join(simulationFileDir,
                                        "psf_0.0.simulationtruth.csv")
    simulationFile = os.path.join(simulationFileDir, "psf_0.0.sim.phs")
    oa = eav.Acceptance_vs_OpeningAngle(scoop_hosts, preferencesFile, steps,
                                        oa_outDir)
    oa.investigate_acceptance_vs_openingAngle()
    fuzz = pfa.PSF_FuzzAnalysis(preferencesFile, maximum_PSF, steps,
                                scoop_hosts, fuzz_outDir)
    fuzz.call_all()
    extraction = eme.ExtractionMethod_Evaluation(simulationFile,
                                                 simulationTruth_path,
                                                 extMethod_dir)
    extraction.evaluate_methods()
    detection = edM.DetectionMethodEvaluation(detectionMethod_dir, 1000, 10,
                                              1.15, scoop_hosts)
    detection.multiple_nsb_rates()
Пример #5
0
def test_get_scoop_simulation_scriptPath():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    simulation_scriptPath = Analysis.get_scoop_simulation_scriptPath()
    existing = False
    if os.path.exists(simulation_scriptPath):
        existing = True
    assert existing == True
Пример #6
0
def test_calculate_stepSize():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    stepSize = Analysis.calculate_stepSize()
    np.testing.assert_almost_equal(
        stepSize,
        0.01,
        2)
Пример #7
0
def test_checkInputValidity_wrongPSF():
    try:
        Analysis = pfa.PSF_FuzzAnalysis(
            preferencesFile, "5", steps, scoop_hosts, output_dir)
        Analysis.checkInputValidity()
        error = False
    except ValueError:
        error = True
    assert error == True
Пример #8
0
def test_call_scoop_once():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.call_scoop_once(step_number=0)
    path = os.path.join(simulation_dir, "iterStep_0", "psf_0.0.sim.phs")
    existing = False
    if os.path.exists(path):
        existing = True
    assert existing == True
Пример #9
0
def test_plot_all2():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.plot_all()
    i = 0
    wild_card_path = os.path.join(output_dir, "Plots", "*", "*.png")
    for path in glob.glob(wild_card_path):
        i += 1
    assert i == 10
Пример #10
0
def test_multiple_scoop_calls():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.multiple_scoop_calls()
    wild_card_path = os.path.join(simulation_dir, "*")
    i = 0
    for path in glob.glob(wild_card_path):
        i += 1
    assert i == steps
Пример #11
0
def test_find_all_simulation_files():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.find_all_simulation_files()
    wild_card_path = os.path.join(simulation_dir, "*", "*.sim.phs")
    i = 0
    for path in glob.glob(wild_card_path):
        i += 1
    assert i == steps
Пример #12
0
def test_call_all():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.call_all()
    wild_card_path = os.path.join(output_dir, "*")
    i = 0
    for path in glob.glob(wild_card_path):
        i += 1
    assert i == 3
Пример #13
0
def test_checkInputValidity_AllCorrect():
    try:
        Analysis = pfa.PSF_FuzzAnalysis(
            preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
        Analysis.checkInputValidity()
        error = False
    except ValueError:
        error = True
    assert error == False
Пример #14
0
def test_checkInputValidity_wrongScoop():
    try:
        Analysis = pfa.PSF_FuzzAnalysis(
            preferencesFile, maximum_PSF, steps, "/foo/bar", output_dir)
        Analysis.checkInputValidity()
        error = False
    except ValueError:
        error = True
    assert error == True
Пример #15
0
def test_checkInputValidity_wrongOutput():
    try:
        Analysis = pfa.PSF_FuzzAnalysis(
            preferencesFile, maximum_PSF, 3.5, scoop_hosts, 3)
        Analysis.checkInputValidity()
        error = False
    except ValueError:
        error = True
    assert error == True
Пример #16
0
def test_call_scoop_for_all4():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.call_scoop_for_all()
    filename = "_".join(["stdev", "fuzzResults.csv"])
    filepath = os.path.join(fuzz_resultDir, "hough", filename)
    existing = False
    if os.path.exists(filepath):
        existing = True
    assert existing == True
Пример #17
0
def test_call_scoop_for_all6():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    Analysis.call_scoop_for_all()
    wild_card_path = os.path.join(
        simulation_dir, "*","hough_reconstructed_muon_events.csv")
    i = 0
    for path in glob.glob(wild_card_path):
        i += 1
    assert i == 10
Пример #18
0
def test_plot_absolute_detected_muons():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    psf_fuzz_csv_path = os.path.join(
        fileDir, "resources", "response_fuzzResults.csv")
    Analysis.plot_absolute_detected_muons(psf_fuzz_csv_path, "hough")
    filename = "hough_absolute_detected_muons.png"
    plotPath = os.path.join(output_dir, "Plots", filename)
    if os.path.exists(plotPath):
        existing = True
    shutil.rmtree(os.path.join(output_dir, "Plots"))
    assert existing == True
Пример #19
0
def test_plot_acceptance_vs_psf():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    psf_fuzz_csv_path = os.path.join(
        fileDir, "resources", "response_fuzzResults.csv")
    Analysis.plot_acceptance_vs_psf(psf_fuzz_csv_path, "ringM")
    plotPath = os.path.join(
        output_dir, "Plots", "ringM", "acceptance_vs_psf.png")
    existing = False
    if os.path.exists(plotPath):
        existing = True
    shutil.rmtree(os.path.join(output_dir, "Plots"))
    assert existing == True
Пример #20
0
def test_get_reconstructed_muons_info():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    muon_props = {
        "muon_ring_cx": 0,
        "muon_ring_cy": 0,
        "muon_ring_r": 1,
        "mean_arrival_time_muon_cluster": 2,
        "muon_ring_overlapp_with_field_of_view": 3,
        "number_of_photons": 3
    }
    event_id = 3
    muon_event_info = Analysis.get_reconstructed_muons_info(
        muon_props, event_id)
    assert len(muon_event_info) == 7
Пример #21
0
def test_save_fuzz_info():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    psf = [0, 0, 0, 0]
    extractionMethod = "hough"
    fuzzParameter = "response"
    muonCount = [3, 4, 5, 6]
    fuzz_avg = [0.5, 0.5, 0.5, 0.5]
    stdev_fuzz = [0.5, 0.5, 0.5, 0.5]
    filename = "_".join([fuzzParameter, "fuzzResults.csv"])
    filepath = os.path.join(fuzz_resultDir, extractionMethod, filename)
    Analysis.save_fuzz_info(
        psf, extractionMethod, fuzzParameter,
        muonCount, fuzz_avg, stdev_fuzz)
    df = pandas.read_csv(filepath)
    assert (df['point_spread_function'] == 0).all()
Пример #22
0
def test_plot_psf_fuzz_hough_ringM_comparison():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    psf_fuzz_csv_path = os.path.join(
        fileDir, "resources", "response_fuzzResults.csv")
    psf_fuzz_csv_path1 = os.path.join(
        fileDir, "resources", "stdev_fuzzResults.csv")
    Analysis.plot_psf_fuzz_hough_ringM_comparison(
        psf_fuzz_csv_path, psf_fuzz_csv_path1, "stdev")
    exists = False
    plotPath = os.path.join(
        output_dir, "Plots", "hough_ringM_psf_stdev_comparison.png")
    if os.path.exists(plotPath):
        existing = True
    shutil.rmtree(os.path.join(output_dir, "Plots"))
    assert existing == True
Пример #23
0
def main(simulation_dir, preferencesFile_path, maximum_PSF, steps, output_dir,
         scoop_hosts):
    Analysis = pfa.PSF_FuzzAnalysis(preferencesFile_path, maximum_PSF, steps,
                                    scoop_hosts, output_dir)
    jobs = Analysis.find_all_simulation_files()
    runInfos = list(
        scoop.futures.map(Analysis.extract_fuzzParam_from_single_run, jobs))
    reconstructed_muon_eventsHs = []
    responseR_avgs = []
    responseR_stdevs = []
    fuzzR_avgs = []
    fuzzR_stdevs = []
    number_muonsHs = []
    reconstructed_muon_eventsRs = []
    responseH_avgs = []
    responseH_stdevs = []
    fuzzH_avgs = []
    fuzzH_stdevs = []
    number_muonsRs = []
    point_spread_functions = []
    for singleRun in runInfos:
        inpath = singleRun['inpath']
        responseR_avgs.append(singleRun['responseR_avg'])
        responseR_stdevs.append(singleRun['responseR_stdev'])
        fuzzR_avgs.append(singleRun['fuzzR_avg'])
        fuzzR_stdevs.append(singleRun['fuzzR_stdev'])
        number_muonsHs.append(singleRun['number_muonsH'])
        responseH_avgs.append(singleRun['responseH_avg'])
        responseH_stdevs.append(singleRun['responseH_stdev'])
        fuzzH_avgs.append(singleRun['fuzzH_avg'])
        fuzzH_stdevs.append(singleRun['fuzzH_stdev'])
        number_muonsRs.append(singleRun['number_muonsR'])
        point_spread_functions.append(singleRun['point_spread_function'])
        Analysis.save_muon_events(singleRun['reconstructed_muon_eventsR'],
                                  inpath, "ringM")
        Analysis.save_muon_events(singleRun['reconstructed_muon_eventsH'],
                                  inpath, "hough")
    Analysis.save_fuzz_info(point_spread_functions, "ringM", "response",
                            number_muonsRs, responseR_avgs, responseR_stdevs)
    Analysis.save_fuzz_info(point_spread_functions, "ringM", "stdev",
                            number_muonsRs, fuzzR_avgs, fuzzR_stdevs)
    Analysis.save_fuzz_info(point_spread_functions, "hough", "response",
                            number_muonsHs, responseH_avgs, responseH_stdevs)
    Analysis.save_fuzz_info(point_spread_functions, "hough", "stdev",
                            number_muonsHs, fuzzH_avgs, fuzzH_stdevs)
Пример #24
0
def test_save_muon_events():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    reconstructed_muon_events = [
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1]
    ]
    simulationFile = os.path.join(
        fileDir, "resources", "100simulations_psf0.0.sim.phs")
    Analysis.save_muon_events(
        reconstructed_muon_events, simulationFile, "hough")
    reconstructedEvent_path = os.path.join(
        fileDir, "resources", "hough_reconstructed_muon_events.csv")
    existing = False
    if os.path.exists(reconstructedEvent_path):
        existing = True
    os.remove(reconstructedEvent_path)
    assert existing == True
Пример #25
0
def test_save_fuzz_info():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    psf = [0, 0, 0, 0]
    extractionMethod = "hough"
    fuzzParameter = "response"
    muonCount = [3, 4, 5, 6]
    fuzz_avg = [0.5, 0.5, 0.5, 0.5]
    stdev_fuzz = [0.5, 0.5, 0.5, 0.5]
    filename = "_".join([fuzzParameter, "fuzzResults.csv"])
    filepath = os.path.join(fuzz_resultDir, extractionMethod, filename)
    Analysis.save_fuzz_info(
        psf, extractionMethod, fuzzParameter,
        muonCount, fuzz_avg, stdev_fuzz)
    existing = False
    if os.path.exists(filepath):
        existing = True
    assert existing == True
Пример #26
0
def test_extraction():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    simulationFile = os.path.join(
        fileDir, "resources", "100simulations_psf0.0.sim.phs")
    run = ps.EventListReader(simulationFile)
    event_id = 3
    for i, event in enumerate(run):
        if i == event_id:
            photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
    muon_props = {
        "muon_ring_cx": 0,
        "muon_ring_cy": 0,
        "muon_ring_r": 1,
        "mean_arrival_time_muon_cluster": 2,
        "muon_ring_overlapp_with_field_of_view": 3,
        "number_of_photons": 3
    }
    returns = Analysis.extraction(
        muon_props, photon_clusters, event_id)
    assert len(returns) == 3
Пример #27
0
def test_get_fuzziness_parameters():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    simulationFile = os.path.join(
        fileDir, "resources", "100simulations_psf0.0.sim.phs")
    run = ps.EventListReader(simulationFile)
    for i, event in enumerate(run):
        if i == 47:
            photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
    muon_props = {
        "muon_ring_cx": 0,
        "muon_ring_cy": 0,
        "muon_ring_r": 1,
        "mean_arrival_time_muon_cluster": 2,
        "muon_ring_overlapp_with_field_of_view": 3,
        "number_of_photons": 3
    }
    normed_response, fuzziness_stdParam = Analysis.get_fuzziness_parameters(
        photon_clusters, muon_props)
    assert (
        isinstance(normed_response, Number) and 
        isinstance(fuzziness_stdParam, Number)
    )
Пример #28
0
def test_calculate_average_and_stdev():
    Analysis = pfa.PSF_FuzzAnalysis(
        preferencesFile, maximum_PSF, steps, scoop_hosts, output_dir)
    fuzz = [1,1,1,1,1,1,1,1,1]
    average_fuzz, fuzz_stdev = Analysis.calculate_average_and_stdev(fuzz)
    assert fuzz_stdev == 0