diff --git a/trident/light_ray.py b/trident/light_ray.py index fa9c2097b..1c1f65760 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -311,11 +311,11 @@ def _calculate_light_ray_solution(self, seed=None, def make_light_ray(self, seed=None, periodic=True, left_edge=None, right_edge=None, min_level=None, start_position=None, end_position=None, - trajectory=None, - fields=None, setup_function=None, + trajectory=None, fields=None, setup_function=None, solution_filename=None, data_filename=None, get_los_velocity=None, use_peculiar_velocity=True, - redshift=None, field_parameters=None, njobs=-1): + redshift=None, redshift_align=None, + field_parameters=None, njobs=-1): """ Actually generate the LightRay by traversing the desired dataset. @@ -419,7 +419,19 @@ def make_light_ray(self, seed=None, periodic=True, redshift will be 0 for a non-cosmological dataset and the dataset redshift for a cosmological dataset. Default: None. - + + :redshift_align: optional, str + + Used with light rays with single datasets to specify where the + redshift is "equal" to the redshift of the dataset, or "redshift" + if that was specified. If "start" or None, the line start will be + at this redshift and the line end will be at a lower redshift. + Other options are "center", so the line start will be greater than + this redshift, the line end will be less, and they will align at the + midpoint, and "everywhere", so the line will be at this redshift + throughout. + Default: None. + :field_parameters: optional, dict Used to set field parameters in light rays. For example, if the 'bulk_velocity' field parameter is set, the relative @@ -517,13 +529,14 @@ def make_light_ray(self, seed=None, periodic=True, self._data = {} # temperature field is automatically added to fields if fields is None: fields = [] - if ('gas', 'temperature') not in fields: - fields.append(('gas', 'temperature')) + if (('gas', 'temperature') not in fields) and \ + ('temperature' not in fields): + fields.append(('gas', 'temperature')) data_fields = fields[:] all_fields = fields[:] all_fields.extend(['l', 'dl', 'redshift']) - all_fields.extend(['x', 'y', 'z']) - data_fields.extend(['x', 'y', 'z']) + all_fields.extend([('gas','x'),('gas','y'),('gas','z')]) + data_fields.extend([('gas','x'),('gas','y'),('gas','z')]) if use_peculiar_velocity: all_fields.extend(['relative_velocity_x', 'relative_velocity_y', 'relative_velocity_z', @@ -552,7 +565,10 @@ def make_light_ray(self, seed=None, periodic=True, mylog.warning("Generating light ray with different redshift than " + "the dataset itself.") my_segment["redshift"] = redshift - + + if redshift_align is None: + redshift_align = 'start' + if setup_function is not None: setup_function(ds) @@ -567,8 +583,8 @@ def make_light_ray(self, seed=None, periodic=True, segment_length = my_segment["traversal_box_fraction"] * \ ds.domain_width[0].in_units("Mpccm / h") next_redshift = my_segment["redshift"] - \ - self._deltaz_forward(my_segment["redshift"], - segment_length) + self._deltaz_forward(my_segment["redshift"], + segment_length) elif my_segment.get("next", None) is None: next_redshift = self.near_redshift else: @@ -675,10 +691,26 @@ def make_light_ray(self, seed=None, periodic=True, sub_data[key] = ds.arr(sub_data[key]).in_cgs() # Get redshift for each lixel. Assume linear relation between l - # and z. so z = z_start - z_range * (l / l_range) - sub_data[('gas', 'redshift')] = my_segment['redshift'] - \ - (sub_data[('gas', 'l')] / ray_length) * \ - (my_segment['redshift'] - next_redshift) + # and z, depending on where they should be "aligned". + # 'start': z = z_dataset - z_range * (l / l_range) + # 'center': z = z_dataset - z_range * ((l - l_range/2) / l_range) + # 'everywhere': z = z_dataset + if redshift_align == 'start': + sub_data[('gas','redshift')] = my_segment['redshift'] - \ + (sub_data[('gas','l')] / ray_length) * \ + (my_segment['redshift'] - next_redshift) + elif redshift_align == 'center': + sub_data[('gas','redshift')] = my_segment['redshift'] - \ + ((sub_data[('gas','l')]-ray_length/2) / ray_length) * \ + (my_segment['redshift'] - next_redshift) + elif redshift_align == 'everywhere': + sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ + my_segment['redshift'] + else: + mylog.warning(f'redshift_align {redshift_align} not recognized. '+\ + 'Using z = z_start for full length') + sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ + my_segment['redshift'] # When using the peculiar velocity, create effective redshift # (redshift_eff) field combining cosmological redshift and diff --git a/trident/ray_generator.py b/trident/ray_generator.py index 8442b7fd4..1b5d83661 100644 --- a/trident/ray_generator.py +++ b/trident/ray_generator.py @@ -30,7 +30,8 @@ def make_simple_ray(dataset_file, start_position, end_position, lines=None, ftype="gas", fields=None, solution_filename=None, data_filename=None, - trajectory=None, redshift=None, field_parameters=None, + trajectory=None, redshift=None, + redshift_align='start', field_parameters=None, setup_function=None, load_kwargs=None, line_database=None, ionization_table=None): """ @@ -124,10 +125,19 @@ def make_simple_ray(dataset_file, start_position, end_position, :redshift: float, optional - Sets the highest cosmological redshift of the ray. By default, it will + Sets the base cosmological redshift of the ray. By default, it will use the cosmological redshift of the dataset, if set, and if not set, it will use a redshift of 0. Default: None + + :redshift_align: optional, str + + Sets the location where the cosmological redshift "aligns" with the base + cosmological redshift. Default is the start of the ray, other options are + 'center', so the start will be higher redshift and the end will be lower, + and 'everywhere', so the full length will be at the base cosmological + redshift + Default: 'start' :field_parameters: optional, dict Used to set field parameters in light rays. For example, @@ -231,7 +241,8 @@ def make_simple_ray(dataset_file, start_position, end_position, solution_filename=solution_filename, data_filename=data_filename, field_parameters=field_parameters, - redshift=redshift) + redshift=redshift, + redshift_align=redshift_align) def make_compound_ray(parameter_filename, simulation_type, near_redshift, far_redshift,