-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from h2020charisma/devel-gg
central moments and arbitrary function as baseline
- Loading branch information
Showing
5 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
import glob | ||
|
||
__all__ = [ | ||
os.path.basename(f)[:-3] | ||
for f in glob.glob(os.path.dirname(__file__)+"/*.py") | ||
if os.path.isfile(f) and not os.path.basename(f).startswith('_') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import numpy as np | ||
from pydantic import validate_arguments | ||
|
||
from ..spectrum import Spectrum | ||
from ramanchada2.misc.spectrum_deco import add_spectrum_method | ||
|
||
|
||
@add_spectrum_method | ||
@validate_arguments(config=dict(arbitrary_types_allowed=True)) | ||
def central_moments(spe: Spectrum, /, | ||
left_idx=0, right_idx=-1, moments=[1, 2, 3, 4], normalize=False | ||
): | ||
mom = dict() | ||
x = spe.x[left_idx:right_idx] | ||
p = spe.y[left_idx:right_idx] | ||
p -= p.min() | ||
p /= p.sum() | ||
mom[1] = np.sum(x*p) | ||
mom[2] = np.sum((x - mom[1])**2 * p) | ||
for i in moments: | ||
if i <= 2: | ||
continue | ||
mom[i] = np.sum((x - mom[1])**i * p) | ||
if normalize and i > 2: | ||
mom[i] /= mom[2] ** i/2 | ||
return [mom[i] for i in moments] |