Exemple #1
0
def initialize_phoebe(output_dir=None, mpi_ncores=0, logger=True):
    if output_dir != None:
        try:
            os.mkdir(output_dir)
        except:
            shutil.rmtree(output_dir)
            os.mkdir(output_dir)
    if logger:
        sys.stdout = Logger(output_dir)
    phoebe.logger(
        clevel='ERROR')  # ignore warnings - for tqdm to work properly
    phoebe.interactive_checks_off()
    phoebe.check_visible_off()
    phoebe.interactive_constraints_off()
    if mpi_ncores != 0:
        phoebe.mpi_on(nprocs=mpi_ncores)
    return output_dir
Exemple #2
0
    #turn off albedos (legacy requirement)
    b.set_value_all('irrad_frac_refl_bol', 0.0)

    if plot: print("running phoebe2 model...")
    b.run_compute(compute='phoebe2', irrad_method='none', model='phoebe2model')
    if gen_comp:
        if plot: print("running phoebe1 model...")
        b.run_compute(compute='phoebe1', refl_num=0, model='phoebe1model')
        b.filter(model='phoebe1model').save('test_blackbody.comp.model')
    else:
        b.import_model(os.path.join(os.path.dirname(__file__),
                                    'test_blackbody.comp.model'),
                       model='phoebe1model')

    phoebe2_val = b.get_value('fluxes@phoebe2model')
    phoebe1_val = b.get_value('fluxes@phoebe1model')

    if plot:
        b.plot(dataset='lc01', show=True)

    assert (np.allclose(phoebe2_val, phoebe1_val, rtol=1e-3, atol=0.))

    return b


if __name__ == '__main__':
    logger = phoebe.logger(clevel='INFO')

    b = test_binary(plot=True, gen_comp=True)
Exemple #3
0
# ## Setup
#
# Let's first make sure we have the latest version of PHOEBE 2.3 installed (uncomment this line if running in an online notebook session such as colab).

# In[1]:

#!pip install -I "phoebe>=2.3,<2.4"

# In[2]:

import phoebe
from phoebe import u  # units
import numpy as np

logger = phoebe.logger('error')

# We'll then start with the bundle from the end of the [emcee tutorial](./emcee.ipynb).  If you're running this notebook locally, you will need to run that first to create the `emcee_advanced_tutorials.bundle` file that we will use here.

# In[3]:

b = phoebe.load('emcee_advanced_tutorials.bundle')

# ## init_from parameter
#
# In cases where [continuing emcee from a previous run](./emcee_continue_from.ipynb) is insufficient, it may be ncessary to resample a new emcee run from the results of a previous run.  This can be useful in several scenarios:
#
# * change the number of walkers
# * resample from the "best" branch when other branches are stuck (NOTE: this is making some assumptions and should be used with caution)
# * change the parameters being sampled (in this case, any NEW parameter will need to have initializing distributions created manually or from some other source)
# * "merge" the results from multiple emcee runs  (if RV- and LC-sensitive parameters were sampled independently but now you want to resample simultaneously)
Exemple #4
0
get_ipython().system('pip install -I "phoebe>=2.1,<2.2"')

# As always, let's do imports and initialize a logger and a new bundle.  See [Building a System](../tutorials/building_a_system.ipynb) for more details.

# In[1]:

get_ipython().run_line_magic('matplotlib', 'inline')

# In[2]:

import phoebe
from phoebe import u  # units
import numpy as np
import matplotlib.pyplot as plt

logger = phoebe.logger()

b = phoebe.default_binary()

# In[3]:

b.set_value(qualifier='pitch', component='primary', value=30)

# Model without Spots
# --------------------------

# In[4]:

b.add_dataset('lc', times=phoebe.linspace(0, 1, 101))

# In[5]:
Exemple #5
0
pb.save('my_passband.pb')

# Getting started
# -----------------
#
# Let us start by importing phoebe, numpy and matplotlib:

# In[1]:

get_ipython().run_line_magic('matplotlib', 'inline')
import phoebe
from phoebe import u  # units
import numpy as np
import matplotlib.pyplot as plt

logger = phoebe.logger(clevel='WARNING')

# Passband transmission function
# -----------------------------------
#
# The passband transmission function is typically a user-provided two-column file. The first column is wavelength, and the second column is passband transmission. For the purposes of this tutorial, we will simulate the passband as a uniform box.

# In[2]:

wl = np.linspace(300, 360, 61)
ptf = np.zeros(len(wl))
ptf[(wl >= 320) & (wl <= 340)] = 1.0

# Let us plot this simulated passband transmission function to see what it looks like:

