<commit_before>from __future__ import print_function
from glob import glob
import os
import matplotlib
matplotlib.use('Agg')
import pylab as plt
import numpy as np
from astrometry.util.fits import fits_table, merge_tables
from astrometry.util.plotutils import PlotSequence

def brickname_from_filename(fn):
    fn = os.path.basename(fn)
    words = fn.split('-')
    assert(len(words) == 3)
    return words[1]

def summary_plots(summaryfn, ps):
    T = fits_table(summaryfn)
    dlo = T.depthlo.copy()
    dd = dlo[2] - dlo[1]
    dlo[0] = dlo[1] - dd

    for band in 'grz':

        I = np.flatnonzero((dlo >= 21.5) * (dlo < 24.8))
        #I = np.flatnonzero((dlo >= 21.5))

        pixarea = (0.262 / 3600.)**2
        
        plt.clf()
        plt.bar(dlo[I], T.get('counts_ptsrc_%s' % band)[I] * pixarea, width=dd)
        plt.xlabel('Depth: %s band' % band)
        #plt.ylabel('Number of pixels')
        plt.ylabel('Area (sq.deg)')
        plt.title('DECaLS DR3 Depth: Point Sources, %s' % band)
        plt.xlim(21.5, 24.8)
        #plt.xlim(21.5, 25.)
        ps.savefig()

        plt.clf()
        plt.bar(dlo[I], T.get('counts_gal_%s' % band)[I] * pixarea, width=dd)
        plt.xlabel('Depth: %s band' % band)
        #plt.ylabel('Number of pixels')
        plt.ylabel('Area (sq.deg)')
        plt.title('DECaLS DR3 Depth: Canonical Galaxy, %s' % band)
        plt.xlim(21.5, 24.8)
        #plt.xlim(21.5, 25.)
        ps.savefig()

    for band in 'grz':
        c = list(reversed(np.cumsum(list(reversed(T.get('counts_gal_%s' % band))))))
        #N = np.sum(T.get('counts_gal_%s' % band))
        # Skip bin with no observations?
        N = np.sum(T.get('counts_gal_%s' % band)[1:])

        plt.clf()
        plt.bar(dlo, c, width=dd)

        target = dict(g=24.0, r=23.4, z=22.5)[band]
        plt.axvline(target)
        plt.axvline(target - 0.3)
        plt.axvline(target - 0.6)
        plt.axhline(N * 0.90)
        plt.axhline(N * 0.95)
        plt.axhline(N * 0.98)
        
        plt.xlabel('Depth: %s band' % band)
        plt.ylabel('Number of pixels')
        plt.title('Depth: SIMP Galaxy, %s' % band)

        ps.savefig()

if __name__ == '__main__':
    outfn = 'dr3-depth.fits'
    summaryfn = 'dr3-depth-summary.fits'

    #ps = PlotSequence('depth')
    #summary_plots(summaryfn, ps)
    #sys.exit(0)
    
    fns = glob('/project/projectdirs/cosmo/work/legacysurvey/dr3/coadd/*/*/*-depth.fits')
    fns.sort()<commit_msg>depth histograms: read from released data directory<commit_after>from __future__ import print_function
from glob import glob
import os
import matplotlib
matplotlib.use('Agg')
import pylab as plt
import numpy as np
from astrometry.util.fits import fits_table, merge_tables
from astrometry.util.plotutils import PlotSequence

def brickname_from_filename(fn):
    fn = os.path.basename(fn)
    words = fn.split('-')
    assert(len(words) == 3)
    return words[1]

def summary_plots(summaryfn, ps):
    T = fits_table(summaryfn)
    dlo = T.depthlo.copy()
    dd = dlo[2] - dlo[1]
    dlo[0] = dlo[1] - dd

    for band in 'grz':

        I = np.flatnonzero((dlo >= 21.5) * (dlo < 24.8))
        #I = np.flatnonzero((dlo >= 21.5))

        pixarea = (0.262 / 3600.)**2
        
        plt.clf()
        plt.bar(dlo[I], T.get('counts_ptsrc_%s' % band)[I] * pixarea, width=dd)
        plt.xlabel('Depth: %s band' % band)
        #plt.ylabel('Number of pixels')
        plt.ylabel('Area (sq.deg)')
        plt.title('DECaLS DR3 Depth: Point Sources, %s' % band)
        plt.xlim(21.5, 24.8)
        #plt.xlim(21.5, 25.)
        ps.savefig()

        plt.clf()
        plt.bar(dlo[I], T.get('counts_gal_%s' % band)[I] * pixarea, width=dd)
        plt.xlabel('Depth: %s band' % band)
        #plt.ylabel('Number of pixels')
        plt.ylabel('Area (sq.deg)')
        plt.title('DECaLS DR3 Depth: Canonical Galaxy, %s' % band)
        plt.xlim(21.5, 24.8)
        #plt.xlim(21.5, 25.)
        ps.savefig()

    for band in 'grz':
        c = list(reversed(np.cumsum(list(reversed(T.get('counts_gal_%s' % band))))))
        #N = np.sum(T.get('counts_gal_%s' % band))
        # Skip bin with no observations?
        N = np.sum(T.get('counts_gal_%s' % band)[1:])

        plt.clf()
        plt.bar(dlo, c, width=dd)

        target = dict(g=24.0, r=23.4, z=22.5)[band]
        plt.axvline(target)
        plt.axvline(target - 0.3)
        plt.axvline(target - 0.6)
        plt.axhline(N * 0.90)
        plt.axhline(N * 0.95)
        plt.axhline(N * 0.98)
        
        plt.xlabel('Depth: %s band' % band)
        plt.ylabel('Number of pixels')
        plt.title('Depth: SIMP Galaxy, %s' % band)

        ps.savefig()

if __name__ == '__main__':
    outfn = 'dr3-depth.fits'
    summaryfn = 'dr3-depth-summary.fits'

    #ps = PlotSequence('depth')
    #summary_plots(summaryfn, ps)
    #sys.exit(0)
    
    #fns = glob('/project/projectdirs/cosmo/work/legacysurvey/dr3/coadd/*/*/*-depth.fits')
    fns = glob('/project/projectdirs/cosmo/data/legacysurvey/dr3/coadd/*/*/*-depth.fits')
    fns.sort()
{'fraction_non_alphanumeric': 0.1661063871860787, 'fraction_numerical': 0.029859600553687957, 'mean_word_length': 2.376502002670227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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}}
{'dir': 'git-commits-cleaned', 'id': '4537214', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1962, 'n_words': 381}