CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Public Attributes | Static Public Attributes
svgfig.Curve Class Reference
Inheritance diagram for svgfig.Curve:
svgfig.CurveAxis svgfig.Ellipse svgfig.Line svgfig.Rect svgfig.HLine svgfig.LineAxis svgfig.VLine svgfig.XAxis svgfig.YAxis

Classes

class  Sample
 nested class Sample More...
 
class  Samples
 end Sample More...
 

Public Member Functions

def __init__ (self, f, low, high, loop=False, **attr)
 
def __repr__ (self)
 
def Path (self, trans=None, local=False)
 
def sample (self, trans=None)
 end nested class More...
 
def subsample (self, left, right, depth, trans=None)
 
def SVG (self, trans=None)
 

Public Attributes

 attr
 
 f
 
 high
 
 last_samples
 
 loop
 
 low
 

Static Public Attributes

dictionary defaults = {}
 
int discontinuity_limit = 5.
 
float linearity_limit = 0.05
 
bool random_sampling = True
 
int recursion_limit = 15
 

Detailed Description

Draws a parametric function as a path.

Curve(f, low, high, loop, attribute=value)

f                      required         a Python callable or string in
                                        the form "f(t), g(t)"
low, high              required         left and right endpoints
loop                   default=False    if True, connect the endpoints
attribute=value pairs  keyword list     SVG attributes

Definition at line 1499 of file svgfig.py.

Constructor & Destructor Documentation

◆ __init__()

def svgfig.Curve.__init__ (   self,
  f,
  low,
  high,
  loop = False,
**  attr 
)

Reimplemented in svgfig.Rect.

Definition at line 1519 of file svgfig.py.

1519  def __init__(self, f, low, high, loop=False, **attr):
1520  self.f = f
1521  self.low = low
1522  self.high = high
1523  self.loop = loop
1524 
1525  self.attr = dict(self.defaults)
1526  self.attr.update(attr)
1527 

Member Function Documentation

◆ __repr__()

def svgfig.Curve.__repr__ (   self)

Reimplemented in svgfig.YAxis, svgfig.XAxis, svgfig.LineAxis, svgfig.CurveAxis, svgfig.Ellipse, svgfig.Rect, svgfig.HLine, svgfig.VLine, and svgfig.Line.

Definition at line 1516 of file svgfig.py.

1516  def __repr__(self):
1517  return "<Curve %s [%s, %s] %s>" % (self.f, self.low, self.high, self.attr)
1518 

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, hippyaddtobaddatafiles.KeepWhileOpenFile.f, svgfig.Curve.f, svgfig.Curve.high, and svgfig.Curve.low.

Referenced by data_sources.json_file.__str__().

◆ Path()

def svgfig.Curve.Path (   self,
  trans = None,
  local = False 
)
Apply the transformation "trans" and return a Path object in
global coordinates.  If local=True, return a Path in local coordinates
(which must be transformed again).

Reimplemented in svgfig.Ellipse, svgfig.Rect, svgfig.HLine, svgfig.VLine, and svgfig.Line.

Definition at line 1654 of file svgfig.py.

1654  def Path(self, trans=None, local=False):
1655  """Apply the transformation "trans" and return a Path object in
1656  global coordinates. If local=True, return a Path in local coordinates
1657  (which must be transformed again)."""
1658 
1659  if isinstance(trans, str): trans = totrans(trans)
1660  if isinstance(self.f, str): self.f = funcRtoR2(self.f)
1661 
1662  self.sample(trans)
1663 
1664  output = []
1665  for s in self.last_samples:
1666  if s.X != None and s.Y != None:
1667  if s.left == None or s.left.Y == None:
1668  command = "M"
1669  else:
1670  command = "L"
1671 
1672  if local: output.append((command, s.x, s.y, False))
1673  else: output.append((command, s.X, s.Y, True))
1674 
1675  if self.loop: output.append(("Z",))
1676  return Path(output, **self.attr)
1677 

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, hippyaddtobaddatafiles.KeepWhileOpenFile.f, svgfig.Curve.f, svgfig.funcRtoR2(), svgfig.Curve.last_samples, svgfig.Curve.loop, CastorLedAnalysis.sample, HcalLedAnalysis.sample, CastorPedestalAnalysis.sample, HcalPedestalAnalysis.sample, svgfig.Curve.sample(), and svgfig.totrans().

