def test_target_completeness_constrainOrbits(self):
        """
        Compare calculated completenesses for multiple targets with constrain orbits set to true
        """

        with RedirectStreams(stdout=self.dev_null):
            TL = TargetList(ntargs=100,
                            constrainOrbits=True,
                            **copy.deepcopy(self.spec))

            mode = filter(lambda mode: mode['detectionMode'] == True,
                          TL.OpticalSystem.observingModes)[0]
            IWA = mode['IWA']
            OWA = mode['OWA']
            rrange = TL.PlanetPopulation.rrange
            maxd = (rrange[1] / np.tan(IWA)).to(u.pc).value
            mind = (rrange[0] / np.tan(OWA)).to(u.pc).value

            #want distances to span from outer edge below IWA to inner edge above OWA
            TL.dist = np.logspace(np.log10(mind / 10.), np.log10(maxd * 10.),
                                  TL.nStars) * u.pc

        Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(
            constrainOrbits=True, **copy.deepcopy(self.spec))
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(
            constrainOrbits=True, **copy.deepcopy(self.spec))

        cBrown = Brown.target_completeness(TL)
        cGarrett = Garrett.target_completeness(TL)

        np.testing.assert_allclose(cGarrett, cBrown, rtol=0.1, atol=1e-6)
    def __init__(self, **specs):

        #define mapping between attributes we need and the IPAC data
        #table loaded in the Planet Population module
        self.atts_mapping = {
            'Name': 'pl_hostname',
            'Spec': 'st_spstr',
            'parx': 'st_plx',
            'Umag': 'st_uj',
            'Bmag': 'st_bj',
            'Vmag': 'st_vj',
            'Rmag': 'st_rc',
            'Imag': 'st_ic',
            'Jmag': 'st_j',
            'Hmag': 'st_h',
            'Kmag': 'st_k',
            'dist': 'st_dist',
            'BV': 'st_bmvj',
            'L': 'st_lum',  #ln(solLum)
            'pmra': 'st_pmra',  #mas/year
            'pmdec': 'st_pmdec',  #mas/year
            'rv': 'st_radv'
        }

        TargetList.__init__(self, **specs)
    def test_target_completeness_def(self):
        """
        Compare calculated completenesses for multiple targets under default population
        settings.
        """

        with RedirectStreams(stdout=self.dev_null):
            TL = TargetList(ntargs=100, **copy.deepcopy(self.spec))

            mode = list(
                filter(lambda mode: mode['detectionMode'] == True,
                       TL.OpticalSystem.observingModes))[0]
            IWA = mode['IWA']
            OWA = mode['OWA']
            rrange = TL.PlanetPopulation.rrange
            maxd = (rrange[1] / np.tan(IWA)).to(u.pc).value
            mind = (rrange[0] / np.tan(OWA)).to(u.pc).value

            #want distances to span from outer edge below IWA to inner edge above OWA
            TL.dist = np.logspace(np.log10(mind / 10.), np.log10(maxd * 10.),
                                  TL.nStars) * u.pc

        Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(
            **copy.deepcopy(self.spec))
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(
            **copy.deepcopy(self.spec))

        cBrown = Brown.target_completeness(TL)
        cGarrett = Garrett.target_completeness(TL)

        np.testing.assert_allclose(cGarrett, cBrown, rtol=0.1, atol=1e-6)

        # test when scaleOrbits == True
        TL.L = np.exp(
            np.random.uniform(low=np.log(0.1),
                              high=np.log(10.),
                              size=TL.nStars))
        Brown.PlanetPopulation.scaleOrbits = True
        Garrett.PlanetPopulation.scaleOrbits = True

        cBrown = Brown.target_completeness(TL)
        cGarrett = Garrett.target_completeness(TL)

        cGarrett = cGarrett[cBrown != 0]
        cBrown = cBrown[cBrown != 0]
        meandiff = np.mean(np.abs(cGarrett - cBrown) / cBrown)

        self.assertLessEqual(meandiff, 0.1)
