Skip to main content

ramansep

PyPI DOI tests

Separate strain from carrier density in Raman maps of 2D materials, using two phonon modes whose lever arms differ.

A single Raman frequency responds to strain and to carrier density at once, so one mode cannot tell the two apart. Two modes with sufficiently different responses form a linear, invertible probe: measure both shift maps, invert a 2x2 matrix per pixel, and obtain a strain map and a carrier-density map with propagated uncertainties.

Status

v0.7.0 (alpha). Implemented and tested (50 tests, Python 3.9-3.13): the inversion core, uncertainty propagation, conditioning diagnostics, a synthetic end-to-end example, two cited coefficient sets for monolayer MoS2, a cited graphene G + 2D set, a peak-fitting front end (Lorentzian and Voigt), the overdetermined multimode GLS inversion with its chi-square model check, the joint Bayesian map inversion with spatial smoothness priors, and lever-arm calibration from the user's own reference measurements. The API may change before v1.0.

Calibrate your own lever arms (new in v0.7)

The shipped coefficient sets all carry the same caveat: lever arms depend on material, mode pair, excitation and substrate. The rigorous response is a calibration on reference states you control -- a strain stage sweep, a gated sweep, any set of points with known (strain, density) -- and calibrate_lever_arms fits the (m, 2) lever-arm matrix from those measurements by weighted least squares, with exact known-noise covariances when shift sigmas are supplied (the Gauss-Markov algebra of the multimode inversion, applied to the transposed problem), a per-mode chi-square consistency check, and an identifiability refusal when the reference states are collinear in the (strain, density) plane (a strain-only sweep cannot determine doping arms, and the fit says so instead of returning one of infinitely many minimizers). CalibrationResult.coefficients() packages a two-mode calibration as a ModeCoefficients -- with a mandatory provenance string -- and result.K feeds MultiModeModel directly for m > 2.

import ramansep as rs
# strain-stage points (density 0) plus gated points (strain 0)
res = rs.calibrate_lever_arms(strain, density, shifts, sigmas=sig,
                              mode_names=["A'1", "2LA(M)"])
coeff = res.coefficients(reference="stage + gate calibration, 2026-09")
model = rs.SeparationModel(coeff)

Anchors, asserted in the tests rather than stated: noise-free shifts from a known matrix are recovered to machine precision; the normal-equation path agrees with an independent QR solve to 1e-10; the orthogonal unit design has exactly the identity covariance; Monte-Carlo scatter matches the reported sigmas; and a calibrate-then-invert round trip through SeparationModel returns the input maps.

More than two modes, with model checking (new in v0.5)

MultiModeModel generalizes the inversion to any number of modes by weighted (Gauss-Markov) least squares: each extra mode shrinks the strain and density uncertainties, and the redundancy buys a per-pixel chi-square goodness-of-fit with m - 2 degrees of freedom, so pixels where strain and density alone cannot explain the shifts (a third latent variable, a phase boundary, a bad fit) are flagged by their p-value map, something no exactly determined two-mode inversion can detect. compare_mode_sets ranks candidate mode subsets by the uncertainty they deliver. For two modes the estimator reduces exactly to the 2x2 core inversion (asserted to machine precision in the tests).

from ramansep import MultiModeModel
mm = MultiModeModel(K)                     # K: (m, 2) lever arms
res = mm.invert([dw1, dw2, dw3], sigmas=[0.15, 0.10, 0.12])
suspect = res.p_value < 1e-3               # model-violation map

Cited coefficient sets (new in v0.2)

