<commit_before>##############################################################
# core routines for software pythonland
# <NAME> 2014-2015
# last update 2015-12-08
##############################################################
"""
This script gathers central functions and object instances for processing SAR images using the software GAMMA within the GUI
Please refer to the descriptions of the individual functions/instances for details
"""

import inspect
import math
import os
import subprocess as sp
from StringIO import StringIO
from Tkinter import *
from glob import glob
from gamma.error import gammaErrorHandler

from osgeo import osr

try:
    import pathos.multiprocessing as mp
except ImportError:
    pass


# suppress console stdout prints, i.e. redirect them to a temporary string object
# call enablePrint() to reverse the effect
def blockPrint():
    if isinstance(sys.stdout, file):
        sys.stdout = StringIO()


# convert between epsg, wkt and proj4 spatial references
# crsText must be of type WKT, PROJ4 or EPSG
# crsOut must be either "wkt", "proj4" or "epsg"
def crsConvert(crsText, crsOut):
    srs = osr.SpatialReference()
    check = None
    for fun in [srs.ImportFromEPSG, srs.ImportFromWkt, srs.ImportFromProj4]:
        try:
            check = fun(crsText)
            if check != 0:
                raise TypeError
            else:
                break
        except TypeError:
            continue
    if check is None:
        raise ValueError("crsText not recognized; must be of type WKT, PROJ4 otr EPSG")
    if crsOut == "wkt":
        return srs.ExportToWkt()
    elif crsOut == "proj4":
        return srs.ExportToProj4()
    elif crsOut == "epsg":
        return int(srs.GetAttrValue("AUTHORITY", 1))
    else:
        raise ValueError("crsOut not recognized; must be either wkt, proj4 or epsg")


# merge two dictionaries
def dictmerge(x, y):
    z = x.copy()
    z.update(y)
    return z
<commit_msg>function: crsConvert: added option "osr" to crsOut argument<commit_after>##############################################################
# core routines for software pythonland
# <NAME> 2014-2015
# last update 2015-12-08
##############################################################
"""
This script gathers central functions and object instances for processing SAR images using the software GAMMA within the GUI
Please refer to the descriptions of the individual functions/instances for details
"""

import inspect
import math
import os
import subprocess as sp
from StringIO import StringIO
from Tkinter import *
from glob import glob
from gamma.error import gammaErrorHandler

from osgeo import osr

try:
    import pathos.multiprocessing as mp
except ImportError:
    pass


# suppress console stdout prints, i.e. redirect them to a temporary string object
# call enablePrint() to reverse the effect
def blockPrint():
    if isinstance(sys.stdout, file):
        sys.stdout = StringIO()


# convert between epsg, wkt and proj4 spatial references
# crsText must be of type WKT, PROJ4 or EPSG
# crsOut must be either "wkt", "proj4", "epsg" or "osr"
# if type "osr" is selected the function will return a spatial reference object of type osr.SpatialReference()
def crsConvert(crsText, crsOut):
    srs = osr.SpatialReference()
    check = None
    for fun in [srs.ImportFromEPSG, srs.ImportFromWkt, srs.ImportFromProj4]:
        try:
            check = fun(crsText)
            if check != 0:
                raise TypeError
            else:
                break
        except TypeError:
            continue
    if check is None:
        raise ValueError("crsText not recognized; must be of type WKT, PROJ4 otr EPSG")
    if crsOut == "wkt":
        return srs.ExportToWkt()
    elif crsOut == "proj4":
        return srs.ExportToProj4()
    elif crsOut == "epsg":
        return int(srs.GetAttrValue("AUTHORITY", 1))
    elif crsOut == "osr":
        return srs
    else:
        raise ValueError("crsOut not recognized; must be either wkt, proj4 or epsg")


# merge two dictionaries
def dictmerge(x, y):
    z = x.copy()
    z.update(y)
    return z

{'fraction_non_alphanumeric': 0.13063611991225932, 'fraction_numerical': 0.012673653424323665, 'mean_word_length': 3.2616822429906542, 'pattern_counts': {'":': 7, '<': 5, '<?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': '594921', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1168, 'n_words': 447}