Exemple #4
0
    def run_ensemble(self, fun, nStars, tA, dtRange, m0, seed):

        TL = TargetList(**{"ntargs":nStars,"seed":seed,'modules':{"StarCatalog": "FakeCatalog", \
                            "TargetList":" ","OpticalSystem": "Nemati", "ZodiacalLight": "Stark", "PostProcessing": " ", \
                            "Completeness": " ","BackgroundSources": "GalaxiesFaintStars", "PlanetPhysicalModel": " ", \
                            "PlanetPopulation": "KeplerLike1"}, "scienceInstruments": [{ "name": "imager"}],  \
                            "starlightSuppressionSystems": [{ "name": "HLC-565"}]   })

        #im sorry
        tlString = "TL = TargetList(**{\"ntargs\":" + str(
            int(nStars)) + ",\"seed\":" + str(int(seed)) + ","
        tlString += " 'modules':{\"StarCatalog\": \"FakeCatalog\" , \"TargetList\": \" \", \"OpticalSystem\": \"Nemati\" ,"
        tlString += " \"ZodiacalLight\": \"Stark\" , \"PostProcessing\": \" \", \"Completeness\": \" \", \"BackgroundSources\": \"GalaxiesFaintStars\" ,"
        tlString += " \"PlanetPhysicalModel\": \" \", \"PlanetPopulation\": \"KeplerLike1\"}, \"scienceInstruments\": "
        tlString += " [{\"name\":\"imager\"}], \"starlightSuppressionSystems\": [{ \"name\": \"HLC-565\"}]  })"

        self.dview.execute(tlString)

        sInds = np.arange(0, TL.nStars)
        ang = self.star_angularSep(TL, 0, sInds, tA)
        sInd_sorted = np.argsort(ang)
        angles = ang[sInd_sorted].to('deg').value

        self.dview['angles'] = angles
        self.dview['tA'] = tA
        self.dview['dtRange'] = dtRange
        self.dview['m0'] = m0
        self.dview['sInd_sorted'] = sInd_sorted
        self.dview['seed'] = seed
        self.lview = self.rc.load_balanced_view()

        async_res = []
        for j in range(int(TL.nStars)):
            print(sInd_sorted[j])
            ar = self.lview.apply_async(fun, sInd_sorted[j])
            async_res.append(ar)

        ar = self.rc._asyncresult_from_jobs(async_res)
        while not ar.ready():
            ar.wait(60.)
            if ar.progress > 0:
                timeleft = ar.elapsed / ar.progress * (nStars - ar.progress)
                if timeleft > 3600.:
                    timeleftstr = "%2.2f hours" % (timeleft / 3600.)
                elif timeleft > 60.:
                    timeleftstr = "%2.2f minutes" % (timeleft / 60.)
                else:
                    timeleftstr = "%2.2f seconds" % timeleft
            else:
                timeleftstr = "who knows"

            print("%4i/%i tasks finished after %4i min. About %s to go." %
                  (ar.progress, nStars, ar.elapsed / 60, timeleftstr))
            sys.stdout.flush()

        print("Tasks complete.")
        sys.stdout.flush()
        res = [ar.get() for ar in async_res]

        return res
