utils.py 1022 Bytes
Newer Older
1
2
# coding: utf-8
import pandas as pd
3
4
5
6
import grass.script as grass
import subprocess
import platform
isWindows = (platform.system() == 'Windows')
7
8
9
10
11

def myJoin(f1Path, f2Path, resultPath):
    df1 = pd.read_table(f1Path, delim_whitespace=True)
    df2 = pd.read_table(f2Path, delim_whitespace=True)
    merge = pd.merge(df1, df2)
12
13
    merge.to_csv(resultPath, header=True, index=False, sep=' ')

14
if isWindows:
15
16
17
18
19
20
21
22
    def getSi():
        si = None
        if hasattr(subprocess, 'STARTUPINFO'):
            si = subprocess.STARTUPINFO()
            si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        return si
else:
    def getSi():
23
24
25
26
27
28
29
30
31
32
33
34
35
        return None

def grass_run_command(*args, **kwargs):
    kwargs['startupinfo'] = getSi()
    return grass.run_command(*args, **kwargs)

def grass_parse_command(*args, **kwargs):
    kwargs['startupinfo'] = getSi()
    return grass.parse_command(*args, **kwargs)

def grass_feed_command(*args, **kwargs):
    kwargs['startupinfo'] = getSi()
    return grass.feed_command(*args, **kwargs)