Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update to what 2.0 will look like

...

Code Block
languagepy
titleExample python code to pretty-print the scalar results and warnings
# print the scalar products with the correct units.
print("------------------\n     RESULTS    \n------------------")
for x in sorted(result["scalar"]):
    if isinstance(result["scalar"][x],float):
        basename = "{:20}: {:>10.3f}"
    else:
        basename = "{:20}: {}"

    if "time" in x:
        basename += " sec"
    elif "size" in x or "offset" in x:
        basename += " arcsec"
    elif "area" in x:  # checking this before background means the
                       # background_area will be given the correct units.
        basename += " pixel^2"
    elif "wavelength" in x:
        basename += " microns"
    elif ((("extracted" in x) or ("sky" in x)) or ("total" in x) or ("brightest" in x)) and ("integrations") not in x:
        basename += " e-/sec"
    elif "background" in x:
        basename += " MJy/sr"
    elif "cr_ramp_rate" in x:
        basename += " events/integration/pixel"
    else:
        pass
    print(basename.format(x,result["scalar"][x]))

if len(result['warnings']) > 0:
    print("----------------\n  WARNINGS  \n----------------")
    for x in result['warnings']:
        print("{:20}: {}".format(x,result['warnings'][x]))
print("------------------")

For formatted output identical to the JWST Webapp, use this code:

Code Block
languagepy
titleExample Python code (new)
from textwrap import wrap

report = result['web_report']
print("-"*30 + " RESULTS " + "-"*30)
for category in report:
    
    print("\033[1m" + category["category"] + "\033[0m")
    print('-'*len(category["category"]))
    for item in category["items"]:
        if "value" in item:
            namelist = wrap(item['name'], width=36, subsequent_indent="    ")
            if len(namelist) > 1:
                for i in range(len(namelist)-1):
                    print(f"{namelist[i]:<36}")
            if "indent" in item and item["indent"]:
                namelist[-1] = "    " + namelist[-1]
            print(f"{namelist[-1]:<36} {item['value']:>16} {item['unit']:<10}")
        else:
            print(f"{item['name']}")
    print()
print("-"*70)

if len(result['warnings']) > 0:
    print("----------------\n  WARNINGS  \n----------------")
    for x in result['warnings']:
        print("{:20}: {}".format(x,result['warnings'][x]))
print("------------------")