• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timcera / pyslice / 12340932278

15 Dec 2024 05:42PM CUT coverage: 45.447%. Remained the same
12340932278

Pull #4

github

web-flow
Merge d90cfa984 into 2ffee6f33
Pull Request #4: build(deps): bump actions/setup-python from 4 to 5

529 of 1164 relevant lines covered (45.45%)

2.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.79
/src/pyslice/pyslice_lib/PySPG/Agrizer.py
1
"""
2
#
3
# :::~ Author: Claudio Juan Tessone <tessonec@imedea.uib.es> (c) 2002-2003
4
#
5
# Distributed According to GNU Generic Purpose License (GPL)
6
# Please visit www.gnu.org
7
"""
8

9
import os
5✔
10
import os.path
5✔
11
import sys
5✔
12

13
from . import Load, PyGrace
5✔
14
from .ParamParser import ParamParser
5✔
15

16

17
class Agrizer(ParamParser):
5✔
18
    box_size = 1.0
5✔
19
    min_value = None
5✔
20
    xcol = 0
5✔
21
    ycol = 1
5✔
22
    xformula = "x"
5✔
23
    yformula = "y"
5✔
24
    xlabel = "x"
5✔
25
    ylabel = "y"
5✔
26
    xscale = "Normal"
5✔
27
    yscale = "Normal"
5✔
28
    minx = 0.0
5✔
29
    maxx = 1.0
5✔
30
    miny = 0.0
5✔
31
    maxy = 1.0
5✔
32

33
    title = ""
5✔
34

35
    def agr(self, outname, inname):
5✔
36
        title = self.title
×
37
        elpath = ""
×
38
        ac_values = self.actual_values()
×
39
        for actual in ac_values:
×
40
            title += " %s=%s " % actual
×
41
            legend = " %s = %s " % actual
×
42

43
            if actual[0] in self.isvariable[:-1]:
×
44
                elpath += "%s-%s/" % actual
×
45

46
        cwd = self._test_paths(elpath)
×
47
        sys.stdout = open(outname, "w")
×
48

49
        ls = Load.loadXY(inname, self.xcol, self.ycol)
×
50
        ls2 = Load.transformXY(ls, self.xformula, self.yformula)
×
51

52
        g1 = PyGrace.GraceDocument()
×
53
        g1.set_data(ls2, legend)
×
54

55
        g1.autoscale()
×
56
        self._extracted_from_hist_30(g1, title)
×
57
        g1.dump()
×
58

59
        os.chdir(cwd)
×
60

61
    def agr_alter(self, pattern, outname=None, autoscale="xy"):
5✔
62
        title = self.title
×
63
        elpath = ""
×
64
        ac_values = self.actual_values()
×
65
        for actual in ac_values:
×
66
            if actual[0] in self.isvariable[:-1]:
×
67
                title += " %s=%s " % actual
×
68
                legend = " %s = %s " % actual
×
69
                elpath += "%s-%s/" % actual
×
70

71
        cwd = self._test_paths(elpath)
×
72
        if isinstance(pattern, str):
×
73
            pattern = [pattern]
×
74
        g1 = PyGrace.GraceDocument()
×
75
        for inname in pattern:
×
76
            for i in self.var:
×
77
                inname = inname.replace("{%s}" % i, f"{i}-{str(self.act_val(i))}")
×
78

79
            if os.path.isfile(inname):
×
80
                if not outname:
×
81
                    outname = f"{inname}.agr"
×
82

83
                else:
84
                    for i in self.var:
×
85
                        outname = outname.replace(f"{i}", f"{i}-{str(self.act_val(i))}")
×
86

87
                ls = Load.loadXY(inname, self.xcol, self.ycol)
×
88
                ls2 = Load.transformXY(ls, self.xformula, self.yformula)
×
89
                g1.set_data(ls2, legend)
×
90
                g1.set_labels(self.xlabel, self.ylabel)
×
91
                g1.set_scale(self.xscale, self.yscale)
×
92
                g1.set_title(title + inname)
×
93
                g1.set_world(self.minx, self.maxx, self.miny, self.maxy)
×
94
                g1.autoscale(autoscale)
×
95
                g1.autoscale()
