LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | List of all members
lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand Class Reference
Inheritance diagram for lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand:

Public Member Functions

def __init__ (self)
 
def get (self, var, x, y)
 
def invoke (self, args, fromTty)
 

Detailed Description

Print an Image

Definition at line 508 of file printers.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.__init__ (   self)

Definition at line 511 of file printers.py.

511  def __init__(self):
512  super(PrintImageCommand, self).__init__("show image",
513  gdb.COMMAND_DATA,
514  gdb.COMPLETE_SYMBOL)
515 

Member Function Documentation

◆ get()

def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.get (   self,
  var,
  x,
  y 
)

Definition at line 516 of file printers.py.

516  def get(self, var, x, y):
517  if False:
518  return var["operator()(int, int, bool)"](x, y, True)
519  else:
520  dimensions = var["_gilView"]["_dimensions"]
521  if x < 0 or x >= dimensions["x"] or y < 0 or y >= dimensions["y"]:
522  raise gdb.GdbError("Pixel (%d, %d) is out of range 0:%d, 0:%d" %
523  (x, y, dimensions["x"] - 1, dimensions["y"] - 1))
524 
525  pixels = var["_gilView"]["_pixels"]["_p"]
526  step = pixels["_step_fn"]["_step"] / \
527  var.type.template_argument(0).sizeof
528 
529  return pixels["m_iterator"][x + y*step]["_v0"]
530 

◆ invoke()

def lsst.gdb.afw.printers.GdbOptionParser.PrintImageCommand.invoke (   self,
  args,
  fromTty 
)

Definition at line 531 of file printers.py.

531  def invoke(self, args, fromTty):
532  self.dont_repeat()
533 
534  parser = GdbOptionParser(
535  "show image" + ("" if argparse else " <image> [<nx> [<ny>]]"))
536  parser.add_option("-a", "--all", action="store_true",
537  help="Display the whole image/mask")
538  parser.add_option("-c", "--center", type="str", nargs=2, default=(None, None,),
539  help="Center the output at (x, y)")
540  parser.add_option("-o", "--origin", type="str", nargs=2, default=(None, None,),
541  help="Print the region starting at (x, y)")
542  parser.add_option("-x", "--xy0", action="store_true",
543  help="Obey the image's (x0, y0)")
544  parser.add_option("-f", "--formatWidth", type="int",
545  default=8, help="Field width for values")
546  parser.add_option("-d", "--dataFmt", default="%.2f",
547  help="Format for values")
548 
549  if argparse:
550  parser.add_option(
551  "image", help="Expression giving image to show")
552  parser.add_option(
553  "width", help="Width of patch to print", default=1, nargs="?")
554  parser.add_option(
555  "height", help="Height of patch to print", default=1, nargs="?")
556 
557  opts = parser.parse_args(args)
558  if opts.help:
559  return
560  else:
561  opts, args = parser.parse_args(args)
562  if opts.help:
563  return
564 
565  if not args:
566  raise gdb.GdbError("Please specify an image")
567 
568  opts.image = args.pop(0)
569 
570  opts.width, opts.height = 1, 1
571  if args:
572  opts.width = int(args.pop(0))
573  if args:
574  opts.height = int(args.pop(0))
575 
576  if args:
577  raise gdb.GdbError(
578  "Unrecognised trailing arguments: %s" % " ".join(args))
579 
580  for i in range(2):
581  val = "0"
582  if opts.origin[i] is None:
583  if opts.center[i] is not None:
584  val = opts.center[i]
585  else:
586  val = opts.origin[i]
587  if opts.center[i] is not None:
588  raise gdb.GdbError(
589  "You may not specify both --center and --origin")
590 
591  val = gdb.parse_and_eval(val)
592  if i == 0:
593  x0 = val
594  else:
595  y0 = val
596 
597  if opts.all:
598  nx, ny = 0, 0
599  else:
600  nx, ny = opts.width, opts.height
601 
602  var = gdb.parse_and_eval(opts.image)
603 
604  if re.search(r"shared_ptr<", str(var.type)):
605  var = var["px"].dereference()
606 
607  if not re.search(r"(lsst::afw::image::)?(Image|Mask|MaskedImage)", str(var.type.unqualified())):
608  raise gdb.GdbError(
609  "Please specify an image, not %s" % var.type)
610 
611  if re.search(r"MaskedImage", str(var.type)) and \
612  not re.search(r"::Image(\s*&)?$", str(var.type)):
613  print("N.b. %s is a MaskedImage; showing image" % (opts.image))
614  var = var["_image"]
615 
616  if re.search(r"shared_ptr<", str(var.type)):
617  var = var["px"].dereference()
618 
619  if var.type.code == gdb.TYPE_CODE_PTR:
620  var = var.dereference() # be nice
621 
622  pixelTypeName = str(var.type.template_argument(0))
623  if opts.dataFmt:
624  dataFmt = opts.dataFmt
625  elif pixelTypeName in ["short", "unsigned short"]:
626  dataFmt = "0x%x"
627  elif pixelTypeName in ["int", "unsigned int"]:
628  dataFmt = "%d"
629  else:
630  dataFmt = "%.2f"
631 
632  if nx == 0:
633  nx = var["_gilView"]["_dimensions"]["x"]
634  if ny == 0:
635  ny = var["_gilView"]["_dimensions"]["y"]
636 
637  if opts.center[0]:
638  x0 -= nx//2
639  y0 -= ny//2
640 
641  if opts.xy0 and not opts.all:
642  arr = var["_origin"]["_vector"]["m_storage"]["m_data"]["array"]
643 
644  x0 -= arr[0]
645  y0 -= arr[1]
646  #
647  # OK, finally time to print
648  #
649  print("%-4s" % "", end=' ')
650  for x in range(x0, x0 + nx):
651  print("%*d" % (opts.formatWidth, x), end=' ')
652  print("")
653 
654  for y in reversed(list(range(y0, y0 + ny))):
655  print("%-4d" % y, end=' ')
656  for x in range(x0, x0 + nx):
657  print("%*s" % (opts.formatWidth, dataFmt %
658  self.get(var, x, y)), end=' ')
659  print("")
660 
661  PrintImageCommand()
daf::base::PropertyList * list
Definition: fits.cc:913

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