Agent skill
raman-fitting
This skill provides guidance for fitting peaks in Raman spectroscopy data, particularly for materials like graphene. Use this skill when tasks involve Raman spectrum analysis, peak fitting (G peak, 2D peak, D peak), or spectroscopic curve fitting using Lorentzian, Gaussian, or Voigt functions.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/raman-fitting
SKILL.md
Raman Spectrum Peak Fitting
Overview
This skill provides procedural knowledge for fitting peaks in Raman spectroscopy data. Raman spectroscopy is commonly used to characterize materials like graphene, carbon nanotubes, and other crystalline structures. Proper peak fitting requires understanding both the physics of Raman scattering and robust numerical fitting techniques.
Critical First Step: Data Exploration
Before any fitting attempts, perform comprehensive data exploration to avoid fundamental misinterpretations:
1. Verify Data Format
- Examine file structure carefully (delimiters, column separators, row numbering)
- Check for locale-specific number formats (e.g.,
47183,554644may use comma as decimal separator) - Identify whether columns represent wavenumber, wavelength, or require conversion
- Look for header rows or metadata that may affect parsing
2. Assess Data Range and Quality
- Determine the wavenumber range covered by the dataset
- Check if expected peak positions fall within the data range
- Identify noise levels and baseline characteristics
- Plot the entire spectrum before attempting any fits
3. Compare Against Expected Values
For graphene Raman spectra, typical peak positions are:
- D peak: ~1350 cm⁻¹ (disorder-induced)
- G peak: ~1580 cm⁻¹ (in-plane vibration)
- 2D peak: ~2700 cm⁻¹ (second-order)
If data range excludes expected peak positions, document this limitation before proceeding.
Peak Fitting Workflow
Step 1: Background Subtraction
- Apply baseline correction before fitting peaks
- Common methods: linear baseline, polynomial fit, or asymmetric least squares
- Document the baseline method used
Step 2: Select Appropriate Peak Function
Choose based on physical broadening mechanisms:
| Function | Use Case |
|---|---|
| Lorentzian | Natural linewidth broadening, homogeneous systems |
| Gaussian | Instrumental broadening, inhomogeneous systems |
| Voigt | Combination of both effects (most physically realistic) |
| Pseudo-Voigt | Computationally simpler approximation to Voigt |
Step 3: Define Fitting Region
- Select regions containing individual peaks
- Avoid arbitrary region changes without documented justification
- Consider overlapping peaks that may require multi-peak fitting
Step 4: Set Physical Constraints
Apply parameter bounds based on physical knowledge:
- Peak positions: within ±50 cm⁻¹ of expected values
- Linewidths (FWHM): typically 10-100 cm⁻¹ for Raman peaks
- Intensities: positive values only
Step 5: Execute Fit and Validate
Fit Quality Validation
Metrics to Check
- R² value: Should be > 0.9 for acceptable fits; < 0.5 indicates fit failure
- Residual analysis: Look for systematic deviations, not random scatter
- Parameter bounds: Parameters hitting bounds indicates fit problems
- Physical plausibility: Compare fitted values against literature
Warning Signs of Fit Failure
- Parameters exactly at constraint boundaries
- R² < 0.5
- Fitted peak position differs > 50 cm⁻¹ from expected
- Fitted linewidth unreasonably narrow (< 5 cm⁻¹) or broad (> 200 cm⁻¹)
- Negative intensity values
Response to Poor Fits
When fits fail, systematically explore alternatives:
- Try different peak functions (Gaussian, Voigt instead of Lorentzian)
- Consider multiple overlapping peaks
- Improve background subtraction
- Adjust fitting region
- Check for data quality issues in that spectral region
Do NOT accept poor fits as "the best possible" without exhausting alternatives.
Code Design Principles
Write Modular, Reusable Code
Instead of creating multiple scripts with duplicated code:
# Define once and reuse
def lorentzian(x, amplitude, center, gamma):
"""Lorentzian peak function."""
return amplitude * gamma**2 / ((x - center)**2 + gamma**2)
def fit_peak(wavenumber, intensity, region, peak_func, initial_guess, bounds):
"""Generic peak fitting with validation."""
mask = (wavenumber >= region[0]) & (wavenumber <= region[1])
x_fit, y_fit = wavenumber[mask], intensity[mask]
popt, pcov = curve_fit(peak_func, x_fit, y_fit, p0=initial_guess, bounds=bounds)
# Validate fit
y_pred = peak_func(x_fit, *popt)
r_squared = 1 - np.sum((y_fit - y_pred)**2) / np.sum((y_fit - np.mean(y_fit))**2)
return popt, pcov, r_squared
Include Sanity Checks
def validate_graphene_peak(peak_name, position, expected, tolerance=50):
"""Check if fitted position is physically reasonable."""
if abs(position - expected) > tolerance:
print(f"WARNING: {peak_name} at {position:.1f} cm⁻¹ differs from expected {expected} cm⁻¹")
return False
return True
Common Pitfalls
- Incomplete Data Exploration: Jumping to fitting without understanding data format and range
- Accepting Poor Fits: Reporting R² < 0.5 as valid results
- Ignoring Physical Constraints: Not checking if results match known material properties
- Code Duplication: Creating multiple scripts instead of parameterized functions
- Arbitrary Region Selection: Changing fitting regions without justification
- Missing Baseline Correction: Fitting raw data without background subtraction
- Single Function Assumption: Not trying alternative peak shapes when fits fail
Output Requirements
When reporting Raman fitting results, include:
- Data format and any preprocessing applied
- Fitting function and justification
- Fitted parameters with uncertainties
- R² or other goodness-of-fit metric
- Comparison to expected literature values
- Any limitations or caveats (e.g., data range issues)
References
For detailed information on Raman spectroscopy fitting approaches, consult references/raman_fitting_guide.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?