Skip to main content

A python package for NE2001

Project description

MWPROP

Jan 2024 v1.0

MWPROP provides NE2001p, a native Python implementation of the original Fortran code for NE2001. The package also contains a required scattering_functions module. NE2001p is accessible from the command line, similar to the Fortran code, or within Python scripts (see below). Future package releases will include additional modules for extensions of the NE2001 model. Please cite the NE2001p research note [arXiv/RNAAS DOI TBD] for use of this package. The NE2001 model is described in detail in Cordes & Lazio (2002; 2003).


Installation:

With pip:

pip install mwprop

With GitHub: github.com/stella-ocker/mwprop.
Standalone scripts NE2001p.py and los_diagnostics.py are provided under the /bin/ directory. These scripts require mwprop to be installed.

Dependencies

  • python >= 3.6 (might work with python >= 3.0)
  • numpy
  • matplotlib
  • scipy
  • astropy
  • mpmath

Comparison to Fortran Version of NE2001:

The input parameters and model components for the Milky Way are identical.

Output is nearly the same but not identical because integrations are done slightly differently to speed up the Python version.

Differences:

  1. Scattering computations are done as an option to give maximum speed for DM to D or D to DM computations
  2. Output can be printed in console or returned in Python dictionaries, Dn, Dv, Du, Dd: Dn = names of variables Dv = values Du = units Dd = descriptions
  3. Numerical integrations use numpy.trapz instead of step-by-step summing.
  4. Clumps are prefiltered for inclusion along a specified line of sight (LoS).
  5. Large-scale components (thin and thick disks, spiral arms) are sampled coarsely (0.1 kpc default sample interval) and cubic splines are used to resample onto a fine grid.
  6. Components with small scale structure (local ISM, Galactic center, clumps, voids) are sampled directly on a fine grid.
  7. Different routines are used for execution to find distance from DM and for DM from distance. This is transparent to the user. [Specify treatment for target DM > terminal DM]
  8. Config file: code imports, reading parameter files, and setting key values (like the Sun-GC distance = 8.5 kpc) are done by importing mwprop.ne2001p.config_ne2001p
    Note the 8.5 kpc distance is needed because model parameters were determined using this value for the original NE2001 code. It cannot be changed by itself.

NE2001p is about 45 times slower than the Fortran implementation.

Forward plan:

  1. NE2001p = this version (p for Python)
  2. NE2001x = next version (x for extended)
  3. NE202(...) = new version, complete redefinition of components and implementation.

Usage:

Command Line Usage: python NE2001p.py ldeg bdeg dmd ndir [-options]

Required arguments: ldeg bdeg dmd ndir (Same as Fortran version)

ldeg, bdeg = Galactic longitude and latitude in deg
dmd = DM (pc/cc) or d (kpc)
ndir >= 0   DM -> d
      < 0    d -> DM

Optional requirements and defaults:

-a  --analysis   Calculates contributions from different model components and writes to file in user's working directory.
                 [False]
-p  --plotting   Plots DM, n_e, scattering vs distance along LoS; saves pdf files in user's working directory.
                 [False]
-s  --scattering Calculates scattering and scintillation parameters, etc.
                 [False] 
-m  --modern     Modern output (suppresses classic Fortran output)
                 [False]
-v  --verbose    Writes results to std out in the 'classic' form of the Fortran version.
                 [False]
-b  --debug      Prints various diagnostics for clumps and integration. Only works for DM->D.
                 [False]
-e  --explain    Show long-form explanation of code.
                 [False]

Script/iPython Usage:

The ne2001() function evaluates NE2001p and can be imported from the mwprop.ne2001p.NE2001 module. The function output consists of four dictionaries:

Dk    => Dictionary keys for output values
Dv    => Numerical output values
Du    => Units of output values
Dd    => Extended output description 

Additional options for ne2001():

classic = True      => print traditional Fortran output (default = True)
dmd_only = True     => compute only DM or distance, no scattering quantities (default = False)
do_analysis = True  => calculate and output diagnostic quantities for the line of sight (default = False)
plotting = True     => plot DM vs distance along LoS, SM also if dmd_only = False (default = False)
verbose = True      => print results to std out (default = False)

iPython Example:

>>> from mwprop.ne2001p import *
>>> from mwprop.ne2001p.NE2001 import ne2001
>>> Dk,Dv,Du,Dd = ne2001(ldeg=45,bdeg=5,dmd=50,ndir=1,classic=False)
>>> Dk['DIST']
'DIST'
>>> Dv['DIST']
2.6366
>>> Du['DIST']
'kpc'
>>> Dd['DIST']
'ModelDistance'

In analysis and plotting modes, output files are saved to a folder called 'output_ne2001p' in the user's working directory.


Diagnostic code los_diagnostics.py

Plots electron density, DM, and C_n^2 along the line of sight designated by l, b, DM or d, and ndir = 1 or -1 (as with NE2001). Also shows the line of sight projected onto the Galactic plane along with spiral arms used in NE2001.

The code can be downloaded from this repository under /bin/ but can be run from any directory, if mwprop is fully installed. Outputs are saved to a folder created in the user's working directory.

>>> Usage:
>>> python los_diagnostics.py  l  b  dmd  ndir   
>>> with l, b in deg, dmd = DM (pc/cc) or distance (kpc) for ndir > or < 0
>>> [same scheme as input to NE2001]

Example plots:

ne_vs_d_arms_57 0_-0 3_71_los_diagnostics

dm_ne_cn2_l_b_dmmax_57 0_-0 3_71_los_diagnostics

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mwprop-1.0.tar.gz (76.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mwprop-1.0.0-py3-none-any.whl (82.5 kB view details)

Uploaded Python 3

mwprop-1.0-py3-none-any.whl (82.5 kB view details)

Uploaded Python 3

File details

Details for the file mwprop-1.0.tar.gz.

File metadata

  • Download URL: mwprop-1.0.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for mwprop-1.0.tar.gz
Algorithm Hash digest
SHA256 e911948b9ad82235b2da367d1890df252d410674968a8e4cb7ea379b9974ff4a
MD5 462771a973781a2cee3e0eed014a810b
BLAKE2b-256 0b65ec952cd68346ecc92b5967b66b4f2128c6ad56b4739ad24d69ac9eeccb38

See more details on using hashes here.

File details

Details for the file mwprop-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mwprop-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 82.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for mwprop-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee84df5fbeefcf907c3d38b66f42169b49dc095cc69f948d56f802d0548be06
MD5 14f2f055419b623de07e086f56c5616e
BLAKE2b-256 eb3ed047b2f006d765158d6a7166eec4553ca341f3266d083ce9f535cc262ac2

See more details on using hashes here.

File details

Details for the file mwprop-1.0-py3-none-any.whl.

File metadata

  • Download URL: mwprop-1.0-py3-none-any.whl
  • Upload date:
  • Size: 82.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for mwprop-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e73e1db697287425b7716001ebaea726fd61bf9165a9b9970489f54b83cb560a
MD5 f441f53811113e6de929e21739e68eb8
BLAKE2b-256 a94d50a4a609b27ea0a7cbe033f147e5fad1b69bf7544ab35e0d9b9903dafbd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page