Skip to content

Commit

Permalink
Merge pull request spacetelescope#1490 from york-stsci/github_ci
Browse files Browse the repository at this point in the history
Moved ON_GITHUB_ACTIONS and ON_READTHEDOCS to constants.py
  • Loading branch information
mfixstsci committed Feb 19, 2024
2 parents f3a19b4 + 719ec4d commit 5805a60
Show file tree
Hide file tree
Showing 32 changed files with 176 additions and 259 deletions.
3 changes: 1 addition & 2 deletions jwql/database/database_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@
from jwql.utils.constants import ANOMALIES_PER_INSTRUMENT
from jwql.utils.constants import FILE_SUFFIX_TYPES
from jwql.utils.constants import JWST_INSTRUMENT_NAMES
from jwql.utils.constants import ON_GITHUB_ACTIONS
from jwql.utils.utils import get_config

ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')


# Monkey patch Query with data_frame method
@property
Expand Down
42 changes: 19 additions & 23 deletions jwql/edb/engineering_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@
from astroquery.mast import Mast
from bokeh.embed import components
from bokeh.layouts import column
from bokeh.models import BoxAnnotation, ColumnDataSource, DatetimeTickFormatter, HoverTool, Range1d
from bokeh.models import BoxAnnotation, ColumnDataSource, DatetimeTickFormatter, HoverTool
from bokeh.models import Range1d
from bokeh.plotting import figure, output_file, show, save
import numpy as np

from jwst.lib.engdb_tools import ENGDB_Service
from jwql.utils.constants import MIRI_POS_RATIO_VALUES
from jwql.utils.constants import ON_GITHUB_ACTIONS
from jwql.utils.credentials import get_mast_base_url, get_mast_token
from jwql.utils.utils import get_config

MAST_EDB_MNEMONIC_SERVICE = 'Mast.JwstEdb.Mnemonics'
MAST_EDB_DICTIONARY_SERVICE = 'Mast.JwstEdb.Dictionary'

# Temporary until JWST operations: switch to test string for MAST request URL
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
if not ON_GITHUB_ACTIONS:
Mast._portal_api_connection.MAST_REQUEST_URL = get_config()['mast_request_url']

Expand Down Expand Up @@ -283,7 +283,7 @@ def __mul__(self, mnem):
before = np.where(common_dates == self.data['dates'][block])[0]

