astrophot.param package#
Submodules#
astrophot.param.module module#
astrophot.param.param module#
- class astrophot.param.param.Param(*args, uncertainty=None, prof=None, **kwargs)[source]#
Bases:
ParamA class that extends the Caskade Param class to include additional functionality. This class is used to define parameters for models in the AstroPhot package.
- property full_shape#
- property initialized#
Check if the parameter is initialized.
- property name_array#
- property prof#
- property uncertainty#
Module contents#
- class astrophot.param.OverrideParam(param: Param, value)[source]#
Bases:
objectContext manager to override a parameter value.
Only inside an
OverrideParamwill the parameter be set to the new value. The original value (and the values of any parent pointer parameters) are saved on entry and restored on exit.Parameters#
- paramParam
The parameter whose value should be temporarily overridden.
- valueobject
The temporary value to assign to param.
Examples#
Override a parameter inside a
@forwardmethod so that it usesnew_valueregardless of what was passed viaparams:class MySim(Module): def __init__(self): super().__init__() self.a = Param("a", None) self.b = Param("b", None) @forward def __call__(self, x, a=None, b=None): with OverrideParam(self.b, 5.0): # b will always be 5.0 here, ignoring params return x + a + self.b.value
- class astrophot.param.Param(*args, uncertainty=None, prof=None, **kwargs)[source]#
Bases:
ParamA class that extends the Caskade Param class to include additional functionality. This class is used to define parameters for models in the AstroPhot package.
- property full_shape#
- property initialized#
Check if the parameter is initialized.
- property name_array#
- property prof#
- property uncertainty#
- class astrophot.param.ValidContext(module: Module)[source]#
Bases:
objectContext manager that transforms parameter values to an unconstrained space.
Inside a
ValidContext, all parameter values are automatically mapped into the range(-inf, inf)via each parameter’sto_valid/from_validtransformations. This is useful when interfacing with samplers or optimizers that expect unconstrained parameters—any value they propose will be mapped back into the parameter’s original valid range on exit.Parameters#
- moduleModule
The module whose parameters should be transformed.
Examples#
Get unconstrained parameter values for use with an optimizer:
with ValidContext(my_module): unconstrained_params = my_module.get_values() # unconstrained_params live in (-inf, inf)
- astrophot.param.forward(method)[source]#
Decorator to define a forward method for a module.
Manages parameter passing and activation for the decorated method. When called, it automatically fills keyword arguments from the module’s
Paramchildren and handles parameter overrides and active context.Parameters#
- method: (Callable)
The forward method to be decorated.
Returns#
- Callable
The decorated forward method.
Examples#
Standard usage of the forward decorator:
class ExampleSim(Module): def __init__(self, a, b, c): super().__init__("example_sim") self.a = a self.b = Param("b", b) self.c = Param("c", c) @forward def example_func(self, x, b=None): return x + self.a + b E = ExampleSim(a=1, b=None, c=3) print(E.example_func(4, params=[5])) # Output: 10