Example #1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.normalization = self.compute_normalization()

        self.model_1d = models.Sersic1D(self.amplitude, self.r_eff, self.n)
Example #2
0
 astmodels.Gaussian2D(amplitude=10.,
                      x_mean=5.,
                      y_mean=5.,
                      x_stddev=3.,
                      y_stddev=3.),
 astmodels.KingProjectedAnalytic1D(amplitude=10., r_core=5., r_tide=2.),
 astmodels.Logarithmic1D(amplitude=10., tau=3.5),
 astmodels.Lorentz1D(amplitude=10., x_0=0.5, fwhm=2.5),
 astmodels.Moffat1D(amplitude=10., x_0=0.5, gamma=1.2, alpha=2.5),
 astmodels.Moffat2D(amplitude=10., x_0=0.5, y_0=1.5, gamma=1.2, alpha=2.5),
 astmodels.Planar2D(slope_x=0.5, slope_y=1.2, intercept=2.5),
 astmodels.RedshiftScaleFactor(z=2.5),
 astmodels.RickerWavelet1D(amplitude=10., x_0=0.5, sigma=1.2),
 astmodels.RickerWavelet2D(amplitude=10., x_0=0.5, y_0=1.5, sigma=1.2),
 astmodels.Ring2D(amplitude=10., x_0=0.5, y_0=1.5, r_in=5., width=10.),
 astmodels.Sersic1D(amplitude=10., r_eff=1., n=4.),
 astmodels.Sersic2D(amplitude=10.,
                    r_eff=1.,
                    n=4.,
                    x_0=0.5,
                    y_0=1.5,
                    ellip=0.0,
                    theta=0.0),
 astmodels.Sine1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.Cosine1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.Tangent1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.ArcSine1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.ArcCosine1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.ArcTangent1D(amplitude=10., frequency=0.5, phase=1.),
 astmodels.Trapezoid1D(amplitude=10., x_0=0.5, width=5., slope=1.),
 astmodels.TrapezoidDisk2D(amplitude=10.,
def findHalfLightSersicdf(pgcs,df1,df2):
    #df1 is galbasedf with including r25- get pgc names from this file
    #df2 is pickle file
    
    halflights = []
    amps = []
    ns = []
    mses = []

    #print('0')
    for i in np.arange(len(pgcs)):
        print(len(pgcs)-i)
        galmask = df2.PGC.isin([pgcs[i]])
        rp = df2.loc[galmask]
        #print(rp)
        pgc=pgcs[i]
        
        if np.isnan(rp.r_arcsec).all()==True:
            halflights.append(np.nan)
            amps.append(np.nan)
            ns.append(np.nan)
            mses.append(np.nan)
            #print('1')
        elif rp.r_arcsec.min()>200:
            halflights.append(np.nan)
            amps.append(np.nan)
            ns.append(np.nan)
            mses.append(np.nan)

            #print('2')
        else:
            try:
                #print('3')
                rp.r_arcsec/=3600.
                r25 = df1.loc[i].R25_DEG
                #print(r25)`=-0
                #r25= r25.tolist()[0]
                #print(r25)
                mask = rp.r_arcsec<2*r25
                #print(mask)
                rp = rp[mask]
                
                #mask = rp.I>0
                #rp = rp[mask]
                ind = np.where(rp.r_arcsec<.5*r25)[0][-1]

                sersic = models.Sersic1D(bounds = {'n':(0,14)})
                outlier_fit = fitting.FittingWithOutlierRemoval(fitting.LevMarLSQFitter(),sigma_clip, niter=3, sigma=2.5)
                fitted_model,filtered_data = outlier_fit(sersic,rp.r_arcsec,rp.I)#,weights=0.1*rp.I)
                filtered_data[:ind]=False

                fit = fitting.LevMarLSQFitter()
                fitted_model = fit(sersic,rp.r_arcsec[~filtered_data],rp.I[~filtered_data])#,weights=(0.1*rp.I[~filtered_data]))
                mse = np.nanmean((rp.I[~filtered_data] - fitted_model(rp.I[~filtered_data]))**2)
                print('')
                print(pgc)
                #print(np.round(mse,decimals=2))
                
                """
                if mse>3.:
                    ns_mse = []
                    for n in nrange:
                        sersic = models.Sersic1D(bounds = {'n':(n,n+1)})
                        outlier_fit = fitting.FittingWithOutlierRemoval(fitting.LevMarLSQFitter(),sigma_clip, niter=3, sigma=3)
                        fitted_model,filtered_data_chisq = outlier_fit(sersic,rp.r_arcsec[~filtered_data],rp.I[~filtered_data])#,weights=(0.1*rp.I[~filtered_data]))
                        m = np.nanmean((rp.I[~filtered_data] - fitted_model(rp.I[~filtered_data]))**2)
                        if m<mse:
                            mse=m
                            ns_mse.append(n)
                            print(mse,n)
                        else:
                            pass
                    if len(ns_mse)==0:
                        print(ns_mse)
                        print('none better')
                        pass
                    else:
                        sersic = models.Sersic1D(bounds = {'n':(ns_mse[-1]-1,ns_mse[-1]+1)})
                        fitted_model = fit(sersic,rp.r_arcsec[~filtered_data],rp.I[~filtered_data])
                """
                re = np.round(fitted_model.r_eff.value*3600*0.9,decimals=3)
                #re*=0.9
                #re = np.round(re,decimals=3)
                n = np.round(fitted_model.n.value,decimals=3)
                #print(re,saloratio,mm15ratio)
                #print(n,mmres.n[i],np.round(mmres['T'][i],decimals=2))

                
                print(re)
                
                if re>250.:
                    halflights.append(np.nan)
                    amps.append('fit fail')
                    ns.append('fit fail')
                    mses.append('fit fail')
                    
                elif re<5.:
                    halflights.append(np.nan)
                    amps.append('fit fail')
                    ns.append('fit fail')
                    mses.append('fit fail')
                    
                else:
                    halflights.append(re)
                    amps.append(fitted_model.amplitude.value)
                    ns.append(n)
                    mses.append(mse)
            except:
                halflights.append(np.nan)
                amps.append('fit fail')
                ns.append('fit fail')
                mses.append('fit fail')


    redf = pd.DataFrame({'PGC':pgcs,'re':halflights,'amp': amps,'n':ns})
    #pgcs = np.asarray(pgcs)
    #halflights = np.asarray(halflights,dtype='float')
    #amps = np.asarray(amps)
    #ns = np.asarray(ns)
    #return(pgcs,halflights,amps,ns,datamasks,nummasked)
    return(redf)