Skip to content

Commit

Permalink
Updated merge and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nat1405 committed Oct 1, 2017
1 parent d06c83b commit bf2fc39
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
11 changes: 11 additions & 0 deletions docs/nifty/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ And run the nifsPipeline with:
**nifsMerge Cube Merging:** To only merge final data cubes use a config.cfg file like this:
*Make sure to populate scienceDirectoryList, telluricDirectoryList and calibrationDirectoryList before running!*

*Note: You can start and stop at step 1,3, or 5, create your own waveoffsetsGRATING.txt file in the merged_MERGETYPE directory, and then start and stop from step
2, 4, or 6 to specify your own offsets for the final cube merging step. This is useful for non-sidereal targets.*

.. code-block:: text
# Nifty configuration file.
Expand Down Expand Up @@ -1266,6 +1269,14 @@ All in-development changes will be tracked here.

- Adding unit tests for each step and integration test for pipeline.

1.0.1 - 2017-10-01
------------------
Minor patches and small feature adding release.

- Fixed bug in nifsFluxCalibration.py
- Added ability to use your own waveoffsets+'GRATING'.txt file in nifsMerge.py
- Updated documentation

1.0.0 - 2017-09-12
------------------
First production release. Works fairly smoothly once raw data is located and sorted
Expand Down
2 changes: 1 addition & 1 deletion nifty/pipeline/nifsUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def interactiveNIFSInput():
)
mergeStop = getParam(
"Stop step of final cube merging? [3]:",
3,
6,
"Choose a stop point for the final cube merging."
)
mergeType = getParam(
Expand Down
69 changes: 60 additions & 9 deletions nifty/pipeline/steps/nifsMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# STDLIB

import getopt
import os, glob, shutil, logging, pkg_resources
import os, glob, shutil, logging, pkg_resources, json
import pexpect as p
import time
from pyraf import iraf
Expand Down Expand Up @@ -97,25 +97,52 @@ def run():
mergeCubes(scienceDirectoryList, "uncorrected", mergeType, use_pq_offsets, im3dtran, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 1 - Merge Uncorrected Cubes - COMPLETED ")
logging.info(" STEP 1 - Merge Uncorrected Individual Observations - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

if valindex == 2:
# Merge merged cubes from each observation.
finalMergeCubes(mergeType, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 2 - Merge Uncorrected Merged Observation Cubes - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

if valindex == 3:
# Merge telluric corrected cubes. These have the "actfbrsn" prefix.
mergeCubes(scienceDirectoryList, "telluricCorrected", mergeType, use_pq_offsets, im3dtran, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 2 - Merge Telluric Corrected Cubes - COMPLETED ")
logging.info(" STEP 3 - Merge Telluric Corrected Individual Observations - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

if valindex == 3:
if valindex == 4:
# Merge merged cubes from each observation.
finalMergeCubes(mergeType, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 4 - Merge Telluric Corrected Merged Observation Cubes - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

if valindex == 5:
# Merge telluric corrected AND flux calibrated cubes. These have the "factfbrsn" prefix.
mergeCubes(scienceDirectoryList, "telCorAndFluxCalibrated", mergeType, use_pq_offsets, im3dtran, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 3 - Merge Telluric Corrected and Flux Calibrated Cubes - COMPLETED ")
logging.info(" STEP 5 - Merge Telluric Corrected and Flux Calibrated Cubes - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

if valindex == 6:
# Merge merged cubes from each observation.
finalMergeCubes(mergeType, over)
logging.info("\n##############################################################################")
logging.info("")
logging.info(" STEP 6 - Merge Telluric Corrected AND Flux Calibrated Cubes - COMPLETED ")
logging.info("")
logging.info("##############################################################################\n")

Expand Down Expand Up @@ -179,6 +206,9 @@ def mergeCubes(obsDirList, cubeType, mergeType, use_pq_offsets, im3dtran, over="
mergedCubes = [] # List of Merged cubes (one merged cube for each science observation directory).
obsidlist = [] # List of science observation id s.

# Store the merged directory
targetDirectory = None

# Pixel scale in arcseconds/pixel.
pixScale = 0.05

Expand All @@ -205,6 +235,7 @@ def mergeCubes(obsDirList, cubeType, mergeType, use_pq_offsets, im3dtran, over="
date = temp3[1]
obsid = temp1[1]
obsPath = temp3[0]
targetDirectory = temp4[0]
os.chdir(obsDir + '/'+unmergedDirectory)

obsidlist.append(obsPath+'/Merged'+suffix+'/'+date+'_'+obsid)
Expand Down Expand Up @@ -388,11 +419,25 @@ def mergeCubes(obsDirList, cubeType, mergeType, use_pq_offsets, im3dtran, over="
n+=1
os.chdir(Merged)

# Copy the merged observation sequence data cubes to the Merged directory.
#for i in range(len(mergedCubes)):
# shutil.copy(mergedCubes[i], './')
os.chdir(path)
# Save the data with JSON so we can grab it in the next step.
mergedData = {}
mergedData['mergedCubes'] = mergedCubes
mergedData['Merged'] = Merged
with open(targetDirectory+"/mergedInfo.txt", "w") as outfile:
json.dump(mergedData, outfile)

# Merge all the individual merged observation sequence data cubes with the same grating.

def finalMergeCubes(mergeType, over):
"""
Merge final merged cubes from all observations.
"""
# Load data from the previous step.
path = os.getcwd()
with open('mergedInfo.txt') as data_file:
mergedData = json.load(data_file)
mergedCubes = mergedData['mergedCubes']
Merged = mergedData['Merged']

if len(mergedCubes)>1:
os.chdir(Merged)
Expand Down Expand Up @@ -432,6 +477,8 @@ def mergeCubes(obsDirList, cubeType, mergeType, use_pq_offsets, im3dtran, over="
else:
iraf.imcombine(inputstring, output = 'temp_merged'+gratlist[n][0]+'.fits', combine = mergeType, offsets = 'waveoffsets'+grat[0]+'.txt')
iraf.fxcopy(input=newcubelist[0]+'[0], temp_merged'+gratlist[n][0]+'.fits', output = 'TOTAL_merged'+gratlist[n][0]+'.fits')
os.chdir(path)

#####################################################################################
# FUNCTIONS #
#####################################################################################
Expand Down Expand Up @@ -498,6 +545,10 @@ def makeWavelengthOffsets(cubelist, grat):
"""
cubeheader0 = astropy.io.fits.open(cubelist[0])
wstart0 = cubeheader0[1].header['CRVAL3']
# If a user provided a waveoffsetsGRATING.txt, skip the creation of it.
if os.path.exists('waveoffsets{0}.txt'.format(grat[0])):
logging.info("\nwaveoffsets file exists; skipping creation of it.")
return
fwave = open('waveoffsets{0}.txt'.format(grat[0]), 'w')
fwave.write('%d %d %d\n' % (0, 0, 0))
for i in range(len(cubelist)):
Expand Down
2 changes: 1 addition & 1 deletion nifty/recipes/defaultConfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fluxCalibrationStop = 6

[mergeConfig]
mergeStart = 1
mergeStop = 3
mergeStop = 6
mergeType = 'median'
use_pq_offsets = True
im3dtran = True
Expand Down

0 comments on commit bf2fc39

Please sign in to comment.