forked from nansencenter/DAPPER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
134 lines (114 loc) · 3.54 KB
/
common.py
File metadata and controls
134 lines (114 loc) · 3.54 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
# This file holds global (DAPPER-wide) imports and settings
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
import builtins
try:
# This will be available if launched as (e.g.)
# (bash)$ kernprof -l -v example_1.py
profile = builtins.profile
except AttributeError:
# Otherwise: provide a pass-through version.
def profile(func): return func
##################################
# 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 scipy.linalg import eig # Necessitates np.real_if_close().
from numpy.linalg import eig
from scipy.linalg import sqrtm, inv, eigh
from numpy import \
pi, nan, \
log, log10, exp, sin, cos, tan, \
sqrt, floor, ceil, \
mean, prod, \
array, asarray, asmatrix, \
linspace, arange, reshape, \
eye, zeros, ones, diag, trace \
##################################
# Installation suggestion
##################################
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
# Choose graphics backend.
try:
from IPython import get_ipython
is_notebook = 'zmq' in str(type(get_ipython())).lower()
except ImportError:
is_notebook = False
if is_notebook:
mpl.use('nbAgg') # interactive
else:
# terminal frontent
if user_is_patrick():
from sys import platform
if platform == 'darwin':
#mpl.use('Qt4Agg') # deprecated
#mpl.use('TkAgg') # has geometry(placement)
mpl.use('MacOSX') # prettier, stable, fast (notable in LivePlot)
else:
pass
# Get Matlab-like interface, and enable interactive plotting
import matplotlib.pyplot as plt
plt.ion()
# Styles
try:
olderr = np.geterr() # gets affected by seaborn (pandas?)
import seaborn as sns
np.seterr(**olderr) # restore np float error treatment
sns.set_style({'image.cmap': 'BrBG', 'legend.frameon': True})
sns_bg = array([0.9176, 0.9176, 0.9490])
sns.set_color_codes()
except ImportError as err:
install_warn(err)
#plt.style.use('ggplot') # 'fivethirtyeight', 'bmh', 'seaborn-darkgrid',
mpl.rcParams['image.cmap'] = 'BrBG'
RGBs = {c: array(mpl.colors.colorConverter.to_rgb(c)) for c in 'bgrmycw'}
# With TkAgg/Qt4Agg backend this causes warning.
import matplotlib.cbook
warnings.filterwarnings("ignore",category=matplotlib.cbook.mplDeprecation)
# With TkAgg/Qt4Agg backend this causes warning.
#mpl.rcParams['toolbar'] = 'None'
#warnings.filterwarnings("ignore",category=UserWarning)
##################################
# Setup DAPPER namespace
##################################
from tools.utils import *
from tools.misc 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 stats import *
from tools.admin import *
from tools.convenience import *
from da_methods import *