コード例 #1
0
def prem(ice):
    '''
    Returns an scipy.interpolate.interp1d function representing the density of the Earth in nucleons m^-3 as a function of radius.
    
    Source: Preliminary Reference Earth Model (PREM) (Dziewonski & Anderson, 1981)
        http://geophysics.ou.edu/solid_earth/prem.html

    Parameters
    ----------
    ice : gnosim.earth.ice.Ice
        The ice object containing the appropriate ice model.  This will be put on the surface of the PREM model.

    Returns
    -------
    f : scipy.interpolate.interp1d
        A function representing the density of the Earth in nucleons m^-3 as a function of radius.
    '''
    lines = prem_string.split('\n')

    radius = [] # km
    density = [] # kg m^-3
    for line in lines:
        if '#' in line:
            continue
    
        parts = line.split()
        if len(parts) != 9:
            continue

        radius.append(float(parts[0]))
        density.append(float(parts[3]))
    
    radius = numpy.array(radius) * gnosim.utils.constants.km_to_m # convert from km to m
    density = numpy.array(density) / gnosim.utils.constants.mass_proton # convert from kg m^-3 to nucleons m^-3
    
    # Overlay ice on the model for the Earth density profile 
    z = numpy.linspace(-1. * ice.ice_thickness, 0., 100.) # m
    radius_ice = gnosim.utils.constants.radius_earth + z # m
    density_ice = ice.density(z) # nucleons m^-3  
    radius = numpy.concatenate([radius, radius_ice]) # Now merge
    density = numpy.concatenate([density, density_ice])

    f = scipy.interpolate.interp1d(radius, density, bounds_error=False, fill_value=0.)
    return f
コード例 #2
0
def volumetricAcceptance(infile, electric_field_threshold=1.e-4):
    reader = h5py.File(infile, 'r')
    ice = gnosim.earth.ice.Ice(reader.attrs['ice_model'], suppress_fun=True)
    efficiency, (efficiency_low, efficiency_high) \
        = gnosim.utils.bayesian_efficiency.confidenceInterval(reader['p_interact'].shape[0],
                                                              numpy.sum(reader['electric_field'][...] > electric_field_threshold))

    volumetric_acceptance = numpy.sum(reader['p_earth'][...] \
                                      * (ice.density(reader['z_0'][...]) / gnosim.utils.constants.density_water)
                                      * (reader['electric_field'][...] > electric_field_threshold)) \
        * (reader.attrs['geometric_factor'] / reader['p_interact'].shape[0]) * gnosim.utils.constants.km_to_m**-3 # km^3 sr

    volumetric_acceptance_error_low = volumetric_acceptance * (
        (efficiency - efficiency_low) / efficiency)
    volumetric_acceptance_error_high = volumetric_acceptance * (
        (efficiency_high - efficiency) / efficiency)

    return reader['energy_neutrino'][0], reader.attrs[
        'config'], volumetric_acceptance, volumetric_acceptance_error_low, volumetric_acceptance_error_high
コード例 #3
0
def getInfo(reader,
            snr,
            gain,
            frequency,
            verbose=True,
            hist_bins=180,
            hist_range=(0.0, 180.0)):
    #reader = h5py.File(setup['reader_file'], 'r')
    config = yaml.load(open(reader.attrs['config']))
    energy_neutrino = reader['energy_neutrino'][0]  #GeV
    if frequency == 0:
        frequency = reader['weighted_freq'][...]
    if verbose == True:
        print('\nDepth:', config['stations']['positions'][0][2], 'm')
        print('Gain:', gain, 'dBi')
        print('SNR:', snr)
        if (numpy.size(frequency) == 1):
            print('Trigger frequency:', frequency * 1000, 'MHz')
        else:
            print('Mean Trigger frequency:',
                  numpy.mean(frequency[frequency > 0]) * 1000, 'MHz')
        print('Neutrio Energy:', energy_neutrino, 'GeV')
        print('Number of events:', len(reader['t'][...]))
    ice = gnosim.earth.ice.Ice(reader.attrs['ice_model'], suppress_fun=True)
    thresh = electricFieldThreshold(
        snr,
        gain,
        config['antenna_definitions']['simple']['temp'],
        config['antenna_definitions']['simple']['frequency_high'] -
        config['antenna_definitions']['simple']['frequency_low'],
        frequency,
        verbose=verbose)
    arrived = reader['p_earth'][...]
    density_factor = (ice.density(reader['z_0'][...]) /
                      gnosim.utils.constants.density_water)
    detected = reader['electric_field'][...] > thresh
    theta_weight = numpy.multiply(numpy.multiply(arrived, detected),
                                  density_factor)
    theta_ant = reader['theta_ant'][...]
    theta_0 = reader['theta_0'][...]
    theta_0_hist, edges = numpy.histogram(theta_0,
                                          bins=hist_bins,
                                          range=hist_range,
                                          weights=theta_weight)
    theta_ant_hist = numpy.histogram(theta_ant,
                                     bins=hist_bins,
                                     range=hist_range,
                                     weights=theta_weight)[0]
    theta_theta_hist, theta_hist_xedges, theta_hist_yedges = numpy.histogram2d(
        theta_ant,
        theta_0,
        bins=(hist_bins, hist_bins),
        range=(hist_range, hist_range),
        weights=theta_weight)
    theta = (edges[1:] + edges[:-1]) / 2.0
    if verbose == True:
        if numpy.size(thresh == 1):
            print('Electric field threshold =', thresh * 1000, 'mV/m')
        else:
            print('Minimum Electric field threshold applied =',
                  min(thresh) * 1000, 'mV/m')
            print('Maximum Electric field threshold applied =',
                  max(thresh) * 1000, 'mV/m')
    return theta_0_hist, theta_ant_hist, theta_theta_hist, theta_hist_xedges, theta_hist_yedges, theta, numpy.mean(
        frequency[frequency > 0]) * 1000, energy_neutrino
