Hey everyone,
I’m running into a really stubborn NameError in a Script CHOP callback DAT (Build 2023.12230, Windows, Python 3.11 bundled) and I’m hoping someone might have seen something similar.
Setup:
I have a V->A network where a TOP to CHOP feeds pixel data (via a Hold CHOP) into a Script CHOP (script_cpu_va). The callback logic is in a Text DAT (va_cpu_callbacks).
Inside va_cpu_callbacks, I define an OlaSynthesizer class. The onCook function gets pixel data, processes it, and calls synthesizer.synthesize_frame(…) on an instance of that class stored in scriptOp.storage.
The Problem:
I consistently get NameError: name ‘np’ is not defined originating from inside the OlaSynthesizer.synthesize_frame method, specifically when it tries to use NumPy functions like np.zeros, np.arange, etc.
What’s Confusing:
-
import numpy as np is present at the top level of the va_cpu_callbacks DAT.
-
Based on standard Python scope rules and debugging advice for similar issues in TD DATs, I’ve also added import numpy as np as the very first line inside the synthesize_frame method definition itself within the class.
-
Despite the local import numpy as np seemingly being present inside the method, the NameError persists on every cook cycle after the synthesizer is initialized.
-
Importing np works fine in the main onCook function and in helper functions defined outside the class but within the DAT. The issue seems specific to accessing np within the synthesize_frame method of the class defined in the same DAT.
Code Snippet (Relevant parts of va_cpu_callbacks):
va_cpu_callbacks DAT
import sys, os, traceback, numpy as np, colorsys, time, td
… (conda path setup) …
try: from scipy.signal import get_window; scipy_available = True
except ImportError: scipy_available = False… (config vars) …
class OlaSynthesizer:
def init(self, …):
import numpy as np # Import here works fine
# … init using np …
self.valid = Truedef synthesize_frame(self, target_amps, target_pans, output_len): # >>> IMPORT IS PRESENT HERE <<< import numpy as np # >>> END IMPORT <<< if not self.valid: return np.zeros(output_len), #... etc ... # >>> Error occurs on lines below using np <<< buffer_l = np.zeros(output_len, dtype=np.float32) buffer_r = np.zeros(output_len, dtype=np.float32) t_indices = np.arange(output_len) # ... rest of method using np ...
… (helper functions with local imports) …
def onCook(scriptOp):
import numpy as np # Import here works fine
synthesizer = scriptOp.storage.get(‘synth_instance’)
# … (synth init using OlaSynthesizer class) …
# … (get input data) …
# … (aggregation logic) …
try:
if synthesizer and num_pixels > 0 and r_array is not None:
# …
# >>> CALL TO METHOD THAT RAISES ERROR <<<
left_out, right_out = synthesizer.synthesize_frame(osc_amps, osc_pans, output_len)
# …
except Exception as e:
scriptOp.addError(f"V->A Synthesis Error: {e}") # Error appears here
# …
return
Attempts:
Confirmed NumPy is installed and importable at the top level and in onCook.
Tried moving class definition to a separate DAT Module (still got the error inside the method, suggesting it wasn't just definition scope).
Forced recompiles using DAT save/TD restart.
Has anyone encountered a situation where an import seems to be ignored specifically within a class method defined in a Script CHOP callback DAT in this build? Is there a known issue or a better way to ensure modules are available in that specific scope?
Thanks for any ideas!