<jupyter_start><jupyter_text>Produce a preview page for all spectra of each rating<jupyter_code>def __output_header(f, title):
    f.write('<!doctype html>\n<html lang="en">\n<head>\n<title>{}</title>'.format(title))
    with open('style.html') as style:
        f.write(style.read())
    f.write('\n</head>\n<body>\n<h1 align="middle">{}</h1>'.format(title))
    f.write('\n<table class="imageTable">')
    return

def __output_row(f, comp_names, num_cols=5):
    f.write('\n<tr>')
    i = 0
    for name in comp_names:
        i+=1
        f.write('\n<td>')
        f.write('<a href="spectra/{0}_spec.png"><img src="spectra/{0}_spec_zoom.png"></a>'
                .format(name))
        f.write('</td>')

    while i < num_cols:
        i+=1
        f.write('\n<td/>')
    return

def __output_footer(f):
    f.write('\n\n</table>\n</body>\n</html>')
    return

def output_header(f, title):
    f.write('<!doctype html>\n<html lang="en">\n<head>\n<title>{}</title>'.format(title))
    with open('style.html') as style:
        f.write(style.read())
    f.write('\n</head>\n<body>')
    f.write('\n<div class="container-fluid">')
    f.write('\n<h1 align="middle">{}</h1>'.format(title))
    return

def output_block_title(f, rating, first, count):
    if not first:
        f.write('\n\n</div><br/>\n')
    spec = 'spectrum' if count == 1 else 'spectra'
    f.write('\n<div>')
    f.write('\n<div class="col-9 d-inline"><h2 class="d-inline font-weight-light text-center text-lg-left mt-4 mb-0">{} Rating {} {}</h2></div>'.format(count, rating, spec))
    f.write('\n<div class="col-3 pull-right d-inline"><a class="btn btn-primary" data-toggle="collapse" href="#spectra{0}" role="button" aria-expanded="false" aria-controls="spectra{0}" style="font-size: x-small;">Toggle</a></div>'.format(rating))
    f.write('\n</div>')
    f.write('\n<div class="row text-center text-lg-left collapse show" id="spectra{}">'.format(rating))

    
def output_img(f, comp_name, rating):
    f.write('\n<div class="col-lg-3 col-md-4 col-6 px-2">')
    f.write('\n<a href="spectra/{0}_spec.png" class="d-block mb-4 h-100"  data-lightbox="rating{1}">'.format(comp_name, rating))
    f.write('\n<img class="img-fluid img-thumbnail" ')
    f.write('src="spectra/{0}_spec_zoom.png" alt="Zoomed preview of spectrum at {0}">'.format(comp_name))
    f.write('\n</a>\n</div>')
    return

def output_footer(f):
    f.write('\n\n</div>\n</div>\n</body>\n</html>')
    return


spectra_votable = votable.parse('askap_spectra.vot', pedantic=False)
table = spectra_votable.get_first_table().to_table()

with open('sb8906/index.html'.format(rating), 'w') as f:
    output_header(f, 'Absorption spectra for SBID 8906')

    for rating in 'ABCDEF':
        targets = table[table['rating']==rating]
        comp_names = sorted(targets['comp_name'])
        print('Rating {} has {} spectra'.format(rating, len(comp_names)))

        output_block_title(f, rating, rating=='A', len(comp_names))

        for name in comp_names:
            output_img(f, name, rating)
                
    output_footer(f)
        

spectra_votable = votable.parse('askap_spectra.vot', pedantic=False)
table = spectra_votable.get_first_table().to_table()

with open('sb8906/detections.html'.format(rating), 'w') as f:
    output_header(f, 'Absorption spectra for SBID 8906 with 3.5σ candidate detections')

    for rating in 'ABCDEF':
        targets = table[table['rating']==rating]
        targets = targets[(1-targets['min_opacity'])/targets['sd_cont'] > 3.5]
        comp_names = sorted(targets['comp_name'])
        print('Rating {} has {} spectra'.format(rating, len(comp_names)))

        output_block_title(f, rating, rating=='A', len(comp_names))

        for name in comp_names:
            output_img(f, name, rating)
                
    output_footer(f)
        


