Пример #1
0
def RadioCuts(val, compradio=False):
    smt = iom.SmartTiming()
    smt(task='RadioAndMock_initialization')

    (pase, realisations, survey) = val

    Rmodel = survey.Rmodel
    snapMF, strSn, smt_add = LoadSnap_multiprocessing(pase,realisations,Rmodel, getstring=True)
    if compradio:   
        (snap,subsmt) = radiomodel.CreateRadioCube(snapMF, Rmodel, realisations[0].mockobs.z_snap, nuobs=pase['nu_obs'])[0:2]
        smt.MergeSMT_simple(subsmt, silent=True)
        
        smt(task='UpdateHeader')  
        realisations[0].z.value    = realisations[0].mockobs.z_snap
        realisations[0].Mvir.value = snap.head['Mvir']*snap.head['hubble']
        realisations[0].updateInformation()
        snap.head['M200'] = realisations[0].M200.value
                     
        """ Here we compute the volume weighted radio emission """         
        radiosum      = np.sum(snap.radi)    
        borders       = 2*realisations[0].R200*snap.head ['hubble']/snap.head ['aexpan']
        whereR200     = np.where( np.sqrt(np.power(snap.pos[:,0],2) + np.power(snap.pos[:,1],2) + np.power(snap.pos[:,2],2) ) < borders/2 )
        radiosum_R200 = np.sum(snap.radi[whereR200])

        # update information on the total radio power (at the rest frame frequency) in the simulational volume
        for kk,real in enumerate(realisations):
             realisations[kk].P_rest.value    = radiosum       # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction
             realisations[kk].Prest_vol.value = radiosum_R200  # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction
    else:
        (snap, MF) = snapMF

    smt(task='Shed_DoMockObs_misc')
    if suut.TestPar(pase['redSnap']): 
         # This is all part of reducing the data load. A shrinked version of the snapshot with less particles is saved in the custom format that is a fork of the gadget format
         redsnap = radiomodel.PiggyBagSnap_cut(snap, snap, float(pase['cutradio']), cutmask = MF )
         strSn   = strSn.replace('cluster.', 'clusterSUBSET.')
         strSn   = strSn.replace(pase['snapfolder'], pase['outf'])
         print(strSn)
         redsnap.savedata(strSn)    # original snapshot
    if compradio:
         print('np.sum(radiocube[0].radi)', np.sum(snap.radi), '-->', np.sum(redsnap.radi), 'i.e.', radiosum, radiosum_R200, 'pickled to', strSn)
         
    return (realisations, Rmodel), smt
Пример #2
0
def LoadSnap_multiprocessing(pase, realisations, Rmodel, getstring=False, verbose=False):
    smt = iom.SmartTiming()
    smt(task='LoadSnaps')   
           
    gcl = realisations[0]

    """ We load the radio cubes """

    strSn = (pase['snapfolder'] + 'SHOCKS_%05i/cluster.%05i.snap.%03i.shocks') % (gcl.mockobs.clid, gcl.mockobs.clid, gcl.mockobs.snap)

#    if suut.TestPar(pase['useMiniCube']):     # subset of snapshot, pickled
#        strSn   = strSn.replace('cluster.', 'clusterSUBSET.') 
#        if verbose: print('Loading snapshot:',strSn)
#        print('___ RunSurvey::LoadSnap_multiprocessing::',strSn,pase['useMiniCube'],suut.TestPar(pase['useMiniCube']))
#        snap    = iom.unpickleObject(strSn)
#        try:
#            snap    = iom.unpickleObject(strSn)
#        except:
#            with open('/data/ErrorLog.txt',"a") as f:
#                for gcl in realisations:
#                    f.write(strSn+'\n')   
#               
#    else: # original snapshot                          
#        if verbose: print('Loading snapshot:',strSn)
#        snap    = loadsnap.Loadsnap(strSn,headerc=pase['headerC'])    # original snapshot
        

    if  suut.TestPar(pase['useMiniCube']):   # asks: original or modified  snapshot?
         strSn   = strSn.replace('cluster.', 'clusterSUBSET.') 
    if verbose: print('Loading snapshot:',strSn)
    snap    = loadsnap.Loadsnap(strSn,headerc=pase['headerC'])                                    
                                    
                                    
    
    """psi and machfiles could become sharred (or global) arrays, but as they are quite small < 1MB, the impact on performance should be snmall"""
    PreSnap = radiomodel.PrepareRadioCube(snap, psiFile=pase['miscdata']+pase['PSItable'], machFile=pase['miscdata']+pase['DSAtable'])
    PreSnap = ( radiomodel.PiggyBagSnap(PreSnap[0]), PreSnap[1] )

    if getstring:
        return PreSnap, strSn, smt
    else:
        return PreSnap, smt
