Skip to content

Commit e9b646b

Browse files
blaltermanclaude
andcommitted
docs(feature-integration): replace incorrect formula refs with units architecture
Remove all thermal speed formula (mw²=2kT) enforcement from feature integration documentation. Replace with accurate units architecture documentation reflecting SolarWindPy's actual implementation pattern. Changes: - Document three-tier units system (storage/display/calculation) - Emphasize bidirectional conversion pattern (display→SI→display) - Correct temperature display units to 10⁵ K - Update validation checklists to check self.units.* conversion - Replace formula-specific constraints with general vector magnitude rules - Remove curve fitting example (distraction from core units pattern) Files updated (9): - 01_memory_hierarchy.md: Rewrote physics constants section - 02_skills_system.md: Updated physics-validator skill validation - 03_subagents.md: Removed formula enforcement, added units validation - 06_output_styles.md: Changed physics-focused style emphasis - 07_slash_commands.md: Updated /physics and /review checklists - 08_plugin_packaging.md: Updated skill description - INDEX.md: Updated workflow example - appendices/plugin_quick_start.md: Updated skill template - appendices/quick_reference.md: Updated command description Validates zero thermal speed formula references remain (grep verified). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e692344 commit e9b646b

9 files changed

Lines changed: 134 additions & 146 deletions

File tree

.claude/docs/feature_integration/01_memory_hierarchy.md

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -223,37 +223,50 @@ Enhanced: CLAUDE.md (orchestrator with imports)
223223
**File:** `.claude/memory/physics-constants.md`
224224

225225
```markdown
226-
# Solar Wind Physics Constants & Formulas
226+
# Solar Wind Physics: Units Architecture
227227

228-
## Critical Formulas
228+
## Units System
229229

230-
### Thermal Speed
231-
**CORRECT:** `mw² = 2kT`
232-
**INCORRECT:** `mw² = 3kT`
230+
### Storage Units (Instrument Measurements)
231+
SolarWindPy stores only directly measured quantities:
232+
- **n:** Number density [cm⁻³]
233+
- **v:** Velocity [km/s]
234+
- **w:** Thermal speed [km/s]
233235

234-
Where:
235-
- `m` = particle mass (kg)
236-
- `w` = thermal speed (m/s)
237-
- `k` = Boltzmann constant (1.380649 × 10⁻²³ J/K)
238-
- `T` = temperature (K)
236+
### Display Units (All Quantities)
237+
All quantities displayed in units defined by `solarwindpy.core.units_constants.Units`:
238+
- Density: cm⁻³ (`self.units.n = 1e6`)
239+
- Velocity/speeds: km/s (`self.units.v = 1e3`)
240+
- Temperature: 10⁵ K (`self.units.temperature = 1e5`)
241+
- Magnetic field: nT (`self.units.bfield = 1e-9`)
242+
- Thermal pressure: pPa (`self.units.pth = 1e-12`)
243+
- See `Units` class for complete list
239244

240-
### Alfvén Speed
241-
```
242-
v_A = B / √(μ₀ρ)
243-
```
244-
- `B` = magnetic field strength (T)
245-
- `μ₀` = permeability of free space (4π × 10⁻⁷ H/m)
246-
- `ρ` = mass density (kg/m³)
245+
### Calculation Units (SI)
246+
All physics calculations performed in SI units via conversion factors.
247+
248+
## Units Conversion Pattern (Display → SI → Display)
249+
250+
**CRITICAL:** All calculations must convert units bidirectionally.
247251

248-
## SI Units (MANDATORY)
252+
```python
253+
# Example from ions.py temperature property (line 222-224)
254+
def temperature(self):
255+
# Input conversion: display → SI
256+
w = self.w.data * self.units.w # km/s → m/s
257+
258+
# Calculate in SI
259+
coeff = 0.5 * m / (self.constants.kb.J * self.units.temperature)
260+
temp = coeff * w.pow(2)
261+
262+
# Output: Result automatically in display units (10⁵ K) via coeff
263+
return temp
264+
```
249265

250-
| Quantity | Unit | Symbol |
251-
|----------|------|--------|
252-
| Velocity | meters/second | m/s |
253-
| Density | per cubic meter | m⁻³ |
254-
| Temperature | Kelvin | K |
255-
| Magnetic Field | Tesla | T |
256-
| Energy | Joules | J |
266+
**Pattern to validate:**
267+
1. Input: `quantity * self.units.<name>` (display → SI)
268+
2. Calculate: Perform physics calculation in SI
269+
3. Output: `result / self.units.<name>` (SI → display)
257270

258271
## Missing Data Convention
259272
**ALWAYS use NaN** for missing/invalid data.
@@ -272,10 +285,11 @@ velocity_missing = 0 # NO!
272285

273286
## Physical Constraints
274287

275-
- ✅ Density > 0 (particles/m³)
276-
- ✅ Temperature > 0 (K)
277-
- ✅ Speed ≥ 0 (m/s)
278-
- ✅ Thermal speed uses factor of 2, not 3
288+
- ✅ Density > 0 (n > 0 in cm⁻³)
289+
- ✅ Temperature > 0 (T > 0 in 10⁵ K)
290+
- ✅ Thermal speed ≥ 0 (w ≥ 0 in km/s, always positive scalar)
291+
- ✅ Vector magnitudes ≥ 0 (e.g., |v|, |B|), though components may be negative
292+
- ✅ Physical constants from `solarwindpy.core.units_constants.Constants`
279293
```
280294

