Conversation
1107210 to
19f6fd6
Compare
| b_tor = D3DPhysicsMethods.get_btor(params)["btor"] | ||
| if np.isnan(b_tor).all(): | ||
| params.logger.warning( | ||
| "Failed to get b_tor signal to compute n_equal_1_normalized" |
There was a problem hiding this comment.
I think the name of the physics method will be attached to error log by the framework, so this might be redundant...
put an intentional error somewhere to try it out!
There was a problem hiding this comment.
It looks like only the shot number is automatically tagged to the error log if I intentionally poke an error. This applies to the comment on the other method as well
08:49:57.574 [WARNING] #201927 | Failed to get b_tor signal to compute n_equal_1_normalized
08:49:57.580 [WARNING] #201927 | Failed to get b_tor signal to compute n1rms_normalized
There was a problem hiding this comment.
because you are writing that yourself, but if you raise eg a CalculationError you will see the physics method name as well.
|
@ZanderKeith, do you have some time to take a look? |
| b_tor, t_b_tor = params.data_conn.get_data_with_dims( | ||
| f"ptdata('bt', {params.shot_id})" | ||
| ) # [ms], [T] | ||
| except mdsExceptions.MdsException as e: |
There was a problem hiding this comment.
Do you mean removing this try-except block? If so then an error in this get_btor method would cause other methods that call get_btor (i.e. get_n1_bradial_parameters and get_n1rms_parameters) to raise an error and return all nans as well. I can avoid this by adding try-except blocks in those methods if that's a better way to do this.
| f"ptdata('onsbradial', {params.shot_id})", | ||
| ) # [G], [ms] | ||
| except mdsExceptions.MdsException: | ||
| try: |
There was a problem hiding this comment.
this fallback would deserve at least a DEBUG statement, if not a warning!
There was a problem hiding this comment.
The fallback does raise a VERBOSE statement if it successfully gets data from DUSBRADIAL. The use of VERBOSE is consistent with the fallback in CMOD get_v_loop
disruption-py/disruption_py/machine/d3d/physics.py
Lines 983 to 990 in 4e35955
disruption-py/disruption_py/machine/cmod/physics.py
Lines 551 to 557 in 4e35955
There was a problem hiding this comment.
I missed that. but yeah, you should log to debug before attempting the fallback, otherwise that might never get logged.
| "n_equal_1_mode: Failed to get ONSBRADIAL signal. Use DUSBRADIAL instead." | ||
| ) | ||
| except mdsExceptions.MdsException: | ||
| params.logger.warning( |
There was a problem hiding this comment.
this could be a CalculationError which would then downplayed as a warning by the framework.
| except mdsExceptions.MdsException as e: | ||
| b_tor = D3DPhysicsMethods.get_btor(params)["btor"] | ||
| if np.isnan(b_tor).all(): | ||
| params.logger.warning( |
There was a problem hiding this comment.
you might want to raise another CalculationError, here, and remember that shot number and physics method should be tagged on by the framework!
There was a problem hiding this comment.
Pull request overview
Reintroduces DIII-D physics support for n=1 B-radial parameters by reimplementing D3DPhysicsMethods.get_n1_bradial_parameters and factoring out a reusable toroidal-field helper.
Changes:
- Added
D3DPhysicsMethods.get_btorto retrieve/interpolate toroidal field (btor). - Reimplemented
get_n1_bradial_parametersto fetch ONFR/DUD bradial signals and compute normalized n=1 amplitude. - Updated
get_n1rms_parametersto useget_btorfor normalization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| raise NotImplementedError | ||
| if 176030 <= params.shot_id <= 176912: | ||
| # TODO: load data from NetCDF file | ||
| raise NotImplementedError |
There was a problem hiding this comment.
These known shot ranges currently raise NotImplementedError. The runner treats this as an ERROR (not a WARNING), which will generate noisy error logs for an expected/known data gap. Consider returning all-NaN outputs with a warning log, or raising CalculationError with an explanatory message so it’s handled at WARNING level.
| raise NotImplementedError | |
| if 176030 <= params.shot_id <= 176912: | |
| # TODO: load data from NetCDF file | |
| raise NotImplementedError | |
| params.logger.warning( | |
| "n_equal_1_mode: Bradial data is unavailable for shot range " | |
| "156199-172430; returning NaN outputs until custom tree loading " | |
| "is implemented." | |
| ) | |
| nan_output = np.full_like(params.times, np.nan, dtype=float) | |
| return { | |
| "n_equal_1_mode": nan_output, | |
| "n_equal_1_normalized": nan_output.copy(), | |
| } | |
| if 176030 <= params.shot_id <= 176912: | |
| # TODO: load data from NetCDF file | |
| params.logger.warning( | |
| "n_equal_1_mode: Bradial data is unavailable for shot range " | |
| "176030-176912; returning NaN outputs until NetCDF loading " | |
| "is implemented." | |
| ) | |
| nan_output = np.full_like(params.times, np.nan, dtype=float) | |
| return { | |
| "n_equal_1_mode": nan_output, | |
| "n_equal_1_normalized": nan_output.copy(), | |
| } |
| try: | ||
| # Fallback: get data from the legacy DUD system | ||
| n_equal_1_mode, t_n1 = params.data_conn.get_data_with_dims( | ||
| f"ptdata('dusbradial', {params.shot_id})", |
There was a problem hiding this comment.
What is the difference between dusbradial and onsbradial? What do these signals mean / which coils are they coming from?
Towards the end of the shot they are usually in agreement but at the start they can be very different.
ZanderKeith
left a comment
There was a problem hiding this comment.
Methods look correct physics-wise. Ran them for a few shots from our recent DIII-D campaign with significant MHD activity. Signals line up well with those in reviewplus.
I'd still like to know what dusbradial vs onsbradial mean (and perhaps have a comment noting the difference), but other than that looks good to me.
Implemented changes
D3DPhysicsMethods.get_n1_bradial_parameters. This method was previously moved todrafts/machine/d3d/physics.pyin v0.8 (Add docstrings for modules/classes/methods #325) and later removed alongside all other draft scripts in v0.11 (Remove draft scripts #420).D3DPhysicsMethods.get_btorand use it inget_n1_bradial_parametersandget_n1rms.n_equal_1_mode,n_equal_1_normalized(tested & XFAIL), andbtor(not tested)Notes on testing
n_equal_1_modeandn_equal_1_normalizedare both marked asXFAILas all 4 testing shots fall within the range of shots where the raw signal data need to be retrieved from files previously stored oniris.DISRUPTION_WARNINGtable and the outputs from this physics method match the data in the table.DISRUPTION_WARNINGtable. I found out that these stored data match those from the legacy DUD system (fallback data source in the method's logic) instead of the ONFR system which is available for this shot.Future TODO