diff --git a/gwemopt/scheduler.py b/gwemopt/scheduler.py index 17d2bc5..9ce50c8 100644 --- a/gwemopt/scheduler.py +++ b/gwemopt/scheduler.py @@ -100,6 +100,7 @@ def get_order_heuristic( being the exposure time. Returns a list of tile indices in the order of observation. """ + keys = tile_struct.keys() exposureids_tiles = {} @@ -205,7 +206,7 @@ def get_order_heuristic( idxs = -1 * np.ones((len(exposureids_tiles.keys()),)) filts = ["n"] * len(exposureids_tiles.keys()) - if nexps == 0: + if (nexps == 0) or (len(exposurelist) == 0): return idxs, filts if params["scheduleType"] == "airmass_weighted": diff --git a/gwemopt/segments.py b/gwemopt/segments.py index a51bfc2..1434c79 100644 --- a/gwemopt/segments.py +++ b/gwemopt/segments.py @@ -46,6 +46,9 @@ def get_telescope_segments(params): def get_moon_radecs(segmentlist, observer): dt = 1.0 / 24.0 + if len(segmentlist) == 0: + return [] + tt = np.arange(segmentlist[0][0], segmentlist[-1][1] + dt, dt) tt_DJD = tt - MJD_TO_DJD diff --git a/gwemopt/utils/parallel.py b/gwemopt/utils/parallel.py new file mode 100644 index 0000000..b51e2f7 --- /dev/null +++ b/gwemopt/utils/parallel.py @@ -0,0 +1,22 @@ +import contextlib + +import joblib +from tqdm import tqdm + + +@contextlib.contextmanager +def tqdm_joblib(tqdm_object): + """Context manager to patch joblib to report into tqdm progress bar given as argument""" + + class TqdmBatchCompletionCallback(joblib.parallel.BatchCompletionCallBack): + def __call__(self, *args, **kwargs): + tqdm_object.update(n=self.batch_size) + return super().__call__(*args, **kwargs) + + old_batch_callback = joblib.parallel.BatchCompletionCallBack + joblib.parallel.BatchCompletionCallBack = TqdmBatchCompletionCallback + try: + yield tqdm_object + finally: + joblib.parallel.BatchCompletionCallBack = old_batch_callback + tqdm_object.close()