281295
##### Memory File 2: DataFrame Patterns
@@ -419,16 +433,14 @@ class TestClassName:
419433
result_large = function(np.random.rand(10000))
420434
assert len(result_large) == 10000
421435

422-
def test_function_physics_validation(self):
423-
"""Validate physics correctness (REQUIRED for scientific functions)."""
424-
# Thermal speed formula check
425-
ion = Ion(temperature=1e5, mass=1.67e-27)
426-
thermal_speed = ion.thermal_speed()
436+
def test_function_units_conversion(self):
437+
"""Validate units conversion pattern (REQUIRED for calculation methods)."""
438+
# Check that calculations use units conversion
439+
import inspect
440+
source = inspect.getsource(ion.temperature.fget)
427441

428-
# Verify mw² = 2kT
429-
k_B = 1.380649e-23
430-
expected = np.sqrt(2 * k_B * 1e5 / 1.67e-27)
431-
np.testing.assert_allclose(thermal_speed, expected, rtol=1e-6)
442+
# Should contain self.units.w for input conversion (display → SI)
443+
assert 'self.units.w' in source, "Missing units conversion in calculation"
432444

433445
def test_function_error_handling(self):
434446
"""Test invalid inputs raise appropriate errors (REQUIRED)."""
@@ -551,7 +563,7 @@ This file provides essential guidance to Claude Code when working with the Solar
551563
**What Goes in Project Memory:**
552564
All SolarWindPy-specific conventions, rules, and knowledge that should be consistent across all team members:
553565

554-
- **Physics constants and formulas** (thermal speed, Alfvén speed, etc.)
566+
- **Units architecture** (storage vs display units, conversion patterns)
555567
- **MultiIndex structure** (M/C/S levels, capitalization rules)
556568
- **Testing requirements** (≥95% coverage, physics validation patterns)
557569
- **DataFrame patterns** (efficient access with .xs(), avoiding SettingWithCopyWarning)
@@ -797,7 +809,7 @@ All SolarWindPy-specific conventions, rules, and knowledge that should be consis
797809
**Measurement Methodology:**
798810

