• 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

12.33
/src/pyslice/pyslice_lib/PySPG/MultiAgrizer.py
1
import os.path
5✔
2
import sys
5✔
3

4
from . import Load, PyGrace
5✔
5
from .ParamParser import ParamParser
5✔
6

7
#
8
#
9
# :::~ Author: Claudio Juan Tessone <tessonec@imedea.uib.es> (c) 2002-2003
10
#
11
# Distributed According to GNU Generic Purpose License (GPL)
12
# Please visit www.gnu.org
13
#
14

15

16
class MultiAgrizer:
5✔
17
    def __init__(self, comm, var_name):
5✔
18
        """
19
        Systematically plots the data generated by comm considering var_name as the last one
20
        the following ones are generated in the same plot
21
        """
22
        self.xcol = 0
×
23
        self.ycol = 1
×
24
        self.zcol = 2
×
25
        self.xformula = "x"
×
26
        self.yformula = "y"
×
27
        self.zformula = "z"
×
28
        self.xlabel = "x"
×
29
        self.ylabel = "y"
×
30
        self.xscale = "Normal"
×
31
        self.yscale = "Normal"
×
32
        self.plottype = "xy"
×
33
        self.autoscale_vars = "xy"
×
34
        self.xmin = 0
×
35
        self.xmax = 1
×
36
        self.xticks = 0.2
×
37
        self.ymin = 0
×
38
        self.ymax = 1
×
39
        self.yticks = 0.2
×
40
        self.title = ""
×
41
        self.dictLabels = None
×
42

43
        commands = [
×
44
            i.strip() for i in comm if (i.strip()[0] != "#" and i.strip() != "")
45
        ]
46
        # print commands
47

48
        pTmp = ParamParser(commands)
×
49
        try:
×
50
            lastvar_idx = pTmp.entities.index(var_name)
×
51
        except Exception:
×
52
            sys.stdout = sys.stderr
×
53
            print("last_var= ", var_name)
×
54
            print("var=", lastvar_idx)
×
55
            print("exiting... -presumible error: last var you provided does not")
×
56
            print(" exist among the variables-")
×
57
            sys.exit()
×
58

59
        self.parser_original = ParamParser(commands[:lastvar_idx])
×
60

61
        lastvarpos = commands.index(
×
62
            filter(lambda x: x.strip()[0] in "+*/-.", commands).pop()
63
        )
64

65
        self.parser_last = ParamParser(commands[lastvar_idx:lastvarpos])
×
66

67
    def set_world(self, xmin, xmax, ymin, ymax, xticks=None, yticks=None):
5✔
68
        """
69
        sets the bounds for the
70
        """
71
        self.xmin = xmin
×
72
        self.xmax = xmax
×
73
        self.ymin = ymin
×
74
        self.ymax = ymax
×
75
        self.xticks = xticks
×
76
        self.yticks = yticks
×
77

78
    def __agr(self, outname, inname):
5✔
79
        """
80
        for the actual values of the iterator self.parser_original, dumps a agr
81
        """
82
        cwd = os.path.abspath(os.path.curdir)
×
83
        #
84
        # Directory where the AGR will be located
85
        #
86
        thepath = self.parser_original.directory_tree(None)
×
87
        #
88
        #
89

90
        os.chdir(thepath)
×
91
        fOut = open(outname, "w")
×
92

93
        g1 = PyGrace.GraceDocument()
×
94
        #
95
        # Genera los paths donde estan los files
96
        #
97
        self.parser_last.reset()
×
98
        for i_state in self.parser_last:
×
99
            fname = self.parser_last.directory_tree(None) + inname
×
100
            legend = " ".join([f"{key}={i_state[key]}" for key in i_state])
×
101
            #       print i_state
102

103
            if self.plottype == "xy":
×
104
                ls = Load.loadXY(fname, self.xcol, self.ycol)
×
105
                ls2 = Load.transformXY(ls, self.xformula, self.yformula)
×
106
            if self.plottype in ["xydy", "xydx"]:
×
107
                ls = Load.loadXYZ(fname, self.xcol, self.ycol, self.zcol)
×
108
                ls2 = Load.transformXYZ(ls, self.xformula, self.yformula, self.zformula)
×
109
            g1.set_data(ls2, legend, self.plottype)
×
110

111
        #
112
        g1.set_labels(self.xlabel, self.ylabel)
×
113
        g1.set_scale(self.xscale, self.yscale)
×
114
        g1.set_title(self.title)
×
115
        g1.autoscale()
×
116
        g1.dump(fOut)
×
117
        #
118
        #
119
        #
120

121
        os.chdir(cwd)
×
122

123
    def doit(self, outname="out.agr", inname="out.dat"):
5✔
124
        """
125
        given the commands, for all the possible values, do the plotting according the given rules
126
        """
127

128
        for _ in self.parser_original:
×
129
            #    print self.parser_original
130
            self.__agr(outname, inname)
×
131

132

133
#
134
#
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