def time_me(**kwargs):
    try:
        start = time.time()
        for _ in range(n_iter):
            pyprofit.make_model(kwargs)
        t = time.time() - start

        return timing_result(t / n_iter, None)
    except pyprofit.error as e:
        return timing_result(0, e)
Esempio n. 2
0
def to_pyprofit_image(params, data, use_mask=True):

    # merge, un-sigma all, un-log some
    sigmas_tofit = data.sigmas[data.tofit]
    allparams = data.model0.copy()
    allparams[data.tofit] = params * sigmas_tofit
    allparams[data.tolog] = 10**allparams[data.tolog]

    fields = ['xcen', 'ycen', 'mag', 're', 'nser', 'ang', 'axrat', 'box']
    s1params = [x for i, x in enumerate(allparams) if i % 2 == 0]
    s2params = [x for i, x in enumerate(allparams) if i % 2 != 0]
    if hasattr(data, 'psf') and len(data.psf) > 0:
        fields.append('convolve')
        s1params.append(True)
        s2params.append(True)

    sparams = [{name: val
                for name, val in zip(fields, params)}
               for params in (s1params, s2params)]
    if data.verbose:
        print(sparams)

    profit_model = {
        'width': data.image.shape[1],
        'height': data.image.shape[0],
        'magzero': data.magzero,
        'psf': data.psf,
        'profiles': {
            'sersic': sparams
        }
    }
    if use_mask:
        profit_model['calcmask'] = data.calcregion
    return allparams, np.array(pyprofit.make_model(profit_model))
Esempio n. 3
0
def to_pyprofit_image(params, data, use_mask=True):

    # merge, un-sigma all, un-log some
    sigmas_tofit = data.sigmas[data.tofit]
    allparams = data.model0.copy()
    allparams[data.tofit] = params * sigmas_tofit
    allparams[data.tolog] = 10**allparams[data.tolog]

    fields = ['xcen','ycen','mag','re','nser','ang','axrat','box']
    s1params = [x for i,x in enumerate(allparams) if i%2 == 0]
    s2params = [x for i,x in enumerate(allparams) if i%2 != 0]
    if hasattr(data, 'psf') and len(data.psf) > 0:
        fields.append('convolve')
        s1params.append(True)
        s2params.append(True)

    sparams = [{name: val for name, val in zip(fields, params)} for params in (s1params, s2params)]
    if data.verbose:
        print sparams

    profit_model = {'width':  data.image.shape[1],
                    'height': data.image.shape[0],
                    'magzero': data.magzero,
                    'psf': data.psf,
                    'profiles': {'sersic': sparams}
                   }
    if use_mask:
        profit_model['calcmask'] = data.calcregion
    return allparams, np.array(pyprofit.make_model(profit_model))
Esempio n. 4
0
def make_image_from_profiles(profiles, allparams, haspsf, data, use_calcinvmask=None):
    if use_calcinvmask is None:
        use_calcinvmask = False
    if data.verbose:
        print(zip(data.names, allparams))

    profit_model = {
        'width':  data.image.shape[1],
        'height': data.image.shape[0],
        'magzero': data.magzero,
        'profiles': profiles
    }
    if haspsf:
        profit_model["psf"] = data.psf

    if use_calcinvmask:
        profit_model['calcmask'] = data.calcinvmask
    if data.engine == "libprofit":
        model = np.array(pyprofit.make_model(profit_model)[0])
    else:
        # TODO: Change this to the model image size
        model = make_model_galsim(
            profit_model["profiles"], data.psf, data.image.shape[0], data.image.shape[1])
        model = make_model_image_galsim(model, data.modelimage, method=data.method)
    return allparams, model
Esempio n. 5
0
def variate(param, start, stop, step):
    for b in np.arange(start, stop, step):
        sp[param] = b
        image = np.array(pyprofit.make_model(model))  # @UndefinedVariable
        w = png.Writer(width, height, greyscale=True)
        with open("/dev/stdout", 'w') as f:
            w.write(f, loggray(image))
            f.flush()
Esempio n. 6
0
def variate(param, start, stop, step):
    for b in np.arange(start, stop, step):
        sp[param] = b
        image = np.array(pyprofit.make_model(model))  # @UndefinedVariable
        w = png.Writer(width, height, greyscale=True)
        with open("/dev/stdout", 'w') as f:
            w.write(f, loggray(image))
            f.flush()
Esempio n. 7
0
 def generate_mass_map(self, shape, convolve_func):
     '''
     gemerate the mass distribution map for a galaxy object
     shape: return 2D image shape
     convolve_func: a 2D kernel if convolution is needed
     '''
     mags = np.array(self.maglist)
     magzero = 2.5 * np.log10(
         self.mass / np.sum(np.power(10, mags / (-2.5))))
     profit_model = {
         'width': shape[1],
         'height': shape[0],
         'magzero': magzero,
         'psf': convolve_func,
         'profiles': self.subCs
     }
     image, _ = pyprofit.make_model(profit_model)
     return image
Esempio n. 8
0
 def generate_SED_IFU(self, shape, convolve_func, wavelength):
     '''
     gemerate the SED IFU for a galaxy object
     shape: return 2D spatial shape
     convolve_func: a 2D kernel if convolution is needed
     wavelength: 1D array, the wavelength sample
     '''
     ny = shape[0]
     nx = shape[1]
     mags = np.array(self.maglist)
     magzero = 2.5 * np.log10(
         self.mass / np.sum(np.power(10, mags / (-2.5))))
     tot_IFU = np.zeros((len(wavelength), ny, nx))
     for key in self.subCs:
         for loop in range(len(self.subCs[key])):
             params = self.subCs[key][loop]
             profit_model = {
                 'width': nx,
                 'height': ny,
                 'magzero': magzero,
                 'psf': convolve_func,
                 'profiles': {
                     key: [params]
                 }
             }
             mass_map, _ = pyprofit.make_model(profit_model)
             sub_IFU = np.zeros((len(wavelength), ny, nx))
             xaxis = np.arange(nx)
             yaxis = np.arange(ny)
             xmesh, ymesh = np.meshgrid(xaxis, yaxis)
             r = np.sqrt((xmesh + 0.5 - self.subCs[key][loop]['xcen'])**2. +
                         (ymesh + 0.5 - self.subCs[key][loop]['ycen'])**2.)
             age_map = Cal_map(r, self.ageparams[key][loop]['type'],
                               self.ageparams[key][loop]['paradic'])
             Z_map = Cal_map(r, self.Zparams[key][loop]['type'],
                             self.Zparams[key][loop]['paradic'])
             for loopy in range(ny):
                 for loopx in range(nx):
                     sub_IFU[:, loopy, loopx] = sed_bc03(
                         wavelength, Z_map[loopy][loopx],
                         age_map[loopy][loopx],
                         np.log10(mass_map[loopy][loopx]))
             tot_IFU += sub_IFU
     return tot_IFU
 def pyprofit_wrap():
     return pyprofit.make_model(kwargs)