Skip to content

Commit

Permalink
array to generator to improve memory usage
Browse files Browse the repository at this point in the history
The baseline rotation at every time step is implemented as a generator.
This uses same memory only when it is called in a for loop, making it more stable.

This change fixes #58
  • Loading branch information
sambit-giri committed Dec 30, 2024
1 parent 1fc3ddc commit 5839138
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

setup(
name='tools21cm',
version='2.2.5',
version='2.2.6',
author='Sambit Giri',
author_email='sambit.giri@gmail.com',
packages=find_packages(where="src"),
Expand Down
8 changes: 4 additions & 4 deletions src/tools21cm/telescope_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ def get_uv_daily_observation(ncells, z, filename=None, total_int_time=4., int_ti
total_observations = int((total_int_time * 3600) / int_time)

if verbose:
print("Generating uv map from daily observations.")
print("Generating uv map from daily observations...")

# Vectorize the observation loop by calculating all rotations at once
time_indices = np.arange(total_observations) + 1
all_rotated_Nbase = np.array([earth_rotation_effect(Nbase, i, int_time, declination) for i in time_indices])
all_rotated_Nbase = (earth_rotation_effect(Nbase, i, int_time, declination) for i in time_indices)

# Grid uv tracks for each observation without individual loops
for rotated_Nbase in tqdm(all_rotated_Nbase, disable=not verbose, desc="Gridding uv tracks"):
Expand All @@ -154,9 +154,9 @@ def get_uv_daily_observation(ncells, z, filename=None, total_int_time=4., int_ti
uv_map /= total_observations # Normalize by the total number of observations

if verbose:
print("Observation complete.")
print("...done")

return uv_map, N_ant
return uv_map, N_ant

def grid_uv_tracks(Nbase, z, ncells, boxsize=None, include_mirror_baselines=False):
"""
Expand Down

0 comments on commit 5839138

Please sign in to comment.