Code Monkey home page Code Monkey logo

Comments (8)

bl06 avatar bl06 commented on August 24, 2024 1

Thanks for quick answer and thanks a lot for making this code available !!

from tls.

hippke avatar hippke commented on August 24, 2024

Hey, sorry you are having trouble. This is the first bug report with respect to multiprocessing, and many people use it, so it appears that it's got something to do with your machine.
Can you please:

  • Try a run without multiprocessing, i.e. add the parameter use_threads=1
  • Provide your Python version from python --version
  • Give some details on the hardware: Is this a new M1 Mac?

from tls.

bl06 avatar bl06 commented on August 24, 2024

I have old MacOs (intel core i7, Catalina) and Python 3.8.12

I am not sure where to specify the use_threads=1. is it in the calling :
model = transitleastsquares(time, flux, use_threads=1) ?
if so then the code crashes :
TypeError: init() got an unexpected keyword argument 'use_threads'

from tls.

hippke avatar hippke commented on August 24, 2024

Please try:

import numpy
import batman
from transitleastsquares import transitleastsquares


if __name__ == "__main__":
    print("Starting test: synthetic...", end="")
    
    numpy.random.seed(seed=0)  # reproducibility
    # Create test data
    start = 48
    days = 365.25 * 3
    samples_per_day = 12  # 48
    samples = int(days * samples_per_day)  # 48
    t = numpy.linspace(start, start + days, samples)

    # Use batman to create transits
    ma = batman.TransitParams()
    ma.t0 = (
        start + 20
    )  # time of inferior conjunction; first transit is X days after start
    ma.per = 365.25  # orbital period
    ma.rp = 6371 / 696342  # 6371 planet radius (in units of stellar radii)
    ma.a = 217  # semi-major axis (in units of stellar radii)
    ma.inc = 90  # orbital inclination (in degrees)
    ma.ecc = 0  # eccentricity
    ma.w = 90  # longitude of periastron (in degrees)
    ma.u = [0.5]  # limb darkening coefficients
    ma.limb_dark = "linear"  # limb darkening model
    m = batman.TransitModel(ma, t)  # initializes model
    original_flux = m.light_curve(ma)  # calculates light curve

    # Create noise and merge with flux
    ppm = 5
    stdev = 10 ** -6 * ppm
    noise = numpy.random.normal(0, stdev, int(samples))
    y = original_flux + noise
    y[1] = numpy.nan
    model = transitleastsquares(t, y)
    results = model.power(
        period_min=360,
        period_max=370,
        transit_depth_min=10 * 10 ** -6,
        oversampling_factor=5,
        duration_grid_step=1.02, 
        verbose=True,
        use_threads=1
    )

    numpy.testing.assert_almost_equal(results.chi2_min, 8831.654060613922, decimal=5)
    numpy.testing.assert_almost_equal(
        results.chi2red_min, 0.6719152511118321, decimal=5
    )

    numpy.testing.assert_almost_equal(
        results.period_uncertainty, 0.216212529678387, decimal=5
    )
    numpy.testing.assert_equal(results.per_transit_count[0], 7)
    numpy.testing.assert_equal(len(results.transit_times), 3)
    numpy.testing.assert_almost_equal(results.period, 365.2582192473641, decimal=5)
    numpy.testing.assert_almost_equal(
        results.transit_times[0], 68.00349264912924, decimal=5
    )
 

from tls.

bl06 avatar bl06 commented on August 24, 2024

that works

Starting test: synthetic...Transit Least Squares TLS 1.0.30 (17 Nov 2021)
Creating model cache for 133 durations
Searching 13148 data points, 278 periods from 360.012 to 369.983 days
Using 1 of 4 CPU threads
100%|█████████████████████████████████████████████████████████████████████████████████████████████| 278/278 periods | 00:06<00:00
Searching for best T0 for period 365.25822 days
100%|████████████████████████████████████████████████████████████████████████████████████| 13148/13148 [00:03<00:00, 3954.28it/s]

from tls.

hippke avatar hippke commented on August 24, 2024

OK great! So at least you can use TLS now. What happens if you just change use_threads=2 in the script?

from tls.

bl06 avatar bl06 commented on August 24, 2024

You script given above works with use_threads=1 or 2 or 3 or 4 !
however the script in the tutorial 1 runs only if results = model.power(use_threads=1)

from tls.

bl06 avatar bl06 commented on August 24, 2024

ok. I found it. If I add
if name == "main":

at the begging of the code of Tutorial 1, then all the use_treads=1 or 2 or 3 or 4 work.

from tls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.