コード例 #4
0
ファイル: acceptance.py プロジェクト: djsouthall/gnosim
def acceptance(infile, cos_theta_bins=None, electric_field_threshold=1.e-4, earth=True, mode_reflections='all'):
    """
    Return volumetric acceptance (km^3 sr) and acceptance (m^2 sr)
    """
    reader = h5py.File(infile, 'r')

    energy_neutrino = reader['energy_neutrino'][0] # GeV

    interaction_length, interaction_length_anti \
        = gnosim.earth.earth.interactionLength(gnosim.utils.constants.density_water * gnosim.utils.constants.mass_proton,
                                               energy_neutrino)
    interaction_length = numpy.sqrt(interaction_length * interaction_length_anti) # m

    if cos_theta_bins is not None:
        n_bins = len(cos_theta_bins) - 1
    else:
        cos_theta_bins = numpy.array([-1., 1.])
        n_bins = 1

    volumetric_acceptance = numpy.zeros(n_bins)
    volumetric_acceptance_error_low = numpy.zeros(n_bins)
    volumetric_acceptance_error_high = numpy.zeros(n_bins)
    acceptance = numpy.zeros(n_bins)
    acceptance_error_low = numpy.zeros(n_bins)
    acceptance_error_high = numpy.zeros(n_bins)
    n_volume = numpy.zeros(n_bins)

    ice_model = reader.attrs['ice_model']
    ice = gnosim.earth.ice.Ice(ice_model,suppress_fun = True)
    for ii in range(0, n_bins):

        theta_min = numpy.degrees(numpy.arccos(cos_theta_bins[ii]))
        theta_max = numpy.degrees(numpy.arccos(cos_theta_bins[ii + 1]))

        if theta_min > theta_max:
            theta_temp = theta_max
            theta_max = theta_min
            theta_min = theta_temp

        print ('  Theta %.3f -- %.3f deg'%(theta_min, theta_max))

        n_total = numpy.sum(numpy.all([reader['theta_0'][...] >= theta_min,
                                       reader['theta_0'][...] <= theta_max],
                                      axis=0))

        if mode_reflections == 'all':
            cut_mode_reflections = numpy.ones(len(reader['solution'][...]))
            n_pass = int(numpy.sum(reader['p_earth'][...] \
                                   * (reader['theta_0'][...] >= theta_min) \
                                   * (reader['theta_0'][...] <= theta_max) \
                                   * (reader['electric_field'][...] > electric_field_threshold)))
            print ('all')
            
        elif mode_reflections == 'direct':
            cut_mode_reflections = numpy.logical_and(reader['solution'][...] >= 0, reader['solution'][...] <= 2)
            n_pass = int(numpy.sum(reader['p_earth'][...] \
                                   * (reader['solution'][...] >= 0) \
                                   * (reader['solution'][...] <= 2) \
                                   * (reader['theta_0'][...] >= theta_min) \
                                   * (reader['theta_0'][...] <= theta_max) \
                                   * (reader['electric_field'][...] > electric_field_threshold)))
            print ('direct')
        elif mode_reflections == 'reflect':
            cut_mode_reflections = numpy.logical_and(reader['solution'][...] >= 3, reader['solution'][...] <= 5)
            n_pass = int(numpy.sum(reader['p_earth'][...] \
                                   * (reader['solution'][...] >= 3) \
                                   * (reader['solution'][...] <= 5) \
                                   * (reader['theta_0'][...] >= theta_min) \
                                   * (reader['theta_0'][...] <= theta_max) \
                                   * (reader['electric_field'][...] > electric_field_threshold)))
            print ('reflect')
        else:
            print ('WARNING: mode reflections %s not recognized'%(mode_reflections))

        print (n_total, n_pass)

        """
        #if allow_reflections:
        if True:
            n_pass = numpy.sum(numpy.all([reader['theta_0'][...] >= theta_min,
                                          reader['theta_0'][...] <= theta_max,
                                          reader['electric_field'][...] > electric_field_threshold],
                                         axis=0))
            print (n_pass)
        #else:
        if False:
            #print 'NO REFLECTIONS'
            n_pass = numpy.sum(numpy.all([reader['theta_0'][...] >= theta_min,
                                          reader['theta_0'][...] <= theta_max,
                                          reader['electric_field'][...] > electric_field_threshold,
                                          reader['solution'][...] >= 0,
                                          reader['solution'][...] <= 2],
                                         axis=0))
            print (n_pass)
        """

        #print (n_total, n_pass, float(n_pass) / n_total, reader.attrs['geometric_factor'])

        #n_volume = numpy.sum(reader['p_earth'][...] \
        #                     * reader['p_detect'][...] \
        #                     * (reader['theta_0'][...] >= theta_min) \
        #                     * (reader['theta_0'][...] <= theta_max))

        try:
            efficiency, (efficiency_low, efficiency_high) = gnosim.utils.bayesian_efficiency.confidenceInterval(n_total, n_pass)
        except:
            efficiency, efficiency_low, efficiency_high = float(n_pass) / n_total, 0., 0.

        if earth:
            # Including effect of Earth attenuation

            print ('test', len(reader['p_earth'][...]))
            print ('test', len(cut_mode_reflections))

            volumetric_acceptance[ii] = numpy.sum(reader['p_earth'][...] \
                                                  * cut_mode_reflections \
                                                  * (reader['theta_0'][...] >= theta_min) \
                                                  * (reader['theta_0'][...] <= theta_max) \
                                                  * (ice.density(reader['z_0'][...]) / gnosim.utils.constants.density_water) \
                                                  * (reader['electric_field'][...] > electric_field_threshold)) \
                * (reader.attrs['geometric_factor'] / (n_total * n_bins)) * gnosim.utils.constants.km_to_m**-3 # km^3 sr
        else:
            # Ignore Effect of Earth attenuation
            volumetric_acceptance[ii] = numpy.sum(cut_mode_reflections \
                                                  * (reader['theta_0'][...] >= theta_min) \
                                                  * (reader['theta_0'][...] <= theta_max) \
                                                  * (ice.density(reader['z_0'][...]) / gnosim.utils.constants.density_water) \
                                                  * (reader['electric_field'][...] > electric_field_threshold)) \
                    * (reader.attrs['geometric_factor'] / (n_total * n_bins)) * gnosim.utils.constants.km_to_m**-3 # km^3 sr

        if n_pass > 0:
            volumetric_acceptance_error_low[ii] = volumetric_acceptance[ii] * ((efficiency - efficiency_low) / efficiency)
            volumetric_acceptance_error_high[ii] = volumetric_acceptance[ii] * ((efficiency_high - efficiency) / efficiency)
        else:
            volumetric_acceptance_error_low[ii] = 0.
            volumetric_acceptance_error_high[ii] = 0.

        acceptance[ii] = volumetric_acceptance[ii] * gnosim.utils.constants.km_to_m**3 / interaction_length # m^2 sr 
        acceptance_error_low[ii] = volumetric_acceptance_error_low[ii] * gnosim.utils.constants.km_to_m**3 / interaction_length
        acceptance_error_high[ii] = volumetric_acceptance_error_high[ii] * gnosim.utils.constants.km_to_m**3 / interaction_length

    reader.close()
    
    if n_bins > 1:
        return volumetric_acceptance, volumetric_acceptance_error_low, volumetric_acceptance_error_high, \
            acceptance, acceptance_error_low, acceptance_error_high
    else:
        return volumetric_acceptance[0], volumetric_acceptance_error_low[0], volumetric_acceptance_error_high[0], \
            acceptance[0], acceptance_error_low[0], acceptance_error_high[0]
