-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-kja' of https://github.com/OpenDendro/dplPy into de…
…v-kja
- Loading branch information
Showing
13 changed files
with
9,328 additions
and
14,830 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
__copyright__ = """ | ||
dplPy for tree ring width time series analyses | ||
Copyright (C) 2023 OpenDendro | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
|
||
__license__ = "GNU GPLv3" | ||
|
||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Date: 12/15/2023 | ||
# Author: Kevin Anchukaitis | ||
# Title: transform.py | ||
# Description: Transforms the raw series using one of several options. | ||
# Doing so gives the series better statistical properties | ||
# prior to detrending and standardization | ||
# example usage: | ||
# >>> import dplpy as dpl | ||
# >>> data = dpl.readers("../tests/data/csv/file.csv") | ||
# >>> dpl.transform(data,transform_type='power') | ||
|
||
from tkinter import Y | ||
import pandas as pd | ||
import numpy as np | ||
|
||
def transform_series(data: pd.DataFrame | pd.Series, transform_type='power'): | ||
transformed_data = data.copy() | ||
|
||
for col in transformed_data.columns: | ||
series = transformed_data[col] | ||
|
||
if transform_type == 'log': | ||
series[series == 0] = 0.01 | ||
transformed_data[col] = np.log(series) | ||
|
||
elif transform_type == 'log6': | ||
series = series + (1/6) | ||
series[series <= 0] = (1/6) | ||
transformed_data[col] = np.log(series) | ||
|
||
elif transform_type == 'inversehypersine': | ||
valid_idx = ~series.isna() | ||
transformed_data.loc[valid_idx, col] = np.log(series[valid_idx] + np.sqrt(series[valid_idx] + 1.0)) | ||
|
||
elif transform_type == 'power': | ||
valid_idx = ~series.isna() | ||
x = series[valid_idx] | ||
original_mean = x.mean() | ||
original_stdev = x.std() | ||
|
||
M = (x[:-1] + x[1:]) / 2 | ||
S = np.abs(x[:-1] - x[1:]) | ||
b = np.polyfit(M, S, 1) | ||
|
||
transformed_data.loc[valid_idx, col] = series[valid_idx] ** (1 - b[0]) | ||
|
||
# Optional: reset mean to original | ||
|
||
return transformed_data |
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
File renamed without changes.
Oops, something went wrong.