-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import numpy as np | ||
import csv | ||
|
||
class EddyData(): | ||
|
||
def __init__(self, filename, time_offset = np.timedelta64(-8, 'h')): | ||
|
||
time_offset = np.timedelta64(-8, 'h') | ||
reader = csv.reader(open(filename,'r',encoding = 'utf-8-sig'), delimiter=',') | ||
columns = None | ||
self.data_structure = {} | ||
|
||
for line in reader: | ||
if columns is None: | ||
columns = line[0:] | ||
self.data_structure = {key:[] for key in columns} | ||
else: | ||
self.data_structure[columns[0]] += [np.datetime64(line[0])+time_offset] | ||
for (key, data) in zip(columns[1:], line[1:]): | ||
self.data_structure[key] += [np.float(data)] | ||
|
||
self.data_structure[columns[0]] = np.array(self.data_structure[columns[0]], dtype = np.datetime64) | ||
for key in columns[1:]: | ||
self.data_structure[key] = np.array(self.data_structure[key]) | ||
|
||
def __apply_filtered_indexes(self, filtered_indexes): | ||
for key in self.data_structure: | ||
self.data_structure[key] = self.data_structure[key][filtered_indexes] | ||
|
||
def filter_by_ustar(self, ustar): | ||
i = np.where(np.all((self.data_structure['qc_co2_flux'] < 1, self.data_structure['ustar'] >= ustar), axis=0)) | ||
self.__apply_filtered_indexes(i) | ||
|
||
def denoise(self, field): | ||
from scipy.signal import detrend | ||
from scipy.optimize import fsolve | ||
from scipy.special import erf | ||
|
||
def find_zscore(f): | ||
def inner_function(zscore): | ||
return 1 - f - erf(zscore / np.sqrt(2.0)) | ||
|
||
return fsolve(inner_function, 3) | ||
|
||
value_m = self.data_structure[field] | ||
dates_m = self.data_structure['Datetime'] | ||
|
||
cleared = False | ||
|
||
while not cleared: | ||
value_m = value_m - np.mean(value_m) | ||
|
||
value_m = detrend(value_m) | ||
|
||
zscore = np.abs(value_m) / np.std(value_m) | ||
|
||
number_of_points = value_m.size | ||
|
||
f = 1/number_of_points | ||
|
||
max_zscore = find_zscore(f) | ||
|
||
i = np.where(zscore <= max_zscore) | ||
|
||
if len(i[0]) == number_of_points: | ||
cleared = True | ||
else: | ||
value_m = value_m[i] | ||
dates_m = dates_m[i] | ||
|
||
_, indexes, _ = np.intersect1d(self.data_structure['Datetime'], dates_m, assume_unique = False, return_indices = True) | ||
|
||
self.__apply_filtered_indexes(indexes) | ||
|
||
def detrend(self, field): | ||
|
||
from scipy.signal import detrend | ||
return_data = self.data_structure[field] | ||
return_data -= np.mean(return_data) | ||
return_data = detrend(return_data) | ||
|
||
return return_data | ||
|
||
@property | ||
def time(self): | ||
return self.data_structure['Datetime'] | ||
|
||
@property | ||
def co2_flux(self): | ||
return self.data_structure['co2_flux'] | ||
|
||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 George Hilley | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.