Ejemplo n.º 1
0
    def test_generator(self):
        """Make sure the CorrelationFunctionSysTest() generator returns the right objects"""
        object_list = ['GalaxyShear', 'BrightStarShear', 'StarXGalaxyDensity',  'StarXGalaxyShear',
                       'StarXStarShear', 'GalaxyDensityCorrelation', 'StarDensityCorrelation']
        for object_type in object_list:
            object_1 = stile.CorrelationFunctionSysTest(object_type)
            object_2 = eval('stile.sys_tests.'+object_type+'SysTest()')
            self.assertEqual(type(object_1), type(object_2))

        self.assertRaises(ValueError, stile.CorrelationFunctionSysTest, 'hello')
        self.assertEqual(type(stile.sys_tests.BaseCorrelationFunctionSysTest()),
                         type(stile.CorrelationFunctionSysTest()))
Ejemplo n.º 2
0
def main():
    # setups
    dh = dummy.DummyDataHandler()
    bin_list = [
        stile.BinStep('ra', low=-1, high=1, step=1),
        stile.BinStep('dec', low=-1, high=1, step=1)
    ]
    sys_test = stile.CorrelationFunctionSysTest(type='GalaxyShear')

    stile_args = {
        'ra_units': 'degrees',
        'dec_units': 'degrees',
        'min_sep': 0.05,
        'max_sep': 1,
        'sep_units': 'degrees',
        'nbins': 20
    }
    data_ids = dh.listData(object_types=['galaxy lens', 'galaxy'],
                           epoch='single',
                           extent='field',
                           data_format='table')

    # do a test without binning
    data = dh.getData(data_ids[0], 'galaxy lens', 'single', 'field', 'table')
    data2 = dh.getData(data_ids[1], 'galaxy', 'single', 'field', 'table')

    # run the test
    results = sys_test(data, data2=data2, config=stile_args)

    fig = sys_test.plot(results)
    fig.savefig(sys_test.short_name + '.png')

    stile.WriteASCIITable('realshear.dat', results)
    print "Done with unbinned systematics test"

    # do with binning
    data = dh.getData(data_ids[0], 'galaxy lens', 'single', 'field', 'table')
    # turns a list of binning schemes into a pseudo-nested list of single bins
    expanded_bin_list = stile.ExpandBinList(bin_list)
    handles_list = []
    deletes_list = []
    # for each set of bins, do the systematics test as above
    for bin_list in expanded_bin_list:
        bins_name = '-'.join([bl.short_name for bl in bin_list])
        data2 = dh.getData(data_ids[1],
                           'galaxy',
                           'single',
                           'field',
                           'table',
                           bin_list=bin_list)
        results = sys_test(data, data2=data2, config=stile_args)
        stile.WriteASCIITable('realshear-' + bins_name + '.dat', results)
        fig = sys_test.plot(results)
        fig.savefig(sys_test.short_name + bins_name + '.png')
        print "Done with binned systematics test", bins_name
Ejemplo n.º 3
0
 def test_plot(self):
     """ Test that the plotting routines successfully generate a plot """
     stile_args = {
         'ra_units': 'degrees',
         'dec_units': 'degrees',
         'min_sep': 0.05,
         'max_sep': 1,
         'sep_units': 'degrees',
         'nbins': 20
     }
     cf = stile.sys_tests.CorrelationFunctionSysTest()
     lens_data = stile.ReadASCIITable(
         '../examples/example_lens_catalog.dat',
         fields={
             'id': 0,
             'ra': 1,
             'dec': 2,
             'z': 3,
             'g1': 4,
             'g2': 5
         })
     source_data = stile.ReadASCIITable(
         '../examples/example_source_catalog.dat',
         fields={
             'id': 0,
             'ra': 1,
             'dec': 2,
             'z': 3,
             'g1': 4,
             'g2': 5
         })
     object_list = [
         'GalaxyShear', 'BrightStarShear', 'StarXGalaxyShear',
         'StarXStarShear'
     ]
     for object_type in object_list:
         obj = stile.CorrelationFunctionSysTest(object_type)
         results = obj(lens_data, source_data, **stile_args)
         pl = obj.plot(results)
         self.assertIsInstance(pl, matplotlib.figure.Figure)
     # Test underscore protection. If there's an underscore in the radius label somewhere,
     # get rid of the non-underscore versions to make sure we hit that branch of the code,
     # then test the plotting again
     names = list(results.dtype.names)
     names_no_units = [n.split(' [')[0] for n in names]
     if 'R_nom' in names_no_units or 'R_nominal' in names_no_units:
         for rname in ['meanR', '<R>', 'R']:
             if rname in names_no_units:
                 index = names_no_units.index(rname)
                 names[index] = 'old_' + names[index]
         results.dtype.names = names
         pl = obj.plot(results)
         self.assertIsInstance(pl, matplotlib.figure.Figure)
         pl.savefig('examine.png')