LSSTApplications  12.1-5-gbdcc3ab,15.0+10,15.0+19,15.0-1-g19261fa+10,15.0-1-g60afb23+19,15.0-1-g615e0bb+11,15.0-1-g6668b0b+6,15.0-1-g788a293+19,15.0-1-ga91101e+19,15.0-1-gae1598d+9,15.0-1-gd076f1f+17,15.0-1-gdf18595+3,15.0-1-gf4f1c34+9,15.0-10-g113cadf7+2,15.0-11-g5674e3b,15.0-2-g100d730+12,15.0-2-g20c4630+8,15.0-2-g35685a8+15,15.0-2-g5dfaa72+8,15.0-2-gf38729e+14,15.0-24-g02ed2a30c+2,15.0-3-g11fe1a0+3,15.0-3-g130a88a+2,15.0-3-g707930d+1,15.0-3-g9103c06+9,15.0-3-ga03b4ca+26,15.0-3-gaec6799+6,15.0-4-g32c2b40+2,15.0-4-g535e784+3,15.0-4-g654b129+17,15.0-5-g23e394c+7,15.0-5-g54bfcd9+2,15.0-5-gb31927c,15.0-6-g4418537+2,15.0-7-g0c26201,15.0-7-g6bb3a066+2,15.0-9-g5661f8f+4,w.2018.18
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.geom.geometry.SphericalBox Class Reference
Inheritance diagram for lsst.geom.geometry.SphericalBox:
lsst.geom.geometry.SphericalRegion

Public Member Functions

def __init__ (self, args)
 
def wraps (self)
 
def getBoundingBox (self)
 
def getMin (self)
 
def getMax (self)
 
def getThetaExtent (self)
 
def getCenter (self)
 
def isEmpty (self)
 
def isFull (self)
 
def containsPoint (self, p)
 
def contains (self, pointOrRegion)
 
def intersects (self, pointOrRegion)
 
def extend (self, pointOrRegion)
 
def shrink (self, box)
 
def setEmpty (self)
 
