-
Notifications
You must be signed in to change notification settings - Fork 15
/
settings.py
328 lines (279 loc) · 8.7 KB
/
settings.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# coding=UTF-8
# ex:ts=4:sw=4:et=on
# Copyright (c) 2013, Mathijs Dumon
# All rights reserved.
# Complete license can be found in the LICENSE file.
import argparse, os
from pyxrd.__version import __version__
from .appdirs import user_data_dir, user_log_dir
### General Information ###
VERSION = __version__
DEBUG = False
FINALIZERS = [] #A list of callables that are called before the main function is left
BGSHIFT = True
LOG_FILENAME = os.path.join(user_log_dir('PyXRD'), 'errors.log')
### The URL where PyXRD looks for updates & the online manual ###
UPDATE_URL = 'http://users.ugent.be/~madumon/pyxrd/'
MANUAL_URL = UPDATE_URL
### Factor to multiply the CSDS average with to obtain the maximum CSDS ###
LOG_NORMAL_MAX_CSDS_FACTOR = 2.5
### What type of residual error we use: ###
# "Rp" = 'standard' pattern Rp factor
# "Rpw" = 'weighted' pattern Rp factor
# "Rpder" = Rp factor of first-derivatives
RESIDUAL_METHOD = "Rp"
### Default wavelength if no Goniometer is available ###
DEFAULT_LAMBDA = 0.154056
### GUI Mode (for HPC turn to False) ###
GUI_MODE = True
### Size of parameter space record in bytes ###
PAR_SPACE_MEMORY_LIMIT = 25 * (1024 * 1024)
### Default Styles & Colors ###
DEFAULT_LAYOUT = "VIEWER" # one of the keys in DEFAULT_LAYOUTS!
DEFAULT_LAYOUTS = {
"FULL": "Full",
"VIEWER": "View-mode"
}
AXES_MANUAL_XMIN = 0.0
AXES_MANUAL_XMAX = 70.0
AXES_XSTRETCH = False
AXES_DSPACING = False
AXES_DEFAULT_WAVELENGTH = 0.154056
AXES_XLIMIT = 0
AXES_XLIMITS = {
0: "Automatic",
1: "Manual"
}
AXES_MANUAL_YMIN = 0.0
AXES_MANUAL_YMAX = 0.0
AXES_YVISIBLE = False
AXES_YNORMALIZE = 0
AXES_YNORMALIZERS = {
0: "Multi normalised",
1: "Single normalised",
2: "Unchanged raw counts",
}
AXES_YLIMIT = 0
AXES_YLIMITS = {
0: "Automatic",
1: "Manual"
}
EXPERIMENTAL_COLOR = "#000000"
CALCULATED_COLOR = "#FF0000"
EXPERIMENTAL_LINEWIDTH = 1.0
CALCULATED_LINEWIDTH = 2.0
CALCULATED_LINESTYLE = "-"
EXPERIMENTAL_LINESTYLE = "-"
CALCULATED_MARKER = ""
EXPERIMENTAL_MARKER = ""
PATTERN_LINE_STYLES = {
"": "Nothing",
"-": "Solid",
"--": "Dashed",
"-.": "Dash Dot",
":": "Dotted"
}
PATTERN_MARKERS = {
"": "No marker",
".": "Point",
",": "Pixel",
"+": "Plus",
"x": "Cross",
"D": "Diamond",
"o": "Circle",
"v": "Triangle down",
"^": "Triangle up",
"<": "Triangle left",
">": "Triangle right",
"8": "Octagon",
"s": "Square",
"p": "Pentagon",
"*": "Star",
"h": "Hexagon",
}
PATTERN_SHIFT_POSITIONS = {
0.42574: "Quartz 0.42574 SiO2",
0.3134: "Silicon 0.31355 Si",
0.2476: "Zincite 0.24759 ZnO",
0.2085: "Corundum 0.2085 Al2O3",
0.4183: "Goethite 0.4183 FeO(OH)",
0.48486: "Gibbsite 0.48486 Al(OH)3",
}
PATTERN_SHIFT_TYPE = "Displacement" # or "Linear"
PATTERN_SMOOTH_TYPES = { 0: "Moving Triangle" }
PATTERN_BG_TYPES = { 0: "Linear", 1: "Pattern" }
DIVERGENCE_MODES = {
"AUTOMATIC": "Automatic divergence",
"FIXED": "Fixed divergence"
}
DEFAULT_DIVERGENCE_MODE = "FIXED"
DEFAULT_SAMPLE_LENGTH = 1.25 # in cm
PLOT_OFFSET = 0.75
PATTERN_GROUP_BY = 1
LABEL_POSITION = 0.35
MARKER_VISIBLE = True
MARKER_X_OFFSET = 0.0
MARKER_Y_OFFSET = 0.05
MARKER_POSITION = 0.0
MARKER_INHERIT_COLOR = True
MARKER_COLOR = "#000000"
MARKER_INHERIT_ANGLE = True
MARKER_ANGLE = 0.0
MARKER_INHERIT_TOP_OFFSET = True
MARKER_TOP_OFFSET = 0.0
MARKER_INHERIT_BASE = True
MARKER_BASE = 1
MARKER_BASES = {
0: "X-axis",
1: "Experimental profile",
2: "Calculated profile",
3: "Lowest of both",
4: "Highest of both"
}
MARKER_INHERIT_TOP = True
MARKER_TOP = 0
MARKER_TOPS = {
0: "Relative to base",
1: "Top of plot"
}
MARKER_INHERIT_STYLE = True
MARKER_STYLE = "none"
MARKER_STYLES = {
"none": "None", "solid": "Solid",
"dashed": "Dash", "dotted": "Dotted",
"dashdot": "Dash-Dotted", "offset": "Display at Y-offset"
}
MARKER_INHERIT_ALIGN = True
MARKER_ALIGN = "left"
MARKER_ALIGNS = {
"left": "Left align",
"center": "Centered",
"right": "Right align"
}
EXCLUSION_FOREG = "#999999"
EXCLUSION_LINES = "#333333"
### Plot Information ###
PLOT_TOP = 0.85
MAX_PLOT_RIGHT = 0.95
PLOT_BOTTOM = 0.0
PLOT_LEFT = 0.05
PLOT_HEIGHT = PLOT_TOP - PLOT_BOTTOM
OUTPUT_PRESETS = [
("Landscape Large print", 8000, 4800, 300.0),
("Landscape Medium print", 6000, 3800, 300.0),
("Landscape Small print", 4000, 2800, 300.0),
("Portrait Large print", 4800, 8000, 300.0),
("Portrait Medium print", 3800, 6000, 300.0),
("Portrait Small print", 2800, 4000, 300.0),
]
### Default Directories & Files ###
DATA_REG = None # set at run-time
DATA_DIRS = [
("DEFAULT_DATA", "./", None),
("USER_DATA", user_data_dir('PyXRD'), None),
("LOG_DIR", user_log_dir('PyXRD'), None),
("DEFAULT_PHASES", "default phases/", "USER_DATA"),
("DEFAULT_COMPONENTS", "default components/", "DEFAULT_DATA"),
("DEFAULT_GONIOS", "default goniometers/", "DEFAULT_DATA"),
("DEFAULT_WL_DISTR", "default wavelength distributions/", "DEFAULT_DATA"),
("APPLICATION_ICONS", "icons/", "DEFAULT_DATA"),
]
DATA_FILES = [
("COMPOSITION_CONV", "composition_conversion.csv", "DEFAULT_DATA"),
("ATOM_SCAT_FACTORS", "atomic scattering factors.atl", "DEFAULT_DATA"),
("MINERALS", "mineral_references.csv", "DEFAULT_DATA"),
]
### Async calculation providers ###
ASYNC_SERER_PROVIDERS = [
"pyxrd.server.provider.Pyro4AsyncServerProvider",
"pyxrd.generic.asynchronous.dummy_async_provider.DummyAsyncServerProvider",
]
ASYNC_SERVER_PRELOAD = True
### Runtime Settings Retrieval ###
SETTINGS_APPLIED = False
ARGS = None
def _parse_args():
""" Parses command line arguments """
parser = argparse.ArgumentParser()
parser.add_argument(
"filename", nargs="?", default="",
help="A PyXRD project filename"
)
parser.add_argument(
"-s", "--script", default="",
help="Can be used to pass a script containing a run() function"
)
parser.add_argument(
"-d", "--debug", dest='debug', action='store_const',
const=True, default=False,
help='Run in debug mode'
)
args = parser.parse_args()
del parser # free some memory
return args
__apply_lock__ = False
def initialize(override_debug=DEBUG):
"""Apply runtime settings, can and needs to be called only once"""
global __apply_lock__, SETTINGS_APPLIED
if not __apply_lock__ and not SETTINGS_APPLIED:
__apply_lock__ = True
# Get command line arguments
global ARGS
ARGS = _parse_args()
# Set gui flag
global GUI_MODE
GUI_MODE = not bool(ARGS.script)
# Set debug flag
global DEBUG
DEBUG = ARGS.debug or override_debug
# Setup data registry:
global DATA_REG, DATA_DIRS, DATA_FILES
from pyxrd.generic.io.data_registry import DataRegistry
DATA_REG = DataRegistry(dirs=DATA_DIRS, files=DATA_FILES)
# If we are running in GUI mode, setup GUI stuff:
if GUI_MODE:
import matplotlib
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf
# Setup matplotlib fonts:
font = {
'weight' : 'heavy', 'size': 14,
'sans-serif' : 'Helvetica, Arial, sans-serif',
'family' : 'sans-serif',
}
matplotlib.rc('font', **font)
mathtext = {
'default': 'regular',
'fontset': 'stixsans',
}
matplotlib.rc('mathtext', **mathtext)
# matplotlib.rc('text', **{'usetex':True})
# Load our own icons:
iconfactory = Gtk.IconFactory()
icons_path = DATA_REG.get_directory_path("APPLICATION_ICONS")
for root, dirnames, filenames in os.walk(icons_path):
for filename in filenames:
if filename.endswith(".png"):
stock_id = filename[:-4] # remove extensions
filename = "%s/%s" % (icons_path, filename)
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
iconset = Gtk.IconSet(pixbuf)
iconfactory.add(stock_id, iconset)
iconfactory.add_default()
# Make sure default directories exist:
for path in DATA_REG.get_all_directories():
try:
os.makedirs(path)
except OSError:
pass
# Free some memory at this point:
import gc
gc.collect()
# Log that we did all of this:
import logging
logger = logging.getLogger(__name__)
logger.info("Runtime settings applied")
__apply_lock__ = False
SETTINGS_APPLIED = True
# ## end of settings