Exemple #5
0
    def test_target_completeness_scaleOrbits(self):
        """
        Compare calculated completenesses for multiple targets with scale orbits set to true
        """
                   
        with RedirectStreams(stdout=self.dev_null):
            TL = TargetList(ntargs=100,**copy.deepcopy(self.spec))
            TL.dist =  np.exp(np.random.uniform(low=np.log(1.0), high=np.log(30.), size=TL.nStars))*u.pc
            TL.L = np.exp(np.random.uniform(low=np.log(0.1), high=np.log(10.), size=TL.nStars))

        Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(scaleOrbits=True,**copy.deepcopy(self.spec))
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(scaleOrbits=True,**copy.deepcopy(self.spec))

        cBrown = Brown.target_completeness(TL)
        cGarrett = Garrett.target_completeness(TL)
        
        cGarrett = cGarrett[cBrown != 0 ]
        cBrown = cBrown[cBrown != 0]
        meandiff = np.mean(np.abs(cGarrett - cBrown)/cBrown)

        self.assertLessEqual(meandiff,0.1)
 def __init__(self, **specs):
     
     #define mapping between attributes we need and the IPAC data
     #table loaded in the Planet Population module
     self.atts_mapping = {'Name':'pl_hostname',
                          'Spec':'st_spstr',
                          'parx':'st_plx',
                          'Umag':'st_uj',
                          'Bmag':'st_bj',
                          'Vmag':'st_vj',
                          'Rmag':'st_rc',
                          'Imag':'st_ic',
                          'Jmag':'st_j',
                          'Hmag':'st_h',
                          'Kmag':'st_k',
                          'dist':'st_dist',
                          'BV':'st_bmvj',
                          'L':'st_lum', #log(Lsun)
                          'pmra':'st_pmra', #mas/year
                          'pmdec':'st_pmdec', #mas/year
                          'rv': 'st_radv'}
     
     TargetList.__init__(self, **specs)
Exemple #7
0
    def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.specs = {'modules':{'BackgroundSources':' '}}
        script = resource_path('test-scripts/template_minimal.json')
        spec = json.loads(open(script).read())     
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(**spec)

        modtype = getattr(EXOSIMS.Prototypes.PostProcessing.PostProcessing,'_modtype')
        pkg = EXOSIMS.PostProcessing
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod)
Exemple #8
0
    def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_minimal.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())
        
        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(ntargs=10,**copy.deepcopy(self.spec))
        self.TL.dist = np.random.uniform(low=0,high=100,size=self.TL.nStars)*u.pc
        
        modtype = getattr(SimulatedUniverse,'_modtype')
        pkg = EXOSIMS.SimulatedUniverse
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__+'.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1],modtype)
                self.assertTrue(mod._modtype is modtype,'_modtype mismatch for %s'%mod.__name__)
                self.allmods.append(mod)
Exemple #9
0
    def setUp(self):

        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_minimal.json')
        self.spec = json.loads(open(self.script).read())

        with RedirectStreams(stdout=self.dev_null):
            self.TL = TargetList(ntargs=10, **copy.deepcopy(self.spec))

        modtype = getattr(OpticalSystem, '_modtype')
        pkg = EXOSIMS.OpticalSystem
        self.allmods = [get_module(modtype)]
        for loader, module_name, is_pkg in pkgutil.walk_packages(
                pkg.__path__, pkg.__name__ + '.'):
            if not is_pkg:
                mod = get_module(module_name.split('.')[-1], modtype)
                self.assertTrue(mod._modtype is modtype,
                                '_modtype mismatch for %s' % mod.__name__)
                self.allmods.append(mod)
 def setUp(self):
     self.dev_null = open(os.devnull, 'w')
     modtype = getattr(
         EXOSIMS.Prototypes.BackgroundSources.BackgroundSources, '_modtype')
     pkg = EXOSIMS.BackgroundSources
     self.allmods = [get_module(modtype)]
     for loader, module_name, is_pkg in pkgutil.walk_packages(
             pkg.__path__, pkg.__name__ + '.'):
         if not is_pkg:
             mod = get_module(module_name.split('.')[-1], modtype)
             self.assertTrue(mod._modtype is modtype,
                             '_modtype mismatch for %s' % mod.__name__)
             self.allmods.append(mod)
     # need a TargetList object for testing
     script = resource_path('test-scripts/template_prototype_testing.json')
     with open(script) as f:
         spec = json.loads(f.read())
     with RedirectStreams(stdout=self.dev_null):
         self.TL = TargetList(**spec)
