示例#1
0
    def setUp(self):
        self.dev_null = open(os.devnull, 'w')
        self.script = resource_path('test-scripts/template_prototype_testing.json')
        with open(self.script) as f:
            self.spec = json.loads(f.read())

        with RedirectStreams(stdout=self.dev_null):
            self.sim = MissionSim.MissionSim(self.script)
        self.TL = self.sim.TargetList
        self.nStars = self.TL.nStars
        self.star_index = np.array(range(0, self.nStars))
        self.Obs = self.sim.Observatory
        self.mode = self.sim.OpticalSystem.observingModes[0]
        self.TK = self.sim.TimeKeeping
        assert self.nStars > 10, "Need at least 10 stars in the target list for the unit test."
        self.unit = 1./u.arcsec**2

        modtype = getattr(EXOSIMS.Prototypes.ZodiacalLight.ZodiacalLight, '_modtype')
        pkg = EXOSIMS.ZodiacalLight
        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)
示例#2
0
    def setUp(self):
        self.spec = json.loads(open(scriptfile).read())

        # quiet the chatter at initialization
        with RedirectStreams(stdout=self.dev_null):
            sim = MissionSim.MissionSim(**self.spec)
        self.targetlist = sim.TargetList
        self.opticalsystem = sim.OpticalSystem
        self.planetpop = sim.PlanetPopulation
示例#3
0
 def setUp(self):
     with RedirectStreams(stdout=self.dev_null):
         sim = MissionSim.MissionSim(scriptfile)
     self.targetlist = sim.modules['TargetList']
     self.nStars = sim.TargetList.nStars
     self.star_index = np.array(range(0, self.nStars))
     self.observatory = sim.Observatory
     self.mode = sim.OpticalSystem.observingModes[0]
     self.timekeeping = sim.TimeKeeping
     assert self.nStars > 10, "Need at least 10 stars in the target list for the unit test."
示例#4
0
    def test_fillPhotometry(self):
        """
        Filling in photometry should result in larger or equal sized target list
        """

        with RedirectStreams(stdout=self.dev_null):
            sim = MissionSim.MissionSim(scriptfile,fillPhotometry=True)

        self.assertTrue(sim.TargetList.fillPhotometry)
        #self.assertGreaterEqual(sim.TargetList.nStars, self.targetlist.nStars)
        self.assertTrue(np.all(sim.TargetList.Imag != 0) and np.all(~np.isnan(sim.TargetList.Imag)))
示例#5
0
                                                    inputVars['D' + okey])
    try:
        obsSpecs['SPC_Characterization'][okey] = float(inputVars['C' + okey])
    except ValueError:
        print '%s=%s cant be converted to float' % (okey,
                                                    inputVars['D' + okey])

# CREATES LIST OF 2 OBSERVING MODES
useSpecs['observingModes'] = [
    obsSpecs['HLC_Detection'], obsSpecs['SPC_Characterization']
]

useSpecs['modules'] = modSpecs[inputVars['TargetType']]
# ==============================================================================

sim = msim.MissionSim(**useSpecs)  # RP
res = sim.SurveySimulation.run_sim()  # JX

# Stored detection information -- if any -- in DRM Dictionary
DRM = sim.SurveySimulation.DRM

# REFORMATTED DDRM
DDRM = reformat_DRM(DRM)

# Simulation specifications ; i.e., all parameters used in simulation
AllSpecs = sim.genOutSpec()
# =========================================================================================
#             OUTPUT CSV FILES
# =========================================================================================
varcsvOut(AllSpecs)
# =========================================================================================
示例#6
0
    def __init__(self,
                 path=None,
                 abins=100,
                 Rbins=30,
                 maxTime=365.0,
                 intCutoff=30.0,
                 dMag=None,
                 WA_targ=None):
        if path is None:
            raise ValueError('path must be specified')
        if path is not None:
            # generate EXOSIMS.MissionSim object to calculate integration times
            self.sim = MissionSim.MissionSim(scriptfile=path)
            print 'Acquired EXOSIMS data from %r' % (path)
        if dMag is not None:
            try:
                float(dMag)
            except TypeError:
                print 'dMag can have only one value'
        if WA_targ is not None:
            try:
                float(WA_targ.value)
            except AttributeError:
                print 'WA_targ must be astropy Quantity'
            except TypeError:
                print 'WA_targ can have only one value'
        self.result = {}
        # minimum and maximum values of semi-major axis and planetary radius
        # NO astropy Quantities
        amin = self.sim.PlanetPopulation.arange[0].to('AU').value
        amax = self.sim.PlanetPopulation.arange[1].to('AU').value
        Rmin = self.sim.PlanetPopulation.Rprange[0].to('earthRad').value
        assert Rmin < 45.0, 'Minimum planetary radius is above extrapolation range'
        if Rmin < 0.35:
            print 'Rmin reset to 0.35*R_earth'
            Rmin = 0.35
        Rmax = self.sim.PlanetPopulation.Rprange[1].to('earthRad').value
        assert Rmax > 0.35, 'Maximum planetary radius is below extrapolation range'
        if Rmax > 45.0:
            print 'Rmax reset to 45.0*R_earth'
        assert Rmax > Rmin, 'Maximum planetary radius is less than minimum planetary radius'
        # need to get Cmin from contrast curve
        mode = filter(lambda mode: mode['detectionMode'] == True,
                      self.sim.OpticalSystem.observingModes)[0]
        WA = np.linspace(mode['IWA'], mode['OWA'], 50)
        syst = mode['syst']
        lam = mode['lam']
        if dMag is None:
            # use dMagLim when dMag not specified
            dMag = self.sim.Completeness.dMagLim
        fZ = self.sim.ZodiacalLight.fZ0
        fEZ = self.sim.ZodiacalLight.fEZ0
        if WA_targ is None:
            core_contrast = syst['core_contrast'](lam, WA)
            contrast = interpolate.interp1d(WA.to('arcsec').value, core_contrast, \
                                    kind='cubic', fill_value=1.0)
            # find minimum value of contrast
            opt = optimize.minimize_scalar(contrast, \
                                       bounds=[mode['IWA'].to('arcsec').value, \
                                               mode['OWA'].to('arcsec').value],\
                                               method='bounded')
            Cmin = opt.fun
            WA_targ = opt.x * u.arcsec

        t_int1 = self.sim.OpticalSystem.calc_intTime(self.sim.TargetList,
                                                     np.array([0]), fZ, fEZ,
                                                     dMag, WA_targ, mode)
        t_int1 = np.repeat(t_int1.value, len(WA)) * t_int1.unit
        sInds = np.repeat(0, len(WA))
        fZ1 = np.repeat(fZ.value, len(WA)) * fZ.unit
        fEZ1 = np.repeat(fEZ.value, len(WA)) * fEZ.unit
        core_contrast = 10.0**(
            -0.4 * self.sim.OpticalSystem.calc_dMag_per_intTime(
                t_int1, self.sim.TargetList, sInds, fZ1, fEZ1, WA, mode))
        contrast = interpolate.interp1d(WA.to('arcsec').value,
                                        core_contrast,
                                        kind='cubic',
                                        fill_value=1.0)
        opt = optimize.minimize_scalar(contrast,
                                       bounds=[
                                           mode['IWA'].to('arcsec').value,
                                           mode['OWA'].to('arcsec').value
                                       ],
                                       method='bounded')
        Cmin = opt.fun

        # find expected values of p and R
        if self.sim.PlanetPopulation.prange[
                0] != self.sim.PlanetPopulation.prange[1]:
            if hasattr(self.sim.PlanetPopulation, 'ps'):
                f = lambda R: self.sim.PlanetPopulation.get_p_from_Rp(
                    R * u.earthRad) * self.sim.PlanetPopulation.dist_radius(R)
                pexp, err = integrate.quad(f,self.sim.PlanetPopulation.Rprange[0].value,\
                                           self.sim.PlanetPopulation.Rprange[1].value,\
                                           epsabs=0,epsrel=1e-6,limit=100)
            else:
                f = lambda p: p * self.sim.PlanetPopulation.dist_albedo(p)
                pexp, err = integrate.quad(f,self.sim.PlanetPopulation.prange[0],\
                                       self.sim.PlanetPopulation.prange[1],\
                                        epsabs=0,epsrel=1e-6,limit=100)
        else:
            pexp = self.sim.PlanetPopulation.prange[0]
        print 'Expected value of geometric albedo: %r' % (pexp)
        if self.sim.PlanetPopulation.Rprange[
                0] != self.sim.PlanetPopulation.Rprange[1]:
            f = lambda R: R * self.sim.PlanetPopulation.dist_radius(R)
            Rexp, err = integrate.quad(f,self.sim.PlanetPopulation.Rprange[0].to('earthRad').value,\
                                       self.sim.PlanetPopulation.Rprange[1].to('earthRad').value,\
                                        epsabs=0,epsrel=1e-4,limit=100)
            Rexp *= u.earthRad.to('AU')
        else:
            Rexp = self.sim.PlanetPopulation.Rprange[0].to('AU').value

        # minimum and maximum separations
        smin = (np.tan(mode['IWA']) * self.sim.TargetList.dist).to('AU').value
        smax = (np.tan(mode['OWA']) * self.sim.TargetList.dist).to('AU').value
        smax[smax > amax] = amax

        # include only stars where smin > amin
        bigger = np.where(smin > amin)[0]
        self.sim.TargetList.revise_lists(bigger)
        smin = smin[bigger]
        smax = smax[bigger]

        # include only stars where smin < amax
        smaller = np.where(smin < amax)[0]
        self.sim.TargetList.revise_lists(smaller)
        smin = smin[smaller]
        smax = smax[smaller]

        # calculate integration times
        sInds = np.arange(self.sim.TargetList.nStars)

        # calculate maximum integration time
        t_int = self.sim.OpticalSystem.calc_intTime(self.sim.TargetList, sInds,
                                                    fZ, fEZ, dMag, WA_targ,
                                                    mode)

        # remove integration times above cutoff
        cutoff = np.where(t_int.to('day').value < intCutoff)[0]
        self.sim.TargetList.revise_lists(cutoff)
        smin = smin[cutoff]
        smax = smax[cutoff]
        t_int = t_int[cutoff]

        print 'Beginning ck calculations'
        ck = self.find_ck(amin, amax, smin, smax, Cmin, pexp, Rexp)
        # offset to account for zero ck values with nonzero completeness
        ck += ck[ck > 0.0].min() * 1e-2
        print 'Finished ck calculations'

        print 'Beginning ortools calculations to determine list of observed stars'
        sInds = self.select_obs(t_int.to('day').value, maxTime, ck)
        print 'Finished ortools calculations'
        # include only stars chosen for observation
        self.sim.TargetList.revise_lists(sInds)
        smin = smin[sInds]
        smax = smax[sInds]
        t_int = t_int[sInds]
        ck = ck[sInds]

        # get contrast array for given integration times
        sInds2 = np.arange(self.sim.TargetList.nStars)
        fZ2 = np.repeat(fZ.value, len(WA)) * fZ.unit
        fEZ2 = np.repeat(fEZ.value, len(WA)) * fEZ.unit
        C_inst = np.zeros((len(sInds2), len(WA)))
        for i in xrange(len(sInds2)):
            t_int2 = np.repeat(t_int[i].value, len(WA)) * t_int.unit
            sInds2a = np.repeat(sInds2[i], len(WA))
            C_inst[i, :] = 10.0**(
                -0.4 * self.sim.OpticalSystem.calc_dMag_per_intTime(
                    t_int2, self.sim.TargetList, sInds2a, fZ2, fEZ2, WA, mode))

        # store number of observed stars in result
        self.result['NumObs'] = {"all": self.sim.TargetList.nStars}
        print 'Number of observed targets: %r' % self.sim.TargetList.nStars

        # find bin edges for semi-major axis and planetary radius in AU
        aedges = np.logspace(np.log10(amin), np.log10(amax), abins + 1)
        Redges = np.logspace(np.log10(Rmin*u.earthRad.to('AU')), \
                         np.log10(Rmax*u.earthRad.to('AU')), Rbins+1)
        # store aedges and Redges in result
        self.result['aedges'] = aedges
        self.result['Redges'] = Redges / u.earthRad.to('AU')

        aa, RR = np.meshgrid(aedges, Redges)  # in AU

        # get depth of search
        print 'Beginning depth of search calculations for observed stars'
        if self.sim.TargetList.nStars > 0:
            DoS = self.DoS_sum(aedges, aa, Redges, RR, pexp, smin, smax, \
                           self.sim.TargetList.dist.to('pc').value, C_inst, WA.to('arcsecond').value)
        else:
            DoS = np.zeros((aa.shape[0] - 1, aa.shape[1] - 1))
        print 'Finished depth of search calculations'
        # store DoS in result
        self.result['DoS'] = {"all": DoS}

        # find occurrence rate grid
        Redges /= u.earthRad.to('AU')
        etas = np.zeros((len(Redges) - 1, len(aedges) - 1))
        # get joint pdf of semi-major axis and radius
        if hasattr(self.sim.PlanetPopulation, 'dist_sma_radius'):
            func = lambda a, R: self.sim.PlanetPopulation.dist_sma_radius(a, R)
        else:
            func = lambda a, R: self.sim.PlanetPopulation.dist_sma(
                a) * self.sim.PlanetPopulation.dist_radius(R)
        aa, RR = np.meshgrid(aedges, Redges)
        r_norm = Redges[1:] - Redges[:-1]
        a_norm = aedges[1:] - aedges[:-1]
        norma, normR = np.meshgrid(a_norm, r_norm)
        tmp = func(aa, RR)
        etas = 0.25 * (tmp[:-1, :-1] + tmp[1:, :-1] + tmp[:-1, 1:] +
                       tmp[1:, 1:]) * norma * normR
        #        for i in xrange(len(Redges)-1):
        #            print('{} out of {}'.format(i+1,len(Redges)-1))
        #            for j in xrange(len(aedges)-1):
        #                etas[i,j] = integrate.dblquad(func,Redges[i],Redges[i+1],lambda x: aedges[j],lambda x: aedges[j+1])[0]
        etas *= self.sim.PlanetPopulation.eta
        self.result['occ_rates'] = {"all": etas}

        # Multiply depth of search with occurrence rates

        print 'Multiplying depth of search grid with occurrence rate grid'
        DoS_occ = DoS * etas * norma * normR
        self.result['DoS_occ'] = {"all": DoS_occ}

        # store MissionSim output specification dictionary
        self.outspec = self.sim.genOutSpec()
        print 'Calculations finished'
