-
Notifications
You must be signed in to change notification settings - Fork 6
/
export.py
70 lines (61 loc) · 2.38 KB
/
export.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
# -*- coding: utf-8 -*-
# from PySide2.QtGui import *
# from PySide2.QtCore import *
from PySide2.QtWidgets import QFileDialog
import os
from functools import reduce
def getLastSaveDirectory(f):
f = str(f)
return os.sep.join(f.split(os.sep)[:-1])
class ExportGraph:
def __init__(self, widget, lastDirectory, p):
self.widget = widget
self.lastDirectory = lastDirectory
self.p = widget.p
def to_image(self):
filters = "png(*.png);;jpg(*.jpg);;bmp(*.bmp);;eps(*.eps);;tif(*.tif);;jpeg(*.jpeg)"
filename, _ = QFileDialog.getSaveFileName(self.widget, u'خروجی منحنی ضریب بازتاب',
self.lastDirectory, filters)
if filename == '':
return
self.lastDirectory = getLastSaveDirectory(filename)
exporter = pg.exporters.ImageExporter(self.p)
exporter.parameters()['width'] = 1920 # (note this also affects height parameter)
#exporter.parameters()['height'] = 600
# save to file
exporter.export(filename)
def to_csv(self):
filters = "txt(*.txt)"
filename, _ = QFileDialog.getSaveFileName(self.widget, u'Export Spectrum',
self.lastDirectory, filters)
if filename == '':
return
self.lastDirectory = getLastSaveDirectory(filename)
A = self.widget.final_building.acc
I = self.widget.final_building.importance_factor
Rux = self.widget.final_building.x_system.Ru
Ruy = self.widget.final_building.y_system.Ru
data = []
for c in self.p.curves:
if c.name() == 'B':
data.append(c.getData())
sep = '\t'
if Rux == Ruy:
Rs = (Rux,)
dirs = ('',)
else:
Rs = (Rux, Ruy)
dirs = ('_x', '_y')
for R, dir_ in zip(Rs, dirs):
fname = f'{filename[:-4]}{dir_}{filename[-4:]}'
fd = open(fname, 'w')
i = 0
numFormat = '%0.10g'
numRows = reduce(max, [len(d[0]) for d in data])
for i in range(numRows):
for d in data:
if i < len(d[0]):
c = A * d[1][i] * I / R
fd.write(numFormat % d[0][i] + sep + numFormat % c)
fd.write('\n')
fd.close()