try:
        extra_info['git hash'] = subprocess.check_output(
            ['git', 'rev-parse', 'HEAD'])
    except subprocess.CalledProcessError:
        extra_info['git hash'] = 'Not in git repo'

    extra_info['file executed'] = os.path.realpath(__file__)

    fileroot = 'roll_mod%i_dust_sdf_%.2f_' % (mod_year, scale_down_factor)
    file_end = 'v1.4_'

    # Mark position of the sun at the start of the survey. Usefull for rolling cadence.
    observatory = Model_observatory(nside=nside)
    conditions = observatory.return_conditions()
    sun_ra_0 = conditions.sunRA  # radians
    offset = create_season_offset(nside, sun_ra_0)
    max_season = 6

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        dither_detailer
    ]
    ddfs = generate_dd_surveys(nside=nside, nexp=nexp, detailers=details)

    # Set up rolling maps
    sg = big_sky_dust()
    roll_maps = slice_wfd_area_quad(sg, scale_down_factor=scale_down_factor)
Exemple #2
0
    def __init__(self,
                 nside=None,
                 mjd_start=59853.5,
                 seed=42,
                 quickTest=True,
                 alt_min=5.,
                 lax_dome=True,
                 cloud_limit=0.3,
                 sim_ToO=None,
                 seeing_db=None,
                 park_after=10.):
        """
        Parameters
        ----------
        nside : int (None)
            The healpix nside resolution
        mjd_start : float (59853.5)
            The MJD to start the observatory up at
        alt_min : float (5.)
            The minimum altitude to compute models at (degrees).
        lax_dome : bool (True)
            Passed to observatory model. If true, allows dome creep.
        cloud_limit : float (0.3)
            The limit to stop taking observations if the cloud model returns something equal or higher
        sim_ToO : sim_targetoO object (None)
            If one would like to inject simulated ToOs into the telemetry stream.
        seeing_db : filename of the seeing data database (None)
            If one would like to use an alternate seeing database
        park_after : float (10)
            Park the telescope after a gap longer than park_after (minutes)
        """

        if nside is None:
            nside = set_default_nside()
        self.nside = nside

        self.cloud_limit = cloud_limit

        self.alt_min = np.radians(alt_min)
        self.lax_dome = lax_dome

        self.mjd_start = mjd_start

        self.sim_ToO = sim_ToO

        self.park_after = park_after / 60. / 24.  # To days

        # Create an astropy location
        self.site = Site('LSST')
        self.location = EarthLocation(lat=self.site.latitude,
                                      lon=self.site.longitude,
                                      height=self.site.height)

        # Load up all the models we need

        mjd_start_time = Time(self.mjd_start, format='mjd')
        # Downtime
        self.down_nights = []
        self.sched_downtime_data = ScheduledDowntimeData(mjd_start_time)
        self.unsched_downtime_data = UnscheduledDowntimeData(mjd_start_time)

        sched_downtimes = self.sched_downtime_data()
        unsched_downtimes = self.unsched_downtime_data()

        down_starts = []
        down_ends = []
        for dt in sched_downtimes:
            down_starts.append(dt['start'].mjd)
            down_ends.append(dt['end'].mjd)
        for dt in unsched_downtimes:
            down_starts.append(dt['start'].mjd)
            down_ends.append(dt['end'].mjd)

        self.downtimes = np.array(list(zip(down_starts, down_ends)),
                                  dtype=list(
                                      zip(['start', 'end'], [float, float])))
        self.downtimes.sort(order='start')

        # Make sure there aren't any overlapping downtimes
        diff = self.downtimes['start'][1:] - self.downtimes['end'][0:-1]
        while np.min(diff) < 0:
            # Should be able to do this wihtout a loop, but this works
            for i, dt in enumerate(self.downtimes[0:-1]):
                if self.downtimes['start'][i + 1] < dt['end']:
                    new_end = np.max([dt['end'], self.downtimes['end'][i + 1]])
                    self.downtimes[i]['end'] = new_end
                    self.downtimes[i + 1]['end'] = new_end

            good = np.where(
                self.downtimes['end'] - np.roll(self.downtimes['end'], 1) != 0)
            self.downtimes = self.downtimes[good]
            diff = self.downtimes['start'][1:] - self.downtimes['end'][0:-1]

        self.seeing_data = SeeingData(mjd_start_time, seeing_db=seeing_db)
        self.seeing_model = SeeingModel()
        self.seeing_indx_dict = {}
        for i, filtername in enumerate(self.seeing_model.filter_list):
            self.seeing_indx_dict[filtername] = i

        self.cloud_data = CloudData(mjd_start_time, offset_year=0)

        self.sky_model = sb.SkyModelPre(speedLoad=quickTest)

        self.observatory = Kinem_model(mjd0=mjd_start)

        self.filterlist = ['u', 'g', 'r', 'i', 'z', 'y']
        self.seeing_FWHMeff = {}
        for key in self.filterlist:
            self.seeing_FWHMeff[key] = np.zeros(hp.nside2npix(self.nside),
                                                dtype=float)

        self.almanac = Almanac(mjd_start=mjd_start)

        # Let's make sure we're at an openable MJD
        good_mjd = False
        to_set_mjd = mjd_start
        while not good_mjd:
            good_mjd, to_set_mjd = self.check_mjd(to_set_mjd)
        self.mjd = to_set_mjd

        sun_moon_info = self.almanac.get_sun_moon_positions(self.mjd)
        season_offset = create_season_offset(self.nside,
                                             sun_moon_info['sun_RA'])
        self.sun_RA_start = sun_moon_info['sun_RA'] + 0
        # Conditions object to update and return on request
        self.conditions = Conditions(nside=self.nside,
                                     mjd_start=mjd_start,
                                     season_offset=season_offset,
                                     sun_RA_start=self.sun_RA_start)

        self.obsID_counter = 0