コード例 #5
0
ファイル: plot_single.py プロジェクト: djsouthall/gnosim
# Solutions

pylab.figure()
pylab.hist(reader['solution'][cut_seen], bins=numpy.arange(6 + 1), alpha=0.5, color='red', normed=True, label='Visible')
pylab.hist(reader['solution'][cut_detected], bins=numpy.arange(6 + 1), alpha=0.5, color='blue', normed=True, label='Detected')
pylab.xlabel('Solution')
pylab.ylabel('PDF')
pylab.title(title)
pylab.legend(loc='upper right')
"""
# Acceptance

electric_field_threshold = 1.e-4
efficiency, (efficiency_low, efficiency_high) \
    = gnosim.utils.bayesian_efficiency.confidenceInterval(reader['p_interact'].shape[0], 
                                                          numpy.sum(reader['electric_field'][...] > electric_field_threshold))


ice = gnosim.earth.ice.Ice(reader.attrs['ice_model'],suppress_fun = True)
volumetric_acceptance = numpy.sum(reader['p_earth'][...] \
                                  * (ice.density(reader['z_0'][...]) / gnosim.utils.constants.density_water)
                                  * (reader['electric_field'][...] > electric_field_threshold) \
    * reader.attrs['geometric_factor']) / float(reader['p_interact'].shape[0]) * gnosim.utils.constants.km_to_m**-3 # km^3 sr

print ('Volumetric Acceptance = %.2e km^3 sr water equivalent'%(volumetric_acceptance))
print ('Efficiency = %.2e (%.2e -- %.2e)'%(efficiency, efficiency_low, efficiency_high))


input("press any key to exit")