Skip to content

Commit

Permalink
Merge pull request #753 from kglotfelty/display_check
Browse files Browse the repository at this point in the history
check DISPLAY environment variable
  • Loading branch information
DougBurke authored Apr 21, 2023
2 parents ab8def2 + 19b9328 commit 3a3e7ee
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 18 deletions.
14 changes: 9 additions & 5 deletions bin/correct_periscope_drift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python

#
# Copyright (C) 2010, 2016, 2019, 2020 Smithsonian Astrophysical Observatory
#
#
# Copyright (C) 2010, 2016, 2019, 2020, 2023
# Smithsonian Astrophysical Observatory
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -45,7 +44,7 @@ from sherpa import plot


TOOLNAME = "correct_periscope_drift"
VERSION = "2 Feb 2021"
VERSION = "28 March 2023"

# Set up the logging/verbose code
initialize_logger(TOOLNAME)
Expand Down Expand Up @@ -527,6 +526,11 @@ def main(opt):
ax_data['yag'], ax_data['zag'] = get_event_yag_zag(evt_ra, evt_dec,
evt_ra_pnt, evt_dec_pnt, evt_roll_pnt)

if 'DISPLAY' not in os.environ or os.environ['DISPLAY'] == "":
if plot.backend.name == 'pylab':
import matplotlib as mpl
mpl.use('Agg')

# Store comments to print in block after all of the sherpa fit output
fit_comments = []
plot_list = []
Expand Down
14 changes: 10 additions & 4 deletions bin/deflare
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python

#
# Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021
# Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2023
# Smithsonian Astrophysical Observatory
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -40,7 +40,10 @@ import os
import sys

import matplotlib
matplotlib.interactive(True)
if 'DISPLAY' in os.environ and os.environ['DISPLAY'] != "":
matplotlib.interactive(True)
else:
matplotlib.use('Agg')

import paramio

Expand All @@ -52,7 +55,7 @@ from ciao_contrib.param_wrapper import open_param_file


toolname = "deflare"
__revision__ = "09 November 2021"
__revision__ = "28 March 2023"

initialize_logger(toolname)

Expand Down Expand Up @@ -124,6 +127,9 @@ def pause():

def wrapup(params, plot_stat):
"Let the user know what has happened."
from ciao_contrib.runtool import add_tool_history
add_tool_history(params["outfile"], toolname, params,
toolversion=__revision__)

labels = {"clean": "lc_clean", "sigma": "lc_sigma_clip",
"usigma": "lc_sigma_uclip"}
Expand Down
11 changes: 7 additions & 4 deletions bin/ecf_calc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Usage:
"""

toolname = "ecf_calc"
__revision__ = "13 November 2019"
__revision__ = "28 March 2023"

import numpy, tempfile, sys, os, paramio

Expand Down Expand Up @@ -69,7 +69,7 @@ def radii_set(radius,bin):


def pause():
input("Press ENTER to close the ChIPS window and exit:")
input("Press ENTER to close the plot window and exit:")


def get_par(argv):
Expand Down Expand Up @@ -357,8 +357,11 @@ def doit():
add_tool_history(outfile,toolname,params)

if plot:
plot_ecf(outfile)
pause()
if 'DISPLAY' not in os.environ or os.environ['DISPLAY'] == "":
sys.stderr.write("DISPLAY not set, skipping plot.\n")
else:
plot_ecf(outfile)
pause()


if __name__ == "__main__":
Expand Down
29 changes: 28 additions & 1 deletion color_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
"""

import os
from os.path import basename

import numpy as np

import matplotlib.pylab as plt
import matplotlib

from pycrates import set_key

Expand Down Expand Up @@ -640,10 +642,35 @@ def write(self, outfile, toolname="color_color"):
self._cr.write(outfile, clobber=True)