799811
*How Time Savings Are Calculated:*
800-
1. **Baseline measurement:** Track time spent repeating context ("remember to use SI units," "check thermal speed formula") in 20 representative sessions
812+
1. **Baseline measurement:** Track time spent repeating context ("remember units conversion pattern," "check display→SI→display") in 20 representative sessions
801813
2. **Average repetition time:** 5-10 minutes per session for context-setting
802814
3. **Session frequency:** Estimate 10-15 development sessions per week based on team activity
803815
4. **Calculation:** (5-10 min/session) × (10-15 sessions/week) = 50-150 min/week saved
@@ -828,10 +840,10 @@ grep "@.claude/memory" /tmp/memory_check.txt
828840

829841
#### Test 2: Context Preservation
830842
```
831-
Session 1: Ask about thermal speed formula
843+
Session 1: Ask about units conversion pattern
832844
Session 2 (new): Ask same question without repeating context
833-
Expected: Claude knows thermal speed is mw²=2kT from memory
834-
Validation: No need to re-explain physics rules
845+
Expected: Claude knows display→SI→display pattern from memory
846+
Validation: No need to re-explain units architecture
835847
```
836848

837849
#### Test 3: Selective Loading

.claude/docs/feature_integration/02_skills_system.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Skills are model-invoked capability packages that Claude autonomously activates
4848
**Pain Points Addressed:**
4949

5050
**Agent Coordination Overhead (HIGH IMPACT)**
51-
*Current state:* Manual agent selection via Task tool requires explicit prompts like "Use PhysicsValidator to verify thermal speed calculations"
52-
*With Skills:* Automatic activation when user requests physics validation, thermal speed checks, or unit verification
51+
*Current state:* Manual agent selection via Task tool requires explicit prompts like "Use PhysicsValidator to verify units conversion patterns"
52+
*With Skills:* Automatic activation when user requests physics validation, units pattern checks, or unit verification
5353
*Reduction:* 40-60% decrease in explicit agent invocation overhead
5454

