def get_keepout(self):
        r'''Instantiate Exosims object to get 2d keepout matrix and place in object.'''
        ## unused -- the below would create a whole MissionSim
        ## sim = EXOSIMS.MissionSim.MissionSim(specfile, nopar=True)
        # create just the Exosims objects we need
        specs = copy.deepcopy(self.specs)
        obs = get_module_from_specs(specs, 'Observatory')(**specs)
        TL = get_module_from_specs(specs, 'TargetList')(**specs)
        TK = get_module_from_specs(specs, 'TimeKeeping')(**specs)

        # get keepout map for entire mission
        startTime = TK.missionStart.copy()
        endTime = TK.missionFinishAbs.copy()
        koangles = self.get_koangles(TL.OpticalSystem)
        # this will typically be cached
        #   koMap: [Mode][Target][Time], e.g. shape = (2, 405, 1827)
        #   time is in 1-day increments
        #   True = observable; False = obstructed
        koMap, koTimes = obs.generate_koMap(TL, startTime, endTime, koangles)

        # save in sim object
        self.startTime = startTime
        self.endTime = endTime
        self.koMap = koMap
        self.koTimesObj = koTimes
        # koTimes is an offset from mission start, in days
        self.koTimes = (koTimes - startTime).value
예제 #2
0
    def test_get_module_from_specs_error(self):
        r"""Test get-from-specs -- error.

        Approach: Load module from a file we know is present."""
        module = 'KnownRVPlanetsNotThere'
        modtype = 'PlanetPopulation'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        with self.assertRaises(ValueError):
            m = get_module_from_specs(specs, modtype)
예제 #3
0
    def test_get_module_from_specs_3(self):
        r"""Test get-from-specs -- non-prototype.

        Approach: Load module from a file we know is present."""
        module = 'KnownRVPlanets'
        modtype = 'PlanetPopulation'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #4
0
    def test_get_module_from_specs_4(self):
        r"""Test get-from-specs -- non-EXOSIMS.

        Approach: Load module from a file we know is present."""
        module = 'tests.TestModules.TimeKeeping.TimeKeepingModified'
        modtype = 'TimeKeeping'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #5
0
    def test_get_module_from_specs_1(self):
        r"""Test get-from-specs -- prototype.

        Approach: Load module from a file we know is present."""
        module = 'TimeKeeping'
        modtype = module
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #6
0
    def test_get_module_from_specs_error(self):
        r"""Test get-from-specs -- error.

        Approach: Load module from a file we know is present."""
        module = 'KnownRVPlanetsNotThere'
        modtype = 'PlanetPopulation'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        with self.assertRaises(ValueError):
            m = get_module_from_specs(specs, modtype)
예제 #7
0
    def test_get_module_from_specs_4(self):
        r"""Test get-from-specs -- non-EXOSIMS.

        Approach: Load module from a file we know is present."""
        module = 'tests.TestModules.TimeKeeping.TimeKeepingModified'
        modtype = 'TimeKeeping'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #8
0
    def test_get_module_from_specs_3(self):
        r"""Test get-from-specs -- non-prototype.

        Approach: Load module from a file we know is present."""
        module = 'KnownRVPlanets'
        modtype = 'PlanetPopulation'
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #9
0
    def test_get_module_from_specs_1(self):
        r"""Test get-from-specs -- prototype.

        Approach: Load module from a file we know is present."""
        module = 'TimeKeeping'
        modtype = module
        # a dictionary
        specs = {'modules': {modtype: module}}
        # basic test
        m = get_module_from_specs(specs, modtype)
        self.validate_module(m, modtype)
