Skip to content

Standardize morph parameters as dictionaries #193

Open
@Luiskitsu

Description

@Luiskitsu

Currently, morph parameters are stored inconsistently — some are scalars (e.g., scale = 1.0) while others like squeeze and funcy are dictionaries. This inconsistency adds unnecessary complexity to the refinement logic and special cases during configuration parsing.

Standardize all morph parameters to be stored as dictionaries. This would allow the refinement to treat all parameters uniformly, simplify the logic in _update_chain().
Tasks:

  • Modify morph_default_config() and morph() to convert scalar inputs into single-entry dictionaries.

  • Simplify refine.py

  • Update tests to reflect the new structure.

In the refine.py the code that will need to be simplified is:

    def _update_chain(self, pvals):
        """Update the parameters in the chain."""
        updated = {}
        for idx, value in enumerate(pvals):
            param, subkey = self.flat_to_grouped[idx]
            if subkey is None:  # Scalar
                updated[param] = value
            else:
                if param not in updated:
                    updated[param] = {}
                updated[param][subkey] = value

        # Apply the reconstructed grouped parameter back to config
        self.chain.config.update(updated)
        return

And also:

# Build flat list of initial parameters and flat_to_grouped mapping
        initial = []
        self.flat_to_grouped = {}

        for p in self.pars:
            val = config[p]
            if isinstance(val, dict):
                for k, v in val.items():
                    initial.append(v)
                    self.flat_to_grouped[len(initial) - 1] = (p, k)
            else:
                initial.append(val)
                self.flat_to_grouped[len(initial) - 1] = (p, None)

        sol, cov_sol, infodict, emesg, ier = leastsq(
            self.residual, initial, full_output=1
        )
        fvec = infodict["fvec"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions