utils

anomaly_query_config.py

Globally defined and used variables for the JWQL query anomaly feature. Variables will be re-defined when anomaly query forms are submitted.

Authors

  • Teagan King

Use

This variables within this module are intended to be directly imported, e.g.:

from jwql.utils.query_config import CHOSEN_INSTRUMENTS

calculations.py

Various math-related functions used by the jwql instrument monitors.

Authors

  • Bryan Hilbert

Use

This module can be imported as such:

from jwql.utils import calculations
mean_val, stdev_val = calculations.mean_stdev(image, sigma_threshold=4)
jwql.utils.calculations.double_gaussian(x, amp1, peak1, sigma1, amp2, peak2, sigma2)[source]

Equate two Gaussians

Parameters:
xnumpy.ndarray

1D array of x values to be fit

paramslist

Gaussian coefficients [amplitude1, peak1, stdev1, amplitude2, peak2, stdev2]

jwql.utils.calculations.double_gaussian_fit(x_values, y_values, input_params)[source]

Fit two Gaussians to the given array

Parameters:
x_valuesnumpy.ndarray

1D array of x values to be fit

y_valuesnumpy.ndarray

1D array of y values to be fit

input_paramslist

Initial guesses for Gaussian coefficients [amplitude1, peak1, stdev1, amplitude2, peak2, stdev2]

Returns:
paramslist

Fitted parameter values

sigmanumpy.ndarray

Uncertainties on the parameters

jwql.utils.calculations.gaussian1d_fit(x_values, y_values, params)[source]

Fit 1D Gaussian to an array. Designed around fitting to histogram of pixel values.

Parameters:
x_valuesnumpy.ndarray

1D array of x values to be fit

y_valuesnumpy.ndarray

1D array of y values to be fit

Returns:
amplitudetup

Tuple of the best fit Gaussian amplitude and uncertainty

peaktup

Tuple of the best fit Gaussian peak position and uncertainty

widthtup

Tuple of the best fit Gaussian width and uncertainty

jwql.utils.calculations.mean_image(cube, sigma_threshold=3)[source]

Combine a stack of 2D images into a mean slope image, using sigma-clipping on a pixel-by-pixel basis

Parameters:
cubenumpy.ndarray

3D array containing a stack of 2D images

sigma_thresholdint

Number of sigma to use when sigma-clipping values in each pixel

Returns:
mean_imagenumpy.ndarray

2D sigma-clipped mean image

stdev_imagenumpy.ndarray

2D sigma-clipped standard deviation image

jwql.utils.calculations.mean_stdev(image, sigma_threshold=3)[source]

Calculate the sigma-clipped mean and stdev of an input array

Parameters:
imagenumpy.ndarray

Array of which to calculate statistics

sigma_thresholdfloat

Number of sigma to use when sigma-clipping

Returns:
mean_valuefloat

Sigma-clipped mean of image

stdev_valuefloat

Sigma-clipped standard deviation of image

constants.py

Globally defined and used variables for the jwql project.

Authors

  • Johannes Sahlmann

  • Matthew Bourque

  • Bryan Hilbert

  • Ben Sunnquist

  • Teagan King

Use

This variables within this module are intended to be directly imported, e.g.:

from jwql.utils.constants import JWST_INSTRUMENT_NAMES

References

Many variables were transferred from an earlier version of utils.py

crds_tools.py

This module contains functions used to indentify and download reference files from CRDS and place them in the expected location, for JWQL to find.

