<commit_before>#!/usr/bin/env python

import sys
import numpy as np
import scipy.ndimage as nd
import pyfits
import imagestats

def rfits(file):
    f = pyfits.open(file, memmap=True)
    hdu = f[0]
    (im, hdr) = (hdu.data, hdu.header)
    f.close()
    return hdu

def daofind(im):
    allstats = imagestats.ImageStats(im)
    stats = imagestats.ImageStats(im, nclip=3)
    mean = stats.mean
    sig = stats.stddev

    smooth = nd.gaussian_filter(im, 2.5)
    
    clip = smooth >= (mean + 0.6)
    labels, num = nd.label(clip)
    pos = nd.center_of_mass(im, labels, range(num+1))
    print num 
    return num, pos[1:]


if __name__ == '__main__':
    hdu = rfits(sys.argv[1])
    image = hdu.data
    hdr = hdu.header
    n, stars = daofind(image)

    if n == 2:
        print "Found boxes and writing positions."
        output = open("init_cen_all", 'w')
        for star in stars:
            (y, x) = star
            output.write("%8.3f   %8.3f\n" % (x,y))
        output.close()
    else:
        print "No or not enough stars found."
    

<commit_msg>add stuff to recenter boxed if no stars found<commit_after>#!/usr/bin/env python

import sys
import numpy as np
import scipy.ndimage as nd
import pyfits
import imagestats

def rfits(file):
    f = pyfits.open(file, memmap=True)
    hdu = f[0]
    (im, hdr) = (hdu.data, hdu.header)
    f.close()
    return hdu

def daofind(im):
    allstats = imagestats.ImageStats(im)
    stats = imagestats.ImageStats(im, nclip=3)
    mean = stats.mean
    sig = stats.stddev

    smooth = nd.gaussian_filter(im, 2.5)
    
    clip = smooth >= (mean + 0.6)
    labels, num = nd.label(clip)
    pos = nd.center_of_mass(im, labels, range(num+1))
    print num 
    return num, pos[1:]


if __name__ == '__main__':
    hdu = rfits(sys.argv[1])
    image = hdu.data
    hdr = hdu.header
    n, stars = daofind(image)

    if n == 2:
        print "Found boxes and writing positions."
        output = open("init_cen_all", 'w')
        for star in stars:
            (y, x) = star
            output.write("%8.3f   %8.3f\n" % (x,y))
        output.close()
    else:
        print "No or not enough stars found."
        output = open("init_cen_all", 'w')
        output.write("130.0   120.0\n")
        output.write("190.0   120.0\n")
        output.close()


{'fraction_non_alphanumeric': 0.1330732553099263, 'fraction_numerical': 0.01907238838318162, 'mean_word_length': 2.297142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5672899', 'n_tokens_mistral': 888, 'n_tokens_neox': 850, 'n_words': 222}