Skip to content

Fix C-MOD TCI-related methods#537

Draft
ZanderKeith wants to merge 12 commits intodevfrom
zk/tci
Draft

Fix C-MOD TCI-related methods#537
ZanderKeith wants to merge 12 commits intodevfrom
zk/tci

Conversation

@ZanderKeith
Copy link
Copy Markdown
Contributor

Two-Color Interferometry can be used to calibrate measurements from Thomson scattering. For a while it has been hardcoded to not do this, and as such the TCI-related methods have gone untested and are broken. This PR fixes some obvious errors so the methods can run to completion, but I'm not sure about functional correctness. The results are similar enough to other density measurements, but these methods should be vetted more thoroughly at some point.

@ZanderKeith ZanderKeith changed the title Zk/tci TCI-related method fixes Mar 31, 2026
@gtrevisan gtrevisan added the machine: C-MOD Related to the Alcator C-MOD tokamak label Mar 31, 2026
@gtrevisan gtrevisan changed the title TCI-related method fixes Fix C-MOD TCI-related methods Mar 31, 2026
Base automatically changed from glt/numpy2 to dev March 31, 2026 20:09
@ZanderKeith ZanderKeith marked this pull request as ready for review April 2, 2026 14:32
@gtrevisan gtrevisan requested review from yumouwei and zapatace April 2, 2026 14:35
Copy link
Copy Markdown
Member

@gtrevisan gtrevisan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for contributing!

I'm hoping:

  • @yumouwei will help out with the more functional approach, including wrt to other C-MOD methods or other machines,
  • @zapatace will be able to focus on the nitty gritty implementation and run some cases himself.

Comment thread disruption_py/machine/cmod/physics.py Outdated

