<commit_before>import os
import shutil
import struct
import itertools
import numpy
import pyfits
from png import Reader
from AstroPNGWriter import AstroPNGWriter
from utilities import which

class AstroPNG(object):
    """
    Yes, this is a class for representing astronomical data in the PNG format.
    We utilize the 16 bit integer format of PNGs, and custom chunks to store
    various metadata such as the FITS header.
    """
    
    def __init__(self, f):
        """        
        :param f:   The path of the image file
        """
        filename, extension = os.path.splitext(f)
        if extension.lower() == '.png':
            self.png = f
            self.fits = None
        else:
            self.fits = f
            self.png = None
        
        self.quantized  = False
        self.clipped    = False
    
    def to_png(self, out_file, bit_depth = 16, clip_on_percentiles = False, crush = True):
        """
        Converts the FITS file to a PNG.
        
        :param out_file:            User specified filename for the PNG
        :param clip_on_percentiles: Clips flux values to a lower and upper percentile
        :param crush:               Call pngcrush on the output image
        
        .. warning:: Setting bit_depth to 8 may reduce the dynamic range of the image.        
        .. warning:: Setting clip_on_percentiles to True reduces the dynamic range of the image.
        """
        if not self.fits:
            raise ValueError, "AstroPNG was not initialized with a FITS image"
        
        hdu = pyfits.open(self.fits)
        header, fluxes = hdu[0].header, hdu[0].data
        
        height, width = fluxes.shape
        
        # Prepare data
        fluxes = numpy.flipud(fluxes)
        fluxes = fluxes.flatten()
        
        if header['BITPIX'] == 16:
            fluxes = fluxes.astype(numpy.uint16)
        <commit_msg>Turning pngcrush off by default<commit_after>import os
import shutil
import struct
import itertools
import numpy
import pyfits
from png import Reader
from AstroPNGWriter import AstroPNGWriter
from utilities import which

class AstroPNG(object):
    """
    Yes, this is a class for representing astronomical data in the PNG format.
    We utilize the 16 bit integer format of PNGs, and custom chunks to store
    various metadata such as the FITS header.
    """
    
    def __init__(self, f):
        """        
        :param f:   The path of the image file
        """
        filename, extension = os.path.splitext(f)
        if extension.lower() == '.png':
            self.png = f
            self.fits = None
        else:
            self.fits = f
            self.png = None
        
        self.quantized  = False
        self.clipped    = False
    
    def to_png(self, out_file, bit_depth = 16, clip_on_percentiles = False, crush = False):
        """
        Converts the FITS file to a PNG.
        
        :param out_file:            User specified filename for the PNG
        :param clip_on_percentiles: Clips flux values to a lower and upper percentile
        :param crush:               Call pngcrush on the output image
        
        .. warning:: Setting bit_depth to 8 may reduce the dynamic range of the image.        
        .. warning:: Setting clip_on_percentiles to True reduces the dynamic range of the image.
        """
        if not self.fits:
            raise ValueError, "AstroPNG was not initialized with a FITS image"
        
        hdu = pyfits.open(self.fits)
        header, fluxes = hdu[0].header, hdu[0].data
        
        height, width = fluxes.shape
        
        # Prepare data
        fluxes = numpy.flipud(fluxes)
        fluxes = fluxes.flatten()
        
        if header['BITPIX'] == 16:
            fluxes = fluxes.astype(numpy.uint16)
        
{'fraction_non_alphanumeric': 0.06934594168636722, 'fraction_numerical': 0.005778828473863935, 'mean_word_length': 1.8396718866517525, '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': '1637210', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1035, 'n_words': 386}