Skip to content

Commit

Permalink
Merge pull request #178 from simontorres/fix_bug_with_file_names
Browse files Browse the repository at this point in the history
fixed file name naming bug that might cause overwritting, therefore l…
  • Loading branch information
Simon Torres authored Jul 11, 2018
2 parents 7de3b2a + 3cbc169 commit c78665e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pipeline/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,13 +1730,14 @@ def read_fits(full_path, technique='Unknown'):
return ccd


def save_extracted(ccd, destination, prefix='e'):
def save_extracted(ccd, destination, prefix='e', target_number=1):
"""Save extracted spectrum while adding a prefix.
Args:
ccd (object): CCDData instance
destination (str): Path where the file will be saved.
prefix (str): Prefix to be added to images. Default `e`.
target_number (int):
Returns:
`ccdproc.CCDData` instance of the image just recorded. although is not
Expand All @@ -1747,6 +1748,10 @@ def save_extracted(ccd, destination, prefix='e'):
assert os.path.isdir(destination)

file_name = ccd.header['GSP_FNAM']
if target_number > 0:
new_suffix = '_target_{:d}.fits'.format(target_number)
file_name = re.sub('.fits', new_suffix, file_name)

new_file_name = prefix + file_name
log.info("Saving uncalibrated(w) extracted spectrum to file: "
"{:s}".format(new_file_name))
Expand Down
12 changes: 10 additions & 2 deletions pipeline/spectroscopy/redspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ def _run(self, data_container, extraction_type):
# if len(trace_list) > 0:
extracted_target_and_lamps = []
for single_trace, single_profile in trace_list:
if len(trace_list) > 1:
target_number = trace_list.index(
[single_trace,
single_profile]) + 1
else:
target_number = 0
try:
# target extraction
extracted = extraction(
Expand All @@ -370,7 +376,8 @@ def _run(self, data_container, extraction_type):
spatial_profile=single_profile,
extraction_name=extraction_type)
save_extracted(ccd=extracted,
destination=self.args.destination)
destination=self.args.destination,
target_number=target_number)
# print(spec_file)

# lamp extraction
Expand All @@ -384,7 +391,8 @@ def _run(self, data_container, extraction_type):
extraction_name=extraction_type)
save_extracted(
ccd=extracted_lamp,
destination=self.args.destination)
destination=self.args.destination,
target_number=target_number)
all_lamps.append(extracted_lamp)
extracted_target_and_lamps.append([extracted,
all_lamps])
Expand Down

0 comments on commit c78665e

Please sign in to comment.