Skip to content

Commit

Permalink
fixed star choice when there are too many clastars in ApplyRecalibrat…
Browse files Browse the repository at this point in the history
…e.py
  • Loading branch information
dvida committed Nov 4, 2024
1 parent 86c1d28 commit 9572e67
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions RMS/Astrometry/ApplyRecalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,33 @@ def recalibrateFF(
# If there more stars than a set limit, sample them randomly using the same seed for reproducibility
if not ignore_max_stars and len(star_dict_ff[jd]) > config.recalibration_max_stars:

# Make a copy so that the original star dictionary is not modified
star_dict_ff = copy.deepcopy(star_dict_ff)

# Python 3+
if hasattr(np.random, 'default_rng'):

# Use the newer Generator-based RNG
rng = np.random.default_rng(seed=0)


# Sample the stars and store them in a copy of the star dictionary
star_dict_ff = {jd: rng.choice(star_dict_ff[jd], config.recalibration_max_stars, replace=False)}

# Python 2
else:

# Use the older RandomState-based RNG
rng = np.random.RandomState(seed=0)

# Sample the stars and store them in a copy of the star dictionary
star_dict_ff = copy.deepcopy(star_dict_ff)
star_dict_ff = {jd: rng.choice(star_dict_ff[jd], config.recalibration_max_stars, replace=False)}
# RandomState.choice requires indices for complex data types
indices = rng.choice(
len(star_dict_ff[jd]),
config.recalibration_max_stars,
replace=False
)

# Use the indices to select the stars
star_dict_ff[jd] = [star_dict_ff[jd][i] for i in indices]


# A list of matching radiuses to try
Expand Down

0 comments on commit 9572e67

Please sign in to comment.