Exemplo n.º 1
0
 def test_get_clouds_using_different_start_month(self):
     # Just changing the starting month
     t2 = Time('2020-05-24', format='isot', scale='tai')
     cloud1 = CloudData(t2)
     self.assertEqual(cloud1.start_time, self.th)
     cloud1.read_data()
     dt = TimeDelta(700000, format='sec')
     self.assertEqual(cloud1(t2 + dt), 0.0)
     dt = TimeDelta(6306840, format='sec')
     self.assertEqual(cloud1(t2 + dt), 0.25)
Exemplo n.º 2
0
 def test_get_clouds(self):
     cloudData = CloudData(self.th, cloud_db=self.cloud_db)
     cloudData.read_data()
     dt = TimeDelta(700000, format='sec')
     self.assertEqual(cloudData(self.th + dt), 0.5)
     dt = TimeDelta(701500, format='sec')
     self.assertEqual(cloudData(self.th + dt), 0.5)
     dt = TimeDelta(705000, format='sec')
     self.assertEqual(cloudData(self.th + dt), 0.375)
     dt = TimeDelta(6306840, format='sec')
     self.assertEqual(cloudData(self.th + dt), 0.0)
Exemplo n.º 3
0
 def test_information_after_initialization(self):
     # Test setting cloud_db explicitly.
     cloudData = CloudData(self.th, cloud_db=self.cloud_db)
     cloudData.read_data()
     self.assertEqual(cloudData.cloud_values.size, self.num_original_values)
     self.assertEqual(cloudData.cloud_dates.size, self.num_original_values)
     # Test that find built-in module automatically.
     cloudData = CloudData(self.th)
     cloudData.read_data()
     self.assertEqual(cloudData.cloud_dates.size, self.num_original_values)
Exemplo n.º 4
0
    def __init__(self, survey_start_time=DEFAULT_START_TIME):
        """Initialize source of simulated cloud levels.

        Args:
           - survey_start_time :: an astropy.time.Time object
             designating the start of the survey.
        """
        self.start_time = survey_start_time
        self.cloud_data = CloudData(DEFAULT_START_TIME)
Exemplo n.º 5
0
 def test_alternate_db(self):
     with getTempFilePath('.alt_cloud.db') as tmpdb:
         cloud_dbfile = tmpdb
         cloud_table = []
         cloud_table.append("cloudId INTEGER PRIMARY KEY")
         cloud_table.append("c_date INTEGER")
         cloud_table.append("cloud DOUBLE")
         with sqlite3.connect(cloud_dbfile) as conn:
             cur = conn.cursor()
             cur.execute("DROP TABLE IF EXISTS Cloud")
             cur.execute("CREATE TABLE Cloud({})".format(
                 ",".join(cloud_table)))
             cur.executemany("INSERT INTO Cloud VALUES(?, ?, ?)",
                             [(1, 9997, 0.5), (2, 10342, 0.125)])
             cur.close()
         cloud1 = CloudData(self.th, tmpdb)
         cloud1.read_data()
         self.assertEqual(cloud1.cloud_values.size, 2)
         self.assertEqual(cloud1.cloud_values[1], 0.125)
Exemplo n.º 6
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,
                 cloud_db=None,
                 cloud_offset_year=0):
        """
        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
        cloud_offset_year : float, opt
            Offset into the cloud database by 'offset_year' years. Default 0.
        cloud_db : filename of the cloud data database (None)
            If one would like to use an alternate seeing database
        """

        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

        # Conditions object to update and return on request
        self.conditions = Conditions(nside=self.nside)

        self.sim_ToO = sim_ToO

        # 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,
                                    cloud_db=cloud_db,
                                    offset_year=cloud_offset_year)
        sched_logger.info(
            f"Using {self.cloud_data.cloud_db} as cloud database with start year {self.cloud_data.start_time.iso}"
        )

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

        self.observatory = ExtendedObservatoryModel()
        self.observatory.configure_from_module()
        # Make it so it respects my requested rotator angles
        self.observatory.params.rotator_followsky = True

        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

        self.obsID_counter = 0
Exemplo n.º 7
0
 def test_basic_information_after_creation(self):
     cloudData = CloudData(self.th, cloud_db=self.cloud_db)
     self.assertEqual(cloudData.start_time, self.th)
     cloudData = CloudData(self.th, cloud_db=self.cloud_db, offset_year=1)
     self.assertEqual(cloudData.start_time,
                      Time('2021-01-01', format='isot', scale='tai'))