diff --git a/RMS/Astrometry/ApplyRecalibrate.py b/RMS/Astrometry/ApplyRecalibrate.py index 2ba630903..7d0079b3a 100644 --- a/RMS/Astrometry/ApplyRecalibrate.py +++ b/RMS/Astrometry/ApplyRecalibrate.py @@ -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