Example scripts

For a default processing with standard parameters, it is recommended to use the method m_process_exposure(). It executes the pipeline in the configured way and extracts the spectra for a certain slit mode.

For all parameter that can be set for the pipeline run please have a look at the pipeline parameters class PipelineParameters that has to be initiated before the run, especially its setting method PipelineParameters.m_set().

Below are three scripts showing a typical usage of NIPS to obtain the spectra from different exposures for different modes: Fixed Slit (FS) observations, Multi Object Spectroscopy (MOS) observations, and Integral Field Spectroscopy (IFS) observations. All three wrappers take their main inputs from a dedicated config file. Those files are also included on this page.

Within the NIPS package, those scripts are located in nips/examples. It is advised to first copy the content of this directory to a local folder before continuing

If the config file is present with the right naming, calling the wrapper is simply:

> python p_extract_fs.py
> python p_extract_mos.py
> python p_extract_ifs.py

Note

Make sure that the paths in the config files point to the right archive and reference file repository

SLIT standard processing

Config File (extraction_config_fs.json):

{
  "output_path": "./",
  "archive_path": "/Volumes/CT1/Archive",
  "ref_path": "/Volumes/CT1/JWST-NIPS-REF_REPOS/nipsref",
  "nid": "3162",
  "env":"OTIS",
  "slitid": ["S200A1"],
  "steps": null
}

Wrapper (p_extract_fs.py):

#!/usr/bin/env python
#########################################################################
# IDENT         p_extract_fs_script.py
# LANGUAGE      Python 3.X
# AUTHOR        P.FERRUIT
# PURPOSE       Script to extract a FS spectrum from an exposure.
#
# 1.0.0 25.03.2018 PF Creation
# 1.0.1 24.09.2019 NL Update
#   1) Added qflags
# 1.0.2 05.02.2021 NL Update
#   1) Using os.path.expandvars() for the path input so
#      so that environment variables can be used.
#########################################################################
# =======================================================================
# Imports
# =======================================================================
import json
import os
import sys
import argparse
import datetime
import time

from nips.pipelines.pipeline import PipelineParameters, Pipeline
# =======================================================================
# Global variables
# =======================================================================
_name = 'p_extract_fs.py'
_version = '1.0.2'
mode = 'fs'
# =======================================================================
# Loading the input arguments
# =======================================================================
# Parsing the input arguments
parser = argparse.ArgumentParser()
parser.add_argument('-config', '--configFile', help='Name of configuration file to use.',
                    default='extraction_config_fs.json')
args = parser.parse_args()
argv = sys.argv
narg = len(argv)-1
print("=====================================")
print(argv[0])
print("Version: ", _version)
print(datetime.datetime.now().isoformat())
print("=====================================")

configuration_file = args.configFile
print("# Using configuration file: {:s}".format(configuration_file))
# =======================================================================
# Loading the input arguments
# =======================================================================
# Reading the configuration file
with open(configuration_file) as data_file:
    data = json.loads(data_file.read())
output_path = os.path.expandvars(data['output_path'])
archive_path = os.path.expandvars(data['archive_path'])
ref_path = os.path.expandvars(data['ref_path'])
nid  = data['nid']
env =  data['env']
slitid = data['slitid']
steps = data['steps']
mode = 'FS'
# Print Input
print("# Exposure unique ID: {:s}".format(nid))
print("# Environment: {:s}".format(env))
if slitid is None:
    print("# Slitid = None, Extracting all fixed slits!")
else:
    for si in slitid:
        print("# Fixed-slit ID: {:s}".format(si))
# =======================================================================
# Initializing the pipeline parameters
# =======================================================================
print("# Initialization of the pipeline")
t0 = time.time()
pl_parameters = PipelineParameters()
# =======================================================================
# Following lines are different use cases. Feel free to uncomment and try!
# =======================================================================
# Set the qflags (exclude hot pixel, shorted pixel and no linearity pixel)
qflags=[4,16,32768]
# Standard run where we give the shutters in the slitid keyword
pl_parameters.m_set(output_path, archive_path, ref_path, nid, env, mode,
                    slitid=slitid, steps=steps, qflags=qflags)
# =======================================================================
# Initializing the pipeline
# =======================================================================
pl = Pipeline()
pl.m_set(pl_parameters)
# =======================================================================
# Run the pipeline
# =======================================================================
pl.m_process_exposure()
# =======================================================================
# The end my friend, the end
# =======================================================================
print("# Script completed in {} minutes".format((time.time() - t0)/60.))

Back to top

MOS standard processing

Note

An example for a MSA config file is located in ./msaconfig. If you are using this option, set the slitid to null.

Config File (extraction_config_mos.json):

{
  "output_path": "./",
  "archive_path": "/Volumes/CT1/Archive",
  "ref_path": "/Volumes/CT1/JWST-NIPS-REF_REPOS/nipsref",
  "nid": "3162",
  "env":"OTIS",
  "slitid": ["[3,349,23]", "[3,349,21]"],
  "steps": null,
  "msafile": null
}

Wrapper (p_extract_mos.py):

#!/usr/bin/env python
#########################################################################
# IDENT         p_extract_mos_script.py
# LANGUAGE      Python 3.X
# AUTHOR        P.FERRUIT
# PURPOSE       Script to extract a MOS spectrum from an exposure.
#
# 1.0.0 25.03.2018 PF Creation
# 1.0.1 05.02.2021 NL Update
#   1) Using os.path.expandvars() for the path input so
#      so that environment variables can be used.
#########################################################################
# =======================================================================
# Imports
# =======================================================================
import json
import os
import sys
import argparse
import datetime
import time