예제 #10
0
    def get_snr(self, seed):
        r'''Instantiate Exosims object to get 2d array of SNR vs. (star,time) and place in object.'''
        ## unused -- the below would create a whole MissionSim
        # create just the Exosims objects we need
        specs = copy.deepcopy(self.specs)
        specs['seed'] = args.seed
        specs['lucky_planets'] = False
        # sim = EXOSIMS.MissionSim.MissionSim(specfile, nopar=True)
        sim = get_module_from_specs(specs, 'SurveySimulation')(**specs)
        # obs = get_module_from_specs(specs, 'Observatory')(**specs)
        # TL  = get_module_from_specs(specs, 'TargetList')( **specs)
        # TK  = get_module_from_specs(specs, 'TimeKeeping')(**specs)

        TK = sim.TimeKeeping

        startTime = TK.missionStart.copy()
        endTime = TK.missionFinishAbs.copy()
        # this will typically be cached
        #   koMap: [Mode][Target][Time], e.g. shape = (2, 405, 1827)
        #   time is in 1-day increments
        #   True = observable; False = obstructed
        # koMap, koTimes = obs.generate_koMap(TL, startTime, endTime, koangles)

        ## code adapted from SurveySimulation.observation_characterization()
        OS = sim.OpticalSystem
        ZL = sim.ZodiacalLight
        TL = sim.TargetList
        SU = sim.SimulatedUniverse
        Obs = sim.Observatory
        TK = sim.TimeKeeping

        allModes = OS.observingModes
        # choose observing modes selected for detection (default marked with a flag)
        # det_mode = list(filter(lambda mode: mode['detectionMode'] == True, allModes))[0]
        # choose obs mode for characterization (default is first spectro/IFS mode)
        spectroModes = list(
            filter(lambda mode: 'spec' in mode['inst']['name'], allModes))
        if np.any(spectroModes):
            char_mode = spectroModes[0]
        # if no spectro mode, default char mode is first observing mode
        else:
            char_mode = allModes[0]

        # this may be too inclusive
        sInds = np.unique(self.char_sind)

        # iterate over days
        dt = 5.0 * u.d  # arbitrary
        N_time = int(5.0 * 365.0 / dt.value)  # Years = 5 -- FIXME!

        nStars = TL.nStars
        nPlans = SU.nPlans
        SNRs = np.full((nPlans, N_time), np.nan)

        print('Computing SNR for %d unique stars and %d times...' %
              (len(sInds), N_time))

        # FIXME: need dt for calc_sig_noise
        # from SS.__init__()
        sInds_all = np.arange(TL.nStars)
        # fEZ = ZL.fEZ0
        fEZ = SU.fEZ
        #dMag = sim.dMagint[sInds_all]

        snr_fail = 0
        pInds_for_sInds = []
        for s_num, sInd in enumerate(sInds):
            pInds = np.where(SU.plan2star == sInd)[0]
            pInds_for_sInds.append(pInds)
            print('Star %d/%d, id = %d, %d planets' %
                  (s_num, len(sInds), sInd, len(pInds)))
            currentTime = startTime.copy()
            for i in range(N_time):
                # bump time, propagate system -- prefer placement at top of loop
                if i > 0:
                    currentTime += dt
                    SU.propag_system(sInd, dt)  # now matches current time
                # calculate current zodiacal light brightness
                fZ = ZL.fZ(Obs, TL, sInd, currentTime, char_mode)[0]
                if False:
                    fEZ = SU.fEZ[sInd]  # index trouble - not sure why
                else:
                    fEZ = ZL.fEZ0
                # find integration time -- refer to above lines from SS.__init__()
                WAs = SU.WA[pInds]
                intTimes = OS.calc_intTime(TL, sInd, fZ, fEZ,
                                           sim.Completeness.dMagLim, WAs,
                                           char_mode)
                # Multi-planet systems will have several intTimes
                # FIXME: this is only OK for Earth Twins scenarios
                intTime = np.amax(intTimes)
                # cap intTime at ~60 days
                # TODO: get from scenario?
                intTime = np.minimum(intTime, np.array(60.0) * u.d)

                # calculate signal and noise (electron count rates)
                # about the call
                #   - TK.currenttime is not set correctly, and fZ is varying, so specify fZ
                #   - c_s_n will use fEZ, dMag, and WA from SU, which is OK
                try:
                    S1, N1 = sim.calc_signal_noise(sInd,
                                                   pInds,
                                                   intTime,
                                                   char_mode,
                                                   fZ=fZ)
                except ValueError:
                    print('calc_signal_noise fail')
                    snr_fail += 1
                    continue
                # valids = np.where(N1 > 0)[0]
                # find SNR
                #   will get some 0/0 here, and that is OK
                #   unacceptable WA sets S = N = 0 => SNR = NaN
                #   these NaNs can then be flagged later on
                with np.errstate(invalid='ignore', divide='ignore'):
                    SNR1 = S1 / N1
                SNRs[pInds, i] = SNR1

        print('SNR computation: failed in %d of %d calls' %
              (snr_fail, N_time * len(sInds)))
        # save results in sim object
        self.SNR_sInds = sInds
        self.SNR_p_for_s = pInds_for_sInds
        self.SNR_dt = dt.value
        self.SNR_nTime = N_time
        self.SNRs = SNRs