Пример #3
0
def DoRun(inputs, smt, verbose=False, countmax=500, countmax_relics=1500):
    """ Please mind that this procedure determines early if the number of detected relics becomes to large!"""  
    (pase, survey) = inputs

    count = 0
    count_relics = 0
    realisations = []
    realisations_list = [] # rotated realisations of one and the same cluster
    survey.GCls = sorted(survey.GCls, key= iom.Object_natural_keys)
    # This checks if the snapshot has to be loaded ...  I would use a pool of loaded, snapshots ... but this is cumbersome
    # Each snapshot is loaded only once ... If the number of models&rotations to be tested is high enough the produced overhead is low
    # This requires that the clusters are ordered due to cluster number and snapshot
    for gcl in survey.GCls:
        if (len(realisations) == 0 or gcl.mockobs.clid != realisations[0].mockobs.clid or gcl.mockobs.snap != realisations[0].mockobs.snap):
            if len(realisations) > 0:
                realisations_list.append(realisations)
            realisations = [gcl] 
        else: 
            realisations.append(gcl)   
            
    realisations_list.append(realisations)       

    for realisations in realisations_list:
            gcl = realisations[0]
            if verbose:
                print('Recognized ID %5i, snap %3i, #%i in cluster file' % (gcl.mockobs.clid, gcl.mockobs.snap, gcl.mockobs.id) )

            smt(task='LoadSnaps')   
            """ We load the radio cubes """
            strSn = (pase['snapfolder'] + 'SHOCKS_%05i/cluster.%05i.snap.%03i.shocks') % (gcl.mockobs.clid, gcl.mockobs.clid, gcl.mockobs.snap)
            """ SMELLY: This causes some issues, as there are two different 'load' versions for one and the same task """
            if suut.TestPar(pase['useMiniCube']):   # original snapshot
                strSn = strSn.replace('cluster.', 'clusterSUBSET.')
            if verbose:
                print('Loading snapshot:', strSn)
            snap = loadsnap.Loadsnap(strSn, headerc=pase['headerC'])

            smt(task='PrepareRadioCubes')   
            PreSnap = radiomodel.PrepareRadioCube(snap, psiFile=pase['miscdata']+pase['PSItable'],
                                                  machFile=pase['miscdata']+pase['DSAtable'])


            if 1==2:
                snap_phd = radiomodel.PrepareRadioCube(snap, psiFile=pase['miscdata'] + pase['PSItable'],
                                                      machFile=pase['miscdata'] + pase['DSAtable'], machmin=0.0)[0]

                print(type(snap_phd.mach))
                Mstat = np.asarray(snap_phd.mach)/1.045+1e-5
                Astat = np.asarray(snap_phd.hsml)/np.asarray(loadsnap.comH_to_phys(snap_phd.head))**2
                Rhostat = np.asarray(snap.rdow)
                Tstat = np.asarray(snap.udow)
                Psistat = np.asarray(snap.DSAPsi)

                bins = np.linspace(-1, 3, num=1300, endpoint=True)
                print(Mstat.shape, Tstat.shape, Psistat.shape)
                M_hist, bin_edges = np.histogram(np.log10(Mstat), bins=bins)
                A_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Astat, bins=bins)
                Rho_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Rhostat, bins=bins)
                T_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Tstat, bins=bins)
                Psi_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Psistat, bins=bins)
                Psi_A_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Psistat*Astat, bins=bins)
                Psi_A_T_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Psistat*Astat*Tstat**(1.5), bins=bins)
                Psi_A_T_Rho_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Psistat*Rhostat*Astat*Tstat**(1.5), bins=bins)
                Psi_A_Rho_hist, bin_edges = np.histogram(np.log10(Mstat), weights=Rhostat*Astat, bins=bins)

                alltogether = np.stack((M_hist, A_hist, Rho_hist, T_hist, Psi_hist, Psi_A_hist, Psi_A_T_hist, Psi_A_T_Rho_hist,Psi_A_Rho_hist), axis=1)
                print( len(snap.mach), alltogether.shape)

                for fr in realisations:
                    np.save("/data/TestForPhD/TestForPhD-%i" % (fr.ids), alltogether)

            PreSnap = (radiomodel.PiggyBagSnap(PreSnap[0], extended=True), PreSnap[1])
            if verbose:
                print(' ___ Particles in snap ___ :', PreSnap[0].radi.shape)  # DEBUGGING

            """ now we'll assign functions to the pool """
            inargs = (PreSnap, pase, realisations, survey)  #(radiocube, B0, kappa, z, strSn, interpolate)  # , int(TestPar(pase['default']))
            stage1_outSmall, smt_small = RadioAndMock_loaded(inargs, verbose=verbose)
            smt.MergeSMT_simple(smt_small)

            mupro_Output_NicePickleClusters([stage1_outSmall], survey.outfolder)
            """ pickles a bunch of single galaxy clusters, they are latter joined into a survey """
            """ It should also pickle the corresponding fits images (in case of a detection) """

          
            """ Block BEGIN: If you choose a poor model then you might end up with way more relic clusters then expected. 
                I presume that those both slows down the process and leads to working memory issues.
                To prevent this I stop the computation if the weighted relic count is way higher than the expected relic count.
                In this case I should let the procedure stop early and  give it the minimum score in the metric ...(also in the metric test)
            """
            for gcl_test in stage1_outSmall[0]:
                # print(survey.outfolder, gcl_test.stoch_drop(survey.seed_dropout))
                count_relics_now = len(gcl_test.filterRelics(**survey.relic_filter_kwargs))
                if count_relics_now > 0:
                    count += 1
                    count_relics += count_relics_now
                    #print(count, count_relics)
                if count > countmax or count_relics > countmax_relics:
                    print('Because the number of relics already now is larger than %i the function DoRun() is terminated.' % countmax_relics)
                    return False, smt
            """  Block END """

            realisations = []  # Clear rotations of clusters, so that append, can work for a new try, ...
            # formerly: del realisations


    if verbose: print("#=== Proccesses completed. Please check for the data output.'")
    if verbose: smt(forced=True)

    return False, smt
