Ejemplo n.º 1
0
def test_write_jsviewer_options(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['<b>a</b>', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath
    t.write(tmpfile,
            format='jsviewer',
            table_id='test',
            max_lines=3,
            jskwargs={'display_length': 5},
            table_class='display hover',
            htmldict=dict(raw_html_cols='b'))

    ref = REFERENCE % dict(
        lines=format_lines(t['a'][:3], t['b'][:3]),
        table_class='display hover',
        table_id='test',
        length='5',
        display_length='5, 10, 25, 50, 100, 500, 1000',
        datatables_css_url=
        'https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css',
        datatables_js_url=
        'https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js',
        jquery_url='https://code.jquery.com/jquery-3.1.1.min.js')
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 2
0
def test_write_jsviewer_local(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['a', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile,
            format='jsviewer',
            table_id='test',
            jskwargs={'use_local_files': True})
    ref = REFERENCE % dict(
        lines=format_lines(t['a'], t['b']),
        table_class='display compact',
        table_id='test',
        length='50',
        display_length='10, 25, 50, 100, 500, 1000',
        datatables_css_url='file://' +
        join(EXTERN_DIR, 'css', 'jquery.dataTables.css'),
        datatables_js_url='file://' +
        join(EXTERN_DIR, 'js', 'jquery.dataTables.min.js'),
        jquery_url='file://' + join(EXTERN_DIR, 'js', 'jquery-3.1.1.min.js'))
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 3
0
def generate_transmission_tables():
    from datetime import datetime
    cur_date = datetime.now().strftime('%Y%m%d')
    datetime.now().strftime('%Y%m%d')
    trans = Transmission()

    energies = np.linspace(2, 150, 1001) * u.keV

    norm_sci_energies = trans.get_transmission()
    norm_sci_energies.write(f'stix_transmission_sci_energies_{cur_date}.csv')
    norm_high_res = trans.get_transmission(energies=energies)
    norm_high_res.write(f'stix_transmission_highres_{cur_date}.csv')

    comps = trans.get_transmission_by_component()

    comps_sci_energies = Table(
        [c.transmission(trans.energies) for c in comps.values()],
        names=[k for k in comps.keys()])
    comps_sci_energies['energy'] = trans.energies
    comps_sci_energies.write(
        f'stix_transmission_by_component_sci_energies_{cur_date}.csv')

    comps_highres = Table([c.transmission(energies) for c in comps.values()],
                          names=[k for k in comps.keys()])
    comps_highres['energy'] = energies
    comps_highres.write(
        f'stix_transmission_by_component_highres_{cur_date}.csv')
Ejemplo n.º 4
0
def test_write_jsviewer_default(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['a', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer')
    ref = REFERENCE % dict(
        lines=format_lines(t['a'], t['b']),
        table_class='display compact',
        table_id=f'table{id(t)}',
        length='50',
        display_length='10, 25, 50, 100, 500, 1000',
        datatables_css_url='https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css',
        datatables_js_url='https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js',
        jquery_url='https://code.jquery.com/jquery-3.1.1.min.js'
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 5
0
def test_write_jsviewer_default(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['a', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer')
    ref = REFERENCE % dict(
        lines=format_lines(t['a'], t['b']),
        table_class='display compact',
        table_id='table%s' % id(t),
        length='50',
        display_length='10, 25, 50, 100, 500, 1000',
        datatables_css_url='https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css',
        datatables_js_url='https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js',
        jquery_url='https://code.jquery.com/jquery-3.1.1.min.js'
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 6
0
    def writer(filename, catalog, fmt=None):
        """
        construct a dict of the data
        this method preserves the data types in the VOTable
        """
        tab_dict = {}
        name_list = []
        for name in catalog[0].names:
            col_name = name
            if catalog[0].galactic:
                if name.startswith('ra'):
                    col_name = 'lon' + name[2:]
                elif name.endswith('ra'):
                    col_name = name[:-2] + 'lon'
                elif name.startswith('dec'):
                    col_name = 'lat' + name[3:]
                elif name.endswith('dec'):
                    col_name = name[:-3] + 'lat'
            col_name = pre + col_name
            tab_dict[col_name] = [getattr(c, name, None) for c in catalog]
            name_list.append(col_name)
        t = Table(tab_dict, meta=meta)
        # re-order the columns
        t = t[[n for n in name_list]]

        if fmt is not None:
            if fmt in ["vot", "vo", "xml"]:
                vot = from_table(t)
                # description of this votable
                vot.description = repr(meta)
                writetoVO(vot, filename)
            elif fmt in ['hdf5']:
                t.write(filename, path='data', overwrite=True)
            elif fmt in ['fits']:
                writeFITSTable(filename, t)
            else:
                ascii.write(t, filename, fmt, overwrite=True)
        else:
            ascii.write(t, filename, overwrite=True)
        return
Ejemplo n.º 7
0
    def writer(filename, catalog, fmt=None):
        """
        construct a dict of the data
        this method preserves the data types in the VOTable
        """
        tab_dict = {}
        name_list = []
        for name in catalog[0].names:
            col_name = name
            if catalog[0].galactic:
                if name.startswith('ra'):
                    col_name = 'lon'+name[2:]
                elif name.endswith('ra'):
                    col_name = name[:-2] + 'lon'
                elif name.startswith('dec'):
                    col_name = 'lat'+name[3:]
                elif name.endswith('dec'):
                    col_name = name[:-3] + 'lat'
            col_name = pre + col_name
            tab_dict[col_name] = [getattr(c, name, None) for c in catalog]
            name_list.append(col_name)
        t = Table(tab_dict, meta=meta)
        # re-order the columns
        t = t[[n for n in name_list]]

        if fmt is not None:
            if fmt in ["vot", "vo", "xml"]:
                vot = from_table(t)
                # description of this votable
                vot.description = repr(meta)
                writetoVO(vot, filename)
            elif fmt in ['hdf5']:
                t.write(filename, path='data', overwrite=True)
            elif fmt in ['fits']:
                writeFITSTable(filename, t)
            else:
                ascii.write(t, filename, fmt, overwrite=True)
        else:
            ascii.write(t, filename, overwrite=True)
        return
Ejemplo n.º 8
0
def test_write_jsviewer_local(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['a', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath

    t.write(tmpfile, format='jsviewer', table_id='test',
            jskwargs={'use_local_files': True})
    ref = REFERENCE % dict(
        lines=format_lines(t['a'], t['b']),
        table_class='display compact',
        table_id='test',
        length='50',
        display_length='10, 25, 50, 100, 500, 1000',
        datatables_css_url='file://' + join(EXTERN_DIR, 'css', 'jquery.dataTables.css'),
        datatables_js_url='file://' + join(EXTERN_DIR, 'js', 'jquery.dataTables.min.js'),
        jquery_url='file://' + join(EXTERN_DIR, 'js', 'jquery-3.1.1.min.js')
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 9
0
def test_write_jsviewer_options(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['<b>a</b>', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'

    tmpfile = tmpdir.join('test.html').strpath
    t.write(tmpfile, format='jsviewer', table_id='test', max_lines=3,
            jskwargs={'display_length': 5}, table_class='display hover',
            htmldict=dict(raw_html_cols='b'))

    ref = REFERENCE % dict(
        lines=format_lines(t['a'][:3], t['b'][:3]),
        table_class='display hover',
        table_id='test',
        length='5',
        display_length='5, 10, 25, 50, 100, 500, 1000',
        datatables_css_url='https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css',
        datatables_js_url='https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js',
        jquery_url='https://code.jquery.com/jquery-3.1.1.min.js'
    )
    with open(tmpfile) as f:
        assert f.read().strip() == ref.strip()
Ejemplo n.º 10
0
 def writer(filename, catalog, fmt=None):
     # construct a dict of the data
     # this method preserves the data types in the VOTable
     tab_dict = {}
     for name in catalog[0].names:
         tab_dict[name] = [getattr(c, name, None) for c in catalog]
     t = Table(tab_dict,meta=meta)
     # re-order the columns
     t = t[[n for n in catalog[0].names]]
     if fmt is not None:
         if fmt in ["vot", "vo", "xml"]:
             vot = from_table(t)
             # description of this votable
             vot.description = repr(meta)
             writetoVO(vot, filename)
         elif fmt in ['hdf5']:
             t.write(filename,path='data',overwrite=True)
         elif fmt in ['fits']:
             writeFITSTable(filename,t)
         else:
             ascii.write(t, filename, fmt)
     else:
         ascii.write(t, filename)
     return
Ejemplo n.º 11
0
 def writer(filename, catalog, fmt=None):
     # construct a dict of the data
     # this method preserves the data types in the VOTable
     tab_dict = {}
     for name in catalog[0].names:
         tab_dict[name] = [getattr(c, name, None) for c in catalog]
     t = Table(tab_dict, meta=meta)
     # re-order the columns
     t = t[[n for n in catalog[0].names]]
     if fmt is not None:
         if fmt in ["vot", "vo", "xml"]:
             vot = from_table(t)
             # description of this votable
             vot.description = repr(meta)
             writetoVO(vot, filename)
         elif fmt in ['hdf5']:
             t.write(filename, path='data', overwrite=True)
         elif fmt in ['fits']:
             writeFITSTable(filename, t)
         else:
             ascii.write(t, filename, fmt)
     else:
         ascii.write(t, filename)
     return
Ejemplo n.º 12
0
def test_write_jsviewer_overwrite(tmpdir):
    t = Table()
    t['a'] = [1, 2, 3, 4, 5]
    t['b'] = ['a', 'b', 'c', 'd', 'e']
    t['a'].unit = 'm'
    tmpfile = tmpdir.join('test.html').strpath

    # normal write
    t.write(tmpfile, format='jsviewer')
    # errors on overwrite
    with pytest.raises(OSError, match="exists"):
        t.write(tmpfile, format='jsviewer')
    # unless specified
    t.write(tmpfile, format='jsviewer', overwrite=True)
Ejemplo n.º 13
0
    if table is None:
        if args.short:
            print "Failed"
        else:
            print "---"
            print "\033[91mNot able to access data for source in archive %s\033[0m" % (
                cat)
            print "---"
        sys.exit(1)

    if args.short:
        print "OK"
        sys.exit(0)

    if len(cols) > 0:
        tab = table
        table = Table()
        for c in cols:
            table.add_column(tab.columns[c])

    if outfile:
        table.write(outfile, format='ascii', delimiter=',')

    print "---"
    print " Table retrieved:"
    table.pprint(max_width=-1)
    print "---"

    sys.exit(0)
Ejemplo n.º 14
0
    
    if table is None:
        if args.short:
            print "Failed"
        else:
            print "---"
            print "\033[91mNot able to access data for source in archive %s\033[0m" % (cat)
            print "---"
        sys.exit(1)
    
    if args.short:
        print "OK"
        sys.exit(0)
    
    if len(cols) > 0:
        tab = table
        table = Table()
        for c in cols:
            table.add_column(tab.columns[c])
    
    if outfile:
        table.write(outfile,format='ascii',delimiter=',')
    
    print "---"
    print " Table retrieved:"    
    table.pprint(max_width=-1)
    print "---"

    sys.exit(0)