spectra_votable = votable.parse('askap_spectra.vot', pedantic=False)
table = spectra_votable.get_first_table().to_table()

with open('sb8906/best.html'.format(rating), 'w') as f:
    output_header(f, 'Absorption spectra for SBID 8906 with 5σ candidate detections')

    for rating in 'ABCDEF':
        targets = table[table['rating']==rating]
        targets = targets[(1-targets['min_opacity'])/targets['sd_cont'] > 5]
        comp_names = sorted(targets['comp_name'])
        print('Rating {} has {} spectra'.format(rating, len(comp_names)))

        output_block_title(f, rating, rating=='A', len(comp_names))

        for name in comp_names:
            output_img(f, name, rating)
                
    output_footer(f)
        



def output_j19_img(f, comp_name, rating):
    f.write('\n<div class="col-4">')
    f.write('\n<a href="spectra/{0}_spec.png" class="d-block mb-4 h-100"  data-lightbox="rating{1}">'.format(comp_name, rating))
    f.write('\n<img class="img-fluid img-thumbnail" ')
    f.write('src="spectra/{0}_spec_zoom.png" alt="Zoomed preview of spectrum at {0}">'.format(comp_name))
    f.write('\n</a>\n</div>')
    f.write('\n<div class="col-8">')
    f.write('\n<a href="jameson19plots/{0}.jpg" class="d-block mb-4 h-100"  data-lightbox="rating{1}">'.format(comp_name, rating))
    f.write('\n<img class="img-fluid img-thumbnail" ')
    f.write('src="jameson19plots/{0}.jpg" alt="Zoomed preview of spectrum at {0}">'.format(comp_name))
    f.write('\n</a>\n</div>')

    return


crossmatch = ['J010029-713825', 'J003809-735023', 'J012639-731501', 'J012350-735041', 'J011132-730209', 
              'J005611-710707', 'J011005-722648', 'J012930-733310', 'J013243-734413', 'J011919-710522', 
              'J011917-710537', 'J012924-733152', 'J012629-732714', 'J013032-731740', 'J005820-713039',
              'J010919-725600', 'J004808-741205', 'J004956-723553', 'J005337-723143', 'J005557-722604', 
              'J010931-713454', 'J011056-731403', 'J011432-732142', 'J013147-734941', 'J003947-713734',
              'J005238-731244', 'J003824-742211', 'J003939-714141', 'J011629-731438']

#targets = table[table['comp_name'] in crossmatch]
#targets
mask = np.isin(table['comp_name'], crossmatch)
targets = table[mask]
comp_names = sorted(targets['comp_name'])
comp_names
#with open('sb8906/best.html'.format(rating), 'w') as f:
#    output_header(f, 'Absorption spectra for SBID 8906 with 5σ candidate detections')

with open('sb8906/j19.html'.format(rating), 'w') as f:
    output_header(f, 'Absorption spectra for SBID 8906 also in Jameson 19')

    for rating in 'ABCDEF':
        targets = table[table['rating']==rating]
        mask = np.isin(targets['comp_name'], crossmatch)
        targets = targets[mask]
        comp_names = sorted(targets['comp_name'])

        output_block_title(f, rating, rating=='A', len(comp_names))

        for name in comp_names:
            output_j19_img(f, name, rating)
                
    output_footer(f)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1863563167910994, 'fraction_numerical': 0.06704728443858879, 'mean_word_length': 3.5760214333556597, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '449265', 'license': 'MIT', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2485, 'n_words': 430, 'path': 'obsolete/GeneratePreviewPages.ipynb', 'repo_name': 'jd-au/GASKAP-HI-Absorption-Pipeline', 'size': '6831'}