Referenced by svgfig.Curve.SVG(), svgfig.Poly.SVG(), svgfig.Line.SVG(), svgfig.Rect.SVG(), and svgfig.Ellipse.SVG().

◆ sample()

def svgfig.Curve.sample (   self,
  trans = None 
)

end nested class

Adaptive-sampling algorithm that chooses the best sample points
for a parametric curve between two endpoints and detects
discontinuities.  Called by SVG().

Definition at line 1576 of file svgfig.py.

1576  def sample(self, trans=None):
1577  """Adaptive-sampling algorithm that chooses the best sample points
1578  for a parametric curve between two endpoints and detects
1579  discontinuities. Called by SVG()."""
1580  oldrecursionlimit = sys.getrecursionlimit()
1581  sys.setrecursionlimit(self.recursion_limit + 100)
1582  try:
1583  # the best way to keep all the information while sampling is to make a linked list
1584  if not (self.low < self.high): raise ValueError("low must be less than high")
1585  low, high = self.Sample(float(self.low)), self.Sample(float(self.high))
1586  low.link(None, high)
1587  high.link(low, None)
1588 
1589  low.evaluate(self.f, trans)
1590  high.evaluate(self.f, trans)
1591 
1592  # adaptive sampling between the low and high points
1593  self.subsample(low, high, 0, trans)
1594 
1595  # Prune excess points where the curve is nearly linear
1596  left = low
1597  while left.right != None:
1598  # increment mid and right
1599  mid = left.right
1600  right = mid.right
1601  if right != None and left.X != None and left.Y != None and mid.X != None and mid.Y != None and right.X != None and right.Y != None:
1602  numer = left.X*(right.Y - mid.Y) + mid.X*(left.Y - right.Y) + right.X*(mid.Y - left.Y)
1603  denom = math.sqrt((left.X - right.X)**2 + (left.Y - right.Y)**2)
1604  if denom != 0. and abs(numer/denom) < self.linearity_limit:
1605  # drop mid (the garbage collector will get it)
1606  left.right = right
1607  right.left = left
1608  else:
1609  # increment left
1610  left = left.right
1611  else:
1612  left = left.right
1613 
1614  self.last_samples = self.Samples(low, high)
1615 
1616  finally:
1617  sys.setrecursionlimit(oldrecursionlimit)
1618 

References funct.abs(), hippyaddtobaddatafiles.KeepWhileOpenFile.f, svgfig.Curve.f, dqmMemoryStats.float, svgfig.Curve.high, svgfig.Curve.linearity_limit, svgfig.Curve.low, svgfig.Curve.recursion_limit, and svgfig.Curve.subsample().

Referenced by svgfig.Curve.Path().

◆ subsample()

def svgfig.Curve.subsample (   self,
  left,
  right,
  depth,
  trans = None 
)
Part of the adaptive-sampling algorithm that chooses the best
sample points.  Called by sample().

Definition at line 1619 of file svgfig.py.

