astrophot.param package#

Submodules#

astrophot.param.module module#

class astrophot.param.module.Module(name: str | None = None, **kwargs)[source]#

Bases: Module

build_params_array_identities()[source]#
build_params_array_names()[source]#
build_params_array_uncertainty()[source]#
build_params_array_units()[source]#

astrophot.param.param module#

class astrophot.param.param.Param(*args, uncertainty=None, prof=None, **kwargs)[source]#

Bases: Param

A 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#
soft_valid(value)[source]#
property uncertainty#

Module contents#

class astrophot.param.Module(name: str | None = None, **kwargs)[source]#

Bases: Module

build_params_array_identities()[source]#
build_params_array_names()[source]#
build_params_array_uncertainty()[source]#
build_params_array_units()[source]#
class astrophot.param.OverrideParam(param: Param, value)[source]#

Bases: object

Context manager to override a parameter value.

Only inside an OverrideParam will 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 @forward method so that it uses new_value regardless of what was passed via params:

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: Param

A 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#
soft_valid(value)[source]#
property uncertainty#
class astrophot.param.ValidContext(module: Module)[source]#

Bases: object

Context 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’s to_valid / from_valid transformations. 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 Param children 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