×
96
                sys.stdout = open(outname, "w")
×
97
                g1.dump()
×
98

99
            else:
100
                sys.stderr.write(f"skipping {inname}... file does not exist\n")
×
101

102
        os.chdir(cwd)
×
103

104
    def _test_paths(self, elpath):
5✔
105
        try:
×
106
            if not os.path.exists(elpath):
×
107
                raise AssertionError("")
×
108
        except Exception:
×
109
            print(f"Error accessing path: '{elpath}'.")
×
110
            sys.exit()
×
111
        result = os.getcwd()
×
112
        os.chdir(elpath)
×
113
        return result
×
114

115
    # TODO Rename this here and in `agr`, `agr_alter` and `hist`
116
    def hist(self, pattern, mustCalculateDif, outname=None, autoscale="xy"):
5✔
117
        title = self.title
×
118
        elpath = ""
×
119
        ac_values = self.actual_values()
×
120

121
        for actual in ac_values:
×
122
            if actual[0] in self.isvariable[:-1]:
×
123
                elpath += "%s-%s/" % actual
×
124
                title += " %s = %s " % actual
×
125

126
        legend = title
×
127
        cwd = os.getcwd()
×
128
        try:
×
129
            if not os.path.exists(elpath):
×
130
                raise AssertionError("")
×
131
        except Exception:
×
132
            print(f"Error accessing path: '{elpath}'.")
×
133
            sys.exit()
×
134

135
        os.chdir(elpath)
×
136
        if isinstance(pattern, str):
×
137
            pattern = [pattern]
×
138
        g1 = PyGrace.GraceDocument()
×
139
        isSomething = 0  # false the document is void
×
140
        if not outname:
×
141
            outname = pattern[0]
×
142
        for i in self.var:
×
143
            outname = outname.replace("{%s}" % i, f"{i}-{str(self.act_val(i))}")
×
144

145
        for inname in pattern:
×
146
            for i in self.var:
×
147
                inname = inname.replace("{%s}" % i, f"{i}-{str(self.act_val(i))}")
×
148

149
            if os.path.isfile(inname):
×
150
                isSomething = 1  # true the document is NOT void
×
151

152
                ls = Load.loadY(inname, 0)
×
153
                if mustCalculateDif:
×
154
                    ls = [ls[i + 1] - ls[i] for i in range(len(ls) - 1)]
×
155
                from . import histogram
×
156

157
                hist = histogram.SPGHistogram(self.box_size)
×
158

159
                for x in ls:
×
160
                    hist.add_value(x)
×
161

162
                ls2 = hist.get_dataset()
×
163

164
                g1.set_data(ls2, legend, "bar")
×
165
            else:
166
                sys.stderr.write(f"skipping {inname}... file does not exist\n")
×
167
        if isSomething:
×
168
            sys.stdout = open(outname, "w")
×
169
            self._extracted_from_hist_30(g1, title)
×
170
            g1.set_world(self.minx, self.maxx, self.miny, self.maxy)
×
171
            g1.autoscale(autoscale)
×
172
            g1.dump()
×
173
        os.chdir(cwd)
×
174

175
    # TODO Rename this here and in `agr`, `agr_alter` and `hist`
176
    def _extracted_from_hist_30(self, g1, title):
5✔
177
        g1.set_labels(self.xlabel, self.ylabel)
×
178
        g1.set_scale(self.xscale, self.yscale)
×
179
        g1.set_title(title)
×
180

181
    def doit(
5✔
182
        self,
183
        outname="out.agr",
184
        inname="out.dat",
185
        pattern=None,
186
        patternname=None,
187
        autoscale="xy",
188
    ):
189
        flag = 1
×
190

191
        while flag:
×
192
            if not pattern:
×
193
                self.agr(outname, inname)
×
194
            else:
195
                self.agr(pattern, patternname)
×
196

197
            flag = next(self)
×
198
        self.reset()
×
199

200
    def dohist(self, pattern, mustCalculateDif=0, patternname=None, autoscale="xy"):
5✔
201
        flag = 1
×
202

203
        while flag:
×
204
            self.hist(pattern, mustCalculateDif, patternname)
×
205
            flag = next(self)
×
206
        self.reset()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc