Skip to content

Commit

Permalink
redo
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Buscombe committed Aug 20, 2017
1 parent f1038e5 commit 086256c
Show file tree
Hide file tree
Showing 180 changed files with 112,939 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PyHum

Written by Daniel Buscombe
while at
Grand Canyon Monitoring and Research Center, U.G. Geological Survey, Flagstaff, AZ
please contact:
[email protected]
for latest code version please visit:
https://github.com/dbuscombe-usgs

====================================
This function is part of PyHum software
This software is in the public domain because it contains materials that originally came
from the United States Geological Survey, an agency of the United States Department of Interior.
For more information, see the official USGS copyright policy at
http://www.usgs.gov/visual-id/credit_usgs.html#copyright

Any use of trade, product, or firm names is for descriptive purposes only and does not imply endorsement by the U.S. government.
====================================
42 changes: 42 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# file GENERATED by distutils, do NOT edit
setup.cfg
setup.py
PyHum/B000.IDX
PyHum/B000.SON
PyHum/B001.IDX
PyHum/B001.SON
PyHum/B002.IDX
PyHum/B002.SON
PyHum/B003.IDX
PyHum/B003.SON
PyHum/RunningStats.cpp
PyHum/RunningStats.h
PyHum/RunningStats.py
PyHum/RunningStats_wrap.cxx
PyHum/__init__.py
PyHum/_gui.py
PyHum/_pyhum_correct.py
PyHum/_pyhum_e1e2.py
PyHum/_pyhum_map.py
PyHum/_pyhum_map_texture.py
PyHum/_pyhum_mosaic.py
PyHum/_pyhum_mosaic_texture.py
PyHum/_pyhum_read.py
PyHum/_pyhum_rmshadows.py
PyHum/_pyhum_texture.py
PyHum/cwt.pyx
PyHum/d_conc.txt
PyHum/dat2mat.py
PyHum/getxy.pyx
PyHum/io.py
PyHum/ppdrc.pyx
PyHum/pyhum_logo_white_sm.png
PyHum/pyread.pyx
PyHum/pyread_single.pyx
PyHum/replace_nans.pyx
PyHum/spec_noise.pyx
PyHum/stdev.pyx
PyHum/test.DAT
PyHum/test.py
PyHum/utils.py
PyHum/write.pyx
16 changes: 16 additions & 0 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Metadata-Version: 1.0
Name: PyHum
Version: 1.0
Summary: a description
Home-page: https://github.com/dbuscombe-usgs/PyHum
Author: Daniel Buscombe
Author-email: [email protected]
License: GPL
Description: PyHum

Keywords: meshing
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Operating System :: POSIX :: Linux
Classifier: Topic :: Scientific/Engineering :: Mathematics
Binary file added PyHum/B000.IDX
Binary file not shown.
Binary file added PyHum/B000.SON
Binary file not shown.
Binary file added PyHum/B001.IDX
Binary file not shown.
Binary file added PyHum/B001.SON
Binary file not shown.
Binary file added PyHum/B002.IDX
Binary file not shown.
Binary file added PyHum/B002.SON
Binary file not shown.
Binary file added PyHum/B003.IDX
Binary file not shown.
Binary file added PyHum/B003.SON
Binary file not shown.
96 changes: 96 additions & 0 deletions PyHum/RunningStats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* http://www.johndcook.com/blog/skewness_kurtosis/ */
#include "RunningStats.h"
#include <cmath>
#include <vector>

RunningStats::RunningStats()
{
Clear();
}

void RunningStats::Clear()
{
n = 0;
M1 = M2 = M3 = M4 = 0.0;
}

void RunningStats::Push(double x)
{
double delta, delta_n, delta_n2, term1;

long long n1 = n;
n++;
delta = x - M1;
delta_n = delta / n;
delta_n2 = delta_n * delta_n;
term1 = delta * delta_n * n1;
M1 += delta_n;
M4 += term1 * delta_n2 * (n*n - 3*n + 3) + 6 * delta_n2 * M2 - 4 * delta_n * M3;
M3 += term1 * delta_n * (n - 2) - 3 * delta_n * M2;
M2 += term1;
}

long long RunningStats::NumDataValues() const
{
return n;
}

double RunningStats::Mean() const
{
return M1;
}

