-
Notifications
You must be signed in to change notification settings - Fork 59
Description
Hi~ I’ve identified an issue with the IONParam class where instances share mutable state, leading to unintended data overwrites when processing multiple ION records (e.g., in BRD4 files). Same problems are with other classes (like EOPParam).
Root Cause:
The class lacks an __init__ method, so prm is defined as a class variable (shared across all instances) in python instead of an instance-specific attribute. This means all IONParam instances reference the same np.ndarray, causing modifications to one instance to corrupt others.
Minimal Reproduction BUG:
import numpy as np
class IONParam_Buggy():
prm = np.zeros(9) # Class variable (shared across all instances)
galileo = IONParam_Buggy()
beidou = IONParam_Buggy()
# Modify galileo's params
galileo.prm[:3] = [175.75, -0.453125, -0.00732421875]
# beidou's params are accidentally overwritten
print(beidou.prm[:3]) # Output: [175.75, -0.453125, -0.00732421875] (BUG)Proposed Fix:
Add an __init__ method to initialize prm (and other attributes) as instance variables, ensuring each instance has independent state:
class IONParam():
def __init__(self): # HERE
self.iod = 0 # and self.
self.prm = np.zeros(9)
self.t_tm = None
self.region = NoneThis may prevent cross-instance data leakage when processing multiple ION records.
Thank you again for your great work!