Skip to content

Commit 3db61e6

Browse files
committed
Removing redundancies and making minor edits.
1 parent 26afdef commit 3db61e6

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

astrocut/cutouts.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _parse_extensions(infile_exts, infile_name, user_exts):
184184

185185
def fits_cut(input_files, coordinates, cutout_size, correct_wcs=False, extension=None,
186186
single_outfile=True, cutout_prefix="cutout", output_dir='.',
187-
memory_only=False, verbose=False, fsspec_kwargs={"anon": True}):
187+
memory_only=False, verbose=False):
188188
"""
189189
Takes one or more fits files with the same WCS/pointing, makes the same cutout in each file,
190190
and returns the result either in a single FITS file with one cutout per extension or in
@@ -270,19 +270,16 @@ def fits_cut(input_files, coordinates, cutout_size, correct_wcs=False, extension
270270
cutout_hdu_dict = {}
271271
num_empty = 0
272272
num_cutouts = 0
273+
fsspec_kwargs = None
273274
for in_fle in input_files:
274275
if verbose:
275276
print("\nCutting out {}".format(in_fle))
276277

277-
u_fsspec = None
278-
fsspec_kw = None
279-
280-
if "s3://" or "gs://" in in_fle:
281-
u_fsspec = True
282-
fsspec_kw = fsspec_kwargs
278+
if "s3://" in in_fle:
279+
fsspec_kwargs = {"anon": True}
283280

284281
warnings.filterwarnings("ignore", category=wcs.FITSFixedWarning)
285-
with fits.open(in_fle, mode='denywrite', memmap=True, use_fsspec=u_fsspec, fsspec_kwargs=fsspec_kw) as hdulist:
282+
with fits.open(in_fle, mode='denywrite', memmap=True, fsspec_kwargs=fsspec_kwargs) as hdulist:
286283

287284
# Sorting out which extension(s) to cutout
288285
all_inds = np.where([x.is_image and (x.data is not None) for x in hdulist])[0]

astrocut/tests/test_cutouts.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ def test_fits_cut(tmpdir, capsys, ffi_type):
189189
cutout_file = cutouts.fits_cut(test_s3_uri, center_coord, cutout_size, output_dir=tmpdir)
190190
assert isinstance(cutout_file, str)
191191
assert "10-x-15" in cutout_file
192-
cutout_hdulist = fits.open(cutout_file)
193-
assert cutout_hdulist[1].data.shape == (15, 10)
192+
193+
with fits.open(cutout_file) as cutout_hdulist:
194+
assert cutout_hdulist[1].data.shape == (15, 10)
194195

195196

196197
def test_normalize_img():

0 commit comments

Comments
 (0)