Skip to content

Commit

Permalink
try fixing paths again
Browse files Browse the repository at this point in the history
  • Loading branch information
cylammarco committed Mar 23, 2023
1 parent d2fe67a commit d6b39a7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
38 changes: 34 additions & 4 deletions src/aspired/spectrum_oneD.py
Original file line number Diff line number Diff line change
Expand Up @@ -5447,6 +5447,7 @@ def save_fits(
overwrite=False,
recreate=True,
empty_primary_hdu=True,
create_folder=False,
):
"""
Save the reduced data to disk, with a choice of any combination of the
Expand Down Expand Up @@ -5522,19 +5523,41 @@ def save_fits(
Set to True to overwrite the FITS data and header.
empty_primary_hdu: boolean (Default: True)
Set to True to leave the Primary HDU blank (Default: True)
create_folder: boolean (Default: False)
Create folder if not exist. Use with caution.
"""

self.create_fits(
output, recreate=recreate, empty_primary_hdu=empty_primary_hdu
)

# create the director if not exist
if create_folder:
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))

# Save file to disk
self.hdu_output.writeto(
filename + ".fits", overwrite=overwrite, output_verify="fix+ignore"
)
if os.path.splitext(filename)[-1].lower() in [".fits", ".fit", ".fts"]:
self.hdu_output.writeto(
filename, overwrite=overwrite, output_verify="fix+ignore"
)

def save_csv(self, output, filename, overwrite, recreate):
else:
self.hdu_output.writeto(
filename + ".fits",
overwrite=overwrite,
output_verify="fix+ignore",
)

def save_csv(
self,
output,
filename,
overwrite=False,
recreate=True,
create_folder=False,
):
"""
Save the reduced data to disk, with a choice of any combination of the
5 sets of data, see below the 'output' parameters for details.
Expand Down Expand Up @@ -5607,11 +5630,18 @@ def save_csv(self, output, filename, overwrite, recreate):
Default is False.
recreate: boolean (Default: False)
Set to True to overwrite the FITS data and header.
create_folder: boolean (Default: False)
Create folder if not exist. Use with caution.
"""

self.create_fits(output, recreate=recreate, empty_primary_hdu=False)

# create the director if not exist
if create_folder:
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))

output_split = output.split("+")

start = 0
Expand Down
7 changes: 3 additions & 4 deletions test/test_onedspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_add_wavelength_science_two_spec():

@pytest.mark.xfail(raises=ValueError)
# science add_wavelengthcalibration to two traces
def test_add_wavelength_science_expect_fail():
def test_add_wavelength_science_expect_fail_wrong_specid():
onedspec = spectral_reduction.OneDSpec(
log_file_name=None, log_level="ERROR"
)
Expand All @@ -453,11 +453,10 @@ def test_add_wavelength_science_expect_fail():

@pytest.mark.xfail(raises=ValueError)
# science add_wavelengthcalibration to two traces
def test_add_wavelength_science_expect_fail():
def test_add_wavelength_science_expect_fail_wrong_shape():
onedspec = spectral_reduction.OneDSpec(
log_file_name=None, log_level="ERROR"
)

onedspec.add_spec(np.arange(100), spec_id=0, stype="science+standard")
onedspec.add_wavelength(
[np.arange(100), np.arange(200)], spec_id=[0], stype="science+standard"
Expand Down Expand Up @@ -901,7 +900,7 @@ def test_add_fit_coeff_science_fail_type():


@pytest.mark.xfail(raises=ValueError)
def test_add_fit_coeff_science_fail_type():
def test_add_fit_coeff_science_fail_wrong_shape():
onedspec = spectral_reduction.OneDSpec(
log_file_name=None, log_level="ERROR"
)
Expand Down
6 changes: 2 additions & 4 deletions test/test_twodspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
HERE = os.path.dirname(os.path.realpath(__file__))

img = image_reduction.ImageReduction(log_file_name=None)
img.add_filelist(
filelist=os.path.join(HERE, "test_data", "sprat_LHS6328.list")
)
img.add_filelist(filelist=os.path.join(HERE, "test_data", "sprat_LHS6328.list"))
img.load_data()
img.reduce()

Expand Down Expand Up @@ -458,7 +456,7 @@ def test_add_arc_hdulist():
assert twodspec.arc_header == arc_fits.header


def test_add_arc_hdulist():
def test_add_arc_CCDData():
twodspec = spectral_reduction.TwoDSpec(log_file_name=None)
twodspec.add_arc(arc_in_CCDData)
assert (twodspec.arc == arc_fits.data).all()
Expand Down

0 comments on commit d6b39a7

Please sign in to comment.