Skip to main content

3D Density Reconstruction from 2D Column Density

This project provides Python functions to reconstruct a 3D density distribution from a 2D column density map using a multi-scale decomposition approach based on constrained diffusion. This method is particularly useful in astrophysics for analyzing gas and dust distributions.

Features

  • compute_mean_density_width(column_density, dx): Derives the mean density and characteristic widths from a column density map.

  • density_reconstruction_3d(data_in, dx): The main function to perform the full 3D density reconstruction from a 2D column density map.

Installation

To use this code, you need to install the following Python packages:

  • numpy

  • scipy

  • matplotlib

  • astropy

  • constrained-diffusion (This is the cdd module used for the core decomposition.)

You can install these using pip:

pip install numpy scipy matplotlib astropy
pip install constrained-diffusion

If constrained-diffusion is a custom package, clone and install it from its repository:

git clone https://github.com/gxli/Volume-Density-Mapper
cd Volume-Density-Mapper
pip install .

or

pip install -i https://test.pypi.org/simple/ volume-density-mapper

or

pip install volume-density-mapper==0.1.2

This example demonstrates how to:

  • Estimate characteristic widths and mean density using compute_mean_density_width.

  • Construct a 3D density cube using density_reconstruction_3d.

#!/usr/bin/env python
# coding: utf-8

import matplotlib.pyplot as plt
import numpy as np
from astropy.io import fits
from volume_density_mapper import *

# --- Load Data and Define Constants ---
nh = fits.getdata('IC348_nh.fits')
header = fits.getheader('IC348_nh.fits')
mh2 = 1.34 * 3.34e-24  # Mass of H2 molecule in g
pc = 3.08e18           # Parsec in cm
dx = header['CDELT2'] / 180 * np.pi * 270 * pc  # Pixel size in cm

# --- Compute Mean Density and Width ---
input_map = nh * mh2
density, width = compute_mean_density_width(input_map, dx)

# --- Reconstruct 3D Density Structure ---
data3d = density_reconstruction_3d(input_map, dx)

print(np.shape(data3d))

Example

import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import cm
import numpy as np
from astropy.io import fits
from astropy import constants as cons
from volume_density_mapper import *



nh = fits.getdata('IC348_nh.fits')
header = fits.getheader('IC348_nh.fits')
mh2 = 1.34*3.34e-24
pc = 3.08e18

plt.figure(dpi = 100)
plt.imshow(np.log10(nh * mh2), origin = 'lower')
Alternative text for the image
plt.colorbar(label=r'Log(surface density ($\rm g cm^{-2}$))')



# charactersitic scale (width) measurements
input_map = nh.copy() * mh2
dx = header['CDELT2']/180*np.pi*270 * pc
#pixel size, the same unit with that of output
density, width = compute_mean_density_width(input_map, dx)

plt.figure(dpi = 100)
plt.imshow(np.log10(density), origin = 'lower')
plt.colorbar(label = r'log(Volume Density (r$g\;cm^{-3}$))')


plt.figure(dpi = 100)
plt.imshow(np.log10(width), origin = 'lower',cmap = 'magma')
plt.colorbar(label = r'log(width (cm))')

plt.show()
Alternative text for the image Alternative text for the image
# restructure the density structure in 3D space

data_in = nh * mh2 # convert to cgs unit
dx = header['CDELT2']/180*np.pi*270 * pc #pixel size, unit as cm (cgs unit)
data3d = density_reconstruction_3d(data_in, dx)

print(np.shape(data3d))

License

This project is open-source and available under the GPL-v3.0 License. See the LICENSE file for details.

References

Metadata

Release files for volume-density-mapper 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for volume-density-mapper 0.1.4
File Size Uploaded Provenance Actions
volume_density_mapper-0.1.4.tar.gz 19.8 kB Without provenance Details for volume_density_mapper-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for volume-density-mapper 0.1.4
File Interpreter ABI Platform Actions
volume_density_mapper-0.1.4-py3-none-any.whl Python 3 none any Details for volume_density_mapper-0.1.4-py3-none-any.whl

Total release size: 38.3 kB

Release files / volume_density_mapper-0.1.4.tar.gz

Download URL volume_density_mapper-0.1.4.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3efe730f99437f83ae422dc1fec02be4865ffe27ab440463b1ef2d8c1d24f463
BLAKE2b-256 checksum
How to use checksums
3b2852c70e1f56ee2f66238c4be684596a2b40dbfd03830f273e6bb5952c1657
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.12

Release files / volume_density_mapper-0.1.4-py3-none-any.whl

Download URL volume_density_mapper-0.1.4-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d7a0fcfe3a050d632e70d54b9606b8cd775ee92213d63333c335d0af0d56e8f
BLAKE2b-256 checksum
How to use checksums
4772842c575f0f0db9df0565936d804eeb4deeb77a148dd8054824893483fe93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.12

Security for volume-density-mapper 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page