<commit_before># -*- coding: utf-8 -*-
"""
Created on Thu May 15 19:53:00 2014

@author: simonfilhol
"""

import gdal, sys, osr, os, time
from gdalconst import *
from tkinter import *
import tkinter.filedialog as tkFileDialog
import matplotlib.pyplot as plt
import numpy as np

# function to load a raster file
def openRaster(InPath=None):
    '''
    openRaster()   Load a raster file into Python console using gdal libraries.\n
    **myRaster, InPath = openRaster("filepath")**\n
    Copyright S Filhol \n
    Dependencies: Tkinter, gdal, sys, os  
    
    Parameters
    ----------    
    **InPath** :  string indicating the file path including the filename      

    Returns
    -------
    **myRaster** :      Raster class object (gdal object) \n
    **InPath** : string indicating the file path including the filename
    '''
    if InPath == None:
        root = Tk()
        root.withdraw()
        InPath = tkFileDialog.askopenfilename()
        time.sleep(.9)
        root.destroy()
        root.quit()
    if InPath is None:
        print('Could not open image')
        sys.exit(1)
    print(InPath)
    myRaster=gdal.Open(InPath)
    return myRaster
    
# function to convert raster data into an array ready for processing
def raster2array(myRaster):
    '''
    raster2array()   Convert Gdal raster object to  2 array. The raster object has to have only one band\n
    **data, dx, dy, transform = raster2array(myRaster)**\n
    Copyright S Filhol \n
    Dependencies: gdal  
    
    Parameters
    ----------    
    **myRaster** :  Raster class object (gdal object) \n    

    Returns
    -------
    **data** :      2D array containing the raster band data \n
    **dx, dy** : spatial resolution of th raster \n
    **transform** : raster transformation information. Very usefull information if you save the data back to raster form or plot data
    '''
    transform = myRaster.GetGeoTransform()
    dx=transform[1]
    dy=transform[5]
    Xsize=myRaster.RasterXSize
    Ysize=myRaster.RasterYSize
    data=myRaster.ReadAsArray(0, 0, Xsize, Ysize)
    myRaster=None
    return data, dx, dy, transform


def makeGeotransform(Xmin, dx, Ymax, dy):
    '''

    :param Xmin: x-coordinate of the upper left corner
    :param dx: pixel resolution x-direction
    :param Ymax: y-coordiante of the upper left corner
    :param dy: pixel resolution y-direction
    :return: a geotranform object ready to use in GDAL functions

    Note: more info http://www.perrygeo.com/python-affine-transforms.html
    '''
    return [Xmin, dx, 0, Ymax, dy, 0]
<commit_msg>corrected<commit_after># -*- coding: utf-8 -*-
"""
Created on Thu May 15 19:53:00 2014

@author: simonfilhol
"""

import gdal, sys, osr, os, time
from gdalconst import *
from tkinter import *
import tkinter.filedialog as tkFileDialog
import matplotlib.pyplot as plt
import numpy as np

# function to load a raster file
def openRaster(InPath=None):
    '''
    openRaster()   Load a raster file into Python console using gdal libraries.\n
    **myRaster, InPath = openRaster("filepath")**\n
    Copyright S Filhol \n
    Dependencies: Tkinter, gdal, sys, os  
    
    Parameters
    ----------    
    **InPath** :  string indicating the file path including the filename      

    Returns
    -------
    **myRaster** :      Raster class object (gdal object) \n
    **InPath** : string indicating the file path including the filename
    '''
    if InPath == None:
        root = Tk()
        root.withdraw()
        InPath = tkFileDialog.askopenfilename()
        time.sleep(.9)
        root.destroy()
        root.quit()
    if InPath is None:
        print('Could not open image')
        sys.exit(1)
    print(InPath)
    myRaster=gdal.Open(InPath)
    return myRaster
    
# function to convert raster data into an array ready for processing
def raster2array(myRaster):
    '''
    raster2array()   Convert Gdal raster object to  2 array. The raster object has to have only one band\n
    **data, dx, dy, transform = raster2array(myRaster)**\n
    Copyright <NAME> \n
    Dependencies: gdal  
    
    Parameters
    ----------    
    **myRaster** :  Raster class object (gdal object) \n    

    Returns
    -------
    **data** :      2D array containing the raster band data \n
    **dx, dy** : spatial resolution of th raster \n
    **transform** : raster transformation information. Very usefull information if you save the data back to raster form or plot data
    '''
    transform = myRaster.GetGeoTransform()
    dx=transform[1]
    dy=transform[5]
    Xsize=myRaster.RasterXSize
    Ysize=myRaster.RasterYSize
    data=myRaster.ReadAsArray(0, 0, Xsize, Ysize)
    myRaster=None
    return data, dx, dy, transform


def makeGeotransform(Xmin, dx, Ymax, dy):
    '''

    :param Xmin: x-coordinate of the upper left corner
    :param dx: pixel resolution x-direction
    :param Ymax: y-coordiante of the upper left corner
    :param dy: pixel resolution y-direction
    :return: a geotranform object ready to use in GDAL functions

    Note: more info http://www.perrygeo.com/python-affine-transforms.html
    '''
    return [Xmin, dx, 0, Ymax, 0, -dy]

{'fraction_non_alphanumeric': 0.10639953316475394, 'fraction_numerical': 0.010114763664656681, 'mean_word_length': 2.6493967352732435, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '174361', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1595, 'n_words': 543}