# In[3]:
Exemple #6
0
    cb.run_compute(compute='phoebe1', refl_num=0, model='phoebe1model')

    phoebe2_val_lc = cb.get_value('fluxes@phoebe2model')
    phoebe1_val_lc = cb.get_value('fluxes@phoebe1model')
    phoebe2_val_rv1 = cb.get_value('rvs@primary@phoebe2model')[2:48]
    phoebe1_val_rv1 = cb.get_value('rvs@primary@phoebe1model')[2:48]
    phoebe2_val_rv2 = cb.get_value('rvs@secondary@phoebe2model')[2:48]
    phoebe1_val_rv2 = cb.get_value('rvs@secondary@phoebe1model')[2:48]

    if plot:
        print "max lc atol {}: rtol: {}".format(np.max(phoebe2_val_lc - phoebe1_val_lc), np.max((phoebe2_val_lc - phoebe1_val_lc)/phoebe1_val_lc))
        print "max rv1 atol: {} rtol: {}".format(np.max(phoebe2_val_rv1 - phoebe1_val_rv1), np.max((phoebe2_val_rv1 - phoebe1_val_rv1)/phoebe1_val_rv1))
        print "max rv2 atol: {} rtol: {}".format(np.max(phoebe2_val_rv2 - phoebe1_val_rv2), np.max((phoebe2_val_rv2 - phoebe1_val_rv2)/phoebe1_val_rv2))

        cb.plot(dataset='lc01', show=True)
        cb.plot(dataset='rv01', show=True)

    assert(np.allclose(phoebe2_val_lc, phoebe1_val_lc, rtol=7e-3, atol=0.))
    # note we can't use relative tolerances because those blow up near 0, so
    # instead we'll fake a relative tolerance by using the amplitude of the RV curve.
    rv_ampl = np.max(np.abs(phoebe1_val_rv1))
    rtol = 7e-3
    assert(np.allclose(phoebe2_val_rv1, phoebe1_val_rv1, rtol=0., atol=rtol*rv_ampl))
    assert(np.allclose(phoebe2_val_rv2, phoebe1_val_rv2, rtol=0., atol=rtol*rv_ampl))
    return cb

if __name__ == '__main__':
    logger = phoebe.logger(clevel='debug')

    cb = test_binary(plot=True)
Exemple #7
0
    b.set_value_all('ld_coeffs', [0.0, 0.0])

    #turn off albedos (legacy requirement)
    b.set_value_all('irrad_frac_refl_bol', 0.0)

    print("running phoebe2 model...")
    b.run_compute(compute='phoebe2', irrad_method='none', model='phoebe2model')
    print("running phoebe1 model...")
    b.run_compute(compute='phoebe1', refl_num=0, model='phoebe1model')

    phoebe2_val = b.get_value('fluxes@phoebe2model')
    phoebe1_val = b.get_value('fluxes@phoebe1model')

    if plot:
        print("rel: ", ((phoebe2_val - phoebe1_val) / phoebe2_val).max())
        print("abs: ", (phoebe2_val - phoebe1_val).max())

        # b.plot(dataset='mesh01', show=True)

        b.plot(dataset='lc01', legend=True, show=True)

    assert (np.allclose(phoebe2_val, phoebe1_val, rtol=2e-3, atol=5e-4))

    return b


if __name__ == '__main__':
    logger = phoebe.logger(clevel='DEBUG')

    b = test_binary(plot=True)
Exemple #8
0
    if plot:
        print("rv@secondary max rel diff: {}".format(
            max(np.abs((phoebe1_val - phoebe2_val) / phoebe2_val))))
    assert (np.allclose(phoebe2_val, phoebe1_val, rtol=1e-1, atol=0.))


def test_binary(plot=False, gen_comp=False):

    ## system = [sma (solRad), period (d)]
    system1 = [11, 2.575]
    system2 = [215., 257.5]
    system3 = [8600., 65000.]

    ind = 0
    for q in [0.5, 1.]:
        for system in [system1, system2, system3]:
            ind += 1

            b = phoebe.Bundle.default_binary()

            b.set_value('sma@binary', system[0])
            b.set_value('period@binary', system[1])
            b.set_value('q', q)

            _beta_vs_legacy(b, ind=ind, plot=plot, gen_comp=gen_comp)


if __name__ == '__main__':
    logger = phoebe.logger('debug')
    test_binary(plot=True, gen_comp=True)
#
# Before starting any script, it is a good habit to initialize a logger and define which levels of information you want printed to the command line (clevel) and dumped to a file (flevel).
#
# The levels from most to least information are:
#
# * DEBUG
# * INFO
# * WARNING
# * ERROR
# * CRITICAL
#

# In[2]:

logger = phoebe.logger(clevel='WARNING',
                       flevel='DEBUG',
                       filename='tutorial.log')

# All of these arguments are optional and will default to clevel='WARNING' if not provided.  There is therefore no need to provide a filename if you don't provide a value for flevel.
#
# So with this logger, anything with "WARNING, ERROR, or CRITICAL levels will be printed to the screen.  All messages of any level will be written to a file named 'tutorial.log' in the current directory.
#
# Note: the logger messages are not included in the outputs shown below.
#
#
#

# Parameters
# ------------------------
#
# Parameters hold a single value, but need to be aware about their own types, limits, and connection with other Parameters (more on this later when we discuss ParameterSets).
Exemple #10
0
# ### Logger
#
# Before starting any script, it is a good habit to initialize a logger and define which levels of information you want printed to the command line (clevel) and dumped to a file (flevel).  A convenience function is provided at the top-level via [phoebe.logger](../api/phoebe.logger.md) to initialize the logger with any desired level.
#
# The levels from most to least information are:
#
# * DEBUG
# * INFO
# * WARNING
# * ERROR
# * CRITICAL
#

# In[2]:

logger = phoebe.logger(clevel='INFO', flevel='DEBUG', filename='tutorial.log')

# All of these arguments are optional and will default to clevel='WARNING' if not provided.  There is therefore no need to provide a filename if you don't provide a value for flevel.
#
# So with this logger, anything with INFO, WARNING, ERROR, or CRITICAL levels will be printed to the screen.  All messages of any level will be written to a file named 'tutorial.log' in the current directory.
#
# Note: the logger messages are not included in the outputs shown below.
#
#
#

# Parameters
# ------------------------
#
# [Parameters](../api/phoebe.parameters.Parameter.md) hold a single value, but need to be aware about their own types, limits, and connection with other Parameters (more on this later when we discuss [ParameterSets](../api/phoebe.parameters.ParameterSet.md)).
#
Exemple #11
0
# In[1]:

#!pip install -I "phoebe>=2.3,<2.4"

# In[2]:

import matplotlib.pyplot as plt

plt.rc('font', family='serif', size=14, serif='STIXGeneral')
plt.rc('mathtext', fontset='stix')

# In[3]:

import phoebe
logger = phoebe.logger('warning')

# In[4]:

b = phoebe.default_binary()

# In[5]:

b.set_value('latex_repr', component='binary', value='orb')
b.set_value('latex_repr', component='primary', value='1')
b.set_value('latex_repr', component='secondary', value='2')

# In[6]:

b.add_distribution(
    {
Exemple #12
0
"""
"""

import phoebe
from phoebe import u
import numpy as np
import matplotlib.pyplot as plt

from nose.tools import assert_raises

phoebe.logger('DEBUG')


def test_limits():
    b = phoebe.Bundle.default_binary()

    assert_raises(ValueError, b.set_value, 'teff@primary', -10)
    # NOTE: celsius not supported for all supported astropy versions (not 1.0)
    #assert_raises(ValueError, b.set_value, 'teff@primary', -10*u.Celsius)

    assert_raises(ValueError, b.set_value, 'requiv@primary', -10 * u.km)

    assert_raises(ValueError, b.set_value, 'ecc@binary', 1.0)

    return b


if __name__ == '__main__':
    logger = phoebe.logger(clevel='INFO')

    b = test_limits()
Exemple #13
0
fitParams = json.load(open(fitParamsFileName))

#%%######################create output folder #################################
#
outputPath = dataPath + datetime.now().strftime(
    '%Y%m%d_%H%M') + '_' + location + '/'
print('output will be written to %s' % outputPath)
logFileName = sysName + '_' + datetime.now().strftime(
    '%Y%m%d_%H%M') + '_log.txt'
os.mkdir(outputPath, )

tl = datetime.now().strftime('%Y%m%d_%H%M')
loggerFileName = outputPath + sysName + '_' + tl + '.log'
logger = phoebe.logger(clevel='CRITICAL',
                       flevel='DEBUG',
                       filename=loggerFileName)

print(sysConfig)
#if wrt2log: fd.write('Sys. Config.:\n')
#if wrt2log: fd.write(str(sysConfig)+'\n')
#if wrt2log: fd.flush()
#%%  set the parameters into the bundle

#k['period@binary@component']=sysConfig['period']
kb = pb.sysConfig2Bundle(sysConfig, kb)
period = sysConfig['period']

sysfm = sysConfig['measMassfn']
initM1 = sysConfig['M1']
initR1 = sysConfig['rp1']