from nips.pipelines.pipeline import PipelineParameters, Pipeline
# =======================================================================
# Global variables
# =======================================================================
_name = 'p_extract_mos.py'
_version = '1.0.1'
mode = 'mos'
# =======================================================================
# Loading the input arguments
# =======================================================================
# Parsing the input arguments
parser = argparse.ArgumentParser()
parser.add_argument('-config', '--configFile', help='Name of configuration file to use.',
                    default='extraction_config_mos.json')
args = parser.parse_args()
argv = sys.argv
narg = len(argv)-1
print("=====================================")
print(argv[0])
print("Version: ", _version)
print(datetime.datetime.now().isoformat())
print("=====================================")

configuration_file = args.configFile
print("# Using configuration file: {:s}".format(configuration_file))
# =======================================================================
# Loading the input arguments
# =======================================================================
# Reading the configuration file
with open(configuration_file) as data_file:
    data = json.loads(data_file.read())
output_path = os.path.expandvars(data['output_path'])
archive_path = os.path.expandvars(data['archive_path'])
ref_path = os.path.expandvars(data['ref_path'])
nid  = data['nid']
env =  data['env']
slitid = data['slitid']
steps = data['steps']
msafile = data['msafile']
mode = 'MOS'
# Print Input
print("# Exposure unique ID: {:s}".format(nid))
print("# Environment: {:s}".format(env))
if slitid is not None:
    for si in slitid:
        print("# Shutter IDs: {:s}".format(si))
# =======================================================================
# Initializing the pipeline parameters
# =======================================================================
print("# Initialization of the pipeline")
t0 = time.time()
pl_parameters = PipelineParameters()
# =======================================================================
# Following lines are different use cases. Feel free to uncomment and try!
# =======================================================================
# Standard run where we give the shutters in the slitid keyword
pl_parameters.m_set(output_path, archive_path, ref_path, nid, env, mode,
                    slitid=slitid, msafile=msafile, steps=steps)
# =======================================================================
# Initializing the pipeline
# =======================================================================
pl = Pipeline()
pl.m_set(pl_parameters)
# =======================================================================
# Run the pipeline
# =======================================================================
pl.m_process_exposure()
# =======================================================================
# The end my friend, the end
# =======================================================================
print("# Script completed in {} minutes".format((time.time() - t0)/60.))

Back to top

IFS standard processing

Config File (extraction_config_ifs.json):

{
  "output_path": "./",
  "archive_path": "/Volumes/CT1/Archive",
  "ref_path": "/Volumes/CT1/JWST-NIPS-REF_REPOS/nipsref",
  "nid": "3189",
  "env":"OTIS",
  "slitid": "12",
  "steps": null
}

Wrapper (p_extract_ifs.py):

#!/usr/bin/env python
#########################################################################
# IDENT         p_extract_ifs_script.py
# LANGUAGE      Python 3.X
# AUTHOR        P.FERRUIT
# PURPOSE       Script to extract a MOS spectrum from an exposure.
#
# 1.0.0 25.03.2018 PF Creation
# 1.0.1 05.02.2021 NL Update
#   1) Using os.path.expandvars() for the path input so
#      so that environment variables can be used.
#########################################################################
# =======================================================================
# Imports
# =======================================================================
import json
import os
import sys
import argparse
import datetime
import time

from nips.pipelines.pipeline import PipelineParameters, Pipeline
# =======================================================================
# Global variables
# =======================================================================
_name = 'p_extract_ifs.py'
_version = '1.0.1'
mode = 'ifs'
# =======================================================================
# Loading the input arguments
# =======================================================================
# Parsing the input arguments
parser = argparse.ArgumentParser()
parser.add_argument('-config', '--configFile', help='Name of configuration file to use',
                    default='extraction_config_ifs.json')
args = parser.parse_args()
argv = sys.argv
narg = len(argv)-1
print("=====================================")
print(argv[0])
print("Version: ", _version)
print(datetime.datetime.now().isoformat())
print("=====================================")

configuration_file = args.configFile
print("# Using configuration file: {:s}".format(configuration_file))
# =======================================================================
# Loading the input arguments
# =======================================================================
# Reading the configuration file
with open(configuration_file) as data_file:
    data = json.loads(data_file.read())
output_path = os.path.expandvars(data['output_path'])
archive_path = os.path.expandvars(data['archive_path'])
ref_path = os.path.expandvars(data['ref_path'])
nid  = data['nid']
env =  data['env']
slitid = data['slitid']
steps = data['steps']
mode = 'IFS'
# Print Input
print("# Exposure unique ID: {:s}".format(nid))
print("# Environment: {:s}".format(env))
print("# Fixed-slit ID: {:s}".format(slitid))
# =======================================================================
# Initializing the pipeline parameters
# =======================================================================
print("# Initialization of the pipeline")
t0 = time.time()
pl_parameters = PipelineParameters()
# =======================================================================
# Following lines are different use cases. Feel free to uncomment and try!
# =======================================================================
# Standard run where we give the shutters in the slitid keyword
# This only gives the pipeline the id of the target slice it will
# still extract all slices!
pl_parameters.m_set(output_path, archive_path, ref_path, nid, env, mode,
                    slitid=slitid, steps=steps)
# =======================================================================
# Initializing the pipeline
# =======================================================================
pl = Pipeline()
pl.m_set(pl_parameters)
# =======================================================================
# Run the pipeline
# =======================================================================
pl.m_process_exposure()
# =======================================================================
# The end my friend, the end
# =======================================================================
print("# Script completed in {} minutes".format((time.time() - t0)/60.))

Back to top