Skip to content

Standardize morph parameters as dictionaries #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks
Luiskitsu opened this issue May 1, 2025 · 0 comments
Open
3 tasks

Standardize morph parameters as dictionaries #193

Luiskitsu opened this issue May 1, 2025 · 0 comments

Comments

@Luiskitsu
Copy link
Contributor

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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants