def MakeNearRay( ipix, lr=None, observer_position=observer_position, collect=False ): ## reads data of LoS in constrained spherical volume around observer in z=0 snapshot ### provide lr = Lightray( dsz0 ) for pool computation ## write ray data to filename = FileNearRay( ipix, model=model, npix=npix ) ## skip if ray was produced already if os.path.isfile( filename ): print 'skip %i' % ipix, return; if lr is None: lr = LightRay( dsz0 ) ## initialize trident.LightRay for off in [ 0., 0.0001, -0.0001]: ## sometimes fails, when LoS is on axis. Try again with small offset try: direction = np.array( hp.pix2vec( nside, ipix) ) + off # shift to not move along edge of cells start_position = path_length_code * direction + observer_position lr.make_light_ray( ## compute LoS and save to .h5 file start_position = start_position, # LoS starts at the edge and ends at observer end_position = observer_position, data_filename = filename, fields = fields[:], redshift = redshift_max_near, ## starting redshift, chosen to end at observer with z=0 use_peculiar_velocity=False, # do not correct redshift for doppler shift from peculiar velocity ) break except: continue if collect: ## write to collection file ### !!! not possible to write to same file in multi processing. Use separate function CollectRays CollectRay( ipix )
def test_light_ray_cosmo_nonperiodic(self): """ This test generates a cosmological light ray using non-periodic segments """ lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.03) lr.make_light_ray(seed=1234567, periodic=False, fields=['temperature', 'density', 'H_number_density'], data_filename='lightray.h5') ds = load('lightray.h5') compare_light_ray_solutions(lr, ds)
def test_light_ray_cosmo(self): """ This test generates a cosmological light ray """ lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.03) lr.make_light_ray( seed=1234567, fields=['temperature', 'density', 'H_p0_number_density'], data_filename='lightray.h5') ds = load('lightray.h5') compare_light_ray_solutions(lr, ds)
def test_light_ray_non_cosmo(self): """ This test generates a non-cosmological light ray """ lr = LightRay(COSMO_PLUS_SINGLE) ray_start = [0,0,0] ray_end = [1,1,1] lr.make_light_ray(start_position=ray_start, end_position=ray_end, fields=['temperature', 'density', 'H_number_density'], data_filename='lightray.h5') ds = load('lightray.h5') compare_light_ray_solutions(lr, ds)
def test_light_ray_cosmo_nested(self): """ This test generates a cosmological light ray confing the ray to a subvolume """ left = np.ones(3) * 0.25 right = np.ones(3) * 0.75 lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.03) lr.make_light_ray(seed=1234567, left_edge=left, right_edge=right, fields=['temperature', 'density', 'H_number_density'], data_filename='lightray.h5') ds = load('lightray.h5') compare_light_ray_solutions(lr, ds)
def test_light_ray_non_cosmo_from_dataset(self): """ This test generates a non-cosmological light ray created from an already loaded dataset """ ds = load(COSMO_PLUS_SINGLE) lr = LightRay(ds) ray_start = [0,0,0] ray_end = [1,1,1] lr.make_light_ray(start_position=ray_start, end_position=ray_end, fields=[('gas', 'temperature'), ('gas', 'density'), ('gas', 'H_p0_number_density')], data_filename='lightray.h5') ds = load('lightray.h5') compare_light_ray_solutions(lr, ds)
def CreateLoSSegments( ipixs, redshift_snapshots=redshift_snapshots[:], redshift_max=redshift_max, ts=ts[:], redshift_accuracy=redshift_accuracy, seed=seed, force=False ): ## creates files with random segments of LoS data of ray through yt-TimeSeries ts that contains grid data of snapshots at redshift_snapshots ## ipixs is a list of the indices given to the rays, defines how many rays are produced ## if not forced to, produce ray only if its data isn't already written to file if not force: try: with h5.File( LoS_observables_file, 'r' ) as f: for ipix in ipixs[:]: try: tmp = f[ '/'.join( [ model, 'chopped', str(ipix), 'DM' + 'overestimate'*overestimate_SM] ) ] ipixs.remove(ipix) except: pass except: pass ## prevent the case of call with empty ipixs if len(ipixs) == 0: return; ''' remove completely ## exclude constrained near ray, go to z=0 instead try: redshift_snapshots.remove( redshift_max_near ) except: pass ''' RS = np.random.RandomState( seed * ( 1 + ipixs[0] ) ) ## index of earliest snapshot to be probed == number of snapshots to be probed # n_snaps = np.where( np.round( redshift_snapshots, redshift_accuracy ) >= redshift_max )[0][0] n_snaps = len( redshift_snapshots ) - 1 # redshift = redshift_max n = np.zeros( len(ipixs) ) ## for all snapshots, starting with the earliest for i_snap in range(n_snaps)[::-1]: ## load snapshot lr = LightRay( ts[i_snap] ) ## set time when rays should enter the snapshot redshift = redshift_snapshots[1+i_snap] new = True flags = np.ones( len(ipixs) ) ## flag whether more segments are needed while np.any( flags ): ## create round of segments for i_flag, ipix in enumerate(ipixs): ## skip those that finished current snapshot if not flags[i_flag]: continue ## in later rounds: for each, read final redshift from previous and continue with that if not new: redshift = h5.File( FilenameSegment( ipix, n[i_flag]-1 ) )['grid/redshift'].value[-1] ## in case redshift is past next snapshot, skip and deflag if redshift <= redshift_snapshots[i_snap]: ###!!!! flags[i_flag] = 0 continue # print 'make segment from z=%.4f' % redshift CreateSegment( lr, RS, redshift, n[i_flag], ipix ) n[i_flag] += 1 ## round finished new = False