如何在 python 中生成洛伦兹二维源
How to produce lorentzian 2D sources in python
我正在尝试制作二维源并将它们添加到图像中。目前我正在通过 Gaussian2D (astropy) 生成高斯源:
min_x = int(rapix[i]) - 300
max_x = int(rapix[i]) + 300
min_y = int(decpix[i]) - 300
max_y = int(decpix[i]) + 300
y, x = np.mgrid[min_y:max_y, min_x:max_x] #HERE I CREATE THE GRID TO PUT THE SOURCES ON
fakesource = Gaussian2D(intensity, rapix[i], decpix[i], dimension, dimension)(x, y)
之前已经定义了强度和维度。我想生成洛伦兹源而不是高斯源,但我没有发现任何类似于 Gaussian2D 的东西。哪种方法最好?
Lorentz1D exists, though no Lorentz2D, but you can define one following the guide for implementing custom models。这是一个基本示例:
from astropy.modeling import Fittable2DModel, Parameter
class Lorentz2D(Fittable2DModel):
amplitude = Parameter()
x_0 = Parameter()
y_0 = Parameter()
fwhm = Parameter
@staticmethod
def evaluate(x, y, amplitude, x_0, y_0, fwhm):
hwhm = fwhm / 2.0
return (amplitude * hwhm /
((x - x_0)**2 + (y - y_0)**2 + hwhm**2)**1.5)
我不知道你的二维洛伦兹模型是不是这样定义的;我刚刚从维基百科改编了这个定义。但您可以根据需要修改此示例。
然后,如果您认为这对其他人有价值,您可以考虑将其提交为 contribution。
我正在尝试制作二维源并将它们添加到图像中。目前我正在通过 Gaussian2D (astropy) 生成高斯源:
min_x = int(rapix[i]) - 300
max_x = int(rapix[i]) + 300
min_y = int(decpix[i]) - 300
max_y = int(decpix[i]) + 300
y, x = np.mgrid[min_y:max_y, min_x:max_x] #HERE I CREATE THE GRID TO PUT THE SOURCES ON
fakesource = Gaussian2D(intensity, rapix[i], decpix[i], dimension, dimension)(x, y)
之前已经定义了强度和维度。我想生成洛伦兹源而不是高斯源,但我没有发现任何类似于 Gaussian2D 的东西。哪种方法最好?
Lorentz1D exists, though no Lorentz2D, but you can define one following the guide for implementing custom models。这是一个基本示例:
from astropy.modeling import Fittable2DModel, Parameter
class Lorentz2D(Fittable2DModel):
amplitude = Parameter()
x_0 = Parameter()
y_0 = Parameter()
fwhm = Parameter
@staticmethod
def evaluate(x, y, amplitude, x_0, y_0, fwhm):
hwhm = fwhm / 2.0
return (amplitude * hwhm /
((x - x_0)**2 + (y - y_0)**2 + hwhm**2)**1.5)
我不知道你的二维洛伦兹模型是不是这样定义的;我刚刚从维基百科改编了这个定义。但您可以根据需要修改此示例。
然后,如果您认为这对其他人有价值,您可以考虑将其提交为 contribution。