Exemplo n.º 1
0
def test_step_from_commandline_par_precedence(command_line_pars,
                                              command_line_config_pars,
                                              reference_pars, expected_pars,
                                              tmp_path, monkeypatch):
    args = []

    class_name = "jwst.stpipe.tests.steps.WithDefaultsStep"
    config_name = "WithDefaultsStep"
    reference_type = f"pars-{config_name.lower()}"
    input_path = join(dirname(__file__), "data", "science.fits")

    if command_line_config_pars:
        command_line_config_path = tmp_path / "with_defaults_step.cfg"
        config = ConfigObj(str(command_line_config_path))
        config["class"] = class_name
        config["name"] = config_name
        for key, value in command_line_config_pars.items():
            config[key] = value
        config.write()
        args.append(str(command_line_config_path.absolute()))
    else:
        args.append(class_name)

    args.append(input_path)

    if command_line_pars:
        for key, value in command_line_pars.items():
            args.append(f"--{key}={value}")

    reference_file_map = {}
    if reference_pars:
        reference_path = tmp_path / f"{reference_type}.asdf"
        parameters = {
            "class": class_name,
            "name": config_name,
        }
        parameters.update(reference_pars)
        model = datamodels.StepParsModel({"parameters": parameters})
        model.save(reference_path)

        reference_file_map[reference_type] = str(reference_path)

    def mock_get_reference_file(dataset,
                                reference_file_type,
                                observatory=None,
                                asn_exptypes=None):
        if reference_file_type in reference_file_map:
            return reference_file_map[reference_file_type]
        else:
            raise CrdsLookupError(
                f"Error determining best reference for '{reference_file_type}'  = \
  Unknown reference type '{reference_file_type}'")

    monkeypatch.setattr(crds_client, "get_reference_file",
                        mock_get_reference_file)

    step = Step.from_cmdline(args)

    for key, value in expected_pars.items():
        assert getattr(step, key) == value
Exemplo n.º 2
0
def test_saving_pars(tmpdir):
    """Save the step parameters from the commandline"""
    cfg_path = t_path(join('steps',
                           'jwst_generic_pars-makeliststep_0002.asdf'))
    saved_path = tmpdir.join('savepars.asdf')
    Step.from_cmdline([cfg_path, '--save-parameters', str(saved_path)])
    assert saved_path.check()
    saved = datamodels.StepParsModel(str(saved_path))
    assert saved.parameters == ParsModelWithPar3.parameters
Exemplo n.º 3
0
import pytest
import jwst
from jwst import datamodels
from jwst.extern.configobj.configobj import ConfigObj
from jwst.refpix import RefPixStep
from jwst.stpipe import Step, crds_client
from jwst.stpipe import cmdline
from jwst.stpipe.config_parser import ValidationError

from .steps import EmptyPipeline, MakeListPipeline, MakeListStep, ProperPipeline
from .util import t_path

from crds.core.exceptions import CrdsLookupError

ParsModelWithPar3 = datamodels.StepParsModel(
    t_path(join('steps', 'jwst_generic_pars-makeliststep_0002.asdf')))
ParsModelWithPar3.parameters.instance.update({'par3': False})

REFPIXSTEP_CRDS_MIRI_PARS = {
    'class': jwst.refpix.refpix_step.RefPixStep,
    'name': 'refpix',
    'odd_even_columns': False,
    'odd_even_rows': False,
    'side_gain': 10.0,
    'side_smoothing_length': 21,
    'use_side_ref_pixels': False
}

CRDS_ERROR_STRING = 'PARS-WITHDEFAULTSSTEP: No parameters found'