1619  def subsample(self, left, right, depth, trans=None):
1620  """Part of the adaptive-sampling algorithm that chooses the best
1621  sample points. Called by sample()."""
1622 
1623  if self.random_sampling:
1624  mid = self.Sample(left.t + random.uniform(0.3, 0.7) * (right.t - left.t))
1625  else:
1626  mid = self.Sample(left.t + 0.5 * (right.t - left.t))
1627 
1628  left.right = mid
1629  right.left = mid
1630  mid.link(left, right)
1631  mid.evaluate(self.f, trans)
1632 
1633  # calculate the distance of closest approach of mid to the line between left and right
1634  numer = left.X*(right.Y - mid.Y) + mid.X*(left.Y - right.Y) + right.X*(mid.Y - left.Y)
1635  denom = math.sqrt((left.X - right.X)**2 + (left.Y - right.Y)**2)
1636 
1637  # if we haven't sampled enough or left fails to be close enough to right, or mid fails to be linear enough...
1638  if depth < 3 or (denom == 0 and left.t != right.t) or denom > self.discontinuity_limit or (denom != 0. and abs(numer/denom) > self.linearity_limit):
1639 
1640  # and we haven't sampled too many points
1641  if depth < self.recursion_limit:
1642  self.subsample(left, mid, depth+1, trans)
1643  self.subsample(mid, right, depth+1, trans)
1644 
1645  else:
1646  # We've sampled many points and yet it's still not a small linear gap.
1647  # Break the line: it's a discontinuity
1648  mid.y = mid.Y = None
1649 

References funct.abs(), svgfig.Curve.discontinuity_limit, hippyaddtobaddatafiles.KeepWhileOpenFile.f, svgfig.Curve.f, svgfig.Curve.linearity_limit, svgfig.Curve.random_sampling, svgfig.Curve.recursion_limit, and svgfig.Curve.subsample().

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().

◆ SVG()

def svgfig.Curve.SVG (   self,
  trans = None 
)
Apply the transformation "trans" and return an SVG object.

Reimplemented in svgfig.YAxis, svgfig.XAxis, svgfig.LineAxis, svgfig.CurveAxis, svgfig.Ellipse, svgfig.Rect, and svgfig.Line.

Definition at line 1650 of file svgfig.py.

1650  def SVG(self, trans=None):
1651  """Apply the transformation "trans" and return an SVG object."""
1652  return self.Path(trans).SVG()
1653 

References SiStripHistoPlotter::PlotParameter.Path, Json::PathArgument.Path, and svgfig.Curve.Path().

Member Data Documentation

◆ attr

svgfig.Curve.attr

◆ defaults

dictionary svgfig.Curve.defaults = {}
static

Definition at line 1510 of file svgfig.py.

Referenced by tree.Tree.reset(), and tree.Tree.var().

◆ discontinuity_limit

int svgfig.Curve.discontinuity_limit = 5.
static

Definition at line 1514 of file svgfig.py.

Referenced by svgfig.Curve.subsample().

◆ f

svgfig.Curve.f

◆ high

svgfig.Curve.high

◆ last_samples

svgfig.Curve.last_samples

Definition at line 1614 of file svgfig.py.

Referenced by svgfig.Curve.Path().

◆ linearity_limit

float svgfig.Curve.linearity_limit = 0.05
static

Definition at line 1513 of file svgfig.py.

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().

◆ loop

svgfig.Curve.loop

Definition at line 1523 of file svgfig.py.

Referenced by svgfig.Poly.__repr__(), svgfig.Curve.Path(), and svgfig.Poly.Path().

◆ low

svgfig.Curve.low

◆ random_sampling

bool svgfig.Curve.random_sampling = True
static

Definition at line 1511 of file svgfig.py.

Referenced by svgfig.Curve.subsample().

◆ recursion_limit

int svgfig.Curve.recursion_limit = 15
static

Definition at line 1512 of file svgfig.py.

Referenced by svgfig.Curve.sample(), and svgfig.Curve.subsample().

dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
svgfig.totrans
def totrans(expr, vars=("x", "y"), globals=None, locals=None)
Definition: svgfig.py:598
mps_fire.Path
Path
Definition: mps_fire.py:298
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
update
#define update(a, b)
Definition: TrackClassifier.cc:10
svgfig.funcRtoR2
def funcRtoR2(expr, var="t", globals=None, locals=None)
Definition: svgfig.py:1469