def __init__(self, name, z, x, y):
self.name = name
self.z = z
self.x = x
self.y = y
self.lDcm = cosmo.luminosity_distance(self.z)*u.Mpc.to(u.cm) / u.Mpc
self.radToKpc = conv.arcsec_per_kpc_proper(self.z)*0.05/u.arcsec*u.kpc
# Grabbing and filling galaxy data
python类arcsec()的实例源码
def __init__(self, name, z, x, y):
self.name = name
self.z = z
self.x = x
self.y = y
self.lDcm = cosmo.luminosity_distance(self.z)*u.Mpc.to(u.cm) / u.Mpc
self.radToKpc = conv.arcsec_per_kpc_proper(self.z)*0.05/u.arcsec*u.kpc
# Grabbing and filling galaxy data
def determinate_seeing_from_white(self, xc, yc, halfsize):
"""
Function used to estimate the observation seeing of an exposure, fitting a gaussian to a brigth source of the image
:param xc: x coordinate in pixels of a bright source
:param yc: y coordinate in pixels of a bright source
:param halfsize: the radius of the area to fit the gaussian
:return: seeing: float
the observational seeing of the image defined as the FWHM of the gaussian
"""
hdulist = self.hdulist_white
data = hdulist[1].data
matrix_data = np.array(self.get_mini_image([xc, yc], halfsize=halfsize))
x = np.arange(0, matrix_data.shape[0], 1)
y = np.arange(0, matrix_data.shape[1], 1)
matrix_x, matrix_y = np.meshgrid(x, y)
amp_init = np.matrix(matrix_data).max()
stdev_init = 0.33 * halfsize
def tie_stddev(model): # we need this for tying x_std and y_std
xstddev = model.x_stddev
return xstddev
g_init = models.Gaussian2D(x_mean=halfsize + 0.5, y_mean=halfsize + 0.5, x_stddev=stdev_init,
y_stddev=stdev_init, amplitude=amp_init, tied={'y_stddev': tie_stddev})
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g_init, matrix_x, matrix_y, matrix_data)
if (g.y_stddev < 0) or (g.y_stddev > halfsize):
raise ValueError('Cannot trust the model, please try other imput parameters.')
seeing = 2.355 * g.y_stddev * self.pixelsize.to('arcsec') # in arcsecs
print('FWHM={:.2f}'.format(seeing))
print('stddev from the 2D gaussian = {:.3f}'.format(g.y_stddev * self.pixelsize.to('arcsec')))
return seeing
def determinate_seeing_from_white(self, xc, yc, halfsize):
"""
Function used to estimate the observation seeing of an exposure, fitting a gaussian to a brigth source of the image
:param xc: x coordinate in pixels of a bright source
:param yc: y coordinate in pixels of a bright source
:param halfsize: the radius of the area to fit the gaussian
:return: seeing: float
the observational seeing of the image defined as the FWHM of the gaussian
"""
matrix_data = np.array(self.get_mini_image([xc, yc], halfsize=halfsize))
x = np.arange(0, matrix_data.shape[0], 1)
y = np.arange(0, matrix_data.shape[1], 1)
matrix_x, matrix_y = np.meshgrid(x, y)
amp_init = np.matrix(matrix_data).max()
stdev_init = 0.33 * halfsize
def tie_stddev(model): # we need this for tying x_std and y_std
xstddev = model.x_stddev
return xstddev
g_init = models.Gaussian2D(x_mean=halfsize + 0.5, y_mean=halfsize + 0.5, x_stddev=stdev_init,
y_stddev=stdev_init, amplitude=amp_init, tied={'y_stddev': tie_stddev})
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g_init, matrix_x, matrix_y, matrix_data)
if (g.y_stddev < 0) or (g.y_stddev > halfsize):
raise ValueError('Cannot trust the model, please try other imput parameters.')
seeing = 2.355 * g.y_stddev * self.pixelsize.to('arcsec') # in arcsecs
print('FWHM={:.2f}'.format(seeing))
print('stddev from the 2D gaussian = {:.3f}'.format(g.y_stddev * self.pixelsize.to('arcsec')))
return seeing
def __init__(self, args, data_container):
"""Init method for ImageProcessor class
Args:
args (object): argparse instance
data_container (object): Contains relevant information of the night
and the data itself.
"""
# TODO (simon): Check how inheritance could be used here.
self.log = logging.getLogger(__name__)
self.args = args
self.instrument = data_container.instrument
self.technique = data_container.technique
self.bias = data_container.bias
self.day_flats = data_container.day_flats
self.dome_flats = data_container.dome_flats
self.sky_flats = data_container.sky_flats
self.data_groups = data_container.data_groups
self.sun_set = data_container.sun_set_time
self.sun_rise = data_container.sun_rise_time
self.morning_twilight = data_container.morning_twilight
self.evening_twilight = data_container.evening_twilight
self.pixel_scale = 0.15 * u.arcsec
self.queue = None
self.trim_section = self.define_trim_section(technique=self.technique)
self.overscan_region = self.get_overscan_region()
self.spec_mode = SpectroscopicMode()
self.master_bias = None
self.master_bias_name = None
self.out_prefix = None
def test_rho_as_angle():
# arctan(100 km, 1 au) * 206264.806 = 0.13787950659645942
rho = rho_as_angle(100 * u.km, {'delta': 1 * u.au})
assert np.isclose(rho.to(u.arcsec).value, 0.13787950659645942)
def test_rho_as_length():
# 1 au * tan(1") = 725.2709438078363
rho = rho_as_length(1 * u.arcsec, {'delta': 1 * u.au})
assert np.isclose(rho.to(u.km).value, 725.2709438078363)
def test_rho_roundtrip():
a = 10 * u.arcsec
eph = {'delta': 1 * u.au}
b = rho_as_angle(rho_as_length(a, eph), eph)
assert np.isclose(a.value, b.to(u.arcsec).value)
def test_str(self):
assert str(CircularAperture(1 * u.arcsec)) == 'Circular aperture, radius 1.0 arcsec'
def test_coma_equivalent_radius(self):
r = 1 * u.arcsec
aper = CircularAperture(r)
assert aper.coma_equivalent_radius() == 1 * u.arcsec
def test_str(self):
assert str(AnnularAperture([1, 2] * u.arcsec)) == 'Annular aperture, radii 1.0–2.0 arcsec'
def test_coma_equivalent_radius(self):
shape = [1, 2] * u.arcsec
aper = AnnularAperture(shape)
assert aper.coma_equivalent_radius() == 1 * u.arcsec
def test_as_length(self):
shape = [1, 2] * u.arcsec
aper = AnnularAperture(shape)
eph = {'delta': 1 * u.au}
assert all(aper.as_length(eph).dim == rho_as_length(shape, eph))
def test_str(self):
assert str(RectangularAperture([1, 2] * u.arcsec)) == 'Rectangular aperture, dimensions 1.0×2.0 arcsec'
def test_coma_equivalent_radius(self):
shape = (0.8, 2) * u.arcsec
aper = RectangularAperture(shape)
r = aper.coma_equivalent_radius()
assert np.isclose(r.value, 0.66776816346357259)
def test_str(self):
assert str(GaussianAperture(1 * u.arcsec)) == 'Gaussian aperture, 1-? width 1.0 arcsec'
def test_coma_equivalent_radius(self):
sigma = 1 * u.arcsec
aper = GaussianAperture(sigma)
assert aper.coma_equivalent_radius() == np.sqrt(np.pi / 2) * u.arcsec
def test_as_length(self):
sig = 1 * u.arcsec
aper = GaussianAperture(sig)
eph = {'delta': 1 * u.au}
assert aper.as_length(eph).dim == rho_as_length(sig, eph)
def test_call(self):
aper = GaussianAperture(1 * u.arcsec)
assert np.isclose(aper(1 * u.arcsec), 0.6065306597126334)
def test_from_flam(self):
fluxd = 6.730018324465526e-14 * u.W / u.m**2 / u.um
aper = 1 * u.arcsec
eph = dict(rh=1.5 * u.au, delta=1.0 * u.au)
S = 1869 * u.W / u.m**2 / u.um
afrho = Afrho.from_fluxd(None, fluxd, aper, eph, S=S)
assert np.isclose(afrho.cm, 1000)