5555
**Repetitive Task Automation (HIGH IMPACT)**
@@ -205,7 +205,7 @@ User Request → Skill Auto-Detection → [Skill OR Task Agent] → Result
205205
```yaml
206206
---
207207
name: physics-validator
208-
description: Automatically validates solar wind physics calculations including thermal speed (mw²=2kT), SI unit consistency, proper NaN handling for missing data, and physical constraint verification. Activates when user mentions physics validation, unit checking, thermal speed, or scientific correctness.
208+
description: Automatically validates solar wind physics calculations focusing on units conversion patterns, proper NaN handling for missing data, and physical constraint verification. Verifies calculations use self.units.* for SI conversion (display units → SI → display units). Activates when user mentions physics validation, unit checking, or scientific correctness.
209209
allowed-tools: [Read, Grep, Bash(python .claude/hooks/physics-validation.py*)]
210210
---
211211

@@ -216,17 +216,21 @@ Ensures all physics calculations in SolarWindPy maintain scientific correctness.
216216

217217
## Automatic Activation Triggers
218218
- "validate physics"
219-
- "check thermal speed"
220-
- "verify units"
219+
- "verify units conversion"
220+
- "check units pattern"
221221
- "ensure SI units"
222222
- "physics correctness"
223223
- Code changes to `solarwindpy/core/ion.py` or `solarwindpy/core/plasma.py`
224224

225225
## Validation Checklist
226-
1. **Thermal Speed Formula:** mw² = 2kT (not 3kT)
227-
2. **SI Units:** velocity (m/s), density (m⁻³), temperature (K)
228-
3. **NaN Handling:** Missing data as NaN, never 0 or -999
229-
4. **Physical Constraints:** Positive densities, temperatures, speeds
226+
1. **Units Conversion Pattern:** Calculations must use `quantity * self.units.<name>` for SI conversion
227+
- Storage units: cm⁻³ (density), km/s (velocity, thermal speed)
228+
- Display units: All quantities per `Units` class (see `solarwindpy.core.units_constants`)
229+
- Calculation units: m⁻³, m/s, K (SI)
230+
- Example: `w = self.w.data * self.units.w` before `w.pow(2)` (ions.py:222)
231+
- Check BOTH input conversion (display→SI) AND output conversion (SI→display)
232+
2. **NaN Handling:** Missing data as NaN, never 0 or -999
233+
3. **Physical Constraints:** Positive densities, temperatures, thermal speeds (scalars ≥ 0; velocity components may be negative)
230234

231235
## Execution Pattern
232236
```bash
@@ -369,7 +373,7 @@ def test_function_name_happy_path():
369373
def test_function_name_physics():
370374
"""Validate physics correctness."""
371375
# Physics-specific assertions
372-
assert thermal_speed_formula_check(result)
376+
assert units_conversion_pattern_check(result)
373377
```
374378

375379
## Integration with TestEngineer Agent
@@ -789,7 +793,7 @@ Validation: Complex multi-step tasks should still use agents
789793

790794
#### Test 4: Auto-activation on File Changes
791795
```
792-
Scenario: Edit solarwindpy/core/ion.py (thermal speed calculation)
796+
Scenario: Edit solarwindpy/core/ion.py (physics calculation method)
793797
Expected: physics-validator skill triggers post-edit
794798
Validation: Verify physics validation report generated
795799
```

.claude/docs/feature_integration/03_subagents.md

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Decision Tree:
9191
└── Use Subagent (independent context, deep expertise)
9292
9393
Examples:
94-
- "Validate thermal speed formula" → Skill (physics-validator)
94+
- "Verify units conversion pattern" → Skill (physics-validator)
9595
- "Check physics correctness in ion.py" → Task (PhysicsValidator)
9696
- "Refactor entire Plasma class for better memory efficiency, analyze trade-offs" → Subagent (dataframe-architect)
9797
```
@@ -233,7 +233,7 @@ Examples:
233233
```yaml
234234
---
235235
name: physics-validator
236-
description: Deep physics analysis specialist for solar wind calculations. Validates thermal speed formulas, unit consistency, physical constraints, and scientific correctness across multiple files.
236+
description: Deep physics analysis specialist for solar wind calculations. Validates units conversion patterns, physical constraints, and scientific correctness across multiple files.
237237
tools: [Read, Grep, Bash(python .claude/hooks/physics-validation.py*), Bash(pytest*)]
238238
model: sonnet
239239
---
@@ -244,38 +244,38 @@ You are a solar wind physics expert specializing in validating scientific correc
244244

245245
## Core Responsibilities
246246

247-
1. **Formula Validation**
248-
- Thermal speed: mw² = 2kT (NOT 3kT)
249-
- Alfvén speed: v_A = B / √(μ₀ρ)
250-
- Plasma frequency: ωₚ = √(nₑe²/(ε₀mₑ))
251-
252-
2. **Unit Consistency (SI Units MANDATORY)**
253-
- Velocity: m/s
254-
- Density: m⁻³
255-
- Temperature: K
256-
- Magnetic Field: T
257-
258-
3. **Physical Constraints**
259-
- All densities, temperatures, speeds > 0
247+
1. **Units Conversion Validation**
248+
- Verify calculations use `self.units.*` for SI conversion
249+
- Storage units: cm⁻³ (density), km/s (velocity, thermal speed)
250+
- Display units: All quantities per `Units` class (see `solarwindpy.core.units_constants`)
251+
- Calculation units: m⁻³ (density), m/s (velocity, thermal speed), K (temperature) - SI
252+
- Flag calculations using raw data without unit conversion (input)
253+
- Flag calculations returning SI results without converting to display units (output)
254+
- Example pattern: `w = self.w.data * self.units.w` → calculate → `result / self.units.output`
255+
256+
2. **Physical Constraints**
257+
- Density > 0 (n > 0 in cm⁻³)
258+
- Temperature > 0 (T > 0 in 10⁵ K)
259+
- Thermal speed ≥ 0 (w ≥ 0 in km/s, always positive scalar)
260+
- Vector magnitudes ≥ 0 (e.g., |v|, |B|), though vector components may be negative
260261
- NaN for missing data (NEVER 0, -999, or sentinels)
261-
- Proton mass: 1.6726219 × 10⁻²⁷ kg
262-
- Boltzmann constant: 1.380649 × 10⁻²³ J/K
262+
- Physical constants from `solarwindpy.core.units_constants.Constants`
263263

264-
4. **Multi-file Analysis**
265-
- Cross-reference formulas across modules
266-
- Identify inconsistencies in physics implementations
267-
- Suggest refactoring for scientific accuracy
264+
3. **Multi-file Analysis**
265+
- Cross-reference units patterns across modules
266+
- Identify inconsistencies in units conversion implementations
267+
- Suggest refactoring for architectural consistency
268268

269269
## Validation Process
270270

271271
1. Read target files using Read tool
272-
2. Search for physics formulas using Grep
273-
3. Validate against canonical formulas (above)
272+
2. Search for units conversion patterns using Grep
273+
3. Validate units conversion patterns (display→SI→display)
274274
4. Run physics validation script: `python .claude/hooks/physics-validation.py`
275275
5. Report findings with:
276276
- ✅ Correct implementations
277-
- ⚠️ Warnings (potential issues)
278-
- ❌ Errors (must fix)
277+
- ⚠️ Warnings (potential issues - missing conversions)
278+
- ❌ Errors (must fix - raw data used in calculations)
279279
- 💡 Recommendations
280280

281281
## Output Format
@@ -657,32 +657,6 @@ print(f"b = {b_fit:.3f} ± {b_err:.3f}")
657657
print(f"R² = {r_squared:.3f}")
658658
```
659659

