Exemplo n.º 1
0
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 )
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)