Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility with arrays and lists as arguments #21

Open
MicheleRonchi opened this issue Sep 2, 2021 · 1 comment
Open

compatibility with arrays and lists as arguments #21

MicheleRonchi opened this issue Sep 2, 2021 · 1 comment
Labels
help wanted Extra attention is needed pull-request-welcome

Comments

@MicheleRonchi
Copy link

Hi,

I'm trying to compute the DM values given the distance and the sky position for a lot of objects.
I have saved the distances and the sky positions in galactic coordinates in numpy.arrays and I was wondering if there is a way to directly pass numpy.arrays as arguments to the methods pygedm.dist_to_dm.

At the moment if I run the following example:

l_gal = np.array([20, 30])
b_gal = np.array([-10, 30])
dist = np.array([1000, 2000])

dm, _ = pygedm.dist_to_dm(l_gal, b_gal, dist, method='ymw16')

The following error comes out:

TypeError: dmdtau(): incompatible function arguments. The following argument types are supported:
    1. (gl: float, gb: float, dordm: float, DM_Host: float, ndir: int, np: int, vbs: int, dirname: str, text: str) -> Dict[str, float]

Looping on the values is a solution but it is also slow for many objects and I'm trying to optimize the script I'm working on.

Thank you very much for the help,

Michele

@telegraphic
Copy link
Collaborator

Hey @MicheleRonchi ,

I did think about doing this but got exhausted of working on the code! Nevertheless you inspired me, so I had a stab at it. There's a first attempt on a new branch numpy-array-issue21.

Currently only works for YMW16, and you need to use the pybind shared object manually (import ymw16).

Here's an example:

import numpy as np
import ymw16
import os
from pkg_resources import resource_filename

DATAPATH = os.path.dirname(resource_filename("pygedm", "spiral.txt"))

gl = np.array([1,2,3,4], dtype='float64')
gb = np.array([1,2,3,4], dtype='float64')
dm = np.array([10, 15, 20, 25], dtype='float64')
out = ymw16.dmdtau_np(gl, gb, dm, 0., 2, 1, 0, DATAPATH, '')

# output is Nx2 array (DM, tau_sc), but needs to be reshaped
print(out.reshape((-1, 2)))

To use this you will need to checkout the branch with git, then install from source with pip install -e .. I don't have time at the moment to properly integrate this with pygedm, could me a month or two before I get around to it (If you're up for the challenge, pull requests always welcome 😄).

For reference to me in the future / anyone else interested, we would need to:

  • Update ymw16_wrapper.py so numpy arrays can be used
  • Write a unit test for YMW16 numpy version
  • Write a NE2001 version (edit ne21c/main.cpp)
  • Update ne2001_wrapper.py
  • Write a unit test for NE2001 numpy version
  • Make sure it works with the high-level pygedm.dist_to_dm and whatnot.
  • Bump version, merge and release to pypi

@telegraphic telegraphic added help wanted Extra attention is needed pull-request-welcome labels Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed pull-request-welcome
Projects
None yet
Development

No branches or pull requests

2 participants