@@ -351,32 +351,96 @@ def free_resolution_parameters(self) -> None:
351351 """Free all parameters in the resolution model."""
352352 self .resolution_model .free_all_parameters ()
353353
354- def get_energy_offset_at_Q (self , Q_index : int ) -> Parameter :
354+ def get_energy_offset (
355+ self ,
356+ Q_index : int | None = None ,
357+ ) -> Parameter | list [Parameter ]:
355358 """Get the energy offset Parameter at a specific Q index.
356359
357360 Args:
358- Q_index (int): The index of the Q value to get the energy
359- offset for.
361+ Q_index (int | None, default=None ): The index of the Q value to get the energy
362+ offset for. If None, get the energy offset for all Q values.
360363
361364 Returns:
362- Parameter: The energy offset Parameter at the specified Q
363- index.
365+ Parameter | list[Parameter] : The energy offset Parameter at the specified Q
366+ index, or a list of Parameters if Q_index is None .
364367
365368 Raises:
366369 ValueError: If no Q values are set in the InstrumentModel.
367370 IndexError: If Q_index is out of bounds.
371+ TypeError: If Q_index is not an int or None.
368372 """
369373 if self ._Q is None :
370374 raise ValueError ('No Q values are set in the InstrumentModel.' )
371375
376+ if Q_index is None :
377+ return self ._energy_offsets
378+
379+ if not isinstance (Q_index , int ):
380+ raise TypeError (f'Q_index must be an int or None, got { type (Q_index ).__name__ } ' )
381+
372382 if Q_index < 0 or Q_index >= len (self ._Q ):
373383 raise IndexError (f'Q_index { Q_index } is out of bounds for Q of length { len (self ._Q )} ' )
374384
375385 return self ._energy_offsets [Q_index ]
376386
387+ def fix_energy_offset (self , Q_index : int | None = None ) -> None :
388+ """Fix energy offset parameters. If Q_index is specified, only
389+ fix the energy offset for that Q value. If Q_index is None, fix
390+ energy offsets for all Q values.
391+
392+ Args:
393+ Q_index (int | None, default=None): The index of the Q value
394+ to fix the energy offset for. If None, fix energy
395+ offsets for all Q values.
396+ """
397+ self ._fix_or_free_energy_offset (Q_index , fixed = True )
398+
399+ def free_energy_offset (self , Q_index : int | None = None ) -> None :
400+ """Free energy offset parameters. If Q_index is specified, only
401+ free the energy offset for that Q value. If Q_index is None,
402+ free energy offsets for all Q values.
403+
404+ Args:
405+ Q_index (int | None, default=None): The index of the Q value
406+ to free the energy offset for. If None, free energy
407+ offsets for all Q values.
408+ """
409+ self ._fix_or_free_energy_offset (Q_index , fixed = False )
410+
377411 # --------------------------------------------------------------
378412 # Private methods
379413 # --------------------------------------------------------------
414+ def _fix_or_free_energy_offset (self , Q_index : int | None = None , fixed : bool = True ) -> None :
415+ """Fix or free energy offset parameters. If Q_index is
416+ specified, only fix or free the energy offset for that Q value.
417+ If Q_index is None, fix or free energy offsets for all Q values.
418+
419+ Args:
420+ Q_index (int | None, default=None): The index of the Q value
421+ to fix or free the energy offset for. If None, fix or
422+ free energy offsets for all Q values.
423+ fixed (bool, default=True): Whether to fix (True) or free
424+ (False) the energy offset.
425+
426+ Raises:
427+ TypeError: If Q_index is not an int or None.
428+ IndexError: If Q_index is out of bounds for the Q values in
429+ the InstrumentModel.
430+ """
431+
432+ if Q_index is None :
433+ for offset in self ._energy_offsets :
434+ offset .fixed = fixed
435+ else :
436+ if not isinstance (Q_index , int ):
437+ raise TypeError (f'Q_index must be an int or None, got { type (Q_index ).__name__ } ' )
438+
439+ if Q_index < 0 or Q_index >= len (self ._Q ):
440+ raise IndexError (
441+ f'Q_index { Q_index } is out of bounds for Q of length { len (self ._Q )} '
442+ )
443+ self ._energy_offsets [Q_index ].fixed = fixed
380444
381445 def _generate_energy_offsets (self ) -> None :
382446 """Generate energy offset Parameters for each Q value."""
0 commit comments