double RunningStats::Variance() const
{
return M2/(n-1.0);
}

double RunningStats::StandardDeviation() const
{
return sqrt( Variance() );
}

double RunningStats::Skewness() const
{
return sqrt(double(n)) * M3/ pow(M2, 1.5);
}

double RunningStats::Kurtosis() const
{
return double(n)*M4 / (M2*M2) - 3.0;
}

RunningStats operator+(const RunningStats a, const RunningStats b)
{
RunningStats combined;

combined.n = a.n + b.n;

double delta = b.M1 - a.M1;
double delta2 = delta*delta;
double delta3 = delta*delta2;
double delta4 = delta2*delta2;

combined.M1 = (a.n*a.M1 + b.n*b.M1) / combined.n;

combined.M2 = a.M2 + b.M2 +
delta2 * a.n * b.n / combined.n;

combined.M3 = a.M3 + b.M3 +
delta3 * a.n * b.n * (a.n - b.n)/(combined.n*combined.n);
combined.M3 += 3.0*delta * (a.n*b.M2 - b.n*a.M2) / combined.n;

combined.M4 = a.M4 + b.M4 + delta4*a.n*b.n * (a.n*a.n - a.n*b.n + b.n*b.n) /
(combined.n*combined.n*combined.n);
combined.M4 += 6.0*delta2 * (a.n*a.n*b.M2 + b.n*b.n*a.M2)/(combined.n*combined.n) +
4.0*delta*(a.n*b.M3 - b.n*a.M3) / combined.n;

return combined;
}

RunningStats& RunningStats::operator+=(const RunningStats& rhs)
{
RunningStats combined = *this + rhs;
*this = combined;
return *this;
}
26 changes: 26 additions & 0 deletions PyHum/RunningStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* http://www.johndcook.com/blog/skewness_kurtosis/ */
#ifndef RUNNINGSTATS_H
#define RUNNINGSTATS_H

class RunningStats
{
public:
RunningStats();
void Clear();
void Push(double x);
long long NumDataValues() const;
double Mean() const;
double Variance() const;
double StandardDeviation() const;
double Skewness() const;
double Kurtosis() const;

friend RunningStats operator+(const RunningStats a, const RunningStats b);
RunningStats& operator+=(const RunningStats &rhs);

private:
long long n;
double M1, M2, M3, M4;
};

#endif
9 changes: 9 additions & 0 deletions PyHum/RunningStats.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* File: RunningStats.i */
%module RunningStats

%{
#define SWIG_FILE_WITH_INIT
#include "RunningStats.h"
%}

%include "RunningStats.h"
98 changes: 98 additions & 0 deletions PyHum/RunningStats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.11
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.





from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_RunningStats', [dirname(__file__)])
except ImportError:
import _RunningStats
return _RunningStats
if fp is not None:
try:
_mod = imp.load_module('_RunningStats', fp, pathname, description)
finally:
fp.close()
return _mod
_RunningStats = swig_import_helper()
del swig_import_helper
else:
import _RunningStats
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)

def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0


class RunningStats(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, RunningStats, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, RunningStats, name)
__repr__ = _swig_repr
def __init__(self):
this = _RunningStats.new_RunningStats()
try: self.this.append(this)
except: self.this = this
def Clear(self): return _RunningStats.RunningStats_Clear(self)
def Push(self, *args): return _RunningStats.RunningStats_Push(self, *args)
def NumDataValues(self): return _RunningStats.RunningStats_NumDataValues(self)
def Mean(self): return _RunningStats.RunningStats_Mean(self)
def Variance(self): return _RunningStats.RunningStats_Variance(self)
def StandardDeviation(self): return _RunningStats.RunningStats_StandardDeviation(self)
def Skewness(self): return _RunningStats.RunningStats_Skewness(self)
def Kurtosis(self): return _RunningStats.RunningStats_Kurtosis(self)
def __iadd__(self, *args): return _RunningStats.RunningStats___iadd__(self, *args)
__swig_destroy__ = _RunningStats.delete_RunningStats
__del__ = lambda self : None;
RunningStats_swigregister = _RunningStats.RunningStats_swigregister
RunningStats_swigregister(RunningStats)

# This file is compatible with both classic and new-style classes.


Loading

0 comments on commit 086256c

Please sign in to comment.