This module uses the crds software package (https://hst-crds.stsci.edu/static/users_guide/index.html) which is installed when the JWST calibration pipeline package is installed. Reference files are identified by supplying some basic metadata from the exposure being calibrated. See https://hst-crds.stsci.edu/static/users_guide/library_use.html#crds-getreferences for a description of the function used for this task.

Author

  • Bryan Hilbert

Use

This module can be used as such:

from mirage.reference_files import crds
params = {'INSTRUME': 'NIRCAM', 'DETECTOR': 'NRCA1'}
reffiles = crds.get_reffiles(params)
jwql.utils.crds_tools.dict_from_yaml(yaml_dict)[source]

Create a dictionary to be used as input to the CRDS getreferences function from the nested dictionary created when a standard Mirage input yaml file is read in.

Parameters:
yaml_dictdict

Nested dictionary from reading in yaml file

Returns
——-
crds_dictdict

Dictionary of information necessary to select refernce files via getreferences().

jwql.utils.crds_tools.env_variables()[source]

Check the values of the CRDS-related environment variables

Returns:
crds_data_pathstr

Full path to the location of the CRDS reference files

jwql.utils.crds_tools.get_reffiles(parameter_dict, reffile_types, download=True)[source]

Determine CRDS’s best reference files to use for a particular observation, and download them if they are not already present in the CRDS_PATH. The determination is made based on the information in the parameter_dictionary.

Parameters:
parameter_dictdict

Dictionary of basic metadata from the file to be processed by the returned reference files (e.g. INSTRUME, DETECTOR, etc)

reffile_typeslist

List of reference file types to look up and download. These must be contained in CRDS’s list of reference file types.

downloadbool

If True (default), the identified best reference files will be downloaded. If False, the dictionary of best reference files will still be returned, but the files will not be downloaded. The use of False is primarily intended to support testing on Travis.

Returns:
reffile_mappingdict

Mapping of downloaded CRDS file locations

jwql.utils.crds_tools.path_check()[source]

Check that the CRDS_PATH environment variable is set. This will be the location to which CRDS reference files are downloaded. If the env variable is not set, default to use $HOME/crds_cache/

Returns:
crds_pathstr

Full path to the location of the CRDS reference files

jwql.utils.crds_tools.server_check()[source]

Check that the CRDS_SERVER_URL environment variable is set. This controls where Mirage will look for CRDS information. If the env variable is not set, set it to the JWST CRDS server.

credentials.py

Utility functions related to accessing remote services and databases.

Authors

  • Johannes Sahlmann

  • Lauren Chambers

Use

This module can be imported as such:

import credentials
token = credentials.get_mast_token()
jwql.utils.credentials.get_mast_token(request=None)[source]

Return MAST token from either Astroquery.Mast, webpage cookies, the JWQL configuration file, or an environment variable.

Parameters:
requestHttpRequest object

Incoming request from the webpage

Returns:
tokenstr or None

User-specific MAST token string, if available

instrument_properties.py

Collection of functions dealing with retrieving/calculating various instrument properties

Authors

  • Bryan Hilbert

Uses

This module can be imported and used as such:

from jwql.utils import instrument_properties as inst
amps = inst.amplifier_info('my_files.fits')
jwql.utils.instrument_properties.amplifier_info(filename, omit_reference_pixels=True)[source]

Calculate the number of amplifiers used to collect the data in a given file using the array size and exposure time of a single frame (This is needed because there is no header keyword specifying how many amps were used.)

Parameters:
filenamestr

Name of fits file to investigate

omit_reference_pixelsbool

If True, return the amp boundary coordinates excluding reference pixels

Returns:
num_ampsint

Number of amplifiers used to read out the data

amp_boundsdict

Dictionary of amplifier boundary coordinates. Keys are strings of the amp number (1-4). Each value is a list composed of two tuples. The first tuple gives the coordinates of the (minimum x, maximum x, and x step value), and the second tuple gives the (minimum y, maximum y, and y step value). These are set up such that a list of indexes for each amplifier can be generated by using np.mgrid[x_min: x_max: x_step, y_min: y_max: y_step]

jwql.utils.instrument_properties.calc_frame_time(instrument, aperture, xdim, ydim, amps, sample_time=1e-05)[source]

Calculate the readout time for a single frame of a given size and number of amplifiers. Note that for NIRISS and FGS, the fast readout direction is opposite to that in NIRCam, so we switch xdim and ydim so that we can keep a single equation.

Parameters:
instrumentstr

Name of the instrument being simulated

aperturestr

Name of aperture being simulated (e.g NRCA1_FULL). Currently this is only used to check for the FGS ACQ1 aperture, which uses a unique value of colpad below.

xdimint

Number of columns in the frame

ydimint

Number of rows in the frame

ampsint

Number of amplifiers used to read out the frame

sample_timefloat

Time to sample a pixel, in seconds. For NIRCam/NIRISS/FGS this is 10 microseconds = 1e-5 seconds

Returns:
frametimefloat

Readout time in seconds for the frame

jwql.utils.instrument_properties.get_obstime(filename)[source]

Extract the observation date and time from a fits file

Parameters:
filenamestr

Name of fits file

Returns:
obs_timedatetime.datetime

Observation date and time

jwql.utils.instrument_properties.mean_time(times)[source]

Given a list of datetime objects, calculate the mean time

Parameters ———_ times : list

List of datetime objects

Returns:
meantime ; datetime.datetime

Mean time of the input times

logging_functions.py

Logging functions for the jwql automation platform.

This module provides decorators to log the execution of modules. Log files are written to the logs/ directory in the jwql central storage area, named by module name and timestamp, e.g. monitor_filesystem/monitor_filesystem_2018-06-20-15:22:51.log

Authors

  • Catherine Martlin

  • Alex Viana (wfc3ql Version)

  • Matthew Bourque

  • Jason Neal

Use

To log the execution of a module, use:

import os
import logging

from jwql.logging.logging_functions import configure_logging
from jwql.logging.logging_functions import log_info
from jwql.logging.logging_functions import log_fail

@log_info
@log_fail
def my_main_function():
    pass

if __name__ == '__main__':

    module = os.path.basename(__file__).replace('.py', '')
    configure_logging(module)

    my_main_function()

Dependencies

The user must have a configuration file named config.json placed in the jwql directory and it must contain keys for log_dir and admin_account.

References

This code is adopted and updated from python routine logging_functions.py written by Alex Viana, 2013 for the WFC3 Quicklook automation platform.

jwql.utils.logging_functions.configure_logging(module)[source]

Configure the log file with a standard logging format.

Parameters:
modulestr

The name of the module being logged.

production_modebool

Whether or not the output should be written to the production environement.

pathstr

Where to write the log if user-supplied path; default to working dir.

Returns:
log_filestr

The path to the file where the log is written to.

jwql.utils.logging_functions.get_log_status(log_file)[source]

Returns the end status of the given log_file (i.e. SUCCESS or FAILURE)

Parameters:
log_filestr

The path to the file where the log is written to

Returns:
statusbool

The status of the execution of the script described by the log file (i.e. SUCCESS or FAILURE)

jwql.utils.logging_functions.log_fail(func)[source]

Decorator to log crashes in the decorated code.

Parameters:
funcfunc

The function to decorate.

Returns:
wrappedfunc

The wrapped function.

jwql.utils.logging_functions.log_info(func)[source]

Decorator to log useful system information.

This function can be used as a decorator to log user environment and system information. Future packages we want to track can be added or removed as necessary.

Parameters:
funcfunc

The function to decorate.

Returns:
wrappedfunc

The wrapped function.

jwql.utils.logging_functions.log_timing(func)[source]

Decorator to time a module or function within a code.

Parameters:
funcfunc

The function to time.

Returns:
wrappedfunc

The wrapped function. Will log the time.

jwql.utils.logging_functions.make_log_file(module)[source]

Create the log file name based on the module name.

The name of the log_file is a combination of the name of the module being logged and the current datetime.

Parameters:
modulestr

The name of the module being logged.

production_modebool

Whether or not the output should be written to the production environment.

pathstr

Where to write the log if user-supplied path; default to working dir.

Returns:
log_filestr

The full path to where the log file will be written to.

mast_utils.py

Various utility functions for interacting with MAST

Authors

  • Bryan Hilbert

Use

This module can be imported as such:

>>> import mast_utils
results = mast_utils.mast_query('nircam', 'NRCA1_FULL', 'NRC_DARK', 53005.1, 53005.2)
jwql.utils.mast_utils.mast_query(instrument, templates, start_date, end_date, aperture=None, detector=None, filter_name=None, pupil=None, grating=None, readpattern=None, lamp=None)[source]

Use astroquery to search MAST for data for given observation templates over a given time range

Parameters:
instrumentstr

Instrument name (e.g. nircam)

templatesstr or list

Single, or list of, templates for the query (e.g. NRC_DARK, MIR_FLATMRS)

start_datefloat

Starting date for the search in MJD

end_datefloat

Ending date for the search in MJD

aperturestr

Detector aperture to search for (e.g. NRCA1_FULL)

detectorstr

Detector name (e.g. MIRIMAGE)

filter_namestr

Fitler element (e.g. F200W)

pupilstr

Pupil element (e.g. F323N)

gratingstr

Grating element (e.g. MIRROR)

readpatternstr

Detector read out pattern (e.g. NISRAPID)

lampstr

Lamp name (e.g. LINE2)

Returns:
query_resultslist

List of dictionaries containing the query results

jwql.utils.mast_utils.mast_query_miri(detector, aperture, templates, start_date, end_date)[source]

Use astroquery to search MAST for data for given observation templates over a given time range for MIRI. MIRI is different than the other instruments in that (to find full frame flats and darks at least) you need to use the detector name rather than the aperture name. There is no full frame aperture name for the MRS detectors.

Parameters:
detectorstr

Name of the detector to search for. One of MIRIMAGE, MIRIFULONG, MIRIFUSHORT.

aperturestr

Aperture name on the detector (e.g. MIRIM_FULL)

templatesstr or list

Single, or list of, templates for the query (e.g. NRC_DARK, MIR_FLATMRS)

start_datefloat

Starting date for the search in MJD

end_datefloat

Ending date for the search in MJD

Returns:
query_resultslist

List of dictionaries containing the query results

monitor_template.py

This module is intended to be a template to aid in creating new monitoring scripts and to demonstrate how to format them to fully utilize the jwql framework.

Each monitoring script must be executable from the command line (i.e. have a if '__name__' == '__main__' section), as well as have a “main” function that calls all other functions, methods, or modules (i.e. the entirety of the code is executed within the scope of the main function), as shown in this example.

Users may utilize the jwql framework functions for logging, setting permissions, parsing filenames, etc. (See related ``import``s).

Authors

  • Catherine Martlin

  • Matthew Bourque

Use

This module can be executed from the command line:

python monitor_template.py

Alternatively, it can be called from a python environment via the following import statements:

from monitor_template import main_monitor_function
from monitor_template import secondary_function

Dependencies

The user must have a configuration file named config.json placed in the jwql directory.

Notes

Any monitoring script written for jwql must adhere to the jwql style guide located at: https://github.com/spacetelescope/jwql/blob/main/style_guide/README.md

jwql.utils.monitor_template.monitor_template_main()[source]

The main function of the monitor_template module.

jwql.utils.monitor_template.second_function(input_value)[source]

This is your axiliary function; you may have many of these.

Parameters:
input_valuestr

Some value to modify in the function.

Returns:
useful_resultstr

The result of modifying the input value.

monitor_utils.py

Various utility functions for instrument monitors

Authors

  • Matthew Bourque

  • Bryan Hilbert

Use

This module can be imported as such:

>>> import monitor_utils
settings = monitor_utils.update_monitor_table('dark_monitor')
jwql.utils.monitor_utils.initialize_instrument_monitor(module)[source]

Configures a log file for the instrument monitor run and captures the start time of the monitor

Parameters:
modulestr

The module name (e.g. dark_monitor)

Returns:
start_timedatetime object

The start time of the monitor

log_filestr

The path to where the log file is stored

jwql.utils.monitor_utils.update_monitor_table(module, start_time, log_file)[source]

Update the monitor database table with information about the instrument monitor run

Parameters:
modulestr

The module name (e.g. dark_monitor)

start_timedatetime object

The start time of the monitor

log_filestr

The path to where the log file is stored

organize_filesystem.py

This module takes a collection of JWST FITS files and moves the files into a MAST-data-cache-like filesystem.

The files that the module will process is provided by the old_filesysem key in the config.json file. The files will be moved into the directory provided by the filesystem key in the config.json file.

For example, the file <old_filesystem>/jw00312/jw00312002001_02102_00001_nrcb4_rateints.fits

will be placed in the directory <filesystem>/jw00312/jw00312002001/.

Authors

  • Matthew Bourque

Use

This module is intended to be executed via the command line as such:

python organize_filesystem.py
jwql.utils.organize_filesystem.organize_filesystem()[source]

The main function of the organize_filesystem module. See module docstrings for further details.

jwql.utils.organize_filesystem.revert_filesystem()[source]

Perform the opposite of organize_filesystem – this function will move files from a MAST-data-cache-like organization to the previous organization.

For example, the file <filesystem>/jw00312/jw00312002001/jw00312002001_02102_00001_nrcb4_rateints.fits` will be placed in the directory ``<old_filesystem>/jw00312/.

permissions.py

Permissions module for managing file permissions for jwql.

This module provides jwql with functions to inspect and set file permissions.

The module takes as input a path to a file or directory, checks whether the owner of the file is the jwql admin account, and if so, (1) set the permissions appropriately, and (2) set the group membership appropriately.

Authors

  • Johannes Sahlmann

Use

This module can be imported and used with

from jwql.permissions import permissions
permissions.set_permissions(pathname)

Required arguments:

pathname - Directory or file for which the default permissions should be set

Notes

Permissions are set and read using the stat module, see https://docs.python.org/3/library/stat.html

Below is a list with the relevant stat attribute names, integer, octal, and string representations.

stat_key stat_mode stat_mode_octal stat_mode_string
-------- --------- --------------- ----------------
S_IFPORT         0             0o0       ?---------
S_IFDOOR         0             0o0       ?---------
 S_IXOTH         1             0o1       ?--------x
 S_IWOTH         2             0o2       ?-------w-
 S_IROTH         4             0o4       ?------r--
 S_IRWXO         7             0o7       ?------rwx
 S_IXGRP         8            0o10       ?-----x---
 S_IWGRP        16            0o20       ?----w----
 S_IRGRP        32            0o40       ?---r-----
 S_IRWXG        56            0o70       ?---rwx---
 S_IEXEC        64           0o100       ?--x------
 S_IXUSR        64           0o100       ?--x------
 S_IWUSR       128           0o200       ?-w-------
S_IWRITE       128           0o200       ?-w-------
 S_IREAD       256           0o400       ?r--------
 S_IRUSR       256           0o400       ?r--------
 S_IRWXU       448           0o700       ?rwx------
 S_ISVTX       512          0o1000       ?--------T
 S_ISGID      1024          0o2000       ?-----S---
 S_ISUID      2048          0o4000       ?--S------
 S_IFIFO      4096             0o0       p---------
 S_IFCHR      8192             0o0       c---------
 S_IFDIR     16384             0o0       d---------
 S_IFBLK     24576             0o0       b---------
 S_IFREG     32768             0o0       ----------
 S_IFLNK     40960             0o0       l---------
S_IFSOCK     49152             0o0       s---------
 S_IFWHT     57344             0o0       w---------
jwql.utils.permissions.get_group_string(pathname)[source]

Return the group of pathname in string representation.

Parameters:
pathnamestr

Directory or file to be inspected.

Returns:
group_namestr

String representation of the group.

jwql.utils.permissions.get_owner_string(pathname)[source]

Return the owner of pathname in string representation.

Parameters:
pathnamestr

Directory or file to be inspected

Returns:
owner_namestr

String representation of the owner.

jwql.utils.permissions.has_permissions(pathname, owner='jwqladm', mode=488, group='jwql_dev')[source]

Return boolean indicating whether pathname has the specified owner, permission, and group scheme.

Parameters:
pathnamestr

Directory or file to be inspected

ownerstr

String representation of the owner

modeint

Integer representation of the permission mode, compatible with os.stat output

groupstr

String representation of the group

Returns:
booleanbool
jwql.utils.permissions.set_permissions(pathname, owner='jwqladm', mode=488, group='jwql_dev', verbose=False)[source]

Set mode and group of the file/directory identfied by pathname, if and only if it is owned by owner.

Parameters:
pathnamestr

Directory or file to be inspected

ownerstr

String representation of the owner

modeint

Integer representation of the permission mode, compatible with os.stat output

groupstr

String representation of the group

verbosebool

Boolean indicating whether verbose output is requested

jwql.utils.permissions.show_permissions(pathname)[source]

Verbose output showing group, user, and permission information for a directory or file.

Parameters:
pathnamestr

Directory or file to be inspected

jwql.utils.permissions.verify_path(pathname)[source]

Verify that pathname is either a directory or a file. If not, an error is raised.

Parameters:
pathnamestr

Directory or file to be inspected

plotting.py

This module is a collection of plotting functions that may be used across the jwql application.

Authors:

  • Joe Filippazzo

Use:

This module can be use as follows:

from jwql.utils import plotting
from pandas import DataFrame
data = DataFrame({'meow': {'foo': 12, 'bar': 23, 'baz': 2},
                  'mix': {'foo': 45, 'bar': 31, 'baz': 23},
                  'deliver': {'foo': 62, 'bar': 20, 'baz': 9}})
data = data.reset_index()
plt = plotting.bar_chart(data, 'index')
jwql.utils.plotting.bar_chart(dataframe, groupcol, datacols=None, **kwargs)[source]

Create a pie chart from a Pandas DataFrame

Parameters:
dataframepandas.DataFrame

A dataframe of values

groupcolstr

The name of the column with the group labels

datacolstr, sequence (optional)

The name or list of names of the column containing the data. In None, uses all columns except groupcol

Returns:
pltobj

The generated bokeh.figure object

preview_image.py

Create a preview image from a fits file containing an observation.

This module creates and saves a “preview image” from a fits file that contains a JWST observation. Data from the user-supplied extension of the file are read in, along with the PIXELDQ extension if present. For each integration in the exposure, the first group is subtracted from the final group in order to create a difference image. The lower and upper limits to be displayed are defined as the clip_percent and (1. - clip_percent) percentile signals. matplotlib is then used to display a linear- or log-stretched version of the image, with accompanying colorbar. The image is then saved.

Authors:

  • Bryan Hilbert

Use:

This module can be imported as such:

from jwql.preview_image.preview_image import PreviewImage
im = PreviewImage(my_file, "SCI")
im.clip_percent = 0.01
im.scaling = 'log'
im.output_format = 'jpg'
im.make_image()
class jwql.utils.preview_image.PreviewImage(filename, extension)[source]

An object for generating and saving preview images, used by generate_preview_images.

Attributes:
clip_percentfloat

The amount to sigma clip the input data by when scaling the preview image. Default is 0.01.

cmapstr

The colormap used by matplotlib in the preview image. Default value is viridis.

dataobj

The data used to generate the preview image.

dqobj

The DQ data used to generate the preview image.

filestr

The filename to generate the preview image from.

output_formatstr

The format to which the preview image is saved. Options are jpg and thumb

preview_output_directorystr or None

The output directory to which the preview image is saved.

scalingstr

The scaling used in the preview image. Default is log.

thumbnail_output_directorystr or None

The output directory to which the thumbnail is saved.

Methods

difference_image(data)

Create a difference image from the data

find_limits(data, pixmap, clipperc)

Find the min and max signal levels after clipping by clipperc

get_data(filename, ext)

Read in data from the given filename and ext

make_figure(image, integration_number, min_value, max_value, scale, maxsize, thumbnail)

Create the matplotlib figure

make_image(max_img_size)

Main function

save_image(fname, thumbnail)

Save the figure

difference_image(data)[source]

Create a difference image from the data. Use last group minus first group in order to maximize signal to noise. With 4D input, make a separate difference image for each integration.

Parameters:
dataobj

4D numpy ndarray array of floats

Returns:
resultobj

3D numpy ndarray containing the difference image(s) from the input exposure

find_limits(data, pixmap, clipperc)[source]

Find the minimum and maximum signal levels after clipping the top and bottom clipperc of the pixels.

Parameters:
dataobj

2D numpy ndarray of floats

pixmapobj

2D numpy ndarray boolean array of science pixel locations (True for science pixels, False for non-science pixels)

clippercfloat

Fraction of top and bottom signal levels to clip (e.g. 0.01 means to clip brightest and dimmest 1% of pixels)

Returns:
resultstuple

Tuple of floats, minimum and maximum signal levels

get_data(filename, ext)[source]

Read in the data from the given file and extension. Also find how many rows/cols of reference pixels are present.

Parameters:
filenamestr

Name of fits file containing data

extstr

Extension name to be read in

Returns:
dataobj

Science data from file. A 2-, 3-, or 4D numpy ndarray

dqobj

2D ndarray boolean map of reference pixels. Science pixels flagged as True and non-science pixels are False

make_figure(image, integration_number, min_value, max_value, scale, maxsize=8, thumbnail=False)[source]

Create the matplotlib figure of the image

Parameters:
imageobj

2D numpy ndarray of floats

integration_numberint

Integration number within exposure

min_valuefloat

Minimum value for display

max_valuefloat

Maximum value for display

scalestr

Image scaling (log, linear)

maxsizeint

Size of the longest dimension of the output figure (inches)

thumbnailbool

True to create a thumbnail image, False to create the full preview image

Returns:
resultobj

Matplotlib Figure object

make_image(max_img_size=8)[source]

The main function of the PreviewImage class.

save_image(fname, thumbnail=False)[source]

Save an image in the requested output format and sets the appropriate permissions

Parameters:
imageobj

A matplotlib figure object

fnamestr

Output filename

thumbnailbool

True if saving a thumbnail image, false for the full preview image.

utils.py

Various utility functions for the jwql project.

Authors

  • Matthew Bourque

  • Lauren Chambers

Use

This module can be imported as such:

>>> import utils
settings = get_config()

References

jwql.utils.utils.check_config_for_key(key)[source]

Check that the config.json file contains the specified key and that the entry is not empty

Parameters:
keystr

The configuration file key to verify

jwql.utils.utils.copy_files(files, out_dir)[source]

Copy a given file to a given directory. Only try to copy the file if it is not already present in the output directory.

Parameters:
fileslist

List of files to be copied

out_dirstr

Destination directory

Returns:
successlist

Files successfully copied (or that already existed in out_dir)

failedlist

Files that were not copied

jwql.utils.utils.download_mast_data(query_results, output_dir)[source]

Example function for downloading MAST query results. From MAST website (https://mast.stsci.edu/api/v0/pyex.html)

Parameters:
query_resultslist

List of dictionaries returned by a MAST query.

output_dirstr

Directory into which the files will be downlaoded

jwql.utils.utils.ensure_dir_exists(fullpath)[source]

Creates dirs from fullpath if they do not already exist.

jwql.utils.utils.filename_parser(filename)[source]

Return a dictionary that contains the properties of a given JWST file (e.g. program ID, visit number, detector, etc.).

Parameters:
filenamestr

Path or name of JWST file to parse

Returns:
filename_dictdict

Collection of file properties

Raises:
ValueError

When the provided file does not follow naming conventions

jwql.utils.utils.filesystem_path(filename, check_existence=True, search=None)[source]

Return the path to a given file in the filesystem.

The full path is returned if check_existence is True, otherwise only the path relative to the filesystem key in the config.json file is returned.

Parameters:
filenamestr

File to locate (e.g. jw86600006001_02101_00008_guider1_cal.fits)

check_existenceboolean

Check to see if the file exists in the expected lcoation

searchstr

A search term to use in a glob.glob statement if the full filename is unkown (e.g. *rate.fits). In this case, the first element of the list of returned values is chosen as the filename.

Returns:
full_pathstr

Full path to the given file, including filename

jwql.utils.utils.get_base_url()[source]

Return the beginning part of the URL to the jwql web app based on which user is running the software.

If the admin account is running the code, the base_url is assumed to be the production URL. If not, the base_url is assumed to be local.

Returns:
base_urlstr

The beginning part of the URL to the jwql web app

jwql.utils.utils.get_config()[source]

Return a dictionary that holds the contents of the jwql config file.

Returns:
settingsdict

A dictionary that holds the contents of the config file.

jwql.utils.utils.initialize_instrument_monitor(module)[source]

Configures a log file for the instrument monitor run and captures the start time of the monitor

Parameters:
modulestr

The module name (e.g. dark_monitor)

Returns:
start_timedatetime object

The start time of the monitor

log_filestr

The path to where the log file is stored

jwql.utils.utils.query_format(string)[source]

Take a string of format lower_case and change it to UPPER CASE

jwql.utils.utils.query_unformat(string)[source]

Take a string of format UPPER CASE and change it to UPPER_CASE