dsavransky / EXOSIMS

Simulator for exoplanet direct imaging space missions
BSD 3-Clause "New" or "Revised" License
25 stars 35 forks source link

popStars filtering broken for lists length > 1 #350

Closed turmon closed 1 year ago

turmon commented 1 year ago

Describe the bug The prototype TargetList can filter stars within a specs-supplied popStars property. This is implemented around line 415 of Prototypes/TargetList.py. Alas, the implementation fails for popStars lists of length > 1. This is because the tmp variable is shrinking in length, but the self.Name variable used to index tmp is not shrinking. The second time through, the loop will fail.

Stack trace:

2347 targets imported from star catalog.
Traceback (most recent call last):
  File "/proj/exep/rhonda/Sandbox/HabEx/Local/ipcluster_ensemble_jpl_driver.py", line 412, in <module>
    message = main(args, xspecs)
  File "/proj/exep/rhonda/Sandbox/HabEx/Local/ipcluster_ensemble_jpl_driver.py", line 304, in main
    sim = EXOSIMS.MissionSim.MissionSim(args.scriptfile, **xspecs)
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/MissionSim.py", line 147, in __init__
    self.SurveySimulation = get_module(specs['modules']['SurveySimulation'],
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/SurveySimulation/coroOnlyScheduler.py", line 55, in __init__
    SurveySimulation.__init__(self, **specs)
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/Prototypes/SurveySimulation.py", line 175, in __init__
    self.SimulatedUniverse = get_module(specs['modules']['SimulatedUniverse'],
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/SimulatedUniverse/DulzPlavchanUniverseEarthsOnly.py", line 12, in __init__
    SimulatedUniverse.__init__(self, **specs)
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/Prototypes/SimulatedUniverse.py", line 141, in __init__
    self.TargetList = get_module(specs['modules']['TargetList'],
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/Prototypes/TargetList.py", line 186, in __init__
    self.populate_target_list(**specs)
  File "/proj/exep/rhonda/Sandbox/HabEx/EXOSIMS/EXOSIMS/Prototypes/TargetList.py", line 268, in populate_target_list
    tmp = tmp[self.Name != n ]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 2346 but corresponding boolean dimension is 2347

Drop into debugger:

(Pdb) self.Name
array(['HIP 57', 'HIP 169 A', 'HIP 171', ..., 'HIP 118310', 'HIP 120005',
       'HIP 120148'], dtype='<U12')
(Pdb) len(self.Name)   
2347
(Pdb) len(tmp)
2346

To Reproduce Steps to reproduce the behavior: Any popStars of length > 1 should tickle this bug.

Suggested fix The following fix works, and is simpler --

        if popStars is not None:
            tmp = np.arange(self.nStars)
            for n in popStars:
                tmp[self.Name == n] = -1

            self.revise_lists(tmp[tmp >= 0])

JSON script: As noted, anything with 2 or more popStars

EXOSIMS version: This is a longstanding issue that has not been triggered because all of our popStars instances have been either [] or singletons.

dsavransky commented 1 year ago

Closed by #352