Skip to content

numpydoc build for base.py in Baseline class #96

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

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 63 additions & 40 deletions src/diffpy/srmise/baselines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ class BaselineFunction(BaseFunction):

Class members
-------------
parameterdict: A dictionary mapping string keys to their index in the
sequence of parameters. These keys apply only to
the default "internal" format.
parformats: A sequence of strings defining what formats are recognized
by a baseline function.
default_formats: A dictionary which maps the strings "default_input" and
"default_output" to strings also appearing in parformats.
"default_input"-> format used internally within the class
"default_output"-> Default format to use when converting
parameters for outside use.
parameterdict: dict
The dictionary mapping string keys to their index in the
sequence of parameters. These keys apply only to
the default "internal" format.
parformats: array-like
The sequence of strings defining what formats are recognized
by a baseline function.
default_formats: dict
The dictionary which maps the strings "default_input" and
"default_output" to strings also appearing in parformats.
"default_input"-> format used internally within the class
"default_output"-> Default format to use when converting
parameters for outside use.

Class methods (implemented by inheriting classes)
-------------------------------------------------
Expand Down Expand Up @@ -70,19 +73,25 @@ def __init__(
):
"""Set parameterdict defined by subclass

parameterdict: A dictionary mapping string keys to their index in a
sequence of parameters for this BaselineFunction subclass.
parformats: A sequence strings containing all allowed input/output
formats defined for the peak function's parameters.
default_formats: A dictionary mapping the string keys "internal" and
"default_output" to formats from parformats.
metadict: Dictionary mapping string keys to tuple (v, m) where v is an
additional argument required by function, and m is a method
whose string output recreates v when passed to eval().
base: A basefunction subclass instance which this one decorates with
additional functionality.
Cache: A class (not instance) which implements caching of BaseFunction
evaluations."""
parameterdict : dict
The dictionary mapping string keys to their index in a
sequence of parameters for this BaselineFunction subclass.
parformats : array-like
The sequence strings containing all allowed input/output
formats defined for the peak function's parameters.
default_formats : dict
The dictionary mapping the string keys "internal" and
default_output" to formats from parformats.
metadict: dict
The dictionary mapping string keys to tuple (v, m) where v is an
additional argument required by function, and m is a method
whose string output recreates v when passed to eval().
base : The basefunction subclass
The basefunction subclass instance which this one decorates with
additional functionality.
Cache : class
The class (not instance) which implements caching of BaseFunction
evaluations."""
BaseFunction.__init__(self, parameterdict, parformats, default_formats, metadict, base, Cache)

# "Virtual" class methods ####
Expand Down Expand Up @@ -111,30 +120,44 @@ class Baseline(ModelPart):
"""Represents a baseline associated with a BaselineFunction subclass."""

def __init__(self, owner, pars, free=None, removable=False, static_owner=False):
"""Set instance members.

owner: an instance of a BaselineFunction subclass
pars: Sequence of parameters which define the baseline
free: Sequence of Boolean variables. If False, the corresponding
parameter will not be changed.
removable: (False) Boolean determines whether the baseline can be removed.
static_owner: (False) Whether or not the owner can be changed with
changeowner()

Note that free and removable are not mutually exclusive. If any
values are not free but removable=True then the entire baseline may be
may be removed during peak extraction, but the held parameters for the
baseline will remain unchanged until that point.
"""Initialize the BaselineComponent instance with specified configurations.

Parameters
----------
owner : BaselineFunction subclass instance
The owner object which is an instance of a subclass of BaselineFunction.
pars : array-like
The sequence of parameters defining the characteristics of the baseline.
free : Sequence of bool, optional
The sequence parallel to `pars` where each boolean value indicates whether
the corresponding parameter is adjustable. If False, that parameter is fixed.
Defaults to None, implying all parameters are free by default.
removable : bool, optional
A flag indicating whether the baseline can be removed during processing.
Defaults to False.
static_owner : bool, optional
Determines if the owner of the baseline can be altered using the
` changeowner()` method. Defaults to False.

Notes
-----
- The `free` and `removable` parameters are independent; a baseline can be marked
as removable even if some of its parameters are fixed (`free` is False). In such
cases, the baseline may be removed during peak extraction, but the fixed
parameters will persist until removal.
"""
ModelPart.__init__(self, owner, pars, free, removable, static_owner)

@staticmethod
def factory(baselinestr, ownerlist):
"""Instantiate a Peak from a string.

Parameters:
baselinestr: string representing Baseline
ownerlist: List of BaseFunctions that owner is in
Parameters
----------
baselinestr : str
The string representing Baseline
ownerlist : array-like
The list of BaseFunctions that owner is in
"""

data = baselinestr.strip().splitlines()
Expand Down
Loading