def plot(self, outfile=None):
""""Plot the color-color diagram -- now using matplotlib
Since this object contains a reference to the primary and
secondary parameters, you can set/change the curve and
label properties before plotting:
>>> matrix = cc(photon_index, absorption, soft, medium, hard, broad)
>>> photon_index.set_curve_style(marker="", color="green", linestyle="-", linewidth=2)
>>> photon_index.set_label_style(color="green")
>>> absorption.set_curve_style(marker="", color="black", linestyle="-.")
>>> absorption.set_label_style(color="black")
>>> matrix.plot()
"""

current_backend = matplotlib.get_backend()
if 'DISPLAY' not in os.environ or os.environ['DISPLAY'] == "":
matplotlib.use('Agg')

try:
self.__plot(outfile)
finally:
matplotlib.use(current_backend)


def __plot(self, outfile=None):
"""
Plot the color-color diagram -- now using matplotlib
Since this object contains a refernce to the primary and
Since this object contains a reference to the primary and
secondary parameters, you can set/change the curve and
label properties before plotting:
Expand Down
7 changes: 6 additions & 1 deletion share/doc/xml/color_color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ and so on. This provides a smoother curve.

</PARAMLIST>

<ADESC title="Changes in the scripts 4.15.2 (April 2023) release">
<PARA>
Updates to work when no DISPLAY is set.
</PARA>
</ADESC>

<ADESC title="About Contributed Software">
<PARA>
Expand All @@ -396,7 +401,7 @@ and so on. This provides a smoother curve.
</PARA>
</ADESC>

<LASTMODIFIED>January 2023</LASTMODIFIED>
<LASTMODIFIED>March 2023</LASTMODIFIED>

</ENTRY>
</cxchelptopics>
Expand Down
8 changes: 7 additions & 1 deletion share/doc/xml/correct_periscope_drift.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ Running tool dmhistory using:
</PARA>
</ADESC>

<ADESC title="Changes in the scripts 4.15.2 (April 2023) release">
<PARA>
Updated to work when no DISPLAY environment variable is set.
</PARA>
</ADESC>

<ADESC title="Changes in the scripts 4.12.2 (April 2020) release">
<PARA>
The script will now run when the verbose parameter is 0.
Expand Down Expand Up @@ -250,7 +256,7 @@ Running tool dmhistory using:
</PARA>
</ADESC>

<LASTMODIFIED>December 2022</LASTMODIFIED>
<LASTMODIFIED>March 2023</LASTMODIFIED>

</ENTRY>
</cxchelptopics>
13 changes: 12 additions & 1 deletion share/doc/xml/deflare.xml
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,17 @@
</ADESC>
-->

<ADESC title="Changes in the scripts 4.15.2 (April 2023) release">
<PARA title="HISTORY">
The script now records the parameter settings in HISTORY records
that can be retrieved using the dmhistory tool.
</PARA>
<PARA title="Display">
The script has been updated to work when there is no DISPLAY
environment variable.
</PARA>
</ADESC>

<ADESC title="Changes in the scripts 4.11.2 (April 2019) release">
<PARA title="Switched to matplotlib">
The plot is now generated with matplotlib rather than ChIPS,
Expand Down Expand Up @@ -666,7 +677,7 @@
</PARA>
</BUGS>

<LASTMODIFIED>December 2022</LASTMODIFIED>
<LASTMODIFIED>March 2023</LASTMODIFIED>

</ENTRY>
</cxchelptopics>
8 changes: 7 additions & 1 deletion share/doc/xml/ecf_calc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@
</DESC>
</PARAM>
</PARAMLIST>

<ADESC title="Changes in the 4.15.2 (April 2023) release">
<PARA>
Updated to skip plots if DISPLAY environment variable is not set.
</PARA>
</ADESC>

<ADESC title="Changes in the 4.11.4 (2019) release">
<PARA>
Expand Down Expand Up @@ -228,6 +234,6 @@
</PARA>
</BUGS>
//-->
<LASTMODIFIED>December 2022</LASTMODIFIED>
<LASTMODIFIED>March 2023</LASTMODIFIED>
</ENTRY>
</cxchelptopics>

0 comments on commit 3a3e7ee

Please sign in to comment.