In [17]:
import galsim
import numpy as np
import matplotlib.pyplot as plt

Define the Sersic model


In [61]:
gal_flux = 1.234e5
gal_rpix = 24.0 
gal_ns   = 2.5 
gal_ba   = 0.8 
gal_pa   = 45.0
  • Use the Sersic function to create a galaxy model

In [62]:
serModel = galsim.Sersic(gal_ns, half_light_radius=gal_rpix, flux=gal_flux)
print serModel.getFlux()
print serModel.centroid() 
print serModel.hasHardEdges() #Returns True if there are any hard edges in the profile, which would require very small k spacing when working in the Fourier domain


123400.0
(0.0, 0.0)
False
  • Use the shear function to apply axis ratio (q=b/a) to the Sersic model

In [63]:
serSBP = serModel.SBProfile

In [64]:
serModelAxis=serModel.shear(q=gal_ba, beta=0.0*galsim.degrees)
print serModelAxis.getFlux()
print serModelAxis.centroid()
print serModel.hasHardEdges()


123400.0
(0.0, 0.0)
False

In [65]:
serModelRotate=serModelAxis.rotate(gal_pa*galsim.degrees)
print serModelAxis.getFlux()
print serModelAxis.centroid()
print serModel.hasHardEdges()


123400.0
(0.0, 0.0)
False

In [66]:
serImg = serModel.drawImage()
serImgAxis = serModelAxis.drawImage()
serImgRotate = serModelRotate.drawImage()

In [71]:
plt.subplot(131)
plt.imshow(numpy.arcsinh(serImg.array))
plt.subplot(132)
plt.imshow(numpy.arcsinh(serImgAxis.array))
plt.subplot(133)
plt.imshow(numpy.arcsinh(serImgRotate.array))


Out[71]:
<matplotlib.image.AxesImage at 0x11da569d0>

In [75]:
serModel = galsim.Sersic(gal_ns, half_light_radius=gal_rpix, flux=gal_flux)
serModel = serModel.shear(q=gal_ba, beta=0.0*galsim.degrees)
serModel = serModel.rotate(gal_pa*galsim.degrees)
serImg = serModel.drawImage()
serImg.addNoise(galsim.PoissonNoise())
plt.figure(1, figsize=(5,5))
plt.imshow(numpy.arcsinh(serImg.array))
plt.savefig('/Users/songhuang/Downloads/temp.png')



In [77]:
serModel1 = galsim.Sersic(3.0, half_light_radius=8.00, flux=1.000e5)
serModel1 = serModel1.shear(q=0.9, beta=0.0*galsim.degrees)
serModel2 = galsim.Sersic(1.0, half_light_radius=45.0, flux=1.345e5)
serModel2 = serModel2.shear(q=0.4, beta=0.0*galsim.degrees)
serModel2 = serModel2.rotate(45.0*galsim.degrees)
serDouble = serModel1 + serModel2

In [80]:
fig, axes = plt.subplots(1, 3, figsize=(15,5))
imgs = serModel1.drawImage().array, serModel2.drawImage().array, serDouble.drawImage().array
titles = "SerComp1", "SerComp2", "SerDouble"
for i in range(3):
        axes[i].imshow(numpy.arcsinh(imgs[i]))
        axes[i].set_title(titles[i])



In [85]:
psfGauss = galsim.Gaussian(fwhm=2.0)
psfImage = psfGauss.drawImage().array 
plt.imshow(numpy.arcsinh(psfImage))


Out[85]:
<matplotlib.image.AxesImage at 0x10a79e710>

In [88]:
psfIm = galsim.image.Image(psfImage)
psfObj = galsim.InterpolatedImage(psfIm, scale=1.0)

In [12]:
gal = fits.open("galaxy_test.fits")[1].data[0]
double(gal["mag"])


Out[12]:
19.5

In [1]:
from makeFakeGalaxy import *

In [2]:
testMakeFake("galaxy_test.fits")


/Users/songhuang/anaconda/lib/python2.7/site-packages/galsim/image.py:237: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if array != None:
/Users/songhuang/anaconda/lib/python2.7/site-packages/galsim/image.py:278: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  elif array != None:
/Users/songhuang/anaconda/lib/python2.7/site-packages/galsim/image.py:329: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  def array(self): return self.image.array
---------------------------------
 Input Flux :  1000.0
 Input Parameters :  2.5 10.0 0.8 40.0
 With Flux :  1000.0
 Output Flux :  963.422
 Shape of the Output Array :  (100, 100)
---------------------------------
---------------------------------
 Input Flux :  1905.46205692
 Input Parameters :  1.0 35.0 0.35 80.0
 With Flux :  1905.46205692
 Output Flux :  1905.46
 Shape of the Output Array :  (350, 350)
---------------------------------
---------------------------------
 Input Flux :  1000.0
 Input Parameters :  4.5 6.0 0.75 60.0
 With Flux :  1000.0
 Output Flux :  925.595
 Shape of the Output Array :  (60, 60)
---------------------------------

In [0]:


In [ ]: