From 3bfdec81c80f88361428f7199043ebc1ab99b4c6 Mon Sep 17 00:00:00 2001 From: "chang.nersc" Date: Mon, 2 Mar 2020 14:28:04 -0800 Subject: [PATCH 1/4] If kwarg `use_brightsky=True`, bright sky exposure factor is used to get the next tile to be observed from the scheduler and also in calculating the exposure time in `ETC.start` and `ETC.update` calls. --- py/surveysim/nightops.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/py/surveysim/nightops.py b/py/surveysim/nightops.py index 92c40ba..04e9630 100644 --- a/py/surveysim/nightops.py +++ b/py/surveysim/nightops.py @@ -13,7 +13,7 @@ def simulate_night(night, scheduler, stats, explist, weather, use_twilight=False, update_interval=10., - plot=False, verbose=False): + use_brightsky=False, plot=False, verbose=False): """Simulate one night of observing. Uses the online tile scheduler and exposure time calculator. @@ -34,6 +34,9 @@ def simulate_night(night, scheduler, stats, explist, weather, Observe during twilight when True. update_interval : float Interval in seconds for simulated ETC updates. + use_brightsky : bool + If True use improved bright sky model in exposure time calculations + (ETC.start and ETC.update calls) plot : bool Generate a plot summarizing the simulated night when True. verbose : bool @@ -131,7 +134,8 @@ def get_weather(mjd): seeing_now, transp_now = get_weather(mjd_now) # Get the next tile to observe from the scheduler. tileid, passnum, snr2frac_start, exposure_factor, airmass, sched_program, mjd_program_end = \ - scheduler.next_tile(mjd_now, ETC, seeing_now, transp_now, sky_now) + scheduler.next_tile(mjd_now, ETC, seeing_now, transp_now, sky_now, + use_brightsky=use_brightsky) if tileid is None: # Deadtime while we delay and try again. mjd_now += NO_TILE_AVAIL_DELAY @@ -165,7 +169,10 @@ def get_weather(mjd): # -- NEXT EXPOSURE --------------------------------------------------- # Get the current observing conditions. seeing_now, transp_now = get_weather(mjd_now) - sky_now = 1. + if use_brightsky: + sky_now = exposure_factor + else: + sky_now = 1. # Use the ETC to control the shutter. mjd_open_shutter = mjd_now ETC.start(mjd_now, tileid, tile_program, snr2frac_start, exposure_factor, @@ -186,7 +193,10 @@ def get_weather(mjd): continue_this_tile = False # Get the current observing conditions. seeing_now, transp_now = get_weather(mjd_now) - sky_now = 1. + if use_brightsky: + sky_now = scheduler.update_exposure_factor(mjd_now, tileid) + else: + sky_now = 1 # Update the SNR. if not ETC.update(mjd_now, seeing_now, transp_now, sky_now): # Current exposure reached its target SNR according to the ETC. From 160422bf13e5bcf6ff5ff5b3cf87962806d240f2 Mon Sep 17 00:00:00 2001 From: "chang.nersc" Date: Mon, 2 Mar 2020 14:29:47 -0800 Subject: [PATCH 2/4] added --brightsky argument in surveysim script which turns on and off the use of bright sky exposure factor --- py/surveysim/scripts/surveysim.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py/surveysim/scripts/surveysim.py b/py/surveysim/scripts/surveysim.py index 6647a94..f3b00ac 100644 --- a/py/surveysim/scripts/surveysim.py +++ b/py/surveysim/scripts/surveysim.py @@ -76,6 +76,8 @@ def parse(options=None): parser.add_argument( '--config-file', default='config.yaml', metavar='CONFIG', help='input configuration file') + parser.add_argument('--brightsky', action='store_true', + help='use improved bright sky model (slower)') if options is None: args = parser.parse_args() @@ -159,7 +161,8 @@ def main(args): if not desisurvey.utils.is_monsoon(night) and not scheduler.ephem.is_full_moon(night): # Simulate one night of observing. surveysim.nightops.simulate_night( - night, scheduler, stats, explist, weather=weather, use_twilight=args.twilight) + night, scheduler, stats, explist, weather=weather, + use_twilight=args.twilight, use_brightsky=args.brightsky) if scheduler.survey_completed(): log.info('Survey complete on {}.'.format(night)) break From 948545e172e90874fd5f45ddd38c80ee8adadf62 Mon Sep 17 00:00:00 2001 From: changhoonhahn Date: Wed, 3 Feb 2021 06:24:51 -0800 Subject: [PATCH 3/4] hacked to run on reduced footprint back in June 2020 --- py/surveysim/exposures.py | 4 ++-- py/surveysim/nightops.py | 4 ++-- py/surveysim/scripts/surveysim.py | 22 +++++++++++++++++++--- py/surveysim/stats.py | 8 ++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/py/surveysim/exposures.py b/py/surveysim/exposures.py index 58d364b..9cd41b3 100644 --- a/py/surveysim/exposures.py +++ b/py/surveysim/exposures.py @@ -27,8 +27,8 @@ class ExposureList(object): The maximum expected number of exposures, which determines the memory size of this object. """ - def __init__(self, restore=None, max_nexp=60000): - self.tiles = desisurvey.tiles.get_tiles() + def __init__(self, restore=None, max_nexp=60000, bgs_footprint=None): + self.tiles = desisurvey.tiles.get_tiles(bgs_footprint=bgs_footprint) self._exposures = np.empty(max_nexp, dtype=[ ('MJD', np.float64), ('EXPTIME', np.float32), diff --git a/py/surveysim/nightops.py b/py/surveysim/nightops.py index 04e9630..e89453b 100644 --- a/py/surveysim/nightops.py +++ b/py/surveysim/nightops.py @@ -169,7 +169,7 @@ def get_weather(mjd): # -- NEXT EXPOSURE --------------------------------------------------- # Get the current observing conditions. seeing_now, transp_now = get_weather(mjd_now) - if use_brightsky: + if use_brightsky and tile_program == 'BRIGHT': sky_now = exposure_factor else: sky_now = 1. @@ -193,7 +193,7 @@ def get_weather(mjd): continue_this_tile = False # Get the current observing conditions. seeing_now, transp_now = get_weather(mjd_now) - if use_brightsky: + if use_brightsky and tile_program == 'BRIGHT': sky_now = scheduler.update_exposure_factor(mjd_now, tileid) else: sky_now = 1 diff --git a/py/surveysim/scripts/surveysim.py b/py/surveysim/scripts/surveysim.py index f3b00ac..496b6e2 100644 --- a/py/surveysim/scripts/surveysim.py +++ b/py/surveysim/scripts/surveysim.py @@ -78,6 +78,8 @@ def parse(options=None): help='input configuration file') parser.add_argument('--brightsky', action='store_true', help='use improved bright sky model (slower)') + parser.add_argument( '--bgs_footprint', type=str, default=None, + help='reduce bgs footprint') if options is None: args = parser.parse_args() @@ -127,20 +129,34 @@ def main(args): if args.tiles_file is not None: config.tiles_file.set_value(args.tiles_file) + if args.bgs_footprint is not None: + bgs_footprint = float(args.bgs_footprint) + else: + bgs_footprint = None + + # Initialize simulation progress tracking. - stats = surveysim.stats.SurveyStatistics(args.start, args.stop) - explist = surveysim.exposures.ExposureList() + print('Initialize simulation progress tracking.') + stats = surveysim.stats.SurveyStatistics(args.start, args.stop, + bgs_footprint=bgs_footprint) + print('Exposure list.') + explist = surveysim.exposures.ExposureList( + bgs_footprint=bgs_footprint) # Initialize the survey strategy rules. + print('Initialize the survey strategy rules.') rules = desisurvey.rules.Rules(args.rules) # Initialize afternoon planning. + print('Initialize afternoon planning.') planner = desisurvey.plan.Planner(rules) # Initialize next tile selection. - scheduler = desisurvey.scheduler.Scheduler() + print('Initialize next tile selection.') + scheduler = desisurvey.scheduler.Scheduler(bgs_footprint=bgs_footprint) # Generate random weather conditions. + print('Generate random weather conditions.') weather = surveysim.weather.Weather(seed=args.seed, replay=args.replay) # Loop over nights. diff --git a/py/surveysim/stats.py b/py/surveysim/stats.py index a3d9185..11267c4 100644 --- a/py/surveysim/stats.py +++ b/py/surveysim/stats.py @@ -32,8 +32,12 @@ class SurveyStatistics(object): the configured output path unless an absolute path is provided. """ - def __init__(self, start_date=None, stop_date=None, restore=None): - self.tiles = desisurvey.tiles.Tiles() + def __init__(self, start_date=None, stop_date=None, restore=None, + tiles_file=None, bgs_footprint=None): + if tiles_file is None: + self.tiles = desisurvey.tiles.Tiles(bgs_footprint=bgs_footprint) + else: + self.tiles = desisurvey.tiles.Tiles(tiles_file=tiles_file, bgs_footprint=bgs_footprint) config = desisurvey.config.Configuration() if start_date is None: self.start_date = config.first_day() From 748911f7895fadf86651ffa5c71d3cdade66d10a Mon Sep 17 00:00:00 2001 From: changhoonhahn Date: Fri, 19 Feb 2021 11:22:33 -0800 Subject: [PATCH 4/4] extra info in the exposure output files --- py/surveysim/exposures.py | 11 +++++++++-- py/surveysim/nightops.py | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/py/surveysim/exposures.py b/py/surveysim/exposures.py index 9cd41b3..4bc0454 100644 --- a/py/surveysim/exposures.py +++ b/py/surveysim/exposures.py @@ -38,6 +38,11 @@ def __init__(self, restore=None, max_nexp=60000, bgs_footprint=None): ('SEEING', np.float32), ('TRANSP', np.float32), ('SKY', np.float32), + ('MOON_ILL', np.float32), + ('MOON_SEP', np.float32), + ('MOON_ALT', np.float32), + ('SUN_SEP', np.float32), + ('SUN_ALT', np.float32) ]) self._tiledata = np.empty(self.tiles.ntiles, dtype=[ ('AVAIL', np.int32), @@ -93,7 +98,8 @@ def update_tiles(self, night, available, planned): self._tiledata['AVAIL'][available] = night_index self._tiledata['PLANNED'][planned] = night_index - def add(self, mjd, exptime, tileID, snr2frac, airmass, seeing, transp, sky): + def add(self, mjd, exptime, tileID, snr2frac, airmass, seeing, transp, sky, + moonill, moonsep, moonalt, sunsep, sunalt): """Record metadata for a single exposure. Parameters @@ -117,7 +123,8 @@ def add(self, mjd, exptime, tileID, snr2frac, airmass, seeing, transp, sky): raise RuntimeError( 'Need to increase max_nexp={}'.format(len(self._exposures))) self._exposures[self.nexp] = ( - mjd, exptime, tileID, snr2frac, airmass, seeing, transp, sky) + mjd, exptime, tileID, snr2frac, airmass, seeing, transp, sky, + moonill, moonsep, moonalt, sunsep, sunalt) self.nexp += 1 tileinfo = self._tiledata[self.tiles.index(tileID)] tileinfo['EXPTIME'] += exptime diff --git a/py/surveysim/nightops.py b/py/surveysim/nightops.py index e89453b..669dcea 100644 --- a/py/surveysim/nightops.py +++ b/py/surveysim/nightops.py @@ -194,8 +194,9 @@ def get_weather(mjd): # Get the current observing conditions. seeing_now, transp_now = get_weather(mjd_now) if use_brightsky and tile_program == 'BRIGHT': - sky_now = scheduler.update_exposure_factor(mjd_now, tileid) + sky_now, moon_ill, moon_sep, moon_alt, sun_sep, sun_alt = scheduler.update_exposure_factor(mjd_now, tileid, return_obs_cond=True) else: + moon_ill, moon_sep, moon_alt, sun_sep, sun_alt = scheduler.get_observing_conditions(mjd_now, tileid) sky_now = 1 # Update the SNR. if not ETC.update(mjd_now, seeing_now, transp_now, sky_now): @@ -212,7 +213,8 @@ def get_weather(mjd): nightstats['nexp'][passnum] += 1 explist.add( mjd_now - ETC.exptime, 86400 * ETC.exptime, tileid, ETC.snr2frac, - airmass, seeing_now, transp_now, sky_now) + airmass, seeing_now, transp_now, sky_now, moon_ill, + moon_sep, moon_alt, sun_sep, sun_alt) scheduler.update_snr(tileid, ETC.snr2frac) if continue_this_tile: