FRBs / pygedm

Python bindings for YMW16, NE2001 and YT2020 electron density models
https://pygedm.readthedocs.io/
42 stars 17 forks source link

igm-mode not working #2

Closed JoschaJ closed 5 years ago

JoschaJ commented 5 years ago

In the functions dist_to_dm and dm_to_dist the argument mode='igm' gives a KeyError. Here is the in- and output from the ipython console:

In [1]: import pyymw16
In [2]: pyymw16.dist_to_dm(204.0, -6.5, 200, mode='igm')
 DM_IGM:   32.73 DM_Host:    0.00 z:  0.046 DM:  284.78 log(tau_sc): -3.311 
Traceback (most recent call last):

  File "<ipython-input-3-40aea8aade18>", line 1, in <module>
    pyymw16.dist_to_dm(204.0, -6.5, 200, mode='igm')

  File "/homes/myname/.local/lib/python3.6/site-packages/pyymw16/__init__.py", line 72, in dist_to_dm
    dm = r['DM'] * u.pc / u.cm**3

KeyError: 'DM'

It seems that from the C++ function dmdtau only the first two returns are put in a dictionary while the rest is printed.

In [1]: import ymw16
In [2]: import os
In [3]: from pkg_resources import resource_filename
In [4]: DATAPATH = os.path.dirname(resource_filename("pyymw16", "spiral.txt"))
In [5]: gl, gb, dist, dm_host, ndir, mode_id, vbs, txt = 204.0, -6.5, 200, 0, 2, -1, 0, ''
In [6]: ymw16.dmdtau(gl, gb, dist, dm_host, ndir, mode_id, vbs, DATAPATH, txt)
Out[6]: {'DM_Gal': 252.05010986328125, 'DM_MC': 0.0} DM_IGM:   32.73 DM_Host:    0.00 z:  0.046 DM:  284.78 log(tau_sc): -3.311 
telegraphic commented 5 years ago

Thanks @Josch6i -- I haven't played around with IGM mode so hadn't identified this. It's on my todo list but not sure when I'll get to it (hence the pull-request-welcome tag)

telegraphic commented 5 years ago

Hey @Josch6i -- I am now getting the data, but haven't tested that the output is as expected.

telegraphic commented 5 years ago

In fact, looks like it doesn't match:

dcprice@dainkoru:/data/install/ymw16$ ./ymw16 -d data/ IGM 204 -6.5 2000 1
IGM: gl= 204.000 gb=  -6.500 DM= 2000.00 DM_Gal:  252.05 DM_MC:    0.00 DM_IGM: 1647.95 DM_Host:  100.00 z:  2.311 Dist:  5336.4 log(tau_sc): -2.218

versus:

In [8]: import pyymw16
   ...: dist, tau = pyymw16.dm_to_dist(204, -6.5, 2000, mode='igm')
   ...: print dist, np.log10(tau.value)
5521.25634766 Mpc -2.18471231199

maybe not subtracting DM of galaxy?

JoschaJ commented 5 years ago

Hey Danny, I can do some testing on Monday and give you feedback.

telegraphic commented 5 years ago

Thanks @Josch6i -- I found the reason why the output differed: the ymw16 command line defaults to a Host DM of 100, whereas my wrapper was plugging in a 0. I'm going to stick with DM_Host=0 as default, as that is more sane behaviour IMO.

PS: Checkout https://github.com/abatten/fruitbat if you're doing redshift calculations!

JoschaJ commented 5 years ago

Hey @telegraphic , I think everything should be good now. I saw fruitbat already but I thought its still nice to have this working consistently. Sorry that I couldn't help with the main issue since I don't have much experience with C++. Thanks!

telegraphic commented 5 years ago

Thanks @Josch6i, appreciate your help 👍