Exemplo n.º 1
0
def bowtie_filter(cfg):
    '''
    Apply the transmittance of bowtie filter, dim: [Ebin, totalNumCells]
    '''
    if not cfg.protocol.bowtie:
        return cfg

    # find bowtie file
    bowtieFile = cfg.protocol.bowtie
    if not os.path.isfile(bowtieFile):
        bowtiePath = get_path().bowtie + "/"
        if os.path.isfile(bowtieFile + ".dat"):
            bowtieFile += ".dat"
        elif os.path.isfile(bowtiePath + bowtieFile):
            bowtieFile = bowtiePath + bowtieFile
        elif os.path.isfile(bowtiePath + bowtieFile + ".dat"):
            bowtieFile = bowtiePath + bowtieFile + ".dat"
        else:
            raise Exception("Cannot find bowtie file: %s or %s.dat" %
                            (bowtieFile, bowtieFile))

    # read bowtie file
    data = np.loadtxt(bowtieFile, dtype=np.single, comments=['#', '%'])

    gammas0 = data[:, 0]
    t0 = data[:, 1:]  # thickness in cm
    bowtieMaterials = ['al', 'graphite', 'cu', 'ti']

    Evec = cfg.spec.Evec
    gammas1 = cfg.det.gammas

    muT = 0
    for i in range(len(bowtieMaterials)):
        mu = GetMu(bowtieMaterials[i], Evec)
        f = interpolate.interp1d(gammas0,
                                 t0[:, i],
                                 kind='linear',
                                 fill_value='extrapolate')
        t1 = f(gammas1) / cfg.det.cosAlphas
        muT += t1 @ mu.reshape(1, len(mu))

    trans = np.exp(-muT)
    cfg.src.filterTrans *= trans

    return cfg
Exemplo n.º 2
0
def flat_filter(cfg):
    '''
    Apply the transmittance of flat filter at source side, dim: [Ebin, totalNumCells]
    '''
    cosineFactors = 1/cfg.det.cosGammas/cfg.det.cosAlphas
    
    Evec = cfg.sim.Evec
    trans = np.ones([cfg.det.totalNumCells, cfg.spec.nEbin], dtype = np.single)
    
    if hasattr(cfg.protocol, "flatFilter"):
        for ii in range(0, round(len(cfg.protocol.flatFilter)/2)):
            material = cfg.protocol.flatFilter[2*ii]
            depth = cfg.protocol.flatFilter[2*ii+1]
            mu = GetMu(material, Evec)
            trans *= np.exp(-depth*0.1*cosineFactors @ mu.reshape(1, mu.size))
    cfg.src.filterTrans *= trans
    
    return cfg