def test_random_like(self): """ Test that the random_like function produces sensible data """ # Try for floats and complex data for dtype in [np.float32, np.float64, np.complex64, np.complex128]: # Test random array creation with same # shape and type as existing array shape = (np.random.randint(1, 50), np.random.randint(1, 50)) ary = np.empty(shape=shape, dtype=dtype) random_ary = mbu.random_like(ary) # Test that that the shape and type is correct self.assertTrue(random_ary.shape == ary.shape) self.assertTrue(random_ary.dtype == dtype) # Test that we're getting complex data out if np.issubdtype(dtype, np.complexfloating): proportion_cplx = np.sum(np.iscomplex(random_ary)) / random_ary.size self.assertTrue(proportion_cplx > 0.9) # Test random array creation with supplied shape and type shape = (np.random.randint(1, 50), np.random.randint(1, 50)) random_ary = mbu.random_like(shape=shape, dtype=dtype) # Test that that the shape and type is correct self.assertTrue(random_ary.shape == shape) self.assertTrue(random_ary.dtype == dtype) # Test that we're getting complex data out if np.issubdtype(dtype, np.complexfloating): proportion_cplx = np.sum(np.iscomplex(random_ary)) / random_ary.size self.assertTrue(proportion_cplx > 0.9)
montblanc.log.setLevel(logging.INFO) slvr_cfg = montblanc.rime_solver_cfg( msfile=args.msfile, sources=montblanc.sources(point=args.npsrc, gaussian=args.ngsrc, sersic=args.nssrc), init_weights='weight', weight_vector=False, dtype='float', auto_correlations=args.auto_correlations, version=args.version) with montblanc.rime_solver(slvr_cfg) as slvr: # Random point source coordinates in the l,m,n (brightness image) domain slvr.lm[:] = mbu.random_like(slvr.lm) * 0.1 # Need a positive semi-definite brightness matrix I, Q, U, V = slvr.stokes[:, :, 0], slvr.stokes[:, :, 1], slvr.stokes[:, :, 2], slvr.stokes[:, :, 3] Q[:] = np.random.random(size=Q.shape) - 0.5 U[:] = np.random.random(size=U.shape) - 0.5 V[:] = np.random.random(size=V.shape) - 0.5 noise = np.random.random(size=(Q.shape)) * 0.1 # Determinant of a brightness matrix # is I^2 - Q^2 - U^2 - V^2, noise ensures # positive semi-definite matrix I[:] = np.sqrt(Q**2 + U**2 + V**2 + noise)
with montblanc.rime_solver(slvr_cfg) as slvr: # Get the lm coordinates lm = sky_parse.shape_arrays(['l','m'], slvr.lm.shape, slvr.lm.dtype) # Get the stokes and alpha parameters stokes, alpha = repeat_brightness_over_time(slvr, sky_parse) # If there are gaussian sources, create their # shape matrix and transfer it. if slvr.dim_global_size('ngsrc') > 0: gauss.shape = sky_parse.shape_arrays(['el','em','eR'], slvr.gauss.shape.shape, slvr.gauss.shape.dtype) # Create observed visibilities and upload them to the GPU observed_vis = mbu.random_like(slvr.observed_vis) slvr.transfer_observed_vis(observed_vis) # Generate random antenna pointing errors point_errors = mbu.random_like(slvr.point_errors) # Generate and transfer a noise vector. weight_vector = mbu.random_like(slvr.weight_vector) slvr.transfer_weight_vector(weight_vector) # Execute the pipeline for i in range(args.count): # Set data on the solver object. Uploads to GPU slvr.transfer_lm(lm) slvr.transfer_stokes(stokes) slvr.transfer_alpha(alpha)
args = parser.parse_args(sys.argv[1:]) # Set the logging level montblanc.log.setLevel(logging.INFO) slvr_cfg = montblanc.rime_solver_cfg(msfile=args.msfile, sources=montblanc.sources(point=args.npsrc, gaussian=args.ngsrc, sersic=args.nssrc), init_weights='weight', weight_vector=False, dtype='float', auto_correlations=args.auto_correlations, version=args.version) with montblanc.rime_solver(slvr_cfg) as slvr: # Random point source coordinates in the l,m,n (brightness image) domain slvr.lm[:] = mbu.random_like(slvr.lm)*0.1 # Need a positive semi-definite brightness matrix I, Q, U, V = slvr.stokes[:,:,0], slvr.stokes[:,:,1], slvr.stokes[:,:,2], slvr.stokes[:,:,3] Q[:] = np.random.random(size=Q.shape)-0.5 U[:] = np.random.random(size=U.shape)-0.5 V[:] = np.random.random(size=V.shape)-0.5 noise = np.random.random(size=(Q.shape))*0.1 # Determinant of a brightness matrix # is I^2 - Q^2 - U^2 - V^2, noise ensures # positive semi-definite matrix I[:] = np.sqrt(Q**2 + U**2 + V**2 + noise) slvr.alpha[:] = mbu.random_like(slvr.alpha) # E beam slvr.E_beam[:] = mbu.random_like(slvr.E_beam)
# Set the logging level montblanc.log.setLevel(logging.INFO) slvr_cfg = montblanc.rime_solver_cfg(msfile=args.msfile, sources=montblanc.sources( point=args.npsrc, gaussian=args.ngsrc, sersic=args.nssrc), init_weights='weight', weight_vector=False, auto_correlations=args.auto_correlations, dtype='double', version=args.version) with montblanc.rime_solver(slvr_cfg) as slvr: # Random point source coordinates in the l,m,n (brightness image) domain lm = mbu.random_like(slvr.lm)*0.1 if args.version in [Options.VERSION_TWO]: # Random brightness matrix for the point sources brightness = mbu.random_like(slvr.brightness) elif args.version in [Options.VERSION_FOUR]: # Need a positive semi-definite brightness # matrix for v4 and v5 stokes = np.empty(shape=slvr.stokes.shape, dtype=slvr.stokes.dtype) I, Q, U, V = stokes[:,:,0], stokes[:,:,1], stokes[:,:,2], stokes[:,:,3] Q[:] = np.random.random(size=Q.shape)-0.5 U[:] = np.random.random(size=U.shape)-0.5 V[:] = np.random.random(size=V.shape)-0.5 noise = np.random.random(size=(Q.shape))*0.1 # Determinant of a brightness matrix # is I^2 - Q^2 - U^2 - V^2, noise ensures