# LOAD JSON SCRIPT FILE
#jfile = 'template_WFIRST_KeplerLike.json'
#jfile = 'template_WFIRST_EarthTwinHabZone.json'
#jfile = 'template_WFIRST_KnownRV.json'
#jfile = 'template_rpateltest_KnownRV.json'
jfile = 'template_rpateltest_KnownRV_2years.json'
scriptfile = os.path.join(os.path.abspath(''), 'scripts', jfile)
print scriptfile

script = open(scriptfile).read()
specs_from_file = json.load(script)

# QUESTION -- DO I HAVE TO RUN THIS EACH TIME OR IS THERE A WAY TO SAVE/LOAD THE OUTPUT?
#JX %time sim = msim.MissionSim(scriptfile)
sim = msim.MissionSim(scriptfile)  #JX
#JX %time sim.SurveySimulation.run_sim()
res = sim.SurveySimulation.run_sim()  #JX

# Stored detection information -- if any -- in DRM Dictionary
DRM = sim.SurveySimulation.DRM

# Simulation specifications ; i.e., all parameters used in simulation
AllSpecs = sim.genOutSpec()

TL = sim.TargetList
SC = sim.StarCatalog
SU = sim.SimulatedUniverse
SSim = sim.SurveySimulation
OS = sim.OpticalSystem
ZL = sim.ZodiacalLight
示例#8
0
    def __init__(self,
                 path=None,
                 abins=100,
                 Rbins=30,
                 maxTime=365.0,
                 intCutoff=30.0,
                 dMag=None,
                 WA_targ=None):
        if path is None:
            raise ValueError('path must be specified')
        if path is not None:
            # generate EXOSIMS.MissionSim object to calculate integration times
            self.sim = MissionSim.MissionSim(scriptfile=path)
            print 'Acquired EXOSIMS data from %r' % (path)
        if dMag is not None:
            try:
                float(dMag)
            except TypeError:
                print 'dMag can have only one value'
        if WA_targ is not None:
            try:
                float(WA_targ.value)
            except AttributeError:
                print 'WA_targ must be astropy Quantity'
            except TypeError:
                print 'WA_targ can have only one value'
        self.result = {}
        # minimum and maximum values of semi-major axis and planetary radius
        # NO astropy Quantities
        amin = self.sim.PlanetPopulation.arange[0].to('AU').value
        amax = self.sim.PlanetPopulation.arange[1].to('AU').value
        Rmin = self.sim.PlanetPopulation.Rprange[0].to('earthRad').value
        assert Rmin < 45.0, 'Minimum planetary radius is above extrapolation range'
        if Rmin < 0.35:
            print 'Rmin reset to 0.35*R_earth'
            Rmin = 0.35
        Rmax = self.sim.PlanetPopulation.Rprange[1].to('earthRad').value
        assert Rmax > 0.35, 'Maximum planetary radius is below extrapolation range'
        if Rmax > 45.0:
            print 'Rmax reset to 45.0*R_earth'
        assert Rmax > Rmin, 'Maximum planetary radius is less than minimum planetary radius'
        # need to get Cmin from contrast curve
        mode = filter(lambda mode: mode['detectionMode'] == True,
                      self.sim.OpticalSystem.observingModes)[0]
        WA = np.linspace(mode['IWA'], mode['OWA'], 50)
        syst = mode['syst']
        lam = mode['lam']
        if dMag is None:
            # use dMagLim when dMag not specified
            dMag = self.sim.Completeness.dMagLim
        fZ = self.sim.ZodiacalLight.fZ0
        fEZ = self.sim.ZodiacalLight.fEZ0
        if WA_targ is None:
            core_contrast = syst['core_contrast'](lam, WA)
            contrast = interpolate.interp1d(WA.to('arcsec').value, core_contrast, \
                                    kind='cubic', fill_value=1.0)
            # find minimum value of contrast
            opt = optimize.minimize_scalar(contrast, \
                                       bounds=[mode['IWA'].to('arcsec').value, \
                                               mode['OWA'].to('arcsec').value],\
                                               method='bounded')
            Cmin = opt.fun
            WA_targ = opt.x * u.arcsec

        t_int1 = self.sim.OpticalSystem.calc_intTime(self.sim.TargetList,
                                                     np.array([0]), fZ, fEZ,
                                                     dMag, WA_targ, mode)
        t_int1 = np.repeat(t_int1.value, len(WA)) * t_int1.unit
        sInds = np.repeat(0, len(WA))
        fZ1 = np.repeat(fZ.value, len(WA)) * fZ.unit
        fEZ1 = np.repeat(fEZ.value, len(WA)) * fEZ.unit
        core_contrast = 10.0**(
            -0.4 * self.sim.OpticalSystem.calc_dMag_per_intTime(
                t_int1, self.sim.TargetList, sInds, fZ1, fEZ1, WA, mode))
        contrast = interpolate.interp1d(WA.to('arcsec').value,
                                        core_contrast,
                                        kind='cubic',
                                        fill_value=1.0)
        opt = optimize.minimize_scalar(contrast,
                                       bounds=[
                                           mode['IWA'].to('arcsec').value,
                                           mode['OWA'].to('arcsec').value
                                       ],
                                       method='bounded')
        Cmin = opt.fun

        # find expected values of p and R
        if self.sim.PlanetPopulation.prange[
                0] != self.sim.PlanetPopulation.prange[1]:
            if hasattr(self.sim.PlanetPopulation, 'ps'):
                f = lambda R: self.sim.PlanetPopulation.get_p_from_Rp(
                    R * u.earthRad) * self.sim.PlanetPopulation.dist_radius(R)
                pexp, err = integrate.quad(f,self.sim.PlanetPopulation.Rprange[0].value,\
                                           self.sim.PlanetPopulation.Rprange[1].value,\
                                           epsabs=0,epsrel=1e-6,limit=100)
            else:
                f = lambda p: p * self.sim.PlanetPopulation.dist_albedo(p)
                pexp, err = integrate.quad(f,self.sim.PlanetPopulation.prange[0],\
                                       self.sim.PlanetPopulation.prange[1],\
                                        epsabs=0,epsrel=1e-6,limit=100)
        else:
            pexp = self.sim.PlanetPopulation.prange[0]
        print 'Expected value of geometric albedo: %r' % (pexp)
        if self.sim.PlanetPopulation.Rprange[
                0] != self.sim.PlanetPopulation.Rprange[1]:
            f = lambda R: R * self.sim.PlanetPopulation.dist_radius(R)
            Rexp, err = integrate.quad(f,self.sim.PlanetPopulation.Rprange[0].to('earthRad').value,\
                                       self.sim.PlanetPopulation.Rprange[1].to('earthRad').value,\
                                        epsabs=0,epsrel=1e-4,limit=100)
            Rexp *= u.earthRad.to('AU')
        else:
            Rexp = self.sim.PlanetPopulation.Rprange[0].to('AU').value

        # include only F G K M stars
        spec = np.array(map(str, self.sim.TargetList.Spec))
        iF = np.where(np.core.defchararray.startswith(spec, 'F'))[0]
        iG = np.where(np.core.defchararray.startswith(spec, 'G'))[0]
        iK = np.where(np.core.defchararray.startswith(spec, 'K'))[0]
        iM = np.where(np.core.defchararray.startswith(spec, 'M'))[0]
        i = np.append(np.append(iF, iG), iK)
        i = np.append(i, iM)
        i = np.unique(i)
        self.sim.TargetList.revise_lists(i)
        print 'Filtered target stars to only include M, K, G, and F type'
        # minimum and maximum separations
        smin = (np.tan(mode['IWA']) * self.sim.TargetList.dist).to('AU').value
        smax = (np.tan(mode['OWA']) * self.sim.TargetList.dist).to('AU').value
        smax[smax > amax] = amax

        # include only stars where smin > amin
        bigger = np.where(smin > amin)[0]
        self.sim.TargetList.revise_lists(bigger)
        smin = smin[bigger]
        smax = smax[bigger]

        # include only stars where smin < amax
        smaller = np.where(smin < amax)[0]
        self.sim.TargetList.revise_lists(smaller)
        smin = smin[smaller]
        smax = smax[smaller]

        # calculate integration times
        sInds = np.arange(self.sim.TargetList.nStars)

        # calculate maximum integration time
        t_int = self.sim.OpticalSystem.calc_intTime(self.sim.TargetList, sInds,
                                                    fZ, fEZ, dMag, WA_targ,
                                                    mode)

        # remove integration times above cutoff
        cutoff = np.where(t_int.to('day').value < intCutoff)[0]
        self.sim.TargetList.revise_lists(cutoff)
        smin = smin[cutoff]
        smax = smax[cutoff]
        t_int = t_int[cutoff]

        print 'Beginning ck calculations'
        ck = self.find_ck(amin, amax, smin, smax, Cmin, pexp, Rexp)
        # offset to account for zero ck values with nonzero completeness
        ck += ck[ck > 0.0].min() * 1e-2
        print 'Finished ck calculations'

        print 'Beginning ortools calculations to determine list of observed stars'
        sInds = self.select_obs(t_int.to('day').value, maxTime, ck)
        print 'Finished ortools calculations'
        # include only stars chosen for observation
        self.sim.TargetList.revise_lists(sInds)
        smin = smin[sInds]
        smax = smax[sInds]
        t_int = t_int[sInds]
        ck = ck[sInds]

        # get contrast array for given integration times
        sInds2 = np.arange(self.sim.TargetList.nStars)
        fZ2 = np.repeat(fZ.value, len(WA)) * fZ.unit
        fEZ2 = np.repeat(fEZ.value, len(WA)) * fEZ.unit
        C_inst = np.zeros((len(sInds2), len(WA)))
        for i in xrange(len(sInds2)):
            t_int2 = np.repeat(t_int[i].value, len(WA)) * t_int.unit
            sInds2a = np.repeat(sInds2[i], len(WA))
            C_inst[i, :] = 10.0**(
                -0.4 * self.sim.OpticalSystem.calc_dMag_per_intTime(
                    t_int2, self.sim.TargetList, sInds2a, fZ2, fEZ2, WA, mode))

        # find which are M K G F stars
        spec = np.array(map(str, self.sim.TargetList.Spec))
        Mlist = np.where(np.core.defchararray.startswith(spec, 'M'))[0]
        Klist = np.where(np.core.defchararray.startswith(spec, 'K'))[0]
        Glist = np.where(np.core.defchararray.startswith(spec, 'G'))[0]
        Flist = np.where(np.core.defchararray.startswith(spec, 'F'))[0]
        print '%r M stars observed' % (len(Mlist))
        print '%r K stars observed' % (len(Klist))
        print '%r G stars observed' % (len(Glist))
        print '%r F stars observed' % (len(Flist))
        print '%r total stars observed' % (len(Mlist) + len(Klist) +
                                           len(Glist) + len(Flist))
        NumObs = {'Mstars':len(Mlist), 'Kstars':len(Klist), 'Gstars':len(Glist),\
              'Fstars':len(Flist), 'all':(len(Mlist)+len(Klist)+len(Glist)\
                           +len(Flist))}
        # store number of observed stars in result
        self.result['NumObs'] = NumObs
        # find bin edges for semi-major axis and planetary radius in AU
        aedges = np.logspace(np.log10(amin), np.log10(amax), abins + 1)
        Redges = np.logspace(np.log10(Rmin*u.earthRad.to('AU')), \
                         np.log10(Rmax*u.earthRad.to('AU')), Rbins+1)
        # store aedges and Redges in result
        self.result['aedges'] = aedges
        self.result['Redges'] = Redges / u.earthRad.to('AU')

        aa, RR = np.meshgrid(aedges, Redges)  # in AU

        # get depth of search for each stellar type
        DoS = {}
        print 'Beginning depth of search calculations for observed M stars'
        if len(Mlist) > 0:
            DoS['Mstars'] = self.DoS_sum(aedges, aa, Redges, RR, pexp, smin[Mlist], \
               smax[Mlist], self.sim.TargetList.dist[Mlist].to('pc').value, C_inst[Mlist,:], WA)
        else:
            DoS['Mstars'] = np.zeros((aa.shape[0] - 1, aa.shape[1] - 1))
        print 'Finished depth of search calculations for observed M stars'
        print 'Beginning depth of search calculations for observed K stars'
        if len(Klist) > 0:
            DoS['Kstars'] = self.DoS_sum(aedges, aa, Redges, RR, pexp, smin[Klist], \
               smax[Klist], self.sim.TargetList.dist[Klist].to('pc').value, C_inst[Klist,:], WA)
        else:
            DoS['Kstars'] = np.zeros((aa.shape[0] - 1, aa.shape[1] - 1))
        print 'Finished depth of search calculations for observed K stars'
        print 'Beginning depth of search calculations for observed G stars'
        if len(Glist) > 0:
            DoS['Gstars'] = self.DoS_sum(aedges, aa, Redges, RR, pexp, smin[Glist], \
               smax[Glist], self.sim.TargetList.dist[Glist].to('pc').value, C_inst[Glist,:], WA)
        else:
            DoS['Gstars'] = np.zeros((aa.shape[0] - 1, aa.shape[1] - 1))
        print 'Finished depth of search calculations for observed G stars'
        print 'Beginning depth of search calculations for observed F stars'
        if len(Flist) > 0:
            DoS['Fstars'] = self.DoS_sum(aedges, aa, Redges, RR, pexp, smin[Flist], \
               smax[Flist], self.sim.TargetList.dist[Flist].to('pc').value, C_inst[Flist,:], WA)
        else:
            DoS['Fstars'] = np.zeros((aa.shape[0] - 1, aa.shape[1] - 1))
        print 'Finished depth of search calculations for observed F stars'
        DoS['all'] = DoS['Mstars'] + DoS['Kstars'] + DoS['Gstars'] + DoS[
            'Fstars']
        # store DoS in result
        self.result['DoS'] = DoS

        # load occurrence data from file
        print 'Loading occurrence data'
        directory = os.path.dirname(os.path.abspath(__file__))
        rates = pickle.load(open(directory + '/Mulders.ocr', 'rb'))

        # values from Mulders
        Redges /= u.earthRad.to('AU')
        Periods = rates['PeriodEdges'] * u.day
        Radii = rates['RpEdges']
        dP = np.log10(Periods[1:] / Periods[:-1]).decompose().value
        dR = np.log10(Radii[1:] / Radii[:-1])
        ddP, ddR = np.meshgrid(dP, dR)

        # extrapolate occurrence values to new grid
        occ_rates = {}
        print 'Extrapolating occurrence rates for M stars'
        occ_rates['Mstars'] = self.find_occurrence(0.35*const.M_sun,ddP,ddR,Radii,\
                 Periods,rates['MstarsMean'],aedges,Redges,\
                              self.sim.PlanetPopulation.dist_sma,amin)
        print 'Extrapolating occurrence rates for K stars'
        occ_rates['Kstars'] = self.find_occurrence(0.70*const.M_sun,ddP,ddR,Radii,\
                 Periods,rates['KstarsMean'],aedges,Redges,\
                              self.sim.PlanetPopulation.dist_sma,amin)
        print 'Extrapolating occurrence rates for G stars'
        occ_rates['Gstars'] = self.find_occurrence(0.91*const.M_sun,ddP,ddR,Radii,\
                 Periods,rates['GstarsMean'],aedges,Redges,\
                              self.sim.PlanetPopulation.dist_sma,amin)
        print 'Extrapolating occurrence rates for F stars'
        occ_rates['Fstars'] = self.find_occurrence(1.08*const.M_sun,ddP,ddR,Radii,\
                 Periods,rates['FstarsMean'],aedges,Redges,\
                              self.sim.PlanetPopulation.dist_sma,amin)
        self.result['occ_rates'] = occ_rates

        # Multiply depth of search with occurrence rates
        r_norm = Redges[1:] - Redges[:-1]
        a_norm = aedges[1:] - aedges[:-1]
        norma, normR = np.meshgrid(a_norm, r_norm)
        DoS_occ = {}
        print 'Multiplying depth of search grid with occurrence rate grid'
        DoS_occ['Mstars'] = DoS['Mstars'] * occ_rates['Mstars'] * norma * normR
        DoS_occ['Kstars'] = DoS['Kstars'] * occ_rates['Kstars'] * norma * normR
        DoS_occ['Gstars'] = DoS['Gstars'] * occ_rates['Gstars'] * norma * normR
        DoS_occ['Fstars'] = DoS['Fstars'] * occ_rates['Fstars'] * norma * normR
        DoS_occ['all'] = DoS_occ['Mstars'] + DoS_occ['Kstars'] + DoS_occ[
            'Gstars'] + DoS_occ['Fstars']
        self.result['DoS_occ'] = DoS_occ

        # store MissionSim output specification dictionary
        self.outspec = self.sim.genOutSpec()
        print 'Calculations finished'
