replace_suffix_ext

jwst.lib.catalog_utils.replace_suffix_ext(filename, old_suffix_list, new_suffix, output_ext='ecsv', output_dir=None)[source]

Replace the suffix and extension of a filename.

If the last suffix in the input filename is in the old_suffix_list then it is replaced by the new_suffix. Otherwise, the new_suffix is appended to the input filename.

Parameters:
filenamestr

The filename to modify.

old_suffix_listlist of str

The list of filename suffixes that will be replaced.

new_suffixstr

The new filename suffix.

output_extstr, optional

The extension of the output filename. The default is ‘ecsv’.

output_dirstr or None, optional

The output directory name. If None then the current directory will be used.

Returns:
resultstr

The modified filename.

Examples

>>> from jwst.lib.catalog_utils import replace_suffix_ext
>>> replace_suffix_ext("jw12345_nrca_i2d.fits", ["i2d"], "cat")
'jw12345_nrca_cat.ecsv'
>>> replace_suffix_ext("jw12345_nrca_cal.fits", ["i2d"], "cat")
'jw12345_nrca_cal_cat.ecsv'
>>> replace_suffix_ext("my_custom_file.fits", ["i2d"], "cat")
'my_custom_file_cat.ecsv'
>>> old_suffixes = ["calints", "crfints"]
>>> replace_suffix_ext("jw12345_nrca_calints.fits", old_suffixes, "phot")
'jw12345_nrca_phot.ecsv'
>>> replace_suffix_ext("jw12345_nrca_crfints.fits", old_suffixes, "phot")
'jw12345_nrca_phot.ecsv'
>>> replace_suffix_ext("jw12345_nrca_i2d.fits", ["i2d"], "cat", output_dir="/jwst/my_catalogs")
'/jwst/my_catalogs/jw12345_nrca_cat.ecsv'