Skip to content

Commit

Permalink
Add parameter to control timeout for scamp and swarp (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
guynir42 authored May 23, 2024
1 parent 7b625fd commit cb47a51
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion extern/nersc-upload-connector
21 changes: 19 additions & 2 deletions improc/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ def __init__(self, **kwargs):
critical=True,
)

self.scamp_timeout = self.add_par(
'scamp_timeout',
60,
int,
'Timeout in seconds for SCAMP to run. Used in SCAMP only. ',
critical=False,
)

self.swarp_timeout = self.add_par(
'swarp_timeout',
60,
int,
'Timeout in seconds for SWARP to run. Used in SWARP only. ',
critical=False,
)

self.enforce_no_new_attrs = True
self.override( kwargs )

Expand Down Expand Up @@ -299,6 +315,7 @@ def _align_swarp( self, image, target, sources, target_sources ):
min_frac_matched=self.pars.min_frac_matched,
min_matched=self.pars.min_matched,
max_arcsec_residual=self.pars.max_arcsec_residual,
timeout=self.pars.swarp_timeout,
)

# Write out the .head file that swarp will use to figure out what to do
Expand Down Expand Up @@ -356,7 +373,7 @@ def _align_swarp( self, image, target, sources, target_sources ):
'-WRITE_XML', 'N' ]

t0 = time.perf_counter()
res = subprocess.run( command, capture_output=True, timeout=60 )
res = subprocess.run(command, capture_output=True, timeout=self.pars.swarp_timeout)
t1 = time.perf_counter()
SCLogger.debug( f"swarp of image took {t1-t0:.2f} seconds" )
if res.returncode != 0:
Expand All @@ -375,7 +392,7 @@ def _align_swarp( self, image, target, sources, target_sources ):
'-WRITE_XML', 'N']

t0 = time.perf_counter()
res = subprocess.run(command, capture_output=True, timeout=60)
res = subprocess.run(command, capture_output=True, timeout=self.pars.swarp_timeout)
t1 = time.perf_counter()
SCLogger.debug(f"swarp of flags took {t1 - t0:.2f} seconds")
if res.returncode != 0:
Expand Down
4 changes: 2 additions & 2 deletions improc/scamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def solve_wcs_scamp( sources, catalog, crossid_radius=2.,
max_sources_to_use=2000, min_frac_matched=0.1,
min_matched=10, max_arcsec_residual=0.15,
magkey='MAG', magerrkey='MAGERR' ):
magkey='MAG', magerrkey='MAGERR', timeout=60 ):
"""Solve for the WCS of image with sourcelist sources, based on catalog.
If scamp does not succeed, will raise a SubprocessFailure
Expand Down Expand Up @@ -121,7 +121,7 @@ def solve_wcs_scamp( sources, catalog, crossid_radius=2.,
]

t0 = time.perf_counter()
res = subprocess.run( command, capture_output=True, timeout=60 )
res = subprocess.run( command, capture_output=True, timeout=timeout )
t1 = time.perf_counter()
SCLogger.debug( f"Scamp with {len(sources)} sources and {len(cat)} catalog stars "
f"(with match_nmax={max_nmatch}) took {t1-t0:.2f} seconds" )
Expand Down
9 changes: 9 additions & 0 deletions pipeline/astro_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def __init__(self, **kwargs):
critical=True
)

self.scamp_timeout = self.add_par(
'scamp_timeout',
300,
int,
'Timeout in seconds for scamp to run',
critical=True
)

self._enforce_no_new_attrs = True

self.override(kwargs)
Expand Down Expand Up @@ -188,6 +196,7 @@ def _solve_wcs_scamp( self, image, sources, catexp, crossid_radius=2. ):
min_matched=self.pars.min_matched_stars,
max_arcsec_residual=self.pars.max_arcsec_residual,
magkey='MAG_G', magerrkey='MAGERR_G',
timeout=self.pars.scamp_timeout,
)

# Update image.header with the new wcs. Process this
Expand Down
17 changes: 15 additions & 2 deletions pipeline/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def __init__(self, **kwargs):
critical=True
)

self.sextractor_timeout = self.add_par(
'sextractor_timeout',
120,
int,
'Timeout for SExtractor, in seconds. ',
critical=False,
)

self._enforce_no_new_attrs = True

self.override(kwargs)
Expand Down Expand Up @@ -637,7 +645,7 @@ def _run_sextractor_once( self, image, apers=[5, ], psffile=None, tempname=None,
]
args.extend( psfargs )
args.append( tmpimage )
res = subprocess.run( args, cwd=tmpimage.parent, capture_output=True, timeout=120 )
res = subprocess.run(args, cwd=tmpimage.parent, capture_output=True, timeout=self.pars.sextractor_timeout)
if res.returncode != 0:
SCLogger.error( f"Got return {res.returncode} from sextractor call; stderr:\n{res.stderr}\n"
f"-------\nstdout:\n{res.stdout}" )
Expand Down Expand Up @@ -747,7 +755,12 @@ def _run_psfex( self, tempname, image, psf_size=None, do_not_cleanup=False ):
'-XML_URL', 'file:///usr/share/psfex/psfex.xsl',
# '-PSFVAR_DEGREES', '4', # polynomial order for PSF fitting across image
sourcefile ]
res = subprocess.run( command, cwd=sourcefile.parent, capture_output=True, timeout=120 )
res = subprocess.run(
command,
cwd=sourcefile.parent,
capture_output=True,
timeout=self.pars.sextractor_timeout
)
if res.returncode == 0:
fwhmmaxtotry = [ fwhmmax ]
break
Expand Down

0 comments on commit cb47a51

Please sign in to comment.