forked from sapphire008/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_py.py
executable file
·104 lines (92 loc) · 3.44 KB
/
init_py.py
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
# -*- coding: utf-8 -*-
"""
Created on Fri May 6 09:44:12 2016
@author: Edward
"""
# matplotlib.use('PS')
import sys
import os
# parsing mode
if len(sys.argv)>1:
if any(['ipy' in argv.lower() for argv in sys.argv]) or \
any(['jupyter' in argv.lower() for argv in sys.argv]) or \
__file__ in sys.argv: # %run magic command
MODE = 'jupyter'
else: # assume this is called from the command line
MODE = sys.argv[1]
else:
MODE = 'academic'
import matplotlib
if sys.platform == 'darwin':
PYPKGPATH = os.path.dirname(os.path.realpath(__file__))
else:
PYPKGPATH = 'D:/Edward/Documents/Assignments/Scripts/Python/'
# PYPKGPATH = '/Users/edward/Documents/Scripts/Python'
sys.path.append(PYPKGPATH)
import glob
pkg_list = [os.path.basename(os.path.normpath(p)) for p in glob.glob(PYPKGPATH+'/*') if os.path.isdir(p)]
def addpythonpkg(pkg=None, recursively=False):
"""Instead of doing complicated import, simply add the path of custom scripts"""
if pkg is None:
# print(pkg_list)
return pkg_list
if isinstance(pkg, str):
pkg = [pkg]
# add packages
for p in pkg:
if p in pkg_list and p not in sys.path:
if recursively:
[sys.path.append(os.path.join(PYPKGPATH, x[0])) for x in os.walk(p)]
else:
sys.path.append(os.path.join(PYPKGPATH, p))
else:
raise(Exception('package %s is not available. Check spelling'%p))
def getaddedpkgs():
"""List packages that has been added"""
added_paths = []
for p in sys.path:
normpath = os.path.basename(os.path.normpath(p))
if normpath in pkg_list and normpath not in added_paths:
added_paths.append(normpath)
return added_paths
def getaddedmodules():
return sys.modules.keys()
#def cd(path=None):
# """overloading cd"""
# if not isinstance(path,str):
# return
# elif path.lower()== 'home':
# os.chdir(PYPKGPATH)
# elif path.lower()== '..':
# os.chdir(os.path.dirname(os.getcwd()))
# else:
# os.chdir(path)
global tableau10
global FONT
global FONTSIZE
if MODE == 'academic':
print('academic mode')
# Do some generic import
addpythonpkg(['Spikes', 'generic', 'Plots'])
import pandas as pd
import numpy as np
from spk_util import *
from MATLAB import *
from ImportData import *
from plots import *
# Added the platelet tableau10
tableau10 = ["#1f77b4","#ff7f0e", "#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"]
FONT = 'D:/Edward/Documents/Assignments/Scripts/Python/PySynapse/resources/Helvetica.ttf'
FONTSIZE = {'title':10, 'xlab':8, 'ylab':8, 'xtick':6,'ytick':6,'texts':6,
'legend': 6, 'legendtitle':6, 'xminortick':6, 'yminortick':6} # font size
elif MODE == 'jupyter':
print('jupyter mode')
addpythonpkg(['generic', 'Plots'])
import pandas as pd
import numpy as np
from MATLAB import *
from plots import *
tableau10 = ["#1f77b4","#ff7f0e", "#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"]
FONT = 'D:/Edward/Documents/Assignments/Scripts/Python/PySynapse/resources/Helvetica.ttf'
FONTSIZE = {'title':12, 'xlab':10, 'ylab':10, 'xtick':8,'ytick':8,'texts':8,
'legend': 8, 'legendtitle':8, 'xminortick':8, 'yminortick':8} # font size