本文整理汇总了Python中galsim.GSObject.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python GSObject.__init__方法的具体用法?Python GSObject.__init__怎么用?Python GSObject.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类galsim.GSObject
的用法示例。
在下文中一共展示了GSObject.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, obj, real_space=None, gsparams=None):
if not isinstance(obj, GSObject):
raise TypeError("Argument to AutoConvolve must be a GSObject.")
# Check whether to perform real space convolution...
# Start by checking if obj has a hard edge.
hard_edge = obj.hasHardEdges()
if real_space is None:
# The automatic determination is to use real_space if obj has hard edges.
real_space = hard_edge
# Warn if doing DFT convolution for objects with hard edges.
if not real_space and hard_edge:
import warnings
msg = """
Doing auto-convolution of object with hard edges.
This might be more accurate and/or faster using real_space=True"""
warnings.warn(msg)
# Can't do real space if object is not analytic, so check for that.
if real_space and not obj.isAnalyticX():
import warnings
msg = """
Object to be auto-convolved is not analytic in real space.
Cannot use real space convolution.
Switching to DFT method."""
warnings.warn(msg)
real_space = False
GSObject.__init__(self, galsim.SBAutoConvolve(obj.SBProfile, real_space=real_space,
gsparams=gsparams))
if hasattr(obj,'noise'):
import warnings
warnings.warn("Unable to propagate noise in galsim.AutoConvolve")
示例2: applyRotation
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def applyRotation(self, theta):
if not isinstance(theta, galsim.Angle):
raise TypeError("Input theta should be an Angle")
sigma = self.SBProfile.getSigma()
bvec = self.SBProfile.getBVec().copy()
bvec.rotate(theta)
GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
示例3: fitImage
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def fitImage(self, image, center=None, normalization='flux'):
"""An obsolete method that is roughly equivalent to
self = galsim.FitShapelet(self.sigma, self.order, image)
"""
new_obj = galsim.FitShapelet(self.sigma, self.order, image, center, normalization)
bvec = new_obj.SBProfile.getBVec()
GSObject.__init__(self, galsim._galsim.SBShapelet(self.sigma, bvec))
示例4: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, *args, **kwargs):
# Check kwargs first:
gsparams = kwargs.pop("gsparams", None)
# Make sure there is nothing left in the dict.
if kwargs:
raise TypeError(
"Add constructor got unexpected keyword argument(s): %s"%kwargs.keys())
if len(args) == 0:
# No arguments. Could initialize with an empty list but draw then segfaults. Raise an
# exception instead.
raise ValueError("Add must be initialized with at least one GSObject.")
elif len(args) == 1:
# 1 argument. Should be either a GSObject or a list of GSObjects
if isinstance(args[0], GSObject):
SBList = [args[0].SBProfile]
elif isinstance(args[0], list):
SBList = []
for obj in args[0]:
if isinstance(obj, GSObject):
SBList.append(obj.SBProfile)
else:
raise TypeError("Input list must contain only GSObjects.")
else:
raise TypeError("Single input argument must be a GSObject or list of them.")
GSObject.__init__(self, galsim.SBAdd(SBList, gsparams=gsparams))
elif len(args) >= 2:
# >= 2 arguments. Convert to a list of SBProfiles
SBList = [obj.SBProfile for obj in args]
GSObject.__init__(self, galsim.SBAdd(SBList, gsparams=gsparams))
示例5: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, real_kimage, imag_kimage, k_interpolant=None, stepk=None,
gsparams=None):
# make sure real_kimage, imag_kimage are really `Image`s, are floats, and are congruent.
if not isinstance(real_kimage, galsim.Image) or not isinstance(imag_kimage, galsim.Image):
raise ValueError("Supplied kimage is not an Image instance")
if ((real_kimage.dtype != np.float32 and real_kimage.dtype != np.float64)
or (imag_kimage.dtype != np.float32 and imag_kimage.dtype != np.float64)):
raise ValueError("Supplied image does not have dtype of float32 or float64!")
if real_kimage.bounds != imag_kimage.bounds:
raise ValueError("Real and Imag kimages must have same bounds.")
if real_kimage.scale != imag_kimage.scale:
raise ValueError("Real and Imag kimages must have same scale.")
# Make sure any `wcs`s are `PixelScale`s.
if ((real_kimage.wcs is not None
and not real_kimage.wcs.isPixelScale())
or (imag_kimage.wcs is not None
and not imag_kimage.wcs.isPixelScale())):
raise ValueError("Real and Imag kimage wcs's must be PixelScale's or None.")
# Check for Hermitian symmetry properties of real_kimage and imag_kimage
shape = real_kimage.array.shape
# If image is even-sized, ignore first row/column since in this case not every pixel has
# a symmetric partner to which to compare.
bd = galsim.BoundsI(real_kimage.xmin + (1 if shape[1]%2==0 else 0),
real_kimage.xmax,
real_kimage.ymin + (1 if shape[0]%2==0 else 0),
real_kimage.ymax)
if not (np.allclose(real_kimage[bd].array,
real_kimage[bd].array[::-1,::-1])
or np.allclose(imag_kimage[bd].array,
-imag_kimage[bd].array[::-1,::-1])):
raise ValueError("Real and Imag kimages must form a Hermitian complex matrix.")
if stepk is None:
stepk = real_kimage.scale
else:
if stepk < real_kimage.scale:
import warnings
warnings.warn(
"Provided stepk is smaller than kimage.scale; overriding with kimage.scale.")
stepk = real_kimage.scale
self._real_kimage = real_kimage
self._imag_kimage = imag_kimage
self._stepk = stepk
self._gsparams = gsparams
# set up k_interpolant if none was provided by user, or check that the user-provided one
# is of a valid type
if k_interpolant is None:
self.k_interpolant = galsim.Quintic(tol=1e-4)
else:
self.k_interpolant = galsim.utilities.convert_interpolant(k_interpolant)
GSObject.__init__(self, galsim._galsim.SBInterpolatedKImage(
self._real_kimage.image, self._imag_kimage.image,
self._real_kimage.scale, self._stepk, self.k_interpolant, gsparams))
示例6: setBVec
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def setBVec(self,bvec):
"""This method is discouraged and will be deprecated."""
bvec_size = ShapeletSize(self.order)
if len(bvec) != bvec_size:
raise ValueError("bvec is the wrong size for the Shapelet order")
import numpy
bvec = LVector(self.order,numpy.array(bvec))
GSObject.__init__(self, galsim._galsim.SBShapelet(self.sigma, bvec))
示例7: setBVec
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def setBVec(self,bvec):
sigma = self.SBProfile.getSigma()
order = self.SBProfile.getBVec().order
bvec_size = galsim.LVectorSize(order)
if len(bvec) != bvec_size:
raise ValueError("bvec is the wrong size for the Shapelet order")
import numpy
bvec = galsim.LVector(order,numpy.array(bvec))
GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
示例8: setOrder
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def setOrder(self,order):
"""This method is discouraged and will be deprecated."""
if self.order == order: return
# Preserve the existing values as much as possible.
if self.order > order:
bvec = LVector(order, self.bvec[0:ShapeletSize(order)])
else:
import numpy
a = numpy.zeros(ShapeletSize(order))
a[0:len(self.bvec)] = self.bvec
bvec = LVector(order,a)
GSObject.__init__(self, galsim._galsim.SBShapelet(self.sigma, bvec))
示例9: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, lam_over_diam, defocus=0.,
astig1=0., astig2=0., coma1=0., coma2=0., trefoil1=0., trefoil2=0., spher=0.,
circular_pupil=True, obscuration=0., interpolant=None, oversampling=1.5,
pad_factor=1.5, suppress_warning=False, flux=1.,
nstruts=0, strut_thick=0.05, strut_angle=0.*galsim.degrees,
gsparams=None):
# Choose dx for lookup table using Nyquist for optical aperture and the specified
# oversampling factor
dx_lookup = .5 * lam_over_diam / oversampling
# Start with the stepk value for Airy:
airy = galsim.Airy(lam_over_diam = lam_over_diam, obscuration = obscuration,
gsparams = gsparams)
stepk_airy = airy.stepK()
# Boost Airy image size by a user-specifed pad_factor to allow for larger, aberrated PSFs
stepk = stepk_airy / pad_factor
# Get a good FFT size. i.e. 2^n or 3 * 2^n.
npix = goodFFTSize(int(np.ceil(2. * np.pi / (dx_lookup * stepk) )))
# Make the psf image using this dx and array shape
optimage = galsim.optics.psf_image(
lam_over_diam=lam_over_diam, dx=dx_lookup, array_shape=(npix, npix), defocus=defocus,
astig1=astig1, astig2=astig2, coma1=coma1, coma2=coma2, trefoil1=trefoil1,
trefoil2=trefoil2, spher=spher, circular_pupil=circular_pupil, obscuration=obscuration,
flux=flux, nstruts=nstruts, strut_thick=strut_thick, strut_angle=strut_angle)
# Initialize the SBProfile
GSObject.__init__(
self, galsim.InterpolatedImage(optimage, x_interpolant=interpolant, dx=dx_lookup,
calculate_stepk=True, calculate_maxk=True,
use_true_center=False, normalization='sb',
gsparams=gsparams))
# The above procedure ends up with a larger image than we really need, which
# means that the default stepK value will be smaller than we need.
# Hence calculate_stepk=True and calculate_maxk=True above.
if not suppress_warning:
# Check the calculated stepk value. If it is smaller than stepk, then there might
# be aliasing.
final_stepk = self.SBProfile.stepK()
if final_stepk < stepk:
import warnings
warnings.warn(
"The calculated stepk (%g) for OpticalPSF is smaller "%final_stepk +
"than what was used to build the wavefront (%g)."%stepk +
"This could lead to aliasing problems. " +
"Using pad_factor >= %f is recommended."%(pad_factor * stepk / final_stepk))
示例10: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, lam_over_diam, defocus=0.,
astig1=0., astig2=0., coma1=0., coma2=0., trefoil1=0., trefoil2=0., spher=0.,
circular_pupil=True, obscuration=0., interpolant=None, oversampling=1.5,
pad_factor=1.5, flux=1., gsparams=None):
# Currently we load optics, noise etc in galsim/__init__.py, but this might change (???)
import galsim.optics
# Choose dx for lookup table using Nyquist for optical aperture and the specified
# oversampling factor
dx_lookup = .5 * lam_over_diam / oversampling
# We need alias_threshold here, so don't wait to make this a default GSParams instance
# if the user didn't specify anything else.
if not gsparams:
gsparams = galsim.GSParams()
# Use a similar prescription as SBAiry to set Airy stepK and thus reference unpadded image
# size in physical units
stepk_airy = min(
gsparams.alias_threshold * .5 * np.pi**3 * (1. - obscuration) / lam_over_diam,
np.pi / 5. / lam_over_diam)
# Boost Airy image size by a user-specifed pad_factor to allow for larger, aberrated PSFs,
# also make npix always *odd* so that opticalPSF lookup table array is correctly centred:
npix = 1 + 2 * (np.ceil(pad_factor * (np.pi / stepk_airy) / dx_lookup)).astype(int)
# Make the psf image using this dx and array shape
optimage = galsim.optics.psf_image(
lam_over_diam=lam_over_diam, dx=dx_lookup, array_shape=(npix, npix), defocus=defocus,
astig1=astig1, astig2=astig2, coma1=coma1, coma2=coma2, trefoil1=trefoil1,
trefoil2=trefoil2, spher=spher, circular_pupil=circular_pupil, obscuration=obscuration,
flux=flux)
# If interpolant not specified on input, use a Quintic interpolant
if interpolant is None:
quintic = galsim.Quintic(tol=1e-4)
self.interpolant = galsim.InterpolantXY(quintic)
else:
self.interpolant = galsim.utilities.convert_interpolant_to_2d(interpolant)
# Initialize the SBProfile
GSObject.__init__(
self, galsim.SBInterpolatedImage(optimage, xInterp=self.interpolant, dx=dx_lookup,
gsparams=gsparams))
# The above procedure ends up with a larger image than we really need, which
# means that the default stepK value will be smaller than we need.
# Thus, we call the function calculateStepK() to refine the value.
self.SBProfile.calculateStepK()
self.SBProfile.calculateMaxK()
示例11: setOrder
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def setOrder(self,order):
curr_bvec = self.SBProfile.getBVec()
curr_order = curr_bvec.order
if curr_order == order: return
# Preserve the existing values as much as possible.
sigma = self.SBProfile.getSigma()
if curr_order > order:
bvec = galsim.LVector(order, curr_bvec.array[0:galsim.LVectorSize(order)])
else:
import numpy
a = numpy.zeros(galsim.LVectorSize(order))
a[0:len(curr_bvec.array)] = curr_bvec.array
bvec = galsim.LVector(order,a)
GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
示例12: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, sigma, order, bvec=None, gsparams=None):
# Make sure order and sigma are the right type:
order = int(order)
sigma = float(sigma)
# Make bvec if necessary
if bvec is None:
bvec = LVector(order)
else:
bvec_size = ShapeletSize(order)
if len(bvec) != bvec_size:
raise ValueError("bvec is the wrong size for the provided order")
import numpy
bvec = LVector(order,numpy.array(bvec))
GSObject.__init__(self, galsim._galsim.SBShapelet(sigma, bvec, gsparams))
示例13: fitImage
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def fitImage(self, image, center=None, normalization='flux'):
"""Fit for a shapelet decomposition of a given image
The optional normalization parameter mirrors the parameter in the GSObject `draw` method.
If the fitted shapelet is drawn with the same normalization value as was used when it
was fit, then the resulting image should be an approximate match to the original image.
For example:
image = ...
shapelet = galsim.Shapelet(sigma, order)
shapelet.fitImage(image,normalization='sb')
shapelet.draw(image=image2, dx=image.scale, normalization='sb')
Then image2 and image should be as close to the same as possible for the given
sigma and order. Increasing the order can improve the fit, as can having sigma match
the natural scale size of the image. However, it should be noted that some images
are not well fit by a shapelet for any (reasonable) order.
@param image The Image for which to fit the shapelet decomposition
@param center The position in pixels to use for the center of the decomposition.
[Default: use the image center (`image.bounds.trueCenter()`)]
@param normalization The normalization to assume for the image.
(Default `normalization = "flux"`)
"""
if not center:
center = image.bounds.trueCenter()
# convert from PositionI if necessary
center = galsim.PositionD(center.x,center.y)
if not normalization.lower() in ("flux", "f", "surface brightness", "sb"):
raise ValueError(("Invalid normalization requested: '%s'. Expecting one of 'flux', "+
"'f', 'surface brightness' or 'sb'.") % normalization)
sigma = self.SBProfile.getSigma()
bvec = self.SBProfile.getBVec().copy()
galsim.ShapeletFitImage(sigma, bvec, image, center)
if normalization.lower() == "flux" or normalization.lower() == "f":
bvec /= image.scale**2
# SBShapelet, like all SBProfiles, is immutable, so we need to reinitialize with a
# new Shapelet object.
GSObject.__init__(self, galsim.SBShapelet(sigma, bvec))
示例14: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, lam_over_r0=None, fwhm=None, interpolant=None, oversampling=1.5, flux=1.,
gsparams=None):
# The FWHM of the Kolmogorov PSF is ~0.976 lambda/r0 (e.g., Racine 1996, PASP 699, 108).
if lam_over_r0 is None :
if fwhm is not None :
lam_over_r0 = fwhm / 0.976
else:
raise TypeError("Either lam_over_r0 or fwhm must be specified for AtmosphericPSF")
else :
if fwhm is None:
fwhm = 0.976 * lam_over_r0
else:
raise TypeError(
"Only one of lam_over_r0 and fwhm may be specified for AtmosphericPSF")
# Set the lookup table sample rate via FWHM / 2 / oversampling (BARNEY: is this enough??)
dx_lookup = .5 * fwhm / oversampling
# Fold at 10 times the FWHM
stepk_kolmogorov = np.pi / (10. * fwhm)
# Odd array to center the interpolant on the centroid. Might want to pad this later to
# make a nice size array for FFT, but for typical seeing, arrays will be very small.
npix = 1 + 2 * (np.ceil(np.pi / stepk_kolmogorov)).astype(int)
atmoimage = kolmogorov_psf_image(
array_shape=(npix, npix), dx=dx_lookup, lam_over_r0=lam_over_r0, flux=flux)
# Run checks on the interpolant and build default if None
if interpolant is None:
quintic = galsim.Quintic(tol=1e-4)
self.interpolant = galsim.InterpolantXY(quintic)
else:
self.interpolant = galsim.utilities.convert_interpolant_to_2d(interpolant)
# Then initialize the SBProfile
GSObject.__init__(
self, galsim.SBInterpolatedImage(atmoimage, xInterp=self.interpolant, dx=dx_lookup,
gsparams=gsparams))
# The above procedure ends up with a larger image than we really need, which
# means that the default stepK value will be smaller than we need.
# Thus, we call the function calculateStepK() to refine the value.
self.SBProfile.calculateStepK()
self.SBProfile.calculateMaxK()
示例15: __init__
# 需要导入模块: from galsim import GSObject [as 别名]
# 或者: from galsim.GSObject import __init__ [as 别名]
def __init__(self, lam_over_diam, defocus=0.,
astig1=0., astig2=0., coma1=0., coma2=0., trefoil1=0., trefoil2=0., spher=0.,
circular_pupil=True, obscuration=0., interpolant=None, oversampling=1.5,
pad_factor=1.5, flux=1.,
nstruts=0, strut_thick=0.05, strut_angle=0.*galsim.degrees,
gsparams=None):
# Currently we load optics, noise etc in galsim/__init__.py, but this might change (???)
import galsim.optics
# Choose dx for lookup table using Nyquist for optical aperture and the specified
# oversampling factor
dx_lookup = .5 * lam_over_diam / oversampling
# We need alias_threshold here, so don't wait to make this a default GSParams instance
# if the user didn't specify anything else.
if not gsparams:
gsparams = galsim.GSParams()
# Use a similar prescription as SBAiry to set Airy stepK and thus reference unpadded image
# size in physical units
stepk_airy = min(
gsparams.alias_threshold * .5 * np.pi**3 * (1. - obscuration) / lam_over_diam,
np.pi / 5. / lam_over_diam)
# Boost Airy image size by a user-specifed pad_factor to allow for larger, aberrated PSFs,
# also make npix always *odd* so that opticalPSF lookup table array is correctly centred:
npix = 1 + 2 * (np.ceil(pad_factor * (np.pi / stepk_airy) / dx_lookup)).astype(int)
# Make the psf image using this dx and array shape
optimage = galsim.optics.psf_image(
lam_over_diam=lam_over_diam, dx=dx_lookup, array_shape=(npix, npix), defocus=defocus,
astig1=astig1, astig2=astig2, coma1=coma1, coma2=coma2, trefoil1=trefoil1,
trefoil2=trefoil2, spher=spher, circular_pupil=circular_pupil, obscuration=obscuration,
flux=flux, nstruts=nstruts, strut_thick=strut_thick, strut_angle=strut_angle)
# Initialize the SBProfile
GSObject.__init__(
self, galsim.InterpolatedImage(optimage, x_interpolant=interpolant, dx=dx_lookup,
calculate_stepk=True, calculate_maxk=True,
use_true_center=False, normalization='sb',
gsparams=gsparams))