Example #1
0
    def create_from_fits(row, tab_ebounds, tab_pars):

        width = np.log10(np.array(tab_pars['halo_scan_width'][0]))
        index = np.log10(tab_pars['halo_scan_index'][0])
        eobs = np.array(tab_ebounds['E_MAX'])
        eobs = np.insert(eobs,0,tab_ebounds['E_MIN'][0])
        eobs = np.log10(eobs)
        eflux = np.log10(np.array(tab_pars['halo_scan_eflux'][0]))

        axis0 = Axis.create_from_centers('width',width)
        axis1 = Axis('eobs',eobs)
        axis2 = Axis.create_from_centers('eflux',eflux)

        sed = MapND([axis0,axis1,axis2],-np.array(row['fit_halo_sed_scan_dlnl']))

        return HaloSED(sed)
Example #2
0
    def create_from_row(row):

        row['E_REF'].unit = 'TeV'
        row['NORM'].unit = 'ph / (m2 TeV s)'
        row['NORM_ERRP'].unit = 'ph / (m2 TeV s)'
        row['NORM_ERRN'].unit = 'ph / (m2 TeV s)'
        
        dfde = row['NORM']
        dfde_unit = u.ph / (u.MeV * u.cm ** 2 * u.s)
        loge = np.log10(np.array(row['E_REF'].to(u.MeV)[0]))

        norm = np.array(row['NORM'].to(dfde_unit)[0])
        norm_errp = np.array(row['NORM_ERRP'].to(dfde_unit)[0])
        norm_errn = np.array(row['NORM_ERRN'].to(dfde_unit)[0])
        norm_err = 0.5 * (norm_errp + norm_errn)

        m = np.isfinite(loge)
        loge = loge[m]
        norm = norm[m]
        norm_err = norm_err[m]

        dloge = loge[1:] - loge[:-1]
        dloge = np.insert(dloge, 0, dloge[0])
        emin = 10 ** (loge - dloge * 0.5)
        emax = 10 ** (loge + dloge * 0.5)
        ectr = 10 ** loge
        deltae = emax - emin
        flux = norm * deltae
        flux_err = norm_err * deltae
        
        # Build Sequence of 1D likelihoods
        
        norm_vals, nll_vals = create_lnl_from_errors(flux, flux_err)
        lnl_maps = []
        
        for i, x in enumerate(loge):
            #print i, x, norm_vals[i]
            axis = Axis.create_from_centers('flux',norm_vals[i])
            lnl_maps += [MapND([axis], nll_vals[i])]

        return SED(lnl_maps, emin, ectr, emax, flux, flux_err)
Example #3
0
    def create_from_row2(row, tab_ebounds):

        ref_flux = np.array(row['REF_FLUX'][0])
        norm = np.array(row['NORM'][0])
        norm_err = np.array(row['NORM_ERR'][0])
                
        flux = norm*ref_flux
        flux_err = norm_err*ref_flux

        ectr = np.array(tab_ebounds['E_REF'])
        emin = np.array(tab_ebounds['E_MIN'])
        emax = np.array(tab_ebounds['E_MAX'])

        norm_vals = np.array(row['NORM_SCAN'][0])*ref_flux[:,np.newaxis]
        nll_vals = -np.array(row['DLOGLIKE_SCAN'][0])
        lnl_maps = []
        
        for i, x in enumerate(ectr):
            axis = Axis.create_from_centers('flux',norm_vals[i])
            lnl_maps += [MapND([axis], nll_vals[i])]

        return SED(lnl_maps, emin, ectr, emax, flux, flux_err)
Example #4
0
    def create_from_fits(filename):

        tab0 = Table.read(filename)
        tab1 = Table.read(filename, 'ENERGIES')
        tab2 = Table.read(filename, 'THETA')
        
        nebin = len(tab1)
        nthbin = len(tab2)
        if 'z' in tab0.columns:        
            model_shape = (17, 9, 9)
            axis_offset = 1
        else:
            model_shape = (9, 9)
            axis_offset = 0
            
        emin = np.array(tab1['E_ledge']/1E6)
        emax = np.array(tab1['E_redge']/1E6)
        ectr = np.array(tab1['E_cen']/1E6)

        thmin = np.array(10**tab2['th_ledge'])
        thmax = np.array(10**tab2['th_redge'])
        thctr = np.array(tab2['th_cen'])
        thedges = np.insert(tab2['th_redge'],0,tab2['th_ledge'][0])
        
        domega = np.pi*(thmax**2-thmin**2)*(np.pi/180.)**2
        
        tab_casc_flux = tab0['casc_flux'].reshape(model_shape + (nebin, nebin, nthbin))
        tab_prim_flux = tab0['prim_flux'].reshape(model_shape + (nebin,))
        tab_inj_flux = tab0['inj_flux'].reshape(model_shape + (nebin,))
        tab_igmf = np.unique(np.array(tab0['igmf'].reshape(model_shape)))
        tab_lcoh = np.unique(np.array(tab0['lcoh'].reshape(model_shape)))
            
        log_igmf = np.log10(tab_igmf)
        log_lcoh = np.log10(tab_lcoh)

        data_casc_flux = np.array(tab_casc_flux/tab_inj_flux[..., np.newaxis, np.newaxis])
        data_prim_flux = np.array(tab_prim_flux/tab_inj_flux)
        
        #data_avg = np.apply_over_axes(np.sum, data_prim_flux, axes=[0,1])/(model_shape[0]*model_shape[1])        
        #data_prim_flux[:,:,:] = data_avg
        
        # Swap axes so that E_inj and E_obs are the first two
        # dimensions
        data_casc_flux = np.rollaxis(data_casc_flux, 2+axis_offset, 0)
        data_casc_flux = np.rollaxis(data_casc_flux, 3+axis_offset, 1)
        data_casc_flux = np.rollaxis(data_casc_flux, 4+axis_offset, 2)
        data_prim_flux = np.rollaxis(data_prim_flux, 2+axis_offset, 0)

        axis_einj = Axis.create_from_centers('einj', np.log10(ectr))
        axis_eobs = Axis.create_from_centers('eobs', np.log10(ectr))
        axis_theta = Axis('th', thedges)
        axis_lcoh = Axis.create_from_centers('log_lcoh', log_lcoh)
        axis_igmf = Axis.create_from_centers('log_igmf', log_igmf)

        model_axes = [axis_lcoh, axis_igmf]
        axes = [axis_einj, axis_eobs, axis_theta]

        if 'z' in tab0.columns:
            tab_z = np.unique(np.array(tab0['z'].reshape(model_shape)))
            axis_z = Axis.create_from_centers('z', tab_z)            
            model_axes = [axis_z] + model_axes
        
        mapnd_casc_flux = MapND([axis_einj, axis_eobs, axis_theta] + model_axes,
                                data_casc_flux, True)
        mapnd_prim_flux = MapND([axis_einj] + model_axes,
                                data_prim_flux, True)

        return CascModel(axes + model_axes, mapnd_casc_flux, mapnd_prim_flux)