@staticmethod
@physics_method(
columns=["nl_ts1", "nl_ts2", "nl_tci1", "nl_tci2"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yumouwei is this the best we can do in terms of naming these new features?

nl_tci1, nl_tci2 : TCI line-integrated density at YAG 1 and 2 timestamps [m^-2]
"""
nl_ts1, nl_ts2, nl_tci1, nl_tci2, time1, time2 = (
CmodThomsonDensityMeasure.compare_ts_tci(params)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear to me -- what's the relationship between this new physics method and the pre-existing get_peaking_factors for C-MOD with a use_ts_tci_calibration = True?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This physics method actually returns the measured densities from the TCI, whereas the get_peaking_factors method would use them to adjust the TS measurements before discarding them.

Comment thread disruption_py/machine/cmod/physics.py Outdated
Comment thread disruption_py/machine/cmod/physics.py
indices2 = indices1 + 1
else:
indices1 = 2 * np.arange(nyag1) + (nyag1 > nyag2)
elif nyag1 < nyag2:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once @yumouwei and maybe @zapatace will have taken a look, I'll try and unleash Copilot, too, in case we missed something. okay?

Comment thread disruption_py/machine/cmod/thomson.py Outdated
Comment thread disruption_py/machine/cmod/thomson.py Outdated
Comment thread examples/tci.py Outdated
Comment thread disruption_py/machine/cmod/physics.py
@gtrevisan
Copy link
Copy Markdown
Member

I ran the new disruption-errors script for C-MOD and got:

disruption-errors.sh cmod_vde -m get_ts_tci_comparison

      1  get_ts_tci_comparison: IndexError('index 101 is out of bounds for axis 0 with size 101')
      1  get_ts_tci_comparison: ValueError('could not broadcast input array from shape (17,13) into shape (250,17)')
      1  get_ts_tci_comparison: ValueError('could not broadcast input array from shape (18,13) into shape (125,18)')
     41  get_ts_tci_comparison: ValueError('cannot reshape array of size 0 into shape (0,newaxis)')

[ ERROR ] #1120217025 | get_ts_tci_comparison: IndexError('index 101 is out of bounds for axis 0 with size 101')
[ ERROR ] #1120203005 | get_ts_tci_comparison: ValueError('cannot reshape array of size 0 into shape (0,newaxis)')
[ ERROR ] #1140226017 | get_ts_tci_comparison: ValueError('could not broadcast input array from shape (17,13) into shape (250,17)')
[ ERROR ] #1120215018 | get_ts_tci_comparison: ValueError('could not broadcast input array from shape (18,13) into shape (125,18)')

1120203005 1120215018 1120217025 1140226017

I tried running for the disruption_warning shotlist, but it was unbearably slow. 🐢

@zapatace
Copy link
Copy Markdown
Contributor

zapatace commented Apr 16, 2026

I run this method with all shots in the disruption warning table (10435 shots). It looks like this diagnostic is only available in 15% of shots.

Percentage of shots with all NaN values per column:
n_e (for reference): 0.057532%
ne_line_int_tci1: 84.265030%
ne_line_int_tci2: 86.403298%
ne_line_int_ts1: 84.236264%
ne_line_int_ts2: 86.384121%

When there is data, the integrated density line follows n_e reasonably. For example, here you have 10 shots.
image

The error logs showed these potential edge cases.
2026-04-15 16:34:28.218 [CRITICAL] #1120801004 | Failed setup! ValueError('Pathological timebase.')
2026-04-15 16:36:12.476 [CRITICAL] #1120816012 | Failed setup! ValueError('Pathological timebase.')
2026-04-15 17:40:29.541 [CRITICAL] #1120914031 | Failed setup! TreeNODATA('No data available. Tree: efit18, Node: \efit_aeqdsk:ali')
2026-04-15 17:56:21.947 [CRITICAL] #1120801017 | Failed setup! ValueError('Pathological timebase.')
2026-04-15 18:06:52.880 [CRITICAL] #1120831018 | Failed setup! ValueError('Pathological timebase.')
2026-04-15 18:26:18.936 [CRITICAL] #1120215001 | Failed setup! TreeFOPENR('Tree not found. Nick: _efit_tree, Tree: efit18')

It could be that there is a problem with the method itself. I have these errors for example.
2026-04-15 15:59:28.017 [ ERROR ] #1140220018 | get_ts_tci_comparison: ValueError('cannot reshape array of size 0 into shape (0,newaxis)')
2026-04-15 15:59:28.138 [ ERROR ] #1160616012 | get_ts_tci_comparison: IndexError('index 101 is out of bounds for axis 0 with size 101')
2026-04-15 15:59:29.704 [ ERROR ] #1160922003 | get_ts_tci_comparison: ValueError('cannot reshape array of size 0 into shape (0,newaxis)')
2026-04-15 15:59:29.760 [ ERROR ] #1150827001 | get_ts_tci_comparison: ValueError('zero-size array to reduction operation minimum which has no identity')
2026-04-15 16:01:37.181 [ ERROR ] #1140228021 | get_ts_tci_comparison: ValueError('could not broadcast input array from shape (17,13) into shape (250,17)')

All log messages here:
log_debug_mode.zip

I would not approve this PR for now. Is there a processing error or is data missing? In any case. I would keep this branch if somenone in the future is interested in using this diagnostic!!!

@gtrevisan
Copy link
Copy Markdown
Member

thanks, @zapatace, but before you compute the "NaN bottom line" like that we really should wait for @ZanderKeith to fix all those IndexErrors and ValueErrors... it seems you did find another handful of errors, though.

@yumouwei
Copy link
Copy Markdown
Contributor

@ZanderKeith I took a look at the changes you made in the branch. Before we work on the implementation, can you give a high-level description of how the functions under CmodThomsonDensityMeasure work (e.g. what's the overall logic, what does each of the function do, how does compare_ts_tci call the other underscored functions), what are your expected outputs, what are you going to use them for, and is there any way we can validate the outputs? For the 2nd & 4th points it'd also be helpful to show some plots.

The changes in physics.py and efit.py are relatively straightforward. I agree with Greg that we should think of a better way to name these signals (I'd prefer names that aren't too specific to a machine's hardware/diagnostics).

@gtrevisan gtrevisan marked this pull request as draft April 29, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

machine: C-MOD Related to the Alcator C-MOD tokamak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants