Coder Social home page Coder Social logo

zeta1999 / pylightcurve-torch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ucl-exoplanets/pylightcurve-torch

0.0 0.0 0.0 223 KB

An exoplanet transit modelling package for deep learning applications in Pytorch.

License: GNU General Public License v3.0

Python 100.00%

pylightcurve-torch's Introduction

PyLightcurve-torch

An exoplanet transit modelling package for deep learning applications in Pytorch.

The code for orbit and flux drop computation is largely adapted from https://github.com/ucl-exoplanets/pylightcurve/ (under a MIT license).

The module pylightcurve_torch.functional.py contains the functions implemented in Pytorch and computing the orbital positions, transit durations and flux drops. (see PyLightcurve repository for more information about the numerical models used).

A TransitModule class is implemented in pylightcurve_torch.nn.py with the following features:

  • Computes time series of planetary positions and primary/secondary flux drops
  • it inherits torch.nn.Module class to benefit from its parameters optimisation and management capabilities and facilitated combination with neural networks
  • native GPU compatibility

Installation

$ pip install pylightcurve-torch

Basic use

from pylightcurve_torch import TransitModule

tm = TransitModule(time, **transit_params)

flux_drop = tm()

If needs be, the returned torch.Tensor can be converted to a numpy.ndarrray using flux_drop.numpy() torch method or flux.cpu().numpy() if the computation took place on a gpu.

Transit parameters

Below is a summary table of the planetary orbital and transit parameters use in PyLightcurve-torch:

Name Pylightcurve alias Description Python type Unit Transit type
a sma_over_rs ratio of semi-major axis by the stellar radius float unitless primary/secondary
P period orbital period float days primary/secondary
e eccentricity orbital eccentricity float unitless primary/secondary
i inclination orbital inclination float degrees primary/secondary
p periastron orbital argument of periastron float degrees primary/secondary
t0 mid_time transit mid-time epoch float days primary/secondary
rp rp_over_rs ratio of planetary by stellar radii float unitless primary/secondary
method method limb-darkening law str primary
ldc limb_darkening_coefficients limb-darkening coefficients list unitless primary
fp fp_over_fs ratio of planetary by stellar fluxes float unitless secondary

A short version of each parameter has been introduced, while maintaining a compatibility with origin PyLightcurve parameter names. All the parameters except method are converted to torch.Parameters when passed to a ``TransitModule```, with double dtype.

Differentiation

One of the main benefits of having a pytorch implementation for modelling transits is offered by its automatic differentiation feature with torch.autograd, stemming from autograd library.

Here is an example of basic usage:

...
tm.fit_param('rp')                  # activates the gradient computation for parameter 'rp'
err = loss(flux, **data)            # loss computation in pytorch 
err.backward()                      # gradients computation 
tm.rp.grad                          # access to computed gradient for parameter 'rp'

More Pytorch support

Several utility methods inherited from PyTorch modules are listed below, simplifying operations on all module's defined tensor parameters.

tm = TransitModule()

# Parameters access (iterators)
tm.parameters()
tm.named_parameters()

# dtype conversions
tm.float()
tm.double()

# Gradient local deactivation
with torch.no_grad():
    flux_no_grad = tm()

# device conversion
tm.cpu()
tm.cuda()

Running performance tests

In addition to traditional unit tests, computation performance tests can be executed this way:

 python tests/performance.py --plot
 

This will measure the computation time for computing forward transits as a function of transit duration, time vector length or batch size. If data have been savec previously, these will be plotted to with the name of the corresponding tag.

pylightcurve-torch's People

Contributors

mariomorvan avatar

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.