def testEquaorialFromGalactic(self):
        lonList = self.raList
        latList = self.decList

        raRad, decRad = utils._equatorialFromGalactic(lonList, latList)
        raDeg, decDeg = utils.equatorialFromGalactic(np.degrees(lonList),
                                                     np.degrees(latList))

        np.testing.assert_array_almost_equal(raRad, np.radians(raDeg), 10)
        np.testing.assert_array_almost_equal(decRad, np.radians(decDeg), 10)

        for lon, lat in zip(lonList, latList):
            raRad, decRad = utils._equatorialFromGalactic(lon, lat)
            raDeg, decDeg = utils.equatorialFromGalactic(np.degrees(lon), np.degrees(lat))
            self.assertAlmostEqual(raRad, np.radians(raDeg), 10)
            self.assertAlmostEqual(decRad, np.radians(decDeg), 10)
    def testEquaorialFromGalactic(self):
        lonList = self.raList
        latList = self.decList

        raRad, decRad = utils._equatorialFromGalactic(lonList, latList)
        raDeg, decDeg = utils.equatorialFromGalactic(np.degrees(lonList),
                                                     np.degrees(latList))

        np.testing.assert_array_almost_equal(raRad, np.radians(raDeg), 10)
        np.testing.assert_array_almost_equal(decRad, np.radians(decDeg), 10)

        for lon, lat in zip(lonList, latList):
            raRad, decRad = utils._equatorialFromGalactic(lon, lat)
            raDeg, decDeg = utils.equatorialFromGalactic(
                np.degrees(lon), np.degrees(lat))
            self.assertAlmostEqual(raRad, np.radians(raDeg), 10)
            self.assertAlmostEqual(decRad, np.radians(decDeg), 10)
Example #3
0
    else:
        raise RuntimeError('Do not know how to get '
                           'physical characteristics for '
                           'sub_dir %s' % sub_dir)

    get_physical_characteristics.teff_dict[sed_name] = tt
    get_physical_characteristics.metal_dict[sed_name] = mm
    get_physical_characteristics.logg_dict[sed_name] = gg

    return tt, mm, gg


if __name__ == "__main__":

    # find the RA, Dec of the north Galactic pole
    ra, dec = equatorialFromGalactic(0.0, 90.0)

    # define a field of view that is a circle of radius 1 degree
    # around that point
    obs = ObservationMetaData(pointingRA=ra,
                              pointingDec=dec,
                              boundType='circle',
                              boundLength=1.0)

    # connect to our database of simulated stars
    # (if you want to do this from off campus, talk to me;
    # there are more authentication steps you need to go through)
    star_db = StarObj(database='LSSTCATSIM',
                      host='fatboy.phys.washington.edu',
                      port=1433,
                      driver='mssql+pymssql')
Example #4
0
    parser.add_argument('--do_2', default=False, action='store_true')
    parser.add_argument('--do_3', default=False, action='store_true')
    parser.add_argument('--do_4', default=False, action='store_true')

    args = parser.parse_args()

    with open('data/htmid_to_obs_map.pickle', 'rb') as in_file:
        htmid_map = pickle.load(in_file)

    tx_dict = htm.getAllTrixels(6)
    tx_list = []
    for htmid in tx_dict:
        if htm.levelFromHtmid(htmid) == 6:
            tx_list.append(tx_dict[htmid])

    gal_n_ra, gal_n_dec = equatorialFromGalactic(0.0, 90.0)
    gal_s_ra, gal_s_dec = equatorialFromGalactic(0.0, -90.0)

    if args.do_1:
        ######### Region 1
        #1) ~600 deg2 along ecliptic plane, say |latitude| < 30 and a 100 deg stretch
        #    in longitude, but with |galactic latitude| > 30 deg

        # must be fully inside one of these two half spaces to have
        # |galactic latitude| > 30
        gal_n_30_hs = htm.halfSpaceFromRaDec(gal_n_ra, gal_n_dec, 60.0)
        gal_s_30_hs = htm.halfSpaceFromRaDec(gal_s_ra, gal_s_dec, 60.0)

        ecl_n_ra, ecl_n_dec = np.degrees(palpy.ecleq(0.0, 0.5 * np.pi,
                                                     59580.0))
        ecl_s_ra, ecl_s_dec = np.degrees(
def generateMicrolensingSlicer(min_crossing_time=1,
                               max_crossing_time=10,
                               t_start=1,
                               t_end=3652,
                               n_events=10000,
                               seed=42,
                               nside=128,
                               filtername='r'):
    """
    Generate a UserPointSlicer with a population of microlensing events. To be used with
    MicrolensingMetric

    Parameters
    ----------
    min_crossing_time : float (1)
        The minimum crossing time for the events generated (days)
    max_crossing_time : float (10)
        The max crossing time for the events generated (days)
    t_start : float (1)
        The night to start generating peaks (days)
    t_end : float (3652)
        The night to end generating peaks (days)
    n_events : int (10000)
        Number of microlensing events to generate
    seed : float (42)
        Random number seed
    nside : int (128)
        HEALpix nside, used to pick which stellar density map to load
    filtername : str ('r')
        The filter to use for the stellar density map
    """
    np.random.seed(seed)

    crossing_times = np.random.uniform(low=min_crossing_time,
                                       high=max_crossing_time,
                                       size=n_events)
    peak_times = np.random.uniform(low=t_start, high=t_end, size=n_events)
    impact_paramters = np.random.uniform(low=0, high=1, size=n_events)

    mapDir = os.path.join(getPackageDir('sims_maps'), 'TriMaps')
    data = np.load(
        os.path.join(mapDir,
                     'TRIstarDensity_%s_nside_%i.npz' % (filtername, nside)))
    starDensity = data['starDensity'].copy()
    # magnitude bins
    bins = data['bins'].copy()
    data.close()

    star_mag = 22
    bin_indx = np.where(bins[1:] >= star_mag)[0].min()
    density_used = starDensity[:, bin_indx].ravel()
    order = np.argsort(density_used)
    # I think the model might have a few outliers at the extreme, let's truncate it a bit
    density_used[order[-10:]] = density_used[order[-11]]

    # now, let's draw N from that distribution squared
    dist = density_used[order]**2
    cumm_dist = np.cumsum(dist)
    cumm_dist = cumm_dist / np.max(cumm_dist)
    uniform_draw = np.random.uniform(size=n_events)
    indexes = np.floor(
        np.interp(uniform_draw, cumm_dist, np.arange(cumm_dist.size)))
    hp_ids = order[indexes.astype(int)]
    gal_l, gal_b = hpid2RaDec(nside, hp_ids, nest=True)
    ra, dec = equatorialFromGalactic(gal_l, gal_b)

    # Set up the slicer to evaluate the catalog we just made
    slicer = slicers.UserPointsSlicer(ra, dec, latLonDeg=True, badval=0)
    # Add any additional information about each object to the slicer
    slicer.slicePoints['peak_time'] = peak_times
    slicer.slicePoints['crossing_time'] = crossing_times
    slicer.slicePoints['impact_parameter'] = impact_paramters

    return slicer