示例#9
0
#     "OpticalSystem": " ",
#     "ZodiacalLight": " ",
#     "BackgroundSources": " ",
#     "PlanetPhysicalModel": " ",
#     "Observatory": " ",
#     "TimeKeeping": " ",
#     "PostProcessing": " ",
#     "Completeness": " ",
#     "TargetList": " ",
#     "SimulatedUniverse": " ",
#     "SurveySimulation": " ",
#     "SurveyEnsemble": " "
#   }}

#sim = MissionSim(scriptfile=inputScript,nopar=True, verbose=True)#,**deepcopy(outspec))
sim = MissionSim(scriptfile=None,nopar=True, verbose=True,**deepcopy(outspec))

#DELETE SSS = [{ "name": "HLC-565",
#       "optics": 0.983647,
#       "lam": 565,
#       "BW": 0.10,
#       "IWA": 0.15,
#       "ohTime": 0.5,
#       "occ_trans": "$HOME/Documents/exosims/fitFilesFolder/WFIRST_cycle6/G22_FIT_565/G22_FIT_565_occ_trans.fits",
#       "core_thruput": "$HOME/Documents/exosims/fitFilesFolder/WFIRST_cycle6/G22_FIT_565/G22_FIT_565_thruput.fits",
#       "core_mean_intensity": "$HOME/Documents/exosims/fitFilesFolder/WFIRST_cycle6/G22_FIT_565/G22_FIT_565_mean_intensity.fits",
#       "core_area": "$HOME/Documents/exosims/fitFilesFolder/WFIRST_cycle6/G22_FIT_565/G22_FIT_565_area.fits",
#       "core_platescale": 0.30
#     }]

#Some Initializations