if len(before) > 0:
new_blocks.append(before[0]) # + 1)
new_blocks.append(before[0]) # + 1)
except IndexError:
# The final block value is usually equal to the length of the array, and will
# therefore cause an Index Error in the lines above. Ignore that error here.
Expand Down Expand Up @@ -421,7 +421,7 @@ def block_stats(self, sigma=3, ignore_vals=[], ignore_edges=False, every_change=
# calculated, remove those every change values and block values from the EdbMnemonic
# instance.
if every_change:
if len(remove_change_indexes) > 0:
if len(remove_change_indexes) > 0:
self.every_change_values = np.delete(self.every_change_values, remove_change_indexes)
self.blocks = np.delete(self.blocks, remove_change_indexes)

Expand All @@ -439,7 +439,7 @@ def block_stats(self, sigma=3, ignore_vals=[], ignore_edges=False, every_change=
stdevs.append(stdevval)
maxs.append(meanval)
mins.append(meanval)
#if hasattr(self, 'every_change_values'):
# if hasattr(self, 'every_change_values'):
# updated_every_change_vals.append(self.every_change_values[i + 1])
self.mean = means
self.median = medians
Expand Down Expand Up @@ -510,9 +510,9 @@ def block_stats_filter_positions(self, sigma=5):
self.data["euvalues"].data[index:self.blocks[i + 1]],
sigma=sigma)
if np.isfinite(meanval):
#this is preventing the nans above from being added. not sure what to do here.
#bokeh cannot deal with nans. but we need entries in order to have the blocks indexes
#remain correct. but maybe we dont care about the block indexes after averaging
# this is preventing the nans above from being added. not sure what to do here.
# bokeh cannot deal with nans. but we need entries in order to have the blocks indexes
# remain correct. but maybe we dont care about the block indexes after averaging
medtimes.append(calc_median_time(self.data["dates"].data[index:self.blocks[i + 1]][good]))
means.append(meanval)
medians.append(medianval)
Expand All @@ -523,7 +523,7 @@ def block_stats_filter_positions(self, sigma=5):
# If there were blocks composed entirely of bad data, meaning no mean values were
# calculated, remove those every change values and block values from the EdbMnemonic
# instance.
if len(remove_change_indexes) > 0:
if len(remove_change_indexes) > 0:
self.every_change_values = np.delete(self.every_change_values, remove_change_indexes)
self.blocks = np.delete(self.blocks, remove_change_indexes)

Expand Down Expand Up @@ -690,37 +690,33 @@ def bokeh_plot(self, show_plot=False, savefig=False, out_dir='./', nominal_value
if plot_mean:
source_mean = ColumnDataSource(data={'mean_x': self.median_times, 'mean_y': self.mean})
mean_data = fig.scatter(x='mean_x', y='mean_y', line_width=1, line_color='orange', alpha=0.75, source=source_mean)
mean_hover_tool = HoverTool(tooltips=[('Mean', '@mean_y'),
('Date', '@mean_x{%d %b %Y %H:%M:%S}')
], mode='mouse', renderers=[mean_data])
mean_hover_tool = HoverTool(tooltips=[('Mean', '@mean_y'), ('Date', '@mean_x{%d %b %Y %H:%M:%S}')],
mode='mouse', renderers=[mean_data])
mean_hover_tool.formatters = {'@mean_x': 'datetime'}
fig.tools.append(mean_hover_tool)

if plot_median:
source_median = ColumnDataSource(data={'median_x': self.median_times, 'median_y': self.median})
median_data = fig.scatter(x='median_x', y='median_y', line_width=1, line_color='orangered', alpha=0.75, source=source_median)
median_hover_tool = HoverTool(tooltips=[('Median', '@median_y'),
('Date', '@median_x{%d %b %Y %H:%M:%S}')
], mode='mouse', renderers=[median_data])
median_hover_tool = HoverTool(tooltips=[('Median', '@median_y'), ('Date', '@median_x{%d %b %Y %H:%M:%S}')],
mode='mouse', renderers=[median_data])
median_hover_tool.formatters = {'@median_x': 'datetime'}
fig.tools.append(median_hover_tool)

# If the max and min arrays are to be plotted, create columndata sources for them as well
# If the max and min arrays are to be plotted, create columndata sources for them as well
if plot_max:
source_max = ColumnDataSource(data={'max_x': self.median_times, 'max_y': self.max})
max_data = fig.scatter(x='max_x', y='max_y', line_width=1, color='black', line_color='black', source=source_max)
max_hover_tool = HoverTool(tooltips=[('Max', '@max_y'),
('Date', '@max_x{%d %b %Y %H:%M:%S}')
], mode='mouse', renderers=[max_data])
max_hover_tool = HoverTool(tooltips=[('Max', '@max_y'), ('Date', '@max_x{%d %b %Y %H:%M:%S}')],
mode='mouse', renderers=[max_data])
max_hover_tool.formatters = {'@max_x': 'datetime'}
fig.tools.append(max_hover_tool)

if plot_min:
source_min = ColumnDataSource(data={'min_x': self.median_times, 'min_y': self.min})
min_data = fig.scatter(x='min_x', y='min_y', line_width=1, color='black', line_color='black', source=source_min)
minn_hover_tool = HoverTool(tooltips=[('Min', '@min_y'),
('Date', '@min_x{%d %b %Y %H:%M:%S}')
], mode='mouse', renderers=[min_data])
minn_hover_tool = HoverTool(tooltips=[('Min', '@min_y'), ('Date', '@min_x{%d %b %Y %H:%M:%S}')],
mode='mouse', renderers=[min_data])
min_hover_tool.formatters = {'@min_x': 'datetime'}
fig.tools.append(min_hover_tool)

Expand Down
10 changes: 2 additions & 8 deletions jwql/instrument_monitors/common_monitors/bad_pixel_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,13 @@
from jwql.shared_tasks.shared_tasks import only_one, run_pipeline, run_parallel_pipeline
from jwql.utils import crds_tools, instrument_properties, monitor_utils
from jwql.utils.constants import DARKS_BAD_PIXEL_TYPES, DARK_EXP_TYPES, FLATS_BAD_PIXEL_TYPES, FLAT_EXP_TYPES
from jwql.utils.constants import JWST_INSTRUMENT_NAMES, JWST_INSTRUMENT_NAMES_MIXEDCASE
from jwql.utils.constants import JWST_INSTRUMENT_NAMES, JWST_INSTRUMENT_NAMES_MIXEDCASE, ON_GITHUB_ACTIONS
from jwql.utils.constants import ON_READTHEDOCS
from jwql.utils.logging_functions import log_info, log_fail
from jwql.utils.mast_utils import mast_query
from jwql.utils.permissions import set_permissions
from jwql.utils.utils import copy_files, create_png_from_fits, ensure_dir_exists, get_config, filesystem_path

# Determine if the code is being run by Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')

# Determine if the code is being run as part of a Readthedocs build
ON_READTHEDOCS = False
if 'READTHEDOCS' in os.environ: # pragma: no cover
ON_READTHEDOCS = os.environ['READTHEDOCS']

if not ON_GITHUB_ACTIONS and not ON_READTHEDOCS:
from jwql.website.apps.jwql.monitor_pages.monitor_bad_pixel_bokeh import BadPixelPlots
Expand Down
34 changes: 13 additions & 21 deletions jwql/instrument_monitors/common_monitors/readnoise_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@
import crds
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt # noqa: E348 (comparison to true)
import numpy as np # noqa: E348 (comparison to true)
from pysiaf import Siaf # noqa: E348 (comparison to true)

# astroquery.mast import that depends on value of auth_mast
# this import has to be made before any other import of astroquery.mast
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')

# Determine if the code is being run as part of a Readthedocs build
ON_READTHEDOCS = False
if 'READTHEDOCS' in os.environ: # pragma: no cover
ON_READTHEDOCS = os.environ['READTHEDOCS']
import matplotlib.pyplot as plt # noqa: E402 (module level import not at top of file)
import numpy as np # noqa: E402 (module level import not at top of file)
from pysiaf import Siaf # noqa: E402 (module level import not at top of file)

from jwql.shared_tasks.shared_tasks import only_one, run_pipeline, run_parallel_pipeline # noqa: E402 (module level import not at top of file)
from jwql.instrument_monitors import pipeline_tools # noqa: E402 (module level import not at top of file)
from jwql.utils import instrument_properties, monitor_utils # noqa: E402 (module level import not at top of file)
from jwql.utils.constants import JWST_INSTRUMENT_NAMES, JWST_INSTRUMENT_NAMES_MIXEDCASE # noqa: E402 (module level import not at top of file)
from jwql.utils.constants import ON_GITHUB_ACTIONS, ON_READTHEDOCS # noqa: E402 (module level import not at top of file)
from jwql.utils.logging_functions import log_info, log_fail # noqa: E402 (module level import not at top of file)
from jwql.utils.monitor_utils import update_monitor_table # noqa: E402 (module level import not at top of file)
from jwql.utils.permissions import set_permissions # noqa: E402 (module level import not at top of file)
from jwql.utils.utils import ensure_dir_exists, filesystem_path, get_config, copy_files # noqa: E402 (module level import not at top of file)

if not ON_GITHUB_ACTIONS and not ON_READTHEDOCS:
# Need to set up django apps before we can access the models
Expand All @@ -67,15 +68,6 @@
# for this monitor
from jwql.website.apps.jwql.monitor_models.readnoise import * # noqa: E402 (module level import not at top of file)

from jwql.shared_tasks.shared_tasks import only_one, run_pipeline, run_parallel_pipeline # noqa: E348 (comparison to true)
from jwql.instrument_monitors import pipeline_tools # noqa: E348 (comparison to true)
from jwql.utils import instrument_properties, monitor_utils # noqa: E348 (comparison to true)
from jwql.utils.constants import JWST_INSTRUMENT_NAMES, JWST_INSTRUMENT_NAMES_MIXEDCASE # noqa: E348 (comparison to true)
from jwql.utils.logging_functions import log_info, log_fail # noqa: E348 (comparison to true)
from jwql.utils.monitor_utils import update_monitor_table # noqa: E348 (comparison to true)
from jwql.utils.permissions import set_permissions # noqa: E348 (comparison to true)
from jwql.utils.utils import ensure_dir_exists, filesystem_path, get_config, copy_files # noqa: E348 (comparison to true)


class Readnoise():
"""Class for executing the readnoise monitor.
Expand Down
3 changes: 1 addition & 2 deletions jwql/tests/test_api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

from jwql.utils.utils import get_base_url
from jwql.utils.constants import JWST_INSTRUMENT_NAMES
from jwql.utils.constants import ON_GITHUB_ACTIONS

# Determine if tests are being run on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')

urls = []

Expand Down
4 changes: 1 addition & 3 deletions jwql/tests/test_bad_pixel_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
from jwql.database.database_interface import FGSBadPixelQueryHistory, FGSBadPixelStats
from jwql.instrument_monitors.common_monitors import bad_pixel_monitor
from jwql.tests.resources import has_test_db

# Determine if tests are being run on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


def test_bad_map_to_list():
Expand Down
3 changes: 1 addition & 2 deletions jwql/tests/test_bias_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from jwql.instrument_monitors.common_monitors import bias_monitor
from jwql.tests.resources import has_test_db
from jwql.utils.utils import get_config

ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


def test_collapse_image():
Expand Down
3 changes: 1 addition & 2 deletions jwql/tests/test_cosmic_ray_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
from jwql.instrument_monitors.common_monitors.cosmic_ray_monitor import CosmicRay
from jwql.database.database_interface import MIRICosmicRayQueryHistory
from jwql.utils.utils import get_config

ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


def define_test_data(nints):
Expand Down
3 changes: 1 addition & 2 deletions jwql/tests/test_dark_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
from jwql.tests.resources import has_test_db
from jwql.utils.monitor_utils import mast_query_darks
from jwql.utils.utils import get_config

ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


def test_find_hot_dead_pixels():
Expand Down
30 changes: 12 additions & 18 deletions jwql/tests/test_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
import pandas as pd
import pytest

from jwql.utils.constants import ON_GITHUB_ACTIONS

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jwql.website.jwql_proj.settings")

# Skip testing this module if on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.website.apps.jwql import data_containers
from jwql.tests.resources import (
MockSessionFileAnomaly, MockSessionGroupAnomaly,
MockGetRequest, MockPostRequest)
from jwql.utils import constants
from jwql.website.apps.jwql import data_containers # noqa: E402 (module level import not at top of file)
from jwql.tests.resources import MockSessionFileAnomaly, MockSessionGroupAnomaly # noqa: E402 (module level import not at top of file)
from jwql.tests.resources import MockGetRequest, MockPostRequest # noqa: E402 (module level import not at top of file)
from jwql.utils import constants # noqa: E402 (module level import not at top of file)

if not ON_GITHUB_ACTIONS:
from jwql.utils.utils import get_config
from jwql.utils.utils import get_config # noqa: E402 (module level import not at top of file)


@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to django models.')
Expand Down Expand Up @@ -142,17 +142,10 @@ def test_get_all_proposals():
(['uncal', 'rate', 'bad'], {'bad'})),
(False, ['rate', 'uncal', 'bad'],
['uncal', 'rate', 'bad']),
(True,
['rate', 'uncal', 'bad',
'o006_crfints', 'o001_crf'],
(['uncal', 'rate', 'o001_crf',
'o006_crfints', 'bad'], {'bad'})),
(False,
['rate', 'uncal', 'bad',
'o006_crfints', 'o001_crf'],
['uncal', 'rate', 'o001_crf',
'o006_crfints', 'bad']),
])
(True, ['rate', 'uncal', 'bad', 'o006_crfints', 'o001_crf'],
(['uncal', 'rate', 'o001_crf', 'o006_crfints', 'bad'], {'bad'})),
(False, ['rate', 'uncal', 'bad', 'o006_crfints', 'o001_crf'],
['uncal', 'rate', 'o001_crf', 'o006_crfints', 'bad'])])
def test_get_available_suffixes(untracked, input_suffixes, expected):
result = data_containers.get_available_suffixes(
input_suffixes, return_untracked=untracked)
Expand Down Expand Up @@ -292,6 +285,7 @@ def test_get_anomaly_form_post_group(mocker):
assert update_mock.call_count == 2
"""


def test_get_dashboard_components():
request = MockPostRequest()

Expand Down
4 changes: 1 addition & 3 deletions jwql/tests/test_database_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
from jwql.database import database_interface as di
from jwql.tests.resources import has_test_db
from jwql.utils.utils import get_config

# Determine if tests are being run on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


@pytest.mark.skipif(ON_GITHUB_ACTIONS, reason='Requires access to development database server.')
Expand Down
12 changes: 5 additions & 7 deletions jwql/tests/test_edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import pytest

from jwql.edb import engineering_database as ed

# Determine if tests are being run on Github Actions
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
from jwql.utils.constants import ON_GITHUB_ACTIONS


def test_add():
Expand Down Expand Up @@ -243,8 +241,8 @@ def test_multiplication():
info['description'] = 'Voltage at some place'
mnemonic1 = ed.EdbMnemonic('TEST_VOLTAGE', Time('2021-12-18T07:20:00'), Time('2021-12-18T07:30:00'), tab, {}, info, blocks=blocks1)
mnemonic1.meta = {'Count': 1,
'TlmMnemonics': [{'TlmMnemonic': 'TEST_VOLTAGE',
'AllPoints': 1}]}
'TlmMnemonics': [{'TlmMnemonic': 'TEST_VOLTAGE',
'AllPoints': 1}]}

dates2 = np.array([datetime(2021, 12, 18, 7, n, 10) for n in range(20, 30)])
data2 = np.array([15, 15, 15, 19, 19, 19, 19, 19, 12, 12])
Expand All @@ -258,8 +256,8 @@ def test_multiplication():
info['description'] = 'Current at some place'
mnemonic2 = ed.EdbMnemonic('TEST_CURRENT', Time('2021-12-18T07:20:10'), Time('2021-12-18T07:30:10'), tab, {}, info, blocks=blocks2)
mnemonic2.meta = {'Count': 1,
'TlmMnemonics': [{'TlmMnemonic': 'TEST_CURRENT',
'AllPoints': 1}]}
'TlmMnemonics': [{'TlmMnemonic': 'TEST_CURRENT',
'AllPoints': 1}]}

prod = mnemonic1 * mnemonic2
assert np.allclose(prod.data["euvalues"].data,
Expand Down
Loading

0 comments on commit 5805a60

Please sign in to comment.