Skip to main content

Reconstructs 3D density distributions from 2D column density maps using constrained diffusion.

Project description

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==0.1.1

or

pip install volume-density-mapper==0.1.1

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 MIT License.

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

volume_density_mapper-0.1.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

volume_density_mapper-0.1.2-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file volume_density_mapper-0.1.2.tar.gz.

File metadata

  • Download URL: volume_density_mapper-0.1.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for volume_density_mapper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 485e556915f07b80ed6a5e9f12c718bd008dc79346433244bf6f71a988488e17
MD5 a14f1e0d98639b486873ac9c1f9d8507
BLAKE2b-256 7858acfccb7f948837ba90ead62bc0295b4a4549853ad4a08f6e18442aa41e9e

See more details on using hashes here.

File details

Details for the file volume_density_mapper-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for volume_density_mapper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 510f21038432b58a6b8d0aae89d1dbe6430b480044ca0e431e5750190ce6c28c
MD5 fbb5701bdcbbc4db8936da86bc13292b
BLAKE2b-256 26fdca611b8d3fa79a19bc7e4ae9e55833c93a1e3fac0147b0e870ee82016cf0

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