Exemplo n.º 1
0
    def calculate(self, **kwargs): 
        ''' Calculate power/bispectrum for catalog 
        '''
        
        # FFt files
        D_fft = spec_fft.FFT('data', self.catalog, **kwargs)
        D_fft_file = D_fft.file_name 
        
        R_fft = spec_fft.FFT('random', self.catalog, **kwargs)
        R_fft_file = R_fft.file_name 

        # if FFT file does not exist
        if not os.path.isfile(D_fft_file): 
            D_fft.calculate()

        if not os.path.isfile(R_fft_file): 
            R_fft.calculate()

        spec_code = spec_fort.fortran_code(self.Type, self.catalog, **kwargs)
        spec_exe = spec_fort.fortran_code2exe(spec_code)
    
        # code and exe modification time 
        spec_code_mod_time = os.path.getmtime(spec_code)
        if not os.path.isfile(spec_exe): 
            spec_exe_mod_time = 0 
        else: 
            spec_exe_mod_time = os.path.getmtime(spec_exe)

        # if code was changed since exe file was last compiled then 
        # compile spec code 
        if spec_exe_mod_time < spec_code_mod_time: 
            spec_fort.compile_fortran_code(spec_code) 
    
        spec = self.catalog['spec']
        if self.Type == 'power': 
            # power spectrum code input: 
            #    random fft file, data fft file, powerspectrum file, Lbox, Nbins  
            spec_cmd = ' '.join([spec_exe, 
                R_fft_file, D_fft_file, self.file_name, str(spec['sscale']), str(spec['grid']/2)
                ]) 

        elif self.Type == 'bispec':     # bispectrum 
            # double check that the counts are there
            # hardcoded
            count_file = '/home/users/rs123/Code/Fortran/counts2quad_n360_nmax40_ncut3_s3'
            self.count_file = count_file 

            if not os.path.isfile(count_file): 
                raise NotImplementedError('Count File does not exist') 

            # bispectrum code input: 
            #   period/data, random fft file, data fft file, bispectrum file  
            spec_cmd = ' '.join([spec_exe, 
                '2', R_fft_file, D_fft_file, self.file_name]) 

        print spec_cmd  
        subprocess.call(spec_cmd.split()) 
            
        return None  
Exemplo n.º 2
0
    def calculate(self, **kwargs):
        ''' Calculate FFT 

        Notes 
        -----
        * bash command for version 5 FFT code is of the form : 
         FFT_FKP_BOSS_cic_il4_v5.exe idata box Ngrid interpol iflag P0  ifc icomp input_file {izbin} output_file
        
        * icomp is hardcoded 0 so that it takes into account completeness!
        '''
        spec = self.catalog['spec']

        FFT_code = spec_fort.fortran_code('fft', self.catalog, **kwargs)
        FFT_exe = spec_fort.fortran_code2exe(FFT_code)  # exe file

        # code and exe modification time to make sure that the exe file is up to date
        FFT_code_mod_time = os.path.getmtime(FFT_code)
        if not os.path.isfile(FFT_exe):
            FFT_exe_mod_time = 0
        else:
            FFT_exe_mod_time = os.path.getmtime(FFT_exe)

        # if code was changed since exe file was last compiled then compile fft code
        if FFT_exe_mod_time < FFT_code_mod_time:
            spec_fort.compile_fortran_code(FFT_code)

        fft_file = self.file_name
        print 'CONSTRUCTING'
        print '============'
        print fft_file
        print ''
        print ''

        if self.Type == 'data':
            N_DorR = 0
        elif self.Type == 'random':
            N_DorR = 1

        cat = self.catalog['catalog']
        # determine "idata"
        if 'cmass' in cat['name'].lower():
            idata = 1
            ifc = 0
        elif cat['name'].lower() == 'lasdamasgeo':
            idata = 2
            ifc = 0
        elif cat['name'].lower() == 'qpm':
            idata = 3
            ifc = 0
        elif cat['name'].lower() == 'patchy':
            idata = 6
            ifc = 0
            izbin = 3  # only for patchy
        elif cat['name'].lower() == 'nseries':
            idata = 9
            ifc = 0
        else:
            raise NameError('Not yet included in FFT code')

        # Bash command for version 5 of FFT code
        FFT_cmd = ' '.join([
            FFT_exe,
            str(idata),
            str(spec['box']),
            str(spec['grid']), "4",
            str(N_DorR),
            str(spec['P0']),
            str(ifc), "0", self.data_file, fft_file
        ])
        if cat['name'].lower() == 'patchy':
            FFT_cmd = ' '.join([
                FFT_exe,
                str(idata),
                str(spec['box']),
                str(spec['grid']), "4",
                str(N_DorR),
                str(spec['P0']),
                str(ifc), "0", self.data_file, "3", fft_file
            ])
        print FFT_cmd

        # Call FFT command
        if self.Type == 'data':
            # don't bother checking if the file exists for mocks and run the damn thing
            subprocess.call(FFT_cmd.split())
        elif self.Type == 'random':
            # random takes longer so check to see if it exists first
            if not os.path.isfile(fft_file) or kwargs['clobber']:
                print "Building ", fft_file
                subprocess.call(FFT_cmd.split())
            else:
                print fft_file, " already exists"
        return None
