From d434c7912f2affacf01720295f633f01355e5ea8 Mon Sep 17 00:00:00 2001 From: Clayton Strawn <33767568+claytonstrawn@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:29:00 -0700 Subject: [PATCH 1/6] using the current form of light_ray from placeholder --- trident/light_ray.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index fa9c2097b..ec2916564 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, field_parameters=None, + redshift_align = 'start',njobs=-1): """ Actually generate the LightRay by traversing the desired dataset. @@ -517,13 +517,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', @@ -676,10 +677,16 @@ def make_light_ray(self, seed=None, periodic=True, # 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) - + if redshift_align == 'start': + sub_data['redshift'] = my_segment['redshift'] - \ + (sub_data['l'] / ray_length) * \ + (my_segment['redshift'] - next_redshift) + elif redshift_align == 'center': + sub_data['redshift'] = my_segment['redshift'] - \ + ((sub_data['l']-ray_length/2) / (ray_length/2)) * \ + (my_segment['redshift'] - next_redshift) + elif redshift_align == 'everywhere': + sub_data['redshift'] = my_segment['redshift'] # When using the peculiar velocity, create effective redshift # (redshift_eff) field combining cosmological redshift and # doppler redshift. From c526bfd5ac34786959736bc5acefb5d4a1567733 Mon Sep 17 00:00:00 2001 From: Clayton Strawn Date: Thu, 30 Mar 2023 16:09:06 -0700 Subject: [PATCH 2/6] added an else clause for redshift_align --- trident/light_ray.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index ec2916564..8fea06255 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -568,8 +568,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: @@ -683,10 +683,14 @@ def make_light_ray(self, seed=None, periodic=True, (my_segment['redshift'] - next_redshift) elif redshift_align == 'center': sub_data['redshift'] = my_segment['redshift'] - \ - ((sub_data['l']-ray_length/2) / (ray_length/2)) * \ + ((sub_data['l']-ray_length/2) / ray_length) * \ (my_segment['redshift'] - next_redshift) elif redshift_align == 'everywhere': - sub_data['redshift'] = my_segment['redshift'] + sub_data['redshift'] = np.ones(sub_data['l'].shape)*my_segment['redshift'] + else: + mylog.warning('redshift_align not recognized. Using z = z_start for full length') + sub_data['redshift'] = np.ones(sub_data['l'].shape)*my_segment['redshift'] + # When using the peculiar velocity, create effective redshift # (redshift_eff) field combining cosmological redshift and # doppler redshift. From c1d6fa0cfb5e6c2374db1a5e623a0db6865e70dc Mon Sep 17 00:00:00 2001 From: Clayton Strawn Date: Thu, 30 Mar 2023 17:38:35 -0700 Subject: [PATCH 3/6] added docstrings for redshift_align --- trident/light_ray.py | 37 +++++++++++++++++++++++++++---------- trident/ray_generator.py | 17 ++++++++++++++--- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index 8fea06255..4abc2772b 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -314,8 +314,8 @@ def make_light_ray(self, seed=None, periodic=True, 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, - redshift_align = 'start',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 @@ -553,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) @@ -678,18 +693,20 @@ def make_light_ray(self, seed=None, periodic=True, # Get redshift for each lixel. Assume linear relation between l # and z. so z = z_start - z_range * (l / l_range) if redshift_align == 'start': - sub_data['redshift'] = my_segment['redshift'] - \ - (sub_data['l'] / ray_length) * \ + sub_data[('gas','redshift')] = my_segment['redshift'] - \ + (sub_data[('gas','l')] / ray_length) * \ (my_segment['redshift'] - next_redshift) elif redshift_align == 'center': - sub_data['redshift'] = my_segment['redshift'] - \ - ((sub_data['l']-ray_length/2) / ray_length) * \ + 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['redshift'] = np.ones(sub_data['l'].shape)*my_segment['redshift'] + sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ + my_segment['redshift'] else: mylog.warning('redshift_align not recognized. Using z = z_start for full length') - sub_data['redshift'] = np.ones(sub_data['l'].shape)*my_segment['redshift'] + 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..5870d126f 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, From f18a7c67fc121c6a5745de07037c54d91565639d Mon Sep 17 00:00:00 2001 From: Clayton Strawn Date: Thu, 30 Mar 2023 18:38:48 -0700 Subject: [PATCH 4/6] added comments explaining the behavior --- trident/light_ray.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index 4abc2772b..ab8b039f7 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -311,7 +311,7 @@ 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, redshift_align=None, @@ -583,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: @@ -691,7 +691,10 @@ 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) + # 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) * \ @@ -704,7 +707,8 @@ def make_light_ray(self, seed=None, periodic=True, sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ my_segment['redshift'] else: - mylog.warning('redshift_align not recognized. Using z = z_start for full length') + mylog.warning(f'redshift_align {redshift_aligh} not recognized. '+\ + 'Using z = z_start for full length') sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ my_segment['redshift'] From 3c033f1b933ceec0774afc31aaac00bb1c2f05d9 Mon Sep 17 00:00:00 2001 From: Clayton Strawn Date: Thu, 30 Mar 2023 19:02:48 -0700 Subject: [PATCH 5/6] fixed typo --- trident/light_ray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index ab8b039f7..25eb04b0e 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -707,7 +707,7 @@ def make_light_ray(self, seed=None, periodic=True, sub_data[('gas','redshift')] = np.ones(sub_data[('gas','l')].shape)*\ my_segment['redshift'] else: - mylog.warning(f'redshift_align {redshift_aligh} not recognized. '+\ + 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'] From 8f03af1aa78fd35124074c502e1e05e08f5f3969 Mon Sep 17 00:00:00 2001 From: Clayton Strawn Date: Thu, 30 Mar 2023 21:45:08 -0700 Subject: [PATCH 6/6] removed trailing whitespaces --- trident/light_ray.py | 8 ++++---- trident/ray_generator.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/trident/light_ray.py b/trident/light_ray.py index 25eb04b0e..1c1f65760 100644 --- a/trident/light_ray.py +++ b/trident/light_ray.py @@ -422,11 +422,11 @@ def make_light_ray(self, seed=None, periodic=True, :redshift_align: optional, str - Used with light rays with single datasets to specify where the + 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 + 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. diff --git a/trident/ray_generator.py b/trident/ray_generator.py index 5870d126f..1b5d83661 100644 --- a/trident/ray_generator.py +++ b/trident/ray_generator.py @@ -133,9 +133,9 @@ def make_simple_ray(dataset_file, start_position, end_position, :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 + 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 + and 'everywhere', so the full length will be at the base cosmological redshift Default: 'start'