def test_BLPS_02_AC():
"""simple binary lens with extended source and different methods to evaluate magnification
- version with adaptivecontouring
"""
params = ModelParameters({
't_0':2456141.593, 'u_0':0.5425, 't_E':62.63*u.day, 'alpha':49.58*u.deg,
's':1.3500, 'q':0.00578, 'rho':0.01})
model = Model(parameters=params)
t = (np.array([6112.5, 6113., 6114., 6115., 6116., 6117., 6118., 6119]) +
2450000.)
ac_name = 'AdaptiveContouring'
methods = [2456113.5, 'Quadrupole', 2456114.5, 'Hexadecapole', 2456116.5,
ac_name, 2456117.5]
accuracy_1 = {'accuracy': 0.04}
accuracy_2 = {'accuracy': 0.01, 'ld_accuracy': 0.0001}
model.set_magnification_methods(methods)
model.set_magnification_methods_parameters({ac_name: accuracy_1})
data = MulensData(data_list=[t, t*0.+16., t*0.+0.01])
model.set_datasets([data])
result = model.data_magnification[0]
expected = np.array([4.69183078, 2.87659723, 1.83733975, 1.63865704,
1.61038135, 1.63603122, 1.69045492, 1.77012807])
np.testing.assert_almost_equal(result, expected, decimal=3)
# Below we test passing the limb coef to VBBL function.
data.bandpass = 'I'
model.set_limb_coeff_u('I', 10.) # This is an absurd value but I needed something quick.
model.set_magnification_methods_parameters({ac_name: accuracy_2})
result = model.data_magnification[0]
np.testing.assert_almost_equal(result[5], 1.6366862, decimal=3)
python类deg()的实例源码
def test_methods_parameters():
"""make sure additional parameters are properly passed to very inner functions"""
params = ModelParameters({
't_0':2456141.593, 'u_0':0.5425, 't_E':62.63*u.day, 'alpha':49.58*u.deg,
's':1.3500, 'q':0.00578, 'rho':0.01})
model = Model(parameters=params)
t = np.array([2456117.])
methods = [2456113.5, 'Quadrupole', 2456114.5, 'Hexadecapole', 2456116.5,
'VBBL', 2456117.5]
model.set_magnification_methods(methods)
data = MulensData(data_list=[t, t*0.+16., t*0.+0.01])
model.set_datasets([data])
result_1 = model.data_magnification[0]
vbbl_options = {'accuracy': 0.1}
methods_parameters = {'VBBL': vbbl_options}
model.set_magnification_methods_parameters(methods_parameters)
result_2 = model.data_magnification[0]
vbbl_options = {'accuracy': 1.e-5}
methods_parameters = {'VBBL': vbbl_options}
model.set_magnification_methods_parameters(methods_parameters)
result_3 = model.data_magnification[0]
assert result_1[0] != result_2[0]
assert result_1[0] != result_3[0]
assert result_2[0] != result_3[0]
def __init__(self, *args, **kwargs):
if not isinstance(args[0], SkyCoord) and 'unit' not in kwargs:
kwargs['unit'] = (u.hourangle, u.deg)
SkyCoord.__init__(self, *args, **kwargs)
def galactic_l(self):
"""
Galactic longitude. Note that for connivance, the values l >
180 degrees are represented as 360-l.
"""
l = self.galactic.l
if l > 180. * u.deg:
l = l - 360. * u.deg
return l
def dalpha_dt(self):
""" change in alpha vs. time in deg/yr"""
return self.parameters['dalpha_dt'].to(u.deg / u.yr).value
def xyz(self):
"""
*Astropy.CartesianRepresentation*
return X,Y,Z positions based on RA, DEC and distance
"""
if self._xyz is None:
ra_dec = [
text.decode('UTF-8') for text in self.data_lists['ra_dec']]
self._xyz = SkyCoord(
ra_dec, distance=self.data_lists['distance'],
unit=(u.hourangle, u.deg, u.au)).cartesian
return self._xyz
def parse_coord(c):
if len(c) == 6:
# h m s d m s
ra = Angle((float(c[0]), float(c[1]), float(c[2])), unit=au.hourangle)
dec = Angle((float(c[3]), float(c[4]), float(c[5])), unit=au.deg)
elif len(c) == 2:
ra = Angle(float(c[0]), unit=au.deg)
dec = Angle(float(c[1]), unit=au.deg)
else:
raise ValueError("invalid coordinate: {0}".format(c))
return (ra, dec)
def input_params(votbl=None):
"""
Parameters
----------
votbl
Returns
-------
"""
if votbl is None:
votbl = empty_vo(rtype='meta')
all_params = []
# POS
pos = Param(votbl, name="INPUT:POS", value="", datatype="char", arraysize="*")
pos.description = ('The center of the region of interest. The coordinate values are '+
'specified in list format (comma separated) in decimal degrees with '+
'no embedded white space followed by an optional coord. system. '+
'Allowed systems are (ICRS) and the default is ICRS.')
all_params.append(pos)
# SIZE
size = Param(votbl, name="INPUT:SIZE", value="0.1", datatype="double", unit="deg")
size.description = ('The radius of the circular region of interest in decimal degrees.'+
'Default sized radius is 0.001 degrees')
all_params.append(size)
# BAND
band = Param(votbl, name="INPUT:BAND", value="ALL", datatype="char", arraysize="*")
band.description = 'Not currently implemented'
all_params.append(band)
# TIME
ptime = Param(votbl, name="INPUT:TIME", value="", datatype="char", arraysize="*")
ptime.description = 'Not currently implemented'
all_params.append(ptime)
# FORMAT
format = Param(votbl, name="INPUT:FORMAT", value="ALL", datatype="char", arraysize="*")
format.description = ('Desired format of retrieved data. \n'+
'Allowed values are HDF5, METADATA')
all_params.append(format)
# Return
return all_params
def test_query_coords(igmsp):
# Single
coord = SkyCoord(ra=0.0019, dec=17.7737, unit='deg')
#
_, _, idx = igmsp.qcat.query_coords(coord)
assert idx[0] >= 0
# Multiple
coords = SkyCoord(ra=[0.0019]*2, dec=[17.7737]*2, unit='deg')
_, _, idxs = igmsp.qcat.query_coords(coords)
assert len(idxs) == 2
# Dataset
_, _, idxs2 = igmsp.qcat.query_coords(coords, groups=['BOSS_DR12'])
assert np.sum(idxs2 >= 0) == 2
_, _, idxs3 = igmsp.qcat.query_coords(coords, groups=['HD-LLS_DR1'])
assert np.sum(idxs3 >= 0) == 0
def test_spectra_in_group(igmsp):
# Missed a source -- raises IOError
coords = SkyCoord(ra=[0.0028, 0.0019], dec=[14.9747, -17.77374], unit='deg')
with pytest.raises(IOError):
spec, meta = igmsp.spectra_in_group(coords, 'BOSS_DR12')
# Another with both missing
coords = SkyCoord(ra=[2.8135,16.5802], dec=[-14.7672, -0.8065], unit='deg')
with pytest.raises(IOError):
spec, meta = igmsp.spectra_in_group(coords, 'GGG')
# Each source has only spectrum in the group
coords = SkyCoord(ra=[0.0028, 0.0019], dec=[14.9747, 17.77374], unit='deg')
spec, meta = igmsp.spectra_in_group(coords, 'BOSS_DR12')
# Test
assert spec.nspec == 2
assert meta['PLATE'][0] == 6177
# Each source has multiple spectra in the group
coords = SkyCoord(ra=[2.8135,16.5802], dec=[14.7672, 0.8065], unit='deg')
spec, meta = igmsp.spectra_in_group(coords, 'GGG')
assert meta['DISPERSER'][0] == 'B600'
qdict = dict(DISPERSER='R400')
spec, meta = igmsp.spectra_in_group(coords, 'GGG', query_dict=qdict)
assert meta['DISPERSER'][0] == 'R400'
# Another with bad grating
qdict = dict(DISPERSER='X400')
with pytest.raises(IOError):
spec, meta = igmsp.spectra_in_group(coords, 'GGG', query_dict=qdict)
'''
# Multiple spectra per group
coords = SkyCoord(ra=[2.8135, 16.5802], dec=[14.7672, 0.8065], unit='deg')
spec, meta = igmsp.coords_to_spectra(coords, 'GGG', all_spec=True)
assert spec.nspec == 4
'''
test_testing_support.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def setUp(self):
self.dir = './test_results'
os.makedirs(self.dir, exist_ok=True)
self.frequency = numpy.linspace(1e8, 1.5e8, 3)
self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7])
self.flux = numpy.array([[100.0], [100.0], [100.0]])
self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
self.config = create_named_configuration('LOWBD2-CORE')
self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
nants = self.config.xyz.shape[0]
assert nants > 1
assert len(self.config.names) == nants
assert len(self.config.mount) == nants
test_testing_support.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def createVis(self, config, dec=-35.0, rmax=None):
self.config = create_named_configuration(config, rmax=rmax)
self.phasecentre = SkyCoord(ra=+15 * u.deg, dec=dec * u.deg, frame='icrs', equinox='J2000')
self.vis = create_visibility(self.config, self.times, self.frequency,
channel_bandwidth=self.channel_bandwidth,
phasecentre=self.phasecentre, weight=1.0,
polarisation_frame=PolarisationFrame('stokesI'))
test_skycomponent.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def test_insert_skycomponent_nearest(self):
dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
polarisation_frame=PolarisationFrame('stokesI'))
self.model.data *= 0.0
insert_skycomponent(self.model, sc, insert_method='Nearest')
# These test a regression but are not known a priori to be correct
self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 1.0, 7)
self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.0, 7)
test_skycomponent.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def test_insert_skycomponent_sinc(self):
dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
polarisation_frame=PolarisationFrame('stokesI'))
self.model.data *= 0.0
insert_skycomponent(self.model, sc, insert_method='Sinc')
# These test a regression but are not known a priori to be correct
self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 0.87684398703184396, 7)
self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.2469311811046056, 7)
test_skycomponent.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def test_insert_skycomponent_lanczos(self):
dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
polarisation_frame=PolarisationFrame('stokesI'))
self.model.data *= 0.0
insert_skycomponent(self.model, sc, insert_method='Lanczos')
# These test a regression but are not known a priori to be correct
self.assertAlmostEqual(self.model.data[0,0,151, 122], 0.87781267543090036, 7)
self.assertAlmostEqual(self.model.data[0,0,152, 122], 0.23817562762032077, 7)
test_skycomponent.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def test_insert_skycomponent_lanczos_bandwidth(self):
dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
polarisation_frame=PolarisationFrame('stokesI'))
self.model.data *= 0.0
insert_skycomponent(self.model, sc, insert_method='Lanczos', bandwidth=0.5)
# These test a regression but are not known a priori to be correct
self.assertAlmostEqual(self.model.data[0,0,151, 122], 0.24031092091707615, 7)
self.assertAlmostEqual(self.model.data[0,0,152, 122], 0.18648989466050975, 7)
test_generic_graph.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def setUp(self):
self.dir = './test_results'
os.makedirs(self.dir, exist_ok=True)
self.lowcore = create_named_configuration('LOWBD2-CORE')
self.times = numpy.linspace(-3, +3, 13) * (numpy.pi / 12.0)
self.frequency = numpy.array([1e8])
self.channel_bandwidth = numpy.array([1e7])
# Define the component and give it some polarisation and spectral behaviour
f = numpy.array([100.0])
self.flux = numpy.array([f])
self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
self.compabsdirection = SkyCoord(ra=17.0 * u.deg, dec=-36.5 * u.deg, frame='icrs', equinox='J2000')
self.comp = create_skycomponent(flux=self.flux, frequency=self.frequency,
direction=self.compabsdirection,
polarisation_frame=PolarisationFrame('stokesI'))
self.image = create_test_image(frequency=self.frequency, phasecentre=self.phasecentre,
cellsize=0.001,
polarisation_frame=PolarisationFrame('stokesI'))
self.image.data[self.image.data < 0.0] = 0.0
self.image_graph = delayed(create_test_image)(frequency=self.frequency,
phasecentre=self.phasecentre,
cellsize=0.001,
polarisation_frame=PolarisationFrame('stokesI'))
test_image_deconvolution_msmfs.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def setUp(self):
self.dir = './test_results'
os.makedirs(self.dir, exist_ok=True)
self.niter = 1000
self.lowcore = create_named_configuration('LOWBD2-CORE')
self.nchan = 5
self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
self.frequency = numpy.linspace(0.9e8, 1.1e8, self.nchan)
self.channel_bandwidth = numpy.array(self.nchan * [self.frequency[1] - self.frequency[0]])
self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
self.vis = create_visibility(self.lowcore, self.times, self.frequency, self.channel_bandwidth,
phasecentre=self.phasecentre, weight=1.0,
polarisation_frame=PolarisationFrame('stokesI'))
self.vis.data['vis'] *= 0.0
# Create model
self.test_model = create_low_test_image_from_gleam(npixel=512, cellsize=0.001,
phasecentre=self.vis.phasecentre,
frequency=self.frequency,
channel_bandwidth=self.channel_bandwidth)
beam = create_low_test_beam(self.test_model)
export_image_to_fits(beam, "%s/test_deconvolve_msmfsclean_beam.fits" % self.dir)
self.test_model.data *= beam.data
export_image_to_fits(self.test_model, "%s/test_deconvolve_msmfsclean_model.fits" % self.dir)
self.vis = predict_2d(self.vis, self.test_model)
assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001,
polarisation_frame=PolarisationFrame('stokesI'))
self.dirty, sumwt = invert_2d(self.vis, self.model)
self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
export_image_to_fits(self.dirty, "%s/test_deconvolve_msmfsclean_dirty.fits" % self.dir)
export_image_to_fits(self.psf, "%s/test_deconvolve_msmfsclean_psf.fits" % self.dir)
window = numpy.ones(shape=self.model.shape, dtype=numpy.bool)
window[..., 129:384, 129:384] = True
self.innerquarter = create_image_from_array(window, self.model.wcs)
test_visibility_gather_scatter.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def setUp(self):
self.lowcore = create_named_configuration('LOWBD2-CORE')
self.times = numpy.linspace(-300.0, 300.0, 11) * numpy.pi / 43200.0
self.frequency = numpy.linspace(1e8, 1.5e9, 7)
self.channel_bandwidth = numpy.array(7 * [self.frequency[1] - self.frequency[0]])
self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
test_image_deconvolution.py 文件源码
项目:algorithm-reference-library
作者: SKA-ScienceDataProcessor
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def setUp(self):
self.dir = './test_results'
os.makedirs(self.dir, exist_ok=True)
self.lowcore = create_named_configuration('LOWBD2-CORE')
self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
self.frequency = numpy.array([1e8])
self.channel_bandwidth = numpy.array([1e6])
self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
self.vis = create_visibility(self.lowcore, self.times, self.frequency,
channel_bandwidth=self.channel_bandwidth,
phasecentre=self.phasecentre, weight=1.0,
polarisation_frame=PolarisationFrame('stokesI'))
self.vis.data['vis'] *= 0.0
# Create model
self.test_model = create_test_image(cellsize=0.001, phasecentre=self.vis.phasecentre,
frequency=self.frequency)
self.vis = predict_2d(self.vis, self.test_model)
assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001,
polarisation_frame=PolarisationFrame('stokesI'))
self.dirty, sumwt = invert_2d(self.vis, self.model)
self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
window = numpy.zeros(shape=self.model.shape, dtype=numpy.bool)
window[..., 129:384, 129:384] = True
self.innerquarter = create_image_from_array(window, self.model.wcs)