Two example sets for monolayer 1H-MoS2 ship with full provenance, and the test-suite reproduces the published separation results of the source paper from them (edge charge of 2.3e12 cm^-2 from a 0.5 cm^-1 A'1 redshift with 2LA(M) unmoved; 0.134% interior tension carrying no significant charge):

  • mos2_a1_2la(): the A'1 + 2LA(M) pair of the source paper. Strain lever arms -5.1 and -20.9 cm^-1 per percent of biaxial strain (frozen-phonon DFT, ratio 4.1); A'1 doping coefficient -2.2 cm^-1 per 1e13 cm^-2 of electrons (measured, Chakraborty et al., Phys. Rev. B 85, 161403(R) (2012)). The 2LA(M) doping coefficient is unmeasured and set to zero; the source paper bounds the consequence of that choice at 16% of a recovered edge charge.
  • mos2_eprime_a1(): the historically used all-optical E' + A'1 pair, built from the measured biaxial Grueneisen parameters of Michail et al., ACS Appl. Mater. Interfaces 16, 49602 (2024). Both optical modes respond weakly to strain, so for equal shift noise this pair returns about five times the strain uncertainty of the A'1 + 2LA(M) pair; it is included for comparison and for workflows where the overtone is not available.

New in v0.3, graphene_g_2d_lee2012(): the G + 2D pair of monolayer graphene, expressing the vector decomposition of Lee et al., Nat. Commun. 3, 1024 (2012) as a linear inversion. Strain axis: -23.5 cm^-1 per percent of randomly oriented uniaxial strain with the measured 2D/G slope of 2.2 +/- 0.2; hole-doping axis: the measured slope 0.70 +/- 0.05. The doping output of this set is deliberately NOT a carrier density but the G-band shift attributable to hole doping (cm^-1): the G-mode doping response of graphene is nonlinear and sign-dependent, so no universal linear per-density rate exists to ship, and the docstring points to the gated calibrations (Froehlicher and Berciaud, Phys. Rev. B 91, 205413 (2015)) a user needs for the conversion on their own substrate.

Each function's docstring states which number comes from which source and the conditions of applicability (for MoS2: 1H monolayer, SiO2-supported, 300 K; 532 nm for the disorder-activated calibration). Check that your sample matches before use.

What this package deliberately does not include

No constants beyond the three documented sets are shipped. Lever arms depend on material, mode pair, excitation wavelength and substrate; a measurement tool that ships unverified constants propagates wrong results. For any other system you provide a ModeCoefficients from the literature or your own calibration, and the reference field is mandatory so the provenance of every number travels with the analysis.

Install

pip install ramansep

For development, clone the repository and pip install -e .[test].

Use

import numpy as np
from ramansep import SeparationModel, ModeCoefficients

coeffs = ModeCoefficients(
    mode1_name="A'1", mode2_name="2LA(M)",
    k1_strain=...,   # cm^-1 per unit strain, from your calibration
    k1_density=...,  # cm^-1 per unit carrier density
    k2_strain=...,
    k2_density=...,
    reference="cite the source of these numbers",
)
model = SeparationModel(coeffs)
result = model.invert(dw_mode1, dw_mode2, sigma1=0.1, sigma2=0.1)
# result.strain, result.density, result.strain_sigma, result.density_sigma

SeparationModel warns when the mode pair is poorly conditioned, i.e. when the two modes respond too similarly for a reliable separation.

Method

The method of using the first-order A'1 mode together with the disorder-activated 2LA(M) overtone, whose strain lever arms differ severalfold while only A'1 responds appreciably to carrier density, is developed in:

T. M. Mahim and M. M. Rahman, "Two Raman phonons quantify the fixed edge charge left by patterning monolayer transition metal dichalcogenides" (under review). Code for the paper itself: https://github.com/Tanvir-Mahmud-Mahim/Width-scaling-in-monolayer-semiconductor-nanoribbon-transistors

This package is the general-purpose, material-agnostic inversion tool; the paper repository reproduces the specific published study.

Peak fitting (new in v0.4)

The roadmap's front end is in: fit_two_modes takes a raw spectrum, fits a Lorentzian to each mode window with a NumPy-only Levenberg-Marquardt solver (analytic Jacobians, linearized 1-sigma uncertainties), and returns exactly the shifts and uncertainties that SeparationModel.invert consumes.

from ramansep import SeparationModel, fit_two_modes, mos2_a1_2la

model = SeparationModel(mos2_a1_2la())
dw1, dw2, s1, s2, fit1, fit2 = fit_two_modes(
    wavenumber, counts,
    window1=(395.0, 415.0), window2=(440.0, 465.0),
    ref1=404.7, ref2=452.0)   # your pristine references
result = model.invert(dw1, dw2, s1, s2)

Two lineshapes are offered and the choice is stated, not hidden: fit_lorentzian for the lifetime lineshape of a phonon, and fit_voigt (v0.6) for instrument-dominated lines, via the Faddeeva function with an analytic Jacobian. The test suite checks both Jacobians against finite differences, exact parameter recovery on noiseless lines, the Voigt profile's exact Gaussian limit at zero Lorentzian width and its convergence to the Lorentzian at zero Gaussian width, statistical compatibility of the reported center uncertainty with the actual scatter on noisy lines, and a full spectrum-to-inversion round trip.

Roadmap

  • v0.2 (done): documented example coefficient sets with citations
  • v0.3 (done): graphene G+2D coefficient set (Lee 2012)
  • v0.4 (done): peak-fitting front end (fit the two modes, feed the inversion)
  • v0.5 (done): overdetermined multimode GLS inversion with per-pixel chi-square model checking and mode-set comparison
  • v0.6 (done): joint Bayesian inversion with spatial priors (bayesian_map_inversion: Gaussian Markov random field smoothness prior on both fields, solved exactly as a sparse linear MAP problem; lam = 0 reproduces the per-pixel GLS maps and sigmas to machine precision, asserted in the tests) and a Voigt fitter (fit_voigt) for instrument-dominated lines
  • v0.7 (done): lever-arm calibration from the user's own reference measurements (calibrate_lever_arms), closing the loop the no-shipped-coefficients policy opens: the package now provides the fit, with uncertainties, chi-square consistency and identifiability refusals -- the user still provides the reference states and the provenance

The roadmap is complete. Deliberate scope, designed out rather than overlooked: no shipped coefficient values beyond the cited example sets (your material and mode pair need your calibration, with its citation -- and v0.7's calibrate_lever_arms is the tool that turns your reference measurements into that calibration); the smoothness weights lam_strain / lam_density are user-chosen regularization, not estimated hyperparameters -- full hierarchical (evidence-maximizing) inference would need assumptions about the noise this package refuses to invent; and the spatial prior is the 4-neighbor lattice with Neumann boundaries, stated plainly, not a tunable kernel zoo.

Support and governance

The package is written and maintained by Tanvir Mahmud Mahim (Department of Electrical and Electronic Engineering, BRAC University), who reviews every change and takes the final decision on scope and releases. There is no separate governance body; design questions are discussed in the open in issues and pull requests, and the standing rule of CONTRIBUTING.md binds the maintainer exactly as it binds contributors: a change that touches physics arrives with a test, and a constant arrives with its source.

Support runs through the issue tracker at https://github.com/TaN-MM-Org/ramansep/issues. Usage questions are welcome there alongside bug reports; a docstring that left a unit or a sign convention unclear is treated as a documentation bug, not as user error. The maintainer aims to respond within a week.

While the version is below 1.0 the API may still move between minor versions; such changes are called out in the release notes, and the roadmap above states what is planned, so that a user can tell a missing feature from an omission by design.

License

Apache-2.0

Metadata

Release files for ramansep 0.7.0

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

Source distribution (sdist)

Source distribution for ramansep 0.7.0
File Size Uploaded
ramansep-0.7.0.tar.gz 41.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ramansep 0.7.0
File Interpreter ABI Platform
ramansep-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 73.4 kB

Release files / ramansep-0.7.0.tar.gz

Download URL ramansep-0.7.0.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0f826296766d04be228aa9874d861909e11ee4b13d5c2726677aa8fcc5f2dc3e
BLAKE2b-256 checksum
How to use checksums
4e54f73013eeff96bf58f6ccb9dcb2b4aac8e19a4ab1bb92c3287a1f0f83ca4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / ramansep-0.7.0-py3-none-any.whl

Download URL ramansep-0.7.0-py3-none-any.whl
Size 31.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dec2cd5634cf7ddf0b719e12c7ec6e5e9b8894d94755ae63ae616260df2533c6
BLAKE2b-256 checksum
How to use checksums
6323e28d442e85779f9b61404a248f492f064593a895c4e80baec3a1f52e2a85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

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