Exemplo n.º 3
0
    def calculate(self, **kwargs): 
        ''' Calculate FFT 

        Notes 
        -----
        * bash command for version 5 FFT code is of the form : 
         FFT_FKP_BOSS_cic_il4_v5.exe idata box Ngrid interpol iflag P0  ifc icomp input_file {izbin} output_file
        
        * icomp is hardcoded 0 so that it takes into account completeness!
        '''
        spec = self.catalog['spec']

        FFT_code = spec_fort.fortran_code('fft', self.catalog, **kwargs)
        FFT_exe = spec_fort.fortran_code2exe(FFT_code)            # exe file 
    
        # code and exe modification time to make sure that the exe file is up to date
        FFT_code_mod_time = os.path.getmtime(FFT_code)
        if not os.path.isfile(FFT_exe): 
            FFT_exe_mod_time = 0 
        else: 
            FFT_exe_mod_time = os.path.getmtime(FFT_exe)

        # if code was changed since exe file was last compiled then compile fft code 
        if FFT_exe_mod_time < FFT_code_mod_time: 
            spec_fort.compile_fortran_code(FFT_code) 
            
        fft_file = self.file_name    
        print 'CONSTRUCTING'
        print '============'
        print fft_file 
        print ''
        print ''

        if self.Type == 'data': 
            N_DorR = 0
        elif self.Type == 'random': 
            N_DorR = 1
    
        cat = self.catalog['catalog']
        # determine "idata"
        if 'cmass' in cat['name'].lower(): 
            idata = 1 
            ifc = 0 
        elif cat['name'].lower() == 'lasdamasgeo': 
            idata = 2
            ifc = 0 
        elif cat['name'].lower() == 'qpm': 
            idata = 3 
            ifc = 0 
        elif cat['name'].lower() == 'patchy': 
            idata = 6
            ifc = 0 
            izbin = 3   # only for patchy 
        elif cat['name'].lower() == 'nseries': 
            idata = 9 
            ifc = 0 
        else: 
            raise NameError('Not yet included in FFT code') 
        
        # Bash command for version 5 of FFT code 
        FFT_cmd = ' '.join([
            FFT_exe, 
            str(idata), 
            str(spec['box']), 
            str(spec['grid']), 
            "4", 
            str(N_DorR), 
            str(spec['P0']), 
            str(ifc), 
            "0", 
            self.data_file, fft_file]) 
        if cat['name'].lower() == 'patchy': 
            FFT_cmd = ' '.join([ FFT_exe, 
                str(idata), str(spec['box']), str(spec['grid']), "4", str(N_DorR), str(spec['P0']), str(ifc), "0", 
                self.data_file, "3", fft_file]) 
        print FFT_cmd
    
        # Call FFT command
        if self.Type == 'data':  
            # don't bother checking if the file exists for mocks and run the damn thing 
            subprocess.call(FFT_cmd.split()) 
        elif self.Type == 'random':      
            # random takes longer so check to see if it exists first
            if not os.path.isfile(fft_file) or kwargs['clobber']: 
                print "Building ", fft_file 
                subprocess.call(FFT_cmd.split())
            else: 
                print fft_file, " already exists" 
        return None  
Exemplo n.º 4
0
    def calculate(self, **kwargs):
        ''' Calculate power/bispectrum for catalog 
        '''

        # FFt files
        D_fft = spec_fft.FFT('data', self.catalog, **kwargs)
        D_fft_file = D_fft.file_name

        R_fft = spec_fft.FFT('random', self.catalog, **kwargs)
        R_fft_file = R_fft.file_name

        # if FFT file does not exist
        if not os.path.isfile(D_fft_file):
            D_fft.calculate()

        if not os.path.isfile(R_fft_file):
            R_fft.calculate()

        spec_code = spec_fort.fortran_code(self.Type, self.catalog, **kwargs)
        spec_exe = spec_fort.fortran_code2exe(spec_code)

        # code and exe modification time
        spec_code_mod_time = os.path.getmtime(spec_code)
        if not os.path.isfile(spec_exe):
            spec_exe_mod_time = 0
        else:
            spec_exe_mod_time = os.path.getmtime(spec_exe)

        # if code was changed since exe file was last compiled then
        # compile spec code
        if spec_exe_mod_time < spec_code_mod_time:
            spec_fort.compile_fortran_code(spec_code)

        spec = self.catalog['spec']
        if self.Type == 'power':
            # power spectrum code input:
            #    random fft file, data fft file, powerspectrum file, Lbox, Nbins
            spec_cmd = ' '.join([
                spec_exe, R_fft_file, D_fft_file, self.file_name,
                str(spec['sscale']),
                str(spec['grid'] / 2)
            ])

        elif self.Type == 'bispec':  # bispectrum
            # double check that the counts are there
            # hardcoded
            count_file = '/home/users/rs123/Code/Fortran/counts2quad_n360_nmax40_ncut3_s3'
            self.count_file = count_file

            if not os.path.isfile(count_file):
                raise NotImplementedError('Count File does not exist')

            # bispectrum code input:
            #   period/data, random fft file, data fft file, bispectrum file
            spec_cmd = ' '.join(
                [spec_exe, '2', R_fft_file, D_fft_file, self.file_name])

        print spec_cmd
        subprocess.call(spec_cmd.split())

        return None