Giter Site home page Giter Site logo

grburgess / cosmogrb Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 7.0 59.47 MB

A cosmological GRB light curve simulator. Because, why not?

Home Page: https://cosmogrb.readthedocs.io/en/latest/

License: BSD 2-Clause "Simplified" License

Python 100.00%
grb cosmology population-synthesis light-curves simulation fermi-science

cosmogrb's Introduction

Travis CI w/ Logo codecov

status

GitHub last commit (branch) GitHub issues GitHub pull requests GitHub contributors

cosmogrb

alt text

Idea

This simulates a cosmological population of GRBs in the Universe from a given space and luminosity distribution.

Light curves / lightcurves

After simulation, a realistic background and temporally evolving spectrum are created. These are then sampled at the single photon level, pushed through the detector responses, simulated with real dead time, and pushed into FITS Event files.

Cool?

import matplotlib.pyplot as plt
%matplotlib inline
from jupyterthemes import jtplot

import cosmogrb
You do not have threeML installed

Demo of Creating a GBM GRB

Instantiate the GRB with its parameters

grb = cosmogrb.GBMGRB_CPL(
    ra=312.0,
    dec=-62.0,
    z=1.0,
    peak_flux=5e-7,
    alpha=-0.66,
    ep=500.0,
    tau=2.0,
    trise=1.0,
    tdecay=1.,
    duration=80.0,
    T0=0.1,
)

Examine the latent lightcurve

time = np.linspace(0, 20, 100)

grb.display_energy_integrated_light_curve(time);

png

energy = np.logspace(1, 3, 100)

grb.display_energy_dependent_light_curve(time, energy, cmap='magma')

png

Simulate the GRB

grb.go(n_cores=6)

Save the GRB to an HDF5 file

grb.save('test_grb.h5')

Reload the GRB

grb_reload = cosmogrb.GRBSave.from_file('test_grb.h5')
fig, axes = plt.subplots(4,4,sharex=True,sharey=False,figsize=(15,15))
row=0
col = 0
for key in grb_reload.keys:
    ax = axes[row][col]
    
    lightcurve = grb_reload[key]['lightcurve']
    
    lightcurve.display_lightcurve(dt=2, ax=ax,lw=.8)
    lightcurve.display_source(ax=ax,lw=.8)
    lightcurve.display_background(ax=ax,lw=.8)
    
    if col < 3:
        col+=1
    else:
        row+=1
        col=0
    
    

png

fig, axes = plt.subplots(4,4,sharex=False,sharey=False,figsize=(15,15))
row=0
col = 0

for key in grb_reload.keys:
    ax = axes[row][col]
    
    lightcurve = grb_reload[key]['lightcurve']
    
    lightcurve.display_count_spectrum(tmin=0, tmax=5, ax=ax)
    lightcurve.display_count_spectrum_source(tmin=0, tmax=5, ax=ax)
    lightcurve.display_count_spectrum_background(tmin=0, tmax=5, ax=ax)

    if col < 3:
        col+=1
    else:
        row+=1
        col=0

png

Convert HDF5 to standard FITS files

cosmogrb.grbsave_to_gbm_fits("test_grb.h5")
!ls SynthGRB_*
SynthGRB_b0.fits      SynthGRB_n3.fits      SynthGRB_n7rsp_n7.rsp

SynthGRB_b0.rsp       SynthGRB_n3.rsp       SynthGRB_n8.fits

SynthGRB_b0rsp_b0.rsp SynthGRB_n3rsp_n3.rsp SynthGRB_n8.rsp

SynthGRB_b1.rsp       SynthGRB_n4.fits      SynthGRB_n8rsp_n8.rsp

SynthGRB_b1rsp_b1.rsp SynthGRB_n4.rsp       SynthGRB_n9.fits

SynthGRB_n0.fits      SynthGRB_n4rsp_n4.rsp SynthGRB_n9.rsp

SynthGRB_n0.rsp       SynthGRB_n5.fits      SynthGRB_n9rsp_n9.rsp

SynthGRB_n0rsp_n0.rsp SynthGRB_n5.rsp       SynthGRB_na.fits

SynthGRB_n1.fits      SynthGRB_n5rsp_n5.rsp SynthGRB_na.rsp

SynthGRB_n1.rsp       SynthGRB_n6.fits      SynthGRB_narsp_na.rsp

SynthGRB_n1rsp_n1.rsp SynthGRB_n6.rsp       SynthGRB_nb.fits

SynthGRB_n2.fits      SynthGRB_n6rsp_n6.rsp SynthGRB_nb.rsp

SynthGRB_n2.rsp       SynthGRB_n7.fits      SynthGRB_nbrsp_nb.rsp

SynthGRB_n2rsp_n2.rsp SynthGRB_n7.rsp

cosmogrb's People

Contributors

eschoesser avatar grburgess avatar wematthias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.