1212from stixcore .util .logging import get_logger
1313from stixcore .util .singleton import Singleton
1414
15- __all__ = [' ECCManager' ]
15+ __all__ = [" ECCManager" ]
1616
17- ECC_CONF_INDEX_FILE = Path (__file__ ).parent .parent / "config" / "data" / "common" \
18- / "ecc" / "ecc_conf_index.json"
17+ ECC_CONF_INDEX_FILE = Path (__file__ ).parent .parent / "config" / "data" / "common" / "ecc" / "ecc_conf_index.json"
1918
2019logger = get_logger (__name__ )
2120
@@ -70,10 +69,10 @@ def _load_index(self):
7069 self .configurations = json .load (f )
7170 logger .info (f"Loaded { len (self .configurations )} ECC configurations from index" )
7271 except FileNotFoundError :
73- logger .warning (f' No ECC configuration index found at: { ECC_CONF_INDEX_FILE } ' )
72+ logger .warning (f" No ECC configuration index found at: { ECC_CONF_INDEX_FILE } " )
7473 self .configurations = []
7574 except json .JSONDecodeError as e :
76- logger .error (f' Error parsing ECC configuration index: { e } ' )
75+ logger .error (f" Error parsing ECC configuration index: { e } " )
7776 self .configurations = []
7877
7978 def find_configuration (self , date = None ):
@@ -94,7 +93,7 @@ def find_configuration(self, date=None):
9493 return None
9594
9695 if date is None :
97- return self .configurations [0 ][' configuration' ]
96+ return self .configurations [0 ][" configuration" ]
9897
9998 # Convert date to string for comparison if it's a datetime object
10099 if isinstance (date , datetime ):
@@ -103,11 +102,11 @@ def find_configuration(self, date=None):
103102 date_str = str (date )
104103
105104 for config in self .configurations :
106- validity_period = config .get (' validityPeriodUTC' , [])
105+ validity_period = config .get (" validityPeriodUTC" , [])
107106 if len (validity_period ) == 2 :
108107 start_date , end_date = validity_period
109108 if start_date <= date_str <= end_date :
110- return config [' configuration' ]
109+ return config [" configuration" ]
111110
112111 logger .warning (f"No ECC configuration found for date: { date } " )
113112 return None
@@ -196,26 +195,23 @@ def create_context(self, date=None):
196195 config = ConfigParser ()
197196 config .read (temp_dir / "post_ecc.ini" )
198197
199- ESS_Config = SimpleNamespace (Max_Gain_Prime = config .getfloat ("DEFAULT" , "Max_Gain_Prime" ,
200- fallback = 1.4 ),
201- Min_Gain_Prime = config .getfloat ("DEFAULT" , "Min_Gain_Prime" ,
202- fallback = 0.4 ),
203- Min_Gain = config .getfloat ("DEFAULT" , "Min_Gain" ,
204- fallback = 0.4 ),
205- Ignore_Max_Gain_Prime_Det_Pix_List = json .loads (
206- config .get ("DEFAULT" ,
207- "Ignore_Max_Gain_Prime_Det_Pix_List" ,
208- fallback = "[]" )),
209- Ignore_Min_Gain_Prime_Det_Pix_List = json .loads (
210- config .get ("DEFAULT" ,
211- "Ignore_Min_Gain_Prime_Det_Pix_List" ,
212- fallback = "[]" )),
213- Ignore_Min_Gain_Det_Pix_List = json .loads (
214- config .get ("DEFAULT" , "Ignore_Min_Gain_Det_Pix_List" ,
215- fallback = "[]" )))
198+ ECC_Config = SimpleNamespace (
199+ Max_Gain_Prime = config .getfloat ("DEFAULT" , "Max_Gain_Prime" , fallback = 1.4 ),
200+ Min_Gain_Prime = config .getfloat ("DEFAULT" , "Min_Gain_Prime" , fallback = 0.4 ),
201+ Min_Gain = config .getfloat ("DEFAULT" , "Min_Gain" , fallback = 0.4 ),
202+ Ignore_Max_Gain_Prime_Det_Pix_List = json .loads (
203+ config .get ("DEFAULT" , "Ignore_Max_Gain_Prime_Det_Pix_List" , fallback = "[]" )
204+ ),
205+ Ignore_Min_Gain_Prime_Det_Pix_List = json .loads (
206+ config .get ("DEFAULT" , "Ignore_Min_Gain_Prime_Det_Pix_List" , fallback = "[]" )
207+ ),
208+ Ignore_Min_Gain_Det_Pix_List = json .loads (
209+ config .get ("DEFAULT" , "Ignore_Min_Gain_Det_Pix_List" , fallback = "[]" )
210+ ),
211+ )
216212
217213 logger .info (f"Read config from in: { temp_dir / 'post_ecc.ini' } " )
218- return temp_dir , ESS_Config
214+ return temp_dir , ECC_Config
219215
220216 except Exception as e :
221217 # Clean up on error
@@ -263,24 +259,18 @@ def context(self, date=None):
263259 FileNotFoundError
264260 if the configuration directory doesn't exist
265261
266- Examples
267- --------
268- >>> with ecc_manager.context(datetime(2021, 6, 15)) as context_path:
269- ... # Use configuration files in context_path
270- ... config_file = context_path / "ecc_cfg_1" / "config.json"
271- ... # Files are automatically cleaned up when exiting the with block
272262 """
273- context_path = None
263+ context = None
274264 try :
275- context_path = self .create_context (date )
276- yield context_path
265+ context = self .create_context (date )
266+ yield context
277267 finally :
278- if context_path is not None :
279- self .cleanup_context (context_path )
268+ if context is not None :
269+ self .cleanup_context (context )
280270
281271
282272# Create singleton instance
283- if ' pytest' in sys .modules :
273+ if " pytest" in sys .modules :
284274 ECCManager .instance = ECCManager (test_data .ecc )
285275else :
286276 ECCManager .instance = ECCManager ()
0 commit comments