Code Monkey home page Code Monkey logo

fruitbat's Introduction

PyPI - Latest Release PyPI - Python Versions PyPI - License Travis Documentation Status Code Coverage JOSS Review Status ascl:1911.010

Fruitbat Logo

FRUITBAT is an open source python package used to estimate the redshift of Fast Radio Bursts (FRB) from their dispersion measure. FRUITBAT combines various dispersion measure (DM) and redshift relations with the YMW16 galactic dispersion measure model into a single easy to use API.

Documentation

The documentation for FRUITBAT can be found at https://fruitbat.readthedocs.io/.

Installation

You can install the latest release of FRUITBAT from PyPi by running the following:

pip install fruitbat

You can install the latest development version of FRUITBAT by cloning this repository:

git clone https://github.com/abatten/fruitbat
cd fruitbat
pip install .

If you are installing the latest development version of FRUITBAT then you will also need to install git-lfs. Instructions for installing git-lfs for your operating system can be found here.

Linux Users

If you are installing FRUITBAT on a linux machine you may see this 'error': ERROR: Failed building wheel for pyymw16. This does not mean the installation failed. The C++ bindings were compiled using MacOS and needed to be recompiled for your machine. The installation process does this for you. You should still be able to run FRUITBAT normally.

Requirements

Below are the listed requirements for running FRUITBAT and the purpose for each requirement.

  • numpy: Array manipulation
  • scipy: Modules for integration and interpolation
  • astropy: Modules for cosmology, coordinates, constants and units
  • matplotlib: Modules for plotting
  • pandas: Reading csv files from FRBCAT
  • pyymw16: Python wrapper for YMW16 galactic dispersion measure model.
  • e13tools: Utility tools for writing docstrings.

Usage

If you want to get started using FRUITBAT there is a Getting Started section of the documentation made just for you! Otherwise the tl;dr is the following:

Most of the calculations will be centred around the Frb class. You can can define an instance of the Frb class with a dispersion measure. To calculate the redshift of the FRB use the method calc_redshift.

>>> import fruitbat
>>> FRB121102 = fruitbat.Frb(557, dm_excess=369)
>>> FRB121102.calc_redshift()
<Quantity 0.37581945>

The calc_redshift function can also be passed a method and/or a cosmology. The method will specify which DM-redshift relation to assume and the cosmology will specify which cosmology to assume.

>>> FRB121102.calc_redshift(method="Zhang2018", cosmology="Planck18")
<Quantity 0.42166019>

It is also possible to specify the coordinates of the burst and use the calc_dm_galaxy function to calculate the DM contribution from the Milky Way using the YMW16 or NE2001 galactic electron distribution model. Performing calc_dm_galaxy will automatically calculate the excess dispersion measure for the redshift calculation.

>>> FRB190222 = fruitbat.Frb(500, raj="12:34:43.5", decj="2:34:15.2")
>>> FRB190222.calc_dm_galaxy()
<Quantity 22.43696785 pc / cm3>
>>> FRB190222.calc_redshift()
<Quantity 0.4808557>

Issues and Contributing

If there is a feature of FRUITBAT that currently does not exist, but you would like it to, you can contribute by openning a Github Issue and outlining the feature. Similar to contributing, if you find a problem with FRUITBAT or are having difficulties using FRUITBAT please do not hesitate to open a Github Issue.

Referencing Fruitbat

If you use FRUITBAT in your research, we would like it if you could add an acknowledgement statement "Some of the results of this paper have been derived using the FRUITBAT package" and reference our paper.

@ARTICLE{2019JOSS....4.1399B,
       author = {{Batten}, Adam},
        title = "{Fruitbat: A Python Package for Estimating Redshifts of Fast Radio Bursts}",
      journal = {The Journal of Open Source Software},
     keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - High Energy Astrophysical Phenomena},
         year = "2019",
        month = "May",
       volume = {4},
       number = {37},
        pages = {1399},
          doi = {10.21105/joss.01399},
archivePrefix = {arXiv},
       eprint = {1905.04294},
 primaryClass = {astro-ph.IM},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2019JOSS....4.1399B},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

fruitbat's People

Contributors

abatten avatar telegraphic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fruitbat's Issues

update dependencies

In the README.md, please consider addingpybind11 to the list of dependencies.

comoving distance differs from docs

Working through:

https://fruitbat.readthedocs.io/en/latest/user_guide/using_fruitbat.html

when I get to "Calculating Distances" and the first subsection, "Comoving Distance", I get

In [22]: frb.calc_comoving_distance()                                                                 
Out[22]: <Quantity 1812.21526231 Mpc>

instead of the 2020.297 value reported. Once I create the next frb object in the code block below this, if I go back and look at calc_comoving_distance() I get the value in the docs. So perhaps the docs were executed out of order?

Expected FRB designation (`name`)

Does fruitbat.Frb support the more up-to-date TNS designation for the name parameter (e.g. FRB 20180110) or only the older-ish one (e.g. FRB180110)? If not, it might be worth adding a simple automatic parser between the two designation to support both 'standards'. Otherwise, I can simply do the parsing before passing it to fruitbat.Frb().

Redshift cross-check/verification

I have built a script to compute the redshift for all FRBs using fruitbat, based on the burst's galactic coordinates and DM. I am trying to verify the estimated redshift is about right and I haven't messed anything up with the code. Is there perhaps some catalogue I could refer to, to cross-check my derived redshifts?

E.g., for FRB 20190214A (arbitrary selection) with:

l=148.5
b=22.03
DM=498.2

I get a redshift of z=1.215. Does this look right?

no cosmology

When I execute the "Custom Cosmologies" part of these docs:
https://fruitbat.readthedocs.io/en/latest/user_guide/using_fruitbat.html

I get:

params = {"H0": 72.4, "Om0": 0.26}                                                           

In [38]: new_cosmology = fruitbat.cosmology.create_cosmology(parameters=params)                       
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-f71389f8752f> in <module>
----> 1 new_cosmology = fruitbat.cosmology.create_cosmology(parameters=params)

AttributeError: module 'fruitbat' has no attribute 'cosmology'

Batten2021 curve out past redshift 3

Hello Adam,

Thanks for making your code available online for us. I'm hoping to compare some work to previous literature, including your mean DM - z relationship in Figure 2 (right) of Batten et al. 2021. Adapting the examples you provide in the documentation, I've tried to plot the actual EAGLE curve via the code below, and have included the resulting plot in an attachment.

As can be seen, this doesn't look quite the same as in the paper, as it blows up approaching redshift 3. I was wondering whether you had any advice on what was going on here?

Many thanks,
Charlie

import fruitbat
from matplotlib import pyplot as plt
fb_dm_vals = np.linspace(.01,5000,20)
fb_batten_z_vals = [fruitbat.Frb(i).calc_redshift(method="Batten2021", cosmology="Planck18") for i in fb_dm_vals]
plt.ylabel('DM')
plt.xlabel('z')
plt.plot(fb_batten_z_vals,fb_dm_vals)
plt.show()

Screenshot 2022-08-08 at 15 35 02

#question

I use pip to install the content in Figure 1, and finally I download it to the local installation C:\Users\61006\Desktop\fruitbat-2.0.1\fruitbat-2.0.1> python setup.py install and it appears File "C:\Users\61006\AppData\Local\Temp\easy_install-68ezzisq\pygedm-3.3.0\setup.py", line 143, in UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 7568: illegal multibyte sequence。I have not been able to solve through many methods

unpickling error when doing the "simple example"

When I run the "simple example" here:

https://fruitbat.readthedocs.io/en/latest/user_guide/getting_started.html#simple-example

I get an UnpicklingError:

FRB180110.calc_redshift(method="Zhang2018", cosmology="Planck18")                                                                        
---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
/usr/lib64/python3.7/site-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
    439             try:
--> 440                 return pickle.load(fid, **pickle_kwargs)
    441             except Exception:

UnpicklingError: invalid load key, 'v'.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-5-9a85f326ef82> in <module>
----> 1 FRB180110.calc_redshift(method="Zhang2018", cosmology="Planck18")

~/.local/lib/python3.7/site-packages/fruitbat/_frb.py in calc_redshift(self, method, cosmology, subtract_host, lookup_table)
    306                 table_name = "".join(["custom_", method, ".npz"])
    307 
--> 308             lookup_table = table.load(table_name)
    309 
    310         self.z = table.get_z_from_table(input_dm, lookup_table)

~/.local/lib/python3.7/site-packages/fruitbat/table.py in load(name, data_dir)
    138 
    139     filename = os.path.join(data_dir, name)
--> 140     return np.load(filename)
    141 
    142 

/usr/lib64/python3.7/site-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
    441             except Exception:
    442                 raise IOError(
--> 443                     "Failed to interpret file %s as a pickle" % repr(file))
    444     finally:
    445         if own_fid:

OSError: Failed to interpret file '/home/zingale/.local/lib/python3.7/site-packages/fruitbat/data/Zhang2018_Planck18.npz' as a pickle

I am using python 3.7.3

Luminosity unit conversion obs_bandwidth

Hey, was playing with luminosity conversion and I'm getting a unit error:

frb = fruitbat.Frb(name='FRB170922', gl=45.07, gb=-38.70, fluence=177, dm=1111,
                   obs_bandwidth=31.25)
frb.calc_dm_galaxy()
frb.calc_redshift()
print(frb.calc_energy())

>>> 1.7065900447006508e+41 erg

But with units on obs_bandwidth:

from astropy import units as u

frb = fruitbat.Frb(name='FRB170922', gl=45.07, gb=-38.70, fluence=177, dm=1111,
                   obs_bandwidth=31.25*u.MHz)
frb.calc_dm_galaxy()
frb.calc_redshift()
print(frb.calc_energy())

>>> [traceback here]
UnitConversionError: 'Jy MHz2 Mpc2 ms' (power) and 'erg' (energy) are not convertible

Also - smallish feature request: compute average luminosity in ergs/s

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.