Skip to content

Commit

Permalink
Merge pull request #105 from brittonsmith/infinity
Browse files Browse the repository at this point in the history
Be more careful about limiting size of line deposition array.
  • Loading branch information
brittonsmith committed Jan 3, 2020
2 parents 99ebe58 + 5354ba3 commit 3d86e4b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ env:
TRIDENT_ION_DATA=$HOME/.trident
TRIDENT_ANSWER_DATA=$HOME/answer_test_data
TRIDENT_CONFIG=$TRIDENT_ION_DATA/config.tri
YT_GOLD=4f56c4c9b534106fd45e8dfe644280755236fb5d
YT_GOLD=3b7ad0cf0e0c4002137100ac22557027d4811273
YT_HEAD=yt-4.0
TRIDENT_GOLD=test-standard-sph-viz-v3
TRIDENT_GOLD=test-standard-sph-viz-v4

before_install:
- |
Expand Down
36 changes: 35 additions & 1 deletion trident/absorption_spectrum/absorption_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ def make_spectrum(self, input_object, output_file=None,
input_ds = input_object.ds
field_data = input_object

# temporary fix for yt-4.0 ytdata selection issue
input_ds.domain_left_edge = input_ds.domain_left_edge.to('code_length')
input_ds.domain_right_edge = input_ds.domain_right_edge.to('code_length')

if self.bin_space == 'velocity':
self.zero_redshift = getattr(input_ds, 'current_redshift', 0)

Expand Down Expand Up @@ -852,7 +856,9 @@ def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
self._get_bin_indices(
my_lambda, self.bin_width,
my_obs[i], window_width_in_bins)
n_vbins = window_width_in_bins * n_vbins_per_bin[i]

window_size = right_index - left_index
n_vbins = window_size * n_vbins_per_bin[i]

# the array of virtual bins in lambda space
vbins = \
Expand All @@ -869,6 +875,12 @@ def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
else:
raise RuntimeError('What bin_space is this?')

if my_vbins.size > 1e6:
mylog.warning(
('About to deposit a line with %d bins.' +
'This may take a while. You might want to consider ' +
'increasing the bin size.') % my_vbins.size)

# the virtual bins and their corresponding opacities
my_vbins, vtau = \
tau_profile(
Expand All @@ -889,6 +901,16 @@ def _add_lines_to_spectrum(self, field_data, use_peculiar_velocity,
my_obs[i], window_width_in_bins)

break

# If we have fixed bins, call it done when the
# spectrum takes up the entire range.
if not self._auto_lambda:
left_ok = vtau[0] < min_tau or left_index <= 0
right_ok = vtau[-1] < min_tau or \
right_index >= self.lambda_field.size
if left_ok and right_ok:
break

window_width_in_bins *= 2

if center_index is None:
Expand Down Expand Up @@ -1041,6 +1063,18 @@ def _get_bin_indices(self, lambda_field, dlambda, lambda_obs,
left_index = (center_index - window_width_in_bins//2)
right_index = (center_index + window_width_in_bins//2)

# if fixed size, make some sensible bounds on size of virtual spectrum
if not self._auto_lambda:
if left_index <= 0 and right_index >= lambda_field.size:
left_index = 0
right_index = lambda_field.size
elif center_index < 0:
left_index = max(left_index, center_index)
right_index = min(right_index, lambda_field.size)
elif center_index > lambda_field.size:
left_index = max(left_index, 0)
right_index = min(right_index, center_index)

return left_index, center_index, right_index

def _get_global_lambda_field(self, comm=None):
Expand Down
5 changes: 5 additions & 0 deletions trident/light_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ def make_light_ray(self, seed=None, periodic=True,
if data_filename is not None:
self._write_light_ray(data_filename, all_data)
ray_ds = load(data_filename)

# temporary fix for yt-4.0 ytdata selection issue
ray_ds.domain_left_edge = ray_ds.domain_left_edge.to('code_length')
ray_ds.domain_right_edge = ray_ds.domain_right_edge.to('code_length')

return ray_ds
else:
return None
Expand Down
4 changes: 4 additions & 0 deletions trident/spectrum_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ def make_spectrum(self, ray, lines='all',
else:
raise RuntimeError("Unrecognized ray type.")

# temporary fix for yt-4.0 ytdata selection issue
ray.domain_left_edge = ray.domain_left_edge.to('code_length')
ray.domain_right_edge = ray.domain_right_edge.to('code_length')

# Clear out any previous spectrum that existed first
self.clear_spectrum()

Expand Down
5 changes: 5 additions & 0 deletions trident/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ def make_onezone_ray(density=1e-26, temperature=1000, metallicity=0.3,

# load dataset and make spectrum
ray = load(filename)

# temporary fix for yt-4.0 ytdata selection issue
ray.domain_left_edge = ray.domain_left_edge.to('code_length')
ray.domain_right_edge = ray.domain_right_edge.to('code_length')

return ray

def import_check():
Expand Down

0 comments on commit 3d86e4b

Please sign in to comment.