660-
### Physics-Based Model Fitting
661-
```python
662-
def thermal_speed_model(T, mass):
663-
"""Thermal speed: w = √(2kT/m)"""
664-
k_B = 1.380649e-23 # J/K
665-
return np.sqrt(2 * k_B * T / mass)
666-
667-
# Fit thermal speed data to extract mass
668-
def fit_func(T, mass):
669-
return thermal_speed_model(T, mass)
670-
671-
mass_fit, mass_cov = curve_fit(
672-
fit_func,
673-
temperatures,
674-
measured_speeds,
675-
bounds=(0, np.inf) # Mass must be positive
676-
)
677-
678-
mass_err = np.sqrt(mass_cov[0, 0])
679-
print(f"Fitted mass: {mass_fit[0]:.3e} ± {mass_err:.3e} kg")
680-
681-
# Compare to known proton mass
682-
proton_mass = 1.6726219e-27 # kg
683-
print(f"Difference from proton mass: {abs(mass_fit[0] - proton_mass) / proton_mass * 100:.1f}%")
684-
```
685-
686660
## Output Format
687661

688662
Provide complete analysis including:
@@ -702,14 +676,14 @@ Provide complete analysis including:
702676
703677
**Automatic Invocation** (Claude decides based on description):
704678
```
705-
User: "I need a comprehensive analysis of thermal speed calculations across all ion classes, checking for formula consistency and proposing refactoring if needed."
679+
User: "I need a comprehensive analysis of units conversion patterns across all ion classes, checking for consistency and proposing refactoring if needed."
706680

707-
Claude: [Automatically invokes physics-validator subagent due to "comprehensive analysis" + "thermal speed" + "formula consistency"]
681+
Claude: [Automatically invokes physics-validator subagent due to "comprehensive analysis" + "units conversion" + "consistency"]
708682
```
709683
710684
**Explicit Invocation:**
711685
```
712-
User: "Use the physics-validator subagent to analyze ion.py for thermal speed correctness."
686+
User: "Use the physics-validator subagent to analyze ion.py for units conversion correctness."
713687

714688
Claude: [Explicitly invokes physics-validator subagent]
715689
```

0 commit comments

Comments
 (0)