-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
143 lines (115 loc) · 3.57 KB
/
Copy pathcommon.py
File metadata and controls
143 lines (115 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# This file holds global (DAPPER-wide) imports and settings
print("Initializing DAPPER...",end="", flush=True)
##################################
# Scientific
##################################
import numpy as np
import scipy as sp
import numpy.random
import scipy.linalg as sla
import numpy.linalg as nla
import scipy.stats as ss
from scipy.linalg import svd
from numpy.linalg import eig
# eig() of scipy.linalg necessitates using np.real_if_close().
from scipy.linalg import sqrtm, inv, eigh
from numpy import \
pi, nan, \
log, log10, exp, sin, cos, tan, \
sqrt, floor, ceil, \
mean, prod, \
diff, cumsum, \
array, asarray, asmatrix, \
linspace, arange, reshape, \
eye, zeros, ones, diag, trace \
# Don't shadow builtins: sum, max, abs, round, pow
##################################
# Tools
##################################
import sys
assert sys.version_info >= (3,5)
import os.path
from time import sleep
from collections import OrderedDict
import warnings
import traceback
import re
import functools
# Pandas changes numpy's error settings. Correct.
olderr = np.geterr()
import pandas as pd
np.seterr(**olderr)
# Profiling. Decorate the function you wish to time with 'profile' below
# Then launch program as: $ kernprof -l -v myprog.py
import builtins
try:
profile = builtins.profile # will exists if launched via kernprof
except AttributeError:
def profile(func): return func # provide a pass-through version.
# Installation suggestions
def install_msg(package):
return """
Could not find (import) package '{0}'. Using fall-back.
[But we recommend installing '{0}' (using pip or conda, etc...)
to improve the functionality of DAPPER.]""".format(package)
def install_warn(import_err):
name = import_err.args[0]
#name = name.split('No module named ')[1]
name = name.split("'")[1]
warnings.warn(install_msg(name))
##################################
# Plotting settings
##################################
def user_is_patrick():
import getpass
return getpass.getuser() == 'pataan'
import matplotlib as mpl
# is_notebook
try:
__IPYTHON__
from IPython import get_ipython
is_notebook = 'zmq' in str(type(get_ipython())).lower()
except (NameError,ImportError):
is_notebook = False
# Choose graphics backend.
if is_notebook:
mpl.use('nbAgg') # interactive
else:
# terminal frontent
if user_is_patrick():
from sys import platform
if platform == 'darwin':
mpl.use('MacOSX') # prettier, stable, fast (notable in LivePlot)
#mpl.use('Qt4Agg') # deprecated
# Has geometry(placement). Causes warning
#mpl.use('TkAgg')
#import matplotlib.cbook
#warnings.filterwarnings("ignore",category=matplotlib.cbook.mplDeprecation)
else:
pass
# Get Matlab-like interface, and enable interactive plotting
import matplotlib.pyplot as plt
plt.ion()
# Styles, e.g. 'fivethirtyeight', 'bmh', 'seaborn-darkgrid'
plt.style.use(['seaborn-darkgrid','tools/DAPPER.mplstyle'])
##################################
# Imports from DAPPER package
##################################
from tools.colors import *
from tools.utils import *
from tools.multiprocessing import *
from tools.math import *
from tools.chronos import *
from tools.stoch import *
from tools.series import *
from tools.matrices import *
from tools.randvars import *
from tools.viz import *
from tools.liveplotting import *
from tools.localization import *
from tools.convenience import *
from tools.data_management import *
from da_methods.stats import *
from da_methods.admin import *
from da_methods.da_methods import *
print("Done") # ... initializing DAPPER