Exemple #11
0
    def __init__(self, orbit_datapath=None, f_nStars=10, **specs):

        ObservatoryL2Halo.__init__(self, **specs)
        self.f_nStars = int(f_nStars)

        # instantiating fake star catalog, used to generate good dVmap
        fTL = TargetList(**{"ntargs":self.f_nStars,'modules':{"StarCatalog": "FakeCatalog", \
                    "TargetList":" ","OpticalSystem": "Nemati", "ZodiacalLight": "Stark", "PostProcessing": " ", \
                    "Completeness": " ","BackgroundSources": "GalaxiesFaintStars", "PlanetPhysicalModel": " ", \
                    "PlanetPopulation": "KeplerLike1"}, "scienceInstruments": [{ "name": "imager"}],  \
                    "starlightSuppressionSystems": [{ "name": "HLC-565"}]   })

        f_sInds = np.arange(0, fTL.nStars)
        dV, ang, dt = self.generate_dVMap(fTL, 0, f_sInds, self.equinox[0])

        # pick out unique angle values
        ang, unq = np.unique(ang, return_index=True)
        dV = dV[:, unq]

        #create dV 2D interpolant
        self.dV_interp = interp.interp2d(dt, ang, dV.T, kind='linear')
    def __init__(self, **specs):

        TargetList.__init__(self, **specs)
Exemple #13
0
    def test_target_completeness_varrange(self):
        """
        Garrett completeness takes different logical pathways depending on which parameters are 
        held constant.  Checking all of these against BrownCompleteness would take multiple hours
        so we'll just run through the Garrett logical branches and check for self-consistency.

        The comparison tests already cover Rp and p constant, so we need to check a constant, e constant
        a + e constant.
        """
            
        with RedirectStreams(stdout=self.dev_null):
            TL = TargetList(ntargs=100,**copy.deepcopy(self.spec))

            mode = filter(lambda mode: mode['detectionMode'] == True, TL.OpticalSystem.observingModes)[0]
            IWA = mode['IWA']
            OWA = mode['OWA']
            rrange = TL.PlanetPopulation.rrange
            maxd = (rrange[1]/np.tan(IWA)).to(u.pc).value
            mind = (rrange[0]/np.tan(OWA)).to(u.pc).value

            #want distances to span from outer edge below IWA to inner edge above OWA
            TL.dist = np.logspace(np.log10(mind/10.),np.log10(maxd*10.),TL.nStars)*u.pc


        #a constant, everything else var
        spec = copy.deepcopy(self.spec)
        spec['arange'] = [1,1]
        spec['Rprange'] = [1,10]
        spec['prange'] = [0.2,0.5]
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(spec))
        cGarrett = Garrett.target_completeness(TL)
        self.assertTrue(np.all(cGarrett[TL.dist > maxd*u.pc] == 0))

        #e constant everything else var
        spec = copy.deepcopy(self.spec)
        spec['erange'] = [0,0]
        spec['Rprange'] = [1,10]
        spec['prange'] = [0.2,0.5]
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(spec))
        cGarrett = Garrett.target_completeness(TL)
        self.assertTrue(np.all(cGarrett[TL.dist > maxd*u.pc] == 0))

        #a and e constant, everything else var
        spec = copy.deepcopy(self.spec)
        spec['arange'] = [1,1]
        spec['erange'] = [0,0]
        spec['Rprange'] = [1,10]
        spec['prange'] = [0.2,0.5]
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(spec))
        cGarrett = Garrett.target_completeness(TL)
        self.assertTrue(np.all(cGarrett[TL.dist > maxd*u.pc] == 0))

        #a constant and constrainOrbits
        spec = copy.deepcopy(self.spec)
        spec['arange'] = [1,1]
        spec['constrainOrbits'] = True
        spec['Rprange'] = [1,10]
        spec['prange'] = [0.2,0.5]
        Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(spec))
        cGarrett = Garrett.target_completeness(TL)
        self.assertTrue(np.all(cGarrett[TL.dist > maxd*u.pc] == 0))
    def __init__(self, **specs):

        TargetList.__init__(self, **specs)