def setFull (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 

Static Public Member Functions

def edge (v1, v2, n)
 

Public Attributes

 min
 
 max
 

Detailed Description

A spherical coordinate space bounding box.

This is similar to a bounding box in cartesian space in that
it is specified by a pair of points; however, a spherical box may
correspond to the entire unit-sphere, a spherical cap, a lune or
the traditional rectangle. Additionally, spherical boxes can span
the 0/360 degree longitude angle discontinuity.

Note that points falling exactly on spherical box edges are
considered to be inside (contained by) the box.

Definition at line 371 of file geometry.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.geom.geometry.SphericalBox.__init__ (   self,
  args 
)
Creates a new spherical box. If no arguments are supplied, then
an empty box is created. If the arguments consist of a single
SphericalRegion, then a copy of its bounding box is created.
Otherwise, the arguments must consist of a pair of 2 (spherical)
or 3 (cartesian 3-vector) element coordinate tuples/lists that
specify the minimum/maximum longitude/latitude angles for the box.
Latitude angles must be within [-90, 90] degrees, and the minimum
latitude angle must be less than or equal to the maximum. If both
minimum and maximum longitude angles lie in the range [0.0, 360.0],
then the maximum can be less than the minimum. For example, a box
with min/max longitude angles of 350/10 deg spans the longitude angle
ranges [350, 360) and [0, 10]. Otherwise, the minimum must be less
than or equal to the maximum, though values can be arbitrary. If
the two are are separated by 360 degrees or more, then the box
spans longitude angles [0, 360). Otherwise, both values are range
reduced. For example, a spherical box with min/max longitude angles
specified as 350/370 deg spans longitude angle ranges [350, 360) and
[0, 10].

Definition at line 384 of file geometry.py.

384  def __init__(self, *args):
385  """
386  Creates a new spherical box. If no arguments are supplied, then
387  an empty box is created. If the arguments consist of a single
388  SphericalRegion, then a copy of its bounding box is created.
389  Otherwise, the arguments must consist of a pair of 2 (spherical)
390  or 3 (cartesian 3-vector) element coordinate tuples/lists that
391  specify the minimum/maximum longitude/latitude angles for the box.
392  Latitude angles must be within [-90, 90] degrees, and the minimum
393  latitude angle must be less than or equal to the maximum. If both
394  minimum and maximum longitude angles lie in the range [0.0, 360.0],
395  then the maximum can be less than the minimum. For example, a box
396  with min/max longitude angles of 350/10 deg spans the longitude angle
397  ranges [350, 360) and [0, 10]. Otherwise, the minimum must be less
398  than or equal to the maximum, though values can be arbitrary. If
399  the two are are separated by 360 degrees or more, then the box
400  spans longitude angles [0, 360). Otherwise, both values are range
401  reduced. For example, a spherical box with min/max longitude angles
402  specified as 350/370 deg spans longitude angle ranges [350, 360) and
403  [0, 10].
404  """
405  if len(args) == 0:
406  self.setEmpty()
407  return
408  elif len(args) == 1:
409  if isinstance(args[0], SphericalRegion):
410  bbox = args[0].getBoundingBox()
411  self.min = tuple(bbox.getMin())
412  self.max = tuple(bbox.getMax())
413  return
414  args = args[0]
415  if len(args) == 2:
416  self.min = sphericalCoords(args[0])
417  self.max = sphericalCoords(args[1])
418  else:
419  raise TypeError('Expecting a spherical region, 2 points, '
420  'or a tuple/list containing 2 points')
421  if self.min[1] > self.max[1]:
422  raise RuntimeError(
423  'Latitude angle minimum is greater than maximum')
424  if (self.max[0] < self.min[0] and
425  (self.max[0] < 0.0 or self.min[0] > 360.0)):
426  raise RuntimeError(
427  'Longitude angle minimum is greater than maximum')
428  # Range-reduce longitude angles
429  if self.max[0] - self.min[0] >= 360.0:
430  self.min = (0.0, self.min[1])
431  self.max = (360.0, self.max[1])
432  else:
433  self.min = (reduceTheta(self.min[0]), self.min[1])
434  self.max = (reduceTheta(self.max[0]), self.max[1])
435 
def sphericalCoords(args)
Definition: geometry.py:108
def __init__(self, minimum, dataRange, Q)
Definition: rgb.py:414
def reduceTheta(theta)
Definition: geometry.py:194

Member Function Documentation

◆ __eq__()

def lsst.geom.geometry.SphericalBox.__eq__ (   self,
  other 
)

Definition at line 732 of file geometry.py.

732  def __eq__(self, other):
733  if isinstance(other, SphericalBox):
734  if self.isEmpty() and other.isEmpty():
735  return True
736  return self.min == other.min and self.max == other.max
737  return False
738 

◆ __hash__()

def lsst.geom.geometry.SphericalBox.__hash__ (   self)

Definition at line 739 of file geometry.py.

739  def __hash__(self):
740  return hash((self.min, self.max))
741 

◆ __repr__()

def lsst.geom.geometry.SphericalBox.__repr__ (   self)
Returns a string representation of this spherical box.

Definition at line 724 of file geometry.py.

724  def __repr__(self):
725  """Returns a string representation of this spherical box.
726  """
727  if self.isEmpty():
728  return ''.join([self.__class__.__name__, '(', ')'])
729  return ''.join([self.__class__.__name__, '(',
730  repr(self.min), ', ', repr(self.max), ')'])
731 

◆ contains()

def lsst.geom.geometry.SphericalBox.contains (   self,
  pointOrRegion 
)
Returns True if this spherical box completely contains the given
point or spherical region. Note that the implementation is
conservative where ellipses are concerned: False may be returned
for an ellipse that is actually completely contained in this box.

Definition at line 503 of file geometry.py.

503  def contains(self, pointOrRegion):
504  """Returns True if this spherical box completely contains the given
505  point or spherical region. Note that the implementation is
506  conservative where ellipses are concerned: False may be returned
507  for an ellipse that is actually completely contained in this box.
508  """
509  if self.isEmpty():
510  return False
511  if isinstance(pointOrRegion, SphericalRegion):
512  b = pointOrRegion.getBoundingBox()
513  if b.isEmpty():
514  return False
515  if b.min[1] < self.min[1] or b.max[1] > self.max[1]:
516  return False
517  if self.wraps():
518  if b.wraps():
519  return b.min[0] >= self.min[0] and b.max[0] <= self.max[0]
520  else:
521  return b.min[0] >= self.min[0] or b.max[0] <= self.max[0]
522  else:
523  if b.wraps():
524  return self.min[0] == 0.0 and self.max[0] == 360.0
525  else:
526  return b.min[0] >= self.min[0] and b.max[0] <= self.max[0]
527  else:
528  return self.containsPoint(sphericalCoords(pointOrRegion))
529 
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
def sphericalCoords(args)
Definition: geometry.py:108

◆ containsPoint()

def lsst.geom.geometry.SphericalBox.containsPoint (   self,
  p 
)
Returns True if this spherical box contains the given point,
which must be specified in spherical coordinates.

Definition at line 491 of file geometry.py.

491  def containsPoint(self, p):
492  """Returns True if this spherical box contains the given point,
493  which must be specified in spherical coordinates.
494  """
495  if p[1] < self.min[1] or p[1] > self.max[1]:
496  return False
497  theta = reduceTheta(p[0])
498  if self.wraps():
499  return theta >= self.min[0] or theta <= self.max[0]
500  else:
501  return theta >= self.min[0] and theta <= self.max[0]
502 
def reduceTheta(theta)
Definition: geometry.py:194

◆ edge()

def lsst.geom.geometry.SphericalBox.edge (   v1,
  v2,
  n 
)
static
Returns a spherical bounding box for the great circle edge
connecting v1 to v2 with plane normal n. All arguments must be
cartesian unit vectors.

Definition at line 743 of file geometry.py.

743  def edge(v1, v2, n):
744  """Returns a spherical bounding box for the great circle edge
745  connecting v1 to v2 with plane normal n. All arguments must be
746  cartesian unit vectors.
747  """
748  theta1, phi1 = sphericalCoords(v1)
749  theta2, phi2 = sphericalCoords(v2)
750  # Compute latitude angle range of the edge
751  minPhi = min(phi1, phi2)
752  maxPhi = max(phi1, phi2)
753  d = n[0] * n[0] + n[1] * n[1]
754  if abs(d) > MIN_FLOAT:
755  # compute the 2 (antipodal) latitude angle extrema of n
756  if abs(n[2]) <= SIN_MIN:
757  ex = (0.0, 0.0, -1.0)
758  else:
759  ex = (n[0] * n[2] / d, n[1] * n[2] / d, -d)
760  # check whether either extremum is inside the edge
761  if between(ex, n, v1, v2):
762  minPhi = min(minPhi, sphericalCoords(ex)[1])
763  ex = (-ex[0], -ex[1], -ex[2])
764  if between(ex, n, v1, v2):
765  maxPhi = max(maxPhi, sphericalCoords(ex)[1])
766  # Compute longitude angle range of the edge
767  if abs(n[2]) <= SIN_MIN:
768  # great circle is very close to a pole
769  d = min(abs(theta1 - theta2), abs(360.0 - theta1 + theta2))
770  if d >= 90.0 and d <= 270.0:
771  # d is closer to 180 than 0/360: edge crosses over a pole
772  minTheta = 0.0
773  maxTheta = 360.0
774  else:
775  # theta1 and theta2 are nearly identical
776  minTheta = min(theta1, theta2)
777  maxTheta = max(theta1, theta2)
778  if maxTheta - minTheta > 180.0:
779  # min/max on opposite sides of 0/360
780  # longitude angle discontinuity
781  tmp = maxTheta
782  maxTheta = minTheta
783  minTheta = tmp
784  elif n[2] > 0.0:
785  minTheta = theta1
786  maxTheta = theta2
787  else:
788  minTheta = theta2
789  maxTheta = theta1
790  # return results
791  return SphericalBox((minTheta, minPhi), (maxTheta, maxPhi))
792 
793 
Angle abs(Angle const &a)
Definition: Angle.h:106
int min
Definition: Coord.cc:82
def sphericalCoords(args)
Definition: geometry.py:108
int max
Definition: BoundedField.cc:99
def between(p, n, v1, v2)
Definition: geometry.py:329

◆ extend()

def lsst.geom.geometry.SphericalBox.extend (   self,
  pointOrRegion 
)
Extends this box to the smallest spherical box S containing
the union of this box with the specified point or spherical region.

Definition at line 559 of file geometry.py.

559  def extend(self, pointOrRegion):
560  """Extends this box to the smallest spherical box S containing
561  the union of this box with the specified point or spherical region.
562  """
563  if self == pointOrRegion:
564  return self
565  if isinstance(pointOrRegion, SphericalRegion):
566  b = pointOrRegion.getBoundingBox()
567  if b.isEmpty():
568  return self
569  elif self.isEmpty():
570  self.min = tuple(b.min)
571  self.max = tuple(b.max)
572  minPhi = min(self.min[1], b.min[1])
573  maxPhi = max(self.max[1], b.max[1])
574  minTheta = self.min[0]
575  maxTheta = self.max[0]
576  if self.wraps():
577  if b.wraps():
578  minMinRa = min(self.min[0], b.min[0])
579  maxMaxRa = max(self.max[0], b.max[0])
580  if maxMaxRa >= minMinRa:
581  minTheta = 0.0
582  maxTheta = 360.0
583  else:
584  minTheta = minMinRa
585  maxTheta = maxMaxRa
586  else:
587  if b.min[0] <= self.max[0] and b.max[0] >= self.min[0]:
588  minTheta = 0.0
589  maxTheta = 360.0
590  elif b.min[0] - self.max[0] > self.min[0] - b.max[0]:
591  minTheta = b.min[0]
592  else:
593  maxTheta = b.max[0]
594  else:
595  if b.wraps():
596  if self.min[0] <= b.max[0] and self.max[0] >= b.min[0]:
597  minTheta = 0.0
598  maxTheta = 360.0
599  elif self.min[0] - b.max[0] > b.min[0] - self.max[0]:
600  maxTheta = b.max[0]
601  else:
602  minTheta = b.min[0]
603  else:
604  if b.min[0] > self.max[0]:
605  if (360.0 - b.min[0] + self.max[0] <
606  b.max[0] - self.min[0]):
607  minTheta = b.min[0]
608  else:
609  maxTheta = b.max[0]
610  elif self.min[0] > b.max[0]:
611  if (360.0 - self.min[0] + b.max[0] <
612  self.max[0] - b.min[0]):
613  maxTheta = b.max[0]
614  else:
615  minTheta = b.min[0]
616  else:
617  minTheta = min(self.min[0], b.min[0])
618  maxTheta = max(self.max[0], b.max[0])
619  self.min = (minTheta, minPhi)
620  self.max = (maxTheta, maxPhi)
621  else:
622  p = sphericalCoords(pointOrRegion)
623  theta, phi = reduceTheta(p[0]), p[1]
624  if self.containsPoint(p):
625  return self
626  elif self.isEmpty():
627  self.min = (theta, phi)
628  self.max = (theta, phi)
629  else:
630  minPhi = min(self.min[1], phi)
631  maxPhi = max(self.max[1], phi)
632  minTheta = self.min[0]
633  maxTheta = self.max[0]
634  if self.wraps():
635  if self.min[0] - theta > theta - self.max[0]:
636  maxTheta = theta
637  else:
638  minTheta = theta
639  elif theta < self.min[0]:
640  if self.min[0] - theta <= 360.0 - self.max[0] + theta:
641  minTheta = theta
642  else:
643  maxTheta = theta
644  elif theta - self.max[0] <= 360.0 - theta + self.min[0]:
645  maxTheta = theta
646  else:
647  minTheta = theta
648  self.min = (minTheta, minPhi)
649  self.max = (maxTheta, maxPhi)
650  return self
651 
int min
Definition: Coord.cc:82
def sphericalCoords(args)
Definition: geometry.py:108
int max
Definition: BoundedField.cc:99
def reduceTheta(theta)
Definition: geometry.py:194

◆ getBoundingBox()

def lsst.geom.geometry.SphericalBox.getBoundingBox (   self)
Returns a bounding box for this spherical region.

Definition at line 442 of file geometry.py.

442  def getBoundingBox(self):
443  """Returns a bounding box for this spherical region.
444  """
445  return self
446 

◆ getCenter()

def lsst.geom.geometry.SphericalBox.getCenter (   self)
Returns an 2-tuple of floats corresponding to the longitude/latitude
angles (in degrees) of the center of this spherical box.

Definition at line 467 of file geometry.py.

467  def getCenter(self):
468  """Returns an 2-tuple of floats corresponding to the longitude/latitude
469  angles (in degrees) of the center of this spherical box.
470  """
471  centerTheta = 0.5 * (self.min[0] + self.max[0])
472  centerPhi = 0.5 * (self.min[1] + self.max[1])
473  if self.wraps():
474  if centerTheta >= 180.0:
475  centerTheta -= 180.0
476  else:
477  centerTheta += 180.0
478  return (centerTheta, centerPhi)
479 

◆ getMax()

def lsst.geom.geometry.SphericalBox.getMax (   self)
Returns the maximum longitude and latitude angles of this
spherical box as a 2-tuple of floats (in units of degrees).

Definition at line 453 of file geometry.py.

453  def getMax(self):
454  """Returns the maximum longitude and latitude angles of this
455  spherical box as a 2-tuple of floats (in units of degrees).
456  """
457  return self.max
458 

◆ getMin()

def lsst.geom.geometry.SphericalBox.getMin (   self)
Returns the minimum longitude and latitude angles of this
spherical box as a 2-tuple of floats (in units of degrees).

Definition at line 447 of file geometry.py.

447  def getMin(self):
448  """Returns the minimum longitude and latitude angles of this
449  spherical box as a 2-tuple of floats (in units of degrees).
450  """
451  return self.min
452 

◆ getThetaExtent()

def lsst.geom.geometry.SphericalBox.getThetaExtent (   self)
Returns the extent in longitude angle of this box.

Definition at line 459 of file geometry.py.

459  def getThetaExtent(self):
460  """Returns the extent in longitude angle of this box.
461  """
462  if self.wraps():
463  return 360.0 - self.min[0] + self.max[0]
464  else:
465  return self.max[0] - self.min[0]
466 

◆ intersects()

def lsst.geom.geometry.SphericalBox.intersects (   self,
  pointOrRegion 
)
Returns True if this spherical box intersects the given point
or spherical region. Note that the implementation is conservative:
True may be returned for a region that does not actually intersect
this box.

Definition at line 530 of file geometry.py.

530  def intersects(self, pointOrRegion):
531  """Returns True if this spherical box intersects the given point
532  or spherical region. Note that the implementation is conservative:
533  True may be returned for a region that does not actually intersect
534  this box.
535  """
536  if self.isEmpty():
537  return False
538  if isinstance(pointOrRegion, SphericalBox):
539  b = pointOrRegion
540  if b.isEmpty():
541  return False
542  if b.min[1] > self.max[1] or b.max[1] < self.min[1]:
543  return False
544  if self.wraps():
545  if b.wraps():
546  return True
547  else:
548  return b.min[0] <= self.max[0] or b.max[0] >= self.min[0]
549  else:
550  if b.wraps():
551  return self.min[0] <= b.max[0] or self.max[0] >= b.min[0]
552  else:
553  return self.min[0] <= b.max[0] and self.max[0] >= b.min[0]
554  elif isinstance(pointOrRegion, SphericalRegion):
555  return pointOrRegion.intersects(self)
556  else:
557  return self.containsPoint(sphericalCoords(pointOrRegion))
558 
def sphericalCoords(args)
Definition: geometry.py:108

◆ isEmpty()

def lsst.geom.geometry.SphericalBox.isEmpty (   self)
Returns True if this spherical box contains no points.

Definition at line 480 of file geometry.py.

480  def isEmpty(self):
481  """Returns True if this spherical box contains no points.
482  """
483  return self.min[1] > self.max[1]
484 

◆ isFull()

def lsst.geom.geometry.SphericalBox.isFull (   self)
Returns True if this spherical box contains every point
on the unit sphere.

Definition at line 485 of file geometry.py.

485  def isFull(self):
486  """Returns True if this spherical box contains every point
487  on the unit sphere.
488  """
489  return self.min == (0.0, -90.0) and self.max == (360.0, 90.0)
490 

◆ setEmpty()

def lsst.geom.geometry.SphericalBox.setEmpty (   self)
Empties this spherical box.

Definition at line 710 of file geometry.py.

710  def setEmpty(self):
711  """Empties this spherical box.
712  """
713  self.min = (0.0, 90.0)
714  self.max = (0.0, -90.0)
715  return self
716 

◆ setFull()

def lsst.geom.geometry.SphericalBox.setFull (   self)
Expands this spherical box to fill the unit sphere.

Definition at line 717 of file geometry.py.

717  def setFull(self):
718  """Expands this spherical box to fill the unit sphere.
719  """
720  self.min = (0.0, -90.0)
721  self.max = (360.0, 90.0)
722  return self
723 

◆ shrink()

def lsst.geom.geometry.SphericalBox.shrink (   self,
  box 
)
Shrinks this box to the smallest spherical box containing
the intersection of this box and the specified one.

Definition at line 652 of file geometry.py.

652  def shrink(self, box):
653  """Shrinks this box to the smallest spherical box containing
654  the intersection of this box and the specified one.
655  """
656  b = box
657  if not isinstance(b, SphericalBox):
658  raise TypeError('Expecting a SphericalBox object')
659  if self == b or self.isEmpty():
660  return self
661  elif b.isEmpty():
662  return self.setEmpty()
663  minPhi = max(self.min[1], b.min[1])
664  maxPhi = min(self.max[1], b.max[1])
665  minTheta = self.min[0]
666  maxTheta = self.max[0]
667  if self.wraps():
668  if b.wraps():
669  minTheta = max(minTheta, b.min[0])
670  maxTheta = min(maxTheta, b.max[0])
671  else:
672  if b.max[0] >= minTheta:
673  if b.min[0] <= maxTheta:
674  if b.max[0] - b.min[0] <= 360.0 - minTheta + maxTheta:
675  minTheta = b.min[0]
676  maxTheta = b.max[0]
677  else:
678  minTheta = max(minTheta, b.min[0])
679  maxTheta = b.max[0]
680  elif b.min[0] <= maxTheta:
681  minTheta = b.min[0]
682  maxTheta = min(maxTheta, b.max[0])
683  else:
684  minPhi = 90.0
685  maxPhi = -90.0
686  else:
687  if b.wraps():
688  if maxTheta >= b.min[0]:
689  if minTheta <= b.max[0]:
690  if maxTheta - minTheta > 360.0 - b.min[0] + b.max[0]:
691  minTheta = b.min[0]
692  maxTheta = b.max[0]
693  else:
694  minTheta = max(minTheta, b.min[0])
695  elif minTheta <= b.max[0]:
696  maxTheta = b.max[0]
697  else:
698  minPhi = 90.0
699  maxPhi = -90.0
700  elif minTheta > b.max[0] or maxTheta < b.min[0]:
701  minPhi = 90.0
702  maxPhi = -90.0
703  else:
704  minTheta = max(minTheta, b.min[0])
705  maxTheta = min(maxTheta, b.max[0])
706  self.min = (minTheta, minPhi)
707  self.max = (maxTheta, maxPhi)
708  return self
709 
int min
Definition: Coord.cc:82
int max
Definition: BoundedField.cc:99

◆ wraps()

def lsst.geom.geometry.SphericalBox.wraps (   self)
Returns True if this spherical box wraps across the 0/360
degree longitude angle discontinuity.

Definition at line 436 of file geometry.py.

436  def wraps(self):
437  """Returns True if this spherical box wraps across the 0/360
438  degree longitude angle discontinuity.
439  """
440  return self.min[0] > self.max[0]
441 

Member Data Documentation

◆ max

lsst.geom.geometry.SphericalBox.max

Definition at line 412 of file geometry.py.

◆ min

lsst.geom.geometry.SphericalBox.min

Definition at line 411 of file geometry.py.


The documentation for this class was generated from the following file: