<commit_before>import glob
from datetime import datetime
from astropy.io import fits

class obs_group:
    def __init__(self, obj=[], flat=[], comp=[]):
        self.images = {'object' :list(obj), 'flat':list(flat), 'comp':list(comp)}
    def add_image(self, im, imgtype):
        try:
            self.images[imgtype].append(im)
        except KeyError:
            print 'Unrecognize d image type:',imgtype
    def get_images(self, img_type=None):
        if img_type == None:
            imgs = []
            for k in self.images.keys():
                imgs.extend(self.images[k])
            return imgs
        return self.images[img_type]

def convert_timestr(s):
    decimal_seconds = '.'+s.split('.')[-1]
    micro_seconds = str(int(float(decimal_seconds)*1.0e6)).rjust(6, '0')
    s = s.split('.')[0]+':'+micro_seconds
    return datetime.strptime(s, '%Y-%m-%dT%H:%M:%S:%f')

#group images with identical fiber pointings that were taken cronologically
def group_obs(direc):
    #Declare fits header IMGTYPEs to ignore
    ignore_types = ['zero']

    #Get list of fits files in direc
    if direc[-1] != '/':
        direc += '/'
    fitsList = glob.glob(direc+'*.fits')+glob.glob(direc+'*.fit')

    #Load fits files
    fitsList = [fits.open(fpath) for fpath in fitsList]

    #Sort files chronologically by DATE-OBS 
    fitsList = sorted(fitsList, key=lambda f: convert_timestr(f[0].header['DATE-OBS']))

    pointings = []
    pointings.append(obs_group())
    prev_fiberConfig = ''
    for f in fitsList:
        h = f[0].header
        n = 1
        fiberConfig = ''<commit_msg>Fixed group number.<commit_after>import glob
from datetime import datetime
from astropy.io import fits

class obs_group:
    def __init__(self, obj=[], flat=[], comp=[]):
        self.images = {'object' :list(obj), 'flat':list(flat), 'comp':list(comp)}
    def add_image(self, im, imgtype):
        try:
            self.images[imgtype].append(im)
        except KeyError:
            print 'Unrecognize d image type:',imgtype
    def get_images(self, img_type=None):
        if img_type == None:
            imgs = []
            for k in self.images.keys():
                imgs.extend(self.images[k])
            return imgs
        return self.images[img_type]

def convert_timestr(s):
    decimal_seconds = '.'+s.split('.')[-1]
    micro_seconds = str(int(float(decimal_seconds)*1.0e6)).rjust(6, '0')
    s = s.split('.')[0]+':'+micro_seconds
    return datetime.strptime(s, '%Y-%m-%dT%H:%M:%S:%f')

#group images with identical fiber pointings that were taken cronologically
def group_obs(direc):
    #Declare fits header IMGTYPEs to ignore
    ignore_types = ['zero']

    #Get list of fits files in direc
    if direc[-1] != '/':
        direc += '/'
    fitsList = glob.glob(direc+'*.fits')+glob.glob(direc+'*.fit')

    #Load fits files
    fitsList = [fits.open(fpath) for fpath in fitsList]

    #Sort files chronologically by DATE-OBS 
    fitsList = sorted(fitsList, key=lambda f: convert_timestr(f[0].header['DATE-OBS']))

    pointings = []
    prev_fiberConfig = ''
    for f in fitsList:
        h = f[0].header
        n = 1
        fiberConfig = ''
{'fraction_non_alphanumeric': 0.1472819216182048, 'fraction_numerical': 0.00695322376738306, 'mean_word_length': 2.8040865384615383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6363061', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1059, 'n_words': 253}