Пример #4
0
def main(parfile, workdir=None, ABC=None, verbose=False, survey=None, index=None, Clfile='clusterCSV/MUSIC2-AGN',
         processTasks=True):

    """
    input: parameter file:
           ABC  : None or a list of parameters (what a pity that a dictionary is not possible with the current abcpmc or ABCpmc module)

    output: some strings to track down the output directories

    once a survey is not None all the default survey values will be used;
    i.e. the parfile will be considered much
    For future: - delete survey findings (or add for different detection parameter)
                or make the Rmodel changeable

    If pase['default'] is False then a run will be made with one shell and one single cluster realisation per snapshot

    For abcpmc MUSIC-2 vanilla use MUSIC2-AGN for clusterCSV and MUSIC2_NVSS02_SSD.parset for parset
               MUSIC-2cooling  use MUSIC2-AGN for clusterCSV and MUSIC2COOL_NVSS.parset         for parset
    """
    RModelID = os.getpid()  # get process id

    seed = random.randrange(4294967295)
    np.random.seed(seed=seed)

    """also possible : np.random.seed(seed=None) 
    ... this here is only to save the seed, which is not needed, because all the random stuff can be reconstructed from the cluster statistics

    processes from random are well seeded even without this, somehow numpy needs this kind of seed
    but only in abcpmc and not ABC

    import random
    random.randrange(sys.maxsize)
    """

    # ===  Read parset; then extract fundamental parameters ... Parset OBLIGATORY has be saved as  'parsets/*.parset'
    if workdir is None: workdir = os.path.dirname(__file__) + '/'
    pase, Z = suut.interpret_parset(parfile, repository=workdir + '/parsets/')
    # TODO: workdir should be the same as pase['miscdir'] yet the issue is that it is unknown before miscdir is known.

    if survey is None:
        surveyN = parfile.replace('.parset', '')
        savefolder = pase['outf'] + surveyN
        logfolder = pase['outf'] + surveyN
    else:
        surveyN = survey.name
        savefolder = survey.outfolder
        logfolder = survey.logfolder

    # Constants
    # ==== Cosmological Parameter - MUSIC-2
    Omega_M = 0.27  # Matter density parameter

    # === Create folder if needed
    iom.check_mkdir(savefolder)
    iom.check_mkdir(logfolder)

    smt = iom.SmartTiming(rate=pase['smarttime_sub'], logf=savefolder + '/smt');
    smt(task='Prepare_Clusters')

    # === Create detection information
    dinfo = cbclass.DetInfo(beam=[float(pase['S_beam']), float(pase['S_beam']), 0], spixel=float(pase['S_pixel']),
                            rms=float(pase['RMSnoise']) * 1e-6,
                            limit=float(pase['RMSnoise']) * float(pase['Detthresh']) * 1e-6,
                            nucen=float(pase['nu_obs']), center=(0, 0), survey='UVcoverage')

    if survey is None:
        """Create all galaxy clusters:
            All these steps are to decide which clusters to use. Better placement: in SurveyUtils"""

        """ Read the cluster lists from MUSIC-2 for all snapshots """
        all_clusters = pd.read_csv('%s%s_allclusters.csv' % (pase['miscdata'], Clfile))
        if verbose:
            all_clusters.info()
        zsnap_list = pd.Series(all_clusters['redshift'].unique())
        snapidlist = pd.Series(all_clusters['snapID'].unique())
        clusterIDs = list(all_clusters['clID'].unique())
        NclusterIDs = [len(all_clusters[all_clusters['redshift'] == z]) for z in zsnap_list]
        misslist = np.loadtxt(pase['miscdata'] + pase['missFile'])
        """ e.g. cluster 10# was not (re)simulated, in neither of the MUSIC-2 simulations (also 7 has some issues?)"""

        GClList = []

        if pase['snaplistz'] != 'None':

            snaplistz = [float(z) for z in iom.str2list(pase['snaplistz'])]
            snapidlist = [float(z) for z in iom.str2list(pase['snapidlist'].replace(' ', ''))]

            zsnap_list = (snaplistz[::-1])[0:11]  # 0:17 List of available sn [0:11]
            snapidlist = (snapidlist[::-1])[0:11]  # 0:17 [0:11]

            NclusterIDs = [len(all_clusters['clID'].unique().tolist())] * len(snaplistz)
            if verbose: print('NclusterIDs', NclusterIDs[0])

        use_list = [True] * len(zsnap_list)  # Also put some False, you don't really want to use the z=4.0 snapshots!
        Vsimu = (1.0 / (myu.H0 / 100.)) ** 3  # Gpc**3 comoving volume

        """ Iterate trough each shell of your z-onion and attribute clusters to them
            with z-range and percentage of covered sky, we have z=0.1
        """
        if not suut.TestPar(pase['default']):
            N_shells = 1
        else:
            N_shells = float(pase['N_shells'])

        shells_z, delta_z = np.linspace(Z[0], Z[1], num=N_shells + 1, retstep=True)
        cosmo = FlatLambdaCDM(H0=myu.H0, Om0=Omega_M)
        DCMRs = cosmo.comoving_volume(shells_z).value / 1e9
        count = 0

        for (zlow, zhigh, VCMlow, VCMhigh) in zip(shells_z[0:-1], shells_z[1:], DCMRs[0:-1], DCMRs[1:]):

            """ Iterate through each shell of the observed volume 
                and assign clusters
            """

            boundaries_z = (zlow, zhigh)
            VCM = (VCMlow, VCMhigh)
            z_central = np.mean(boundaries_z)
            if not suut.TestPar(pase['default']):
                z_central = 0.051
            choosen = suut.assign_snaps(zsnap_list, boundaries_z, VCM[1] - VCM[0], NclusterIDs,
                                        sigma_z=float(pase['sigma_z']),
                                        skycoverage=float(pase['surv_compl']), Vsimu=Vsimu, use_list=use_list,
                                        fake=(not suut.TestPar(pase['default'])), logmode=None)

            for (snap, kk) in choosen:
                l = all_clusters[(all_clusters["clID"] == clusterIDs[kk])
                                 & (all_clusters["snapID"] == snapidlist[snap])]
                """ It would be good if you could directly access the element like in an ordered list, 
                    as this would dramatically speed up the process
                """

                """ Skips missing snapshots --> they will also miss in the .csv"""
                if len(l) == 0:
                    if verbose:
                        print('__ Missing snapshot:', clusterIDs[kk], snapidlist[snap])
                    continue

                ids = int(l["clID"])
                M200 = float(l["M200"])

                # Filter for the cluster masses. Please mind that this filtering step is also redshift dependent
                if suut.TestPar(pase['empicut']) and np.log10(M200) < (13.6 + 2 * z_central):
                    continue

                count += 1

                # Decide on the projection of the cluster
                # it would be great if a random initializer between 0 and 1 could have been saved,
                if suut.TestPar(pase['rotation']):
                    theta = np.arccos(uniform(0, 2) - 1)
                    phi = uniform(0, 2 * np.pi)
                    psi = uniform(0, 2 * np.pi)
                else:
                    theta = 0
                    phi = 0
                    psi = 0

                # Create mockObs and the galaxyCluster_simulation
                mockObs = cbclass.MockObs(count, theta=theta, phi=phi, psi=psi, snap=snapidlist[snap],
                                          z_snap=zsnap_list[snap], clid=ids,
                                          snapfolder=pase['xrayfolder'], xrayfolder=pase['xrayfolder'],
                                          headerc=pase['headerC'])
                GClList.append(
                    cbclass.Galaxycluster_simulation("MUSIC2%05i-%06i-%06i" % (ids, snapidlist[snap], count), count,
                                                     z=z_central, M200=M200, dinfo=dinfo,
                                                     mockobs=mockObs))  # , **addargs

        # Also create a list of the chosen clusters for later loockup
        GClList = sorted(GClList, key=lambda x: (x.mockobs.clid, -x.mockobs.snap))

        if verbose: print('Length of GClList:', len(GClList))
        """ New approach: Create a list of modes for the radio emission (Rmodels)
        """
        surmodel = None
        if ABC is None:
            """CAVEAT: The issue with the currently used ABC routines is that you have to give them arrays. Which is why 
               the corresponding model associated has to be defined at this layer.
               Giving the procedure a function which would create this array would allow all of this to be defined 
               in the top layer of ABC
            """

            RModel = cbclass.RModel(RModelID, effList=[float(pase['eff'])], B0=float(pase['B0']),
                                    kappa=float(pase['kappa']), compress=float(pase['compress']))

            if suut.TestPar(pase['redSnap']):
                RModel.effList = RModel.effList[0]
        elif len(ABC) == 1:
            """ Vary only efficiency """
            (lgeff) = ABC
            RModel = cbclass.RModel(RModelID, effList=[10 ** lgeff], B0=1, kappa=0.5, compress=float(pase['compress']))
        elif len(ABC) == 2:
            """ Vary efficiency and B0"""
            (lgeff, lgB0) = ABC
            RModel = cbclass.RModel(RModelID, effList=[10 ** lgeff], B0=10 ** lgB0, kappa=0.5,
                                    compress=float(pase['compress']))
            print('#== Begin Processing task')
        elif len(ABC) == 3:
            """ Varies the standard model """
            (lgeff, lgB0, kappa) = ABC
            RModel = cbclass.RModel(RModelID, effList=[10 ** lgeff], B0=10 ** lgB0, kappa=kappa,
                                    compress=float(pase['compress']))
        elif len(ABC) == 4:
            """ Varies the standard model + detection probability """
            (lgeff, lgB0, kappa, survey_filter_pca_b) = ABC
            RModel = cbclass.RModel(RModelID, effList=[10 ** lgeff], B0=10 ** lgB0, kappa=kappa,
                                    compress=float(pase['compress']))
            surmodel = cbclass.SurModel(b=survey_filter_pca_b)
        elif len(ABC) == 6:
            (lgeff, lgB0, kappa, lgt0, lgt1, lgratio) = ABC
            RModel = cbclass.PreModel_Hoeft(RModelID, effList=[10 ** lgeff], B0=10 ** lgB0, kappa=kappa,
                                            compress=float(pase['compress']), t0=10**lgt0, t1=10**lgt1, ratio=10**lgratio)
            Rm = RModel
        elif len(ABC) == 7:
            (lgeff, lgB0, kappa, survey_filter_pca_b, lgratio, lgt0, lgt1) = ABC
            RModel = cbclass.PreModel_Hoeft(RModelID, effList=[10 ** lgeff], B0=10 ** lgB0, kappa=kappa,
                                            compress=float(pase['compress']), t0=10 ** lgt0, t1=10 ** lgt1,
                                            ratio=10 ** lgratio)
            Rm = RModel
            surmodel = cbclass.SurModel(b=survey_filter_pca_b)
        else:
            print('RunSurvey::main: model unknown')
            return


        """ Create survey """
        outfolder = '%s_%05i/' % (logfolder, RModelID)
        survey = cbclass.Survey(GClList, survey='%s' % (parfile.replace('.parset', '')),
                                emi_max=float(pase['RMSnoise']) * 1e-3 * 200,
                                cnt_levels=[float(pase['RMSnoise']) * 2 ** i for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
                                saveFITS=(ABC is None), savewodetect=suut.TestPar(pase['savewodetect']), dinfo=dinfo,
                                surshort='MUSIC2', Rmodel=RModel, outfolder=outfolder, logfolder=logfolder)
        survey.set_surmodel(surmodel)
        survey.set_seed_dropout()
    else:
        """ If you directly loaded a survey, just use its internal Rmodel """
        RModel = survey.Rmodel

    if verbose: print('Outfolder:', survey.outfolder)

    """=== Create a Task Cube, modify it & save it 
    The function of this Taskcube formerly was to keep track of all the computations that were already done in my multiproccecing version of ClusterBuster 
    Now it is outdated and isn't maintained anymore. After a BUG I didn't want to fix I decommisened this functionality
    """

    Taskcube = np.zeros((len(survey.GCls), len([RModel])))
    # A cube of all possible entries , efficiency is always fully computed and thus not in the Taskcube

    if suut.TestPar(pase['reCube']):
        Taskcube = np.load(logfolder + '/TaskCube.npy')
        smt.MergeSMT_simple(iom.unpickleObject(logfolder + '/smt'))
    if int(pase['reCL']) + int(pase['reRM']) > 0:
        for (GCl_ii, RModelID), status in np.ndenumerate(Taskcube[:, :]):
            if verbose: print('GCl_ii, RModelID:', GCl_ii, RModelID)
            if GClList[GCl_ii].mockobs.clid > int(pase['reCL']) and int(pase['reRM']):
                break
            else:
                Taskcube[GCl_ii, RModelID] = 1
    np.save(logfolder + '/TaskCube',
            Taskcube)  # also to be pickled/saved: Levels Cluster&TaskID --> B0, kappa, (z) -->  eff0
    """"""

    if verbose: print('#== Begin Processing task')

    """ This is the most important task! """
    while processTasks:
        processTasks, smt = DoRun((pase, survey), smt, verbose=verbose)

    print('RModelID %i of run %s finished' % (RModelID, surveyN))
    return survey
Пример #5
0
def RadioAndMock(val, verbose=True):
    smt = iom.SmartTiming()
    smt(task='RadioAndMock_initialization')

    (pase, realisations, survey) = val
    Rmodel = survey.Rmodel

    PreSnap, smt_add = LoadSnap_multiprocessing(pase, realisations, Rmodel)

    if len(PreSnap) > 0:
        snapMF = PreSnap
        (radiosnap, subsmt) = radiomodel.CreateRadioCube(snapMF, Rmodel, realisations[0].mockobs.z_snap, nuobs=pase['nu_obs'])[0:2]
        smt.MergeSMT_simple(subsmt, silent=True) 

    """ This weird interresult comes from
        output.put( outp + (Rmodel,)) #Rmodel is added to the tuple
        (radiocube, subsmt, Rmodel) = stage1_out.get()
        stage1_list.append( ( radiocube, Rmodel, survey) )
    """
    radiocube = (radiosnap, Rmodel, survey) #Rmodel is added to the tuple


    ##=== Stage II - DoMockObs
    if verbose: print('Start compiling MockObservations for further models of cluster #%5i and snap #%3i with in total %i realisations.' % (realisations[0].mockobs.clid , realisations[0].mockobs.snap,  len(realisations)))


    smt(task='Shed_DoMockObs') 
    # This result of this computation is  independent of rotation and because of this was put here
    for kk, real in enumerate(realisations): # update information on the total radio power (at the rest frame frequency) in the simulational volume
             """ This is wrong and has to be fixed in the future!!!! """
             
             """ also possible: realisations[kk].Rvir       = radiocube[0].head['Rvir']"""
             if realisations[kk].M200.value == 0:
                 try:
                     realisations[kk].M200.value = radiocube[0].head['M200']
                 except:
                     realisations[kk].Mvir.value = radiocube[0].head['Mvir']
                 realisations[kk].updateInformation(massproxis=True)
             
    """ Here we compute the volume weighted radio emission """         
    radiosum  = np.sum(radiocube[0].radi)
    borders   = 2*realisations[0].R200*radiocube[0].head ['hubble']/radiocube[0].head ['aexpan']
    whereR200 = np.where( np.sqrt(np.power(radiocube[0].pos[:,0],2) + np.power(radiocube[0].pos[:,1],2) + np.power(radiocube[0].pos[:,2],2) ) < borders/2 )
    radiosum_R200 = np.sum(radiocube[0].radi[whereR200])

    # update information on the total radio power (at the rest frame frequency) in the simulational volume
    for kk,real in enumerate(realisations):
         realisations[kk].P_rest.value    = radiosum       # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction
         realisations[kk].Prest_vol.value = radiosum_R200  # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction

    smt(task='Shed_DoMockObs_misc')
    locations = [survey.outfolder]
    
    if not suut.TestPar(pase['cutradio']):
        radiocubeUse = radiocube
    else:  
        print('Beware, This is slow and should not be paralised!!!! This part is not implemented')
        radiocubeUse = None #radiomodel.PiggyBagSnap_cut(snap, radiocube[0], float(pase['cutradio'])),Rmodel,survey)]
    (nouse, subsmt, GClrealisations_used, Rmodel) = mockobs.Run_MockObs(radiocubeUse, realisations, saveFITS=survey.saveFITS, savewodetect=survey.savewodetect, writeClusters=True) #Mach=pase['Mach'], Dens=pase['Dens'],
    smt.MergeSMT_simple(subsmt, silent=True)

    return (GClrealisations_used,  Rmodel), smt
Пример #6
0
def RadioAndMock_loaded(val, verbose=True):
    smt = iom.SmartTiming()
    smt(task='RadioAndMock_initialization')                
    (snapMF,  pase, realisations, survey) = val
    Rmodel = survey.Rmodel

    ##=== Stage II - DoMockObs
    if verbose:
        print('Start compiling MockObservations for further models of cluster #%5i snap #%3i with in total %i realisations.'
              % (realisations[0].mockobs.clid, realisations[0].mockobs.snap, len(realisations)))

    GClrealisations_return = []
    smt(task='Shed_DoMockObs_misc') 
    # This result of this computation is  independent of rotation and because of this was put here
    
    for kk, realisation in enumerate(realisations): # update information on the total radio power (at the rest frame frequency) in the simulational volume
        """ This is wrong and has to be fixed in the future!!!! 
        Currently, we make this code really SMELLY and hard to understand
        """
        (radiosnap, subsmt, poisson_factor) = radiomodel.CreateRadioCube(snapMF, Rmodel, realisation.mockobs.z_snap,
                                                         nuobs=pase['nu_obs'], logging=False)[0:3]
        smt.MergeSMT_simple(subsmt, silent=True)

        """ also possible: realisations[kk].Rvir       = radiocube[0].head['Rvir']"""
        if realisations[kk].M200.value == 0:
            try:
                realisations[kk].M200.value = radiosnap.head['M200']
            except:
                realisations[kk].Mvir.value = radiosnap.head['Mvir']
            realisations[kk].updateInformation(massproxis=True)

        """ Here we add the radio emission due to pre-existing electrons """
        if isinstance(Rmodel, cbclass.PreModel_Gelszinnis):
            randfactor = 10**np.random.normal(0, Rmodel.p_sigma, 1)
            realisation.PreNorm = randfactor*Rmodel.p0
            radiosnap.radiPre += realisations.PreNorm * radiosnap.radiPre
        elif isinstance(Rmodel, cbclass.PreModel_Hoeft):
            realisation.poisson_factor = poisson_factor

        """ Here we compute the volume weighted radio emission """   
        radiosum      = np.sum(radiosnap.radi)
        borders       = 2*realisations[0].R200*radiosnap.head ['hubble']/radiosnap.head ['aexpan']
        whereR200     = np.where(np.sqrt(np.power(radiosnap.pos[:,0], 2) + np.power(radiosnap.pos[:,1], 2)
                                         + np.power(radiosnap.pos[:,2], 2)) < borders/2)
        radiosum_R200 = np.sum(radiosnap.radi[whereR200])
        # update information on the total radio power (at the rest frame frequency) in the simulational volume
        realisations[kk].P_rest.value    = radiosum       # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction
        realisations[kk].Prest_vol.value = radiosum_R200  # This is for a frequency differing from 1.4 GHz and an efficiency of 1, in PostProcessing.py we apply a further correction

        if not suut.TestPar(pase['cutradio']):

            radiosnapUse = copy.deepcopy(radiosnap)
            if hasattr(radiosnapUse, 'radiPre'):
                radiosnapUse.radi += radiosnapUse.radiPre
                #print('Run_MockObs:: Ratio of PREs to total emission', (np.sum(radiosnapUse.radiPre)) / (np.sum(radiosnapUse.radi) + np.sum(radiosnapUse.radiPre)))

            radiocube = (radiosnapUse, Rmodel, survey)  # Rmodel is added to the tuple
        else:
            print('Beware, This is slow and should not be paralised!!!! This part is not implemented')
            radiocube = (radiosnap, Rmodel, survey)  # Rmodel is added to the tuple

        smt(task='Shed_DoMockObs')
        (nouse, subsmt, GClrealisation_used, Rmodel) = mockobs.Run_MockObs(radiocube, [realisation],
                                                                           saveFITS=survey.saveFITS,  savewodetect=survey.savewodetect,
                                                                           side_effects=True)
        GClrealisations_return += GClrealisation_used
        smt.MergeSMT_simple(subsmt, silent=True)
        
    return (GClrealisations_return, Rmodel), smt