コード例 #1
0
ファイル: Core_GMT.py プロジェクト: EarthByte/citcoms
def get_T_from_grdinfo(grid_filename):
    '''get a -T value from grdinfo on a grid file'''
    if which('GMT'):
        cmd = 'grdinfo -C %(grid_filename)s' % vars()
    else:
        cmd = 'gmt grdinfo -C %(grid_filename)s' % vars()
    s = subprocess.check_output( cmd, shell=True, universal_newlines=True)
    if verbose: print( Core_Util.now(), cmd )
    l = s.split()
    min = float(l[5])
    max = float(l[6])

    # FIXME: stop gap measure 
    if min == max : 
        min = 0.0
        max = 1.0
        dt  = 0.01
        T = '-T%(min)s/%(max)s/%(dt)s' % vars()
        if verbose: print( Core_Util.now(), 'get_T_from_grdinfo: WARNING: min==max, setting T =', T )
        return T

    if   max >=  10000000    : dt =  1000000.0
    elif max >=    100000    : dt =     1000.0
    elif max >=      1000    : dt =      100.0
    elif max >=         1    : dt =         .1
    elif max >=         0.1  : dt =         .01
    elif max >=         0.01 : dt =         .001
    else                     : dt =        1.0

    T = '-T%(min)s/%(max)s/%(dt)s' % vars()
    if verbose: print( Core_Util.now(), 'get_T_from_grdinfo: T =', T )
    return T
コード例 #2
0
ファイル: Core_GMT.py プロジェクト: EarthByte/citcoms
def get_T_from_minmax(xyz_filename) :
    ''' get a -T value from minmax on a xyz file'''
    if which('GMT'):
        cmd = 'minmax -C %(xyz_filename)s' % vars()
    else:
        cmd = 'gmt minmax -C %(xyz_filename)s' % vars()
    s = subprocess.check_output( cmd, shell=True, universal_newlines=True)
    if verbose: print( Core_Util.now(), cmd )
    l = s.split()
    min = float(l[4])
    max = float(l[5])

    # FIXME: stop gap measure 
    if min == max : 
        print( Core_Util.now(), 'get_T_from_minmax: WARNING: min == max: min =', min, '; max =', max )
        min = 0.0
        max = 1.0
        dt  = 0.01
        T = '-T%(min)s/%(max)s/%(dt)s' % vars()
        if verbose: print( Core_Util.now(), 'get_T_from_minmax: T =', T )
        return T

    if   max >=  10000000    : dt =  1000000.0
    elif max >=    100000    : dt =     1000.0
    elif max >=      1000    : dt =      100.0
    elif max >=         1    : dt =         .1
    elif max >=         0.1  : dt =         .01
    elif max >=         0.01 : dt =         .001
    else                     : dt =        1.0

    T = '-T%(min)s/%(max)s/%(dt)s' % vars()
    if verbose: print( Core_Util.now(), 'get_T_from_minmax: T =', T )
    return T
コード例 #3
0
ファイル: Core_GMT5.py プロジェクト: ojashvirautela/citcoms
def end_postscript(ps):
    '''End a postscript'''

    if verbose: print(Core_Util.now(), 'end_postscript:')

    opts = {'T': '', 'O': '', 'R': '0/1/0/1', 'J': 'x1.0'}
    callgmt('psxy', '', opts, '>>', ps)
コード例 #4
0
ファイル: Core_GMT5.py プロジェクト: ojashvirautela/citcoms
def get_T_from_minmax(xyz_filename):
    ''' get a -T value from minmax on a xyz file'''
    cmd = 'minmax -C %(xyz_filename)s' % vars()
    s = subprocess.check_output(cmd, shell=True, universal_newlines=True)
    if verbose: print(Core_Util.now(), cmd)
    l = s.split()
    min = float(l[4])
    max = float(l[5])

    if max >= 10000000: dt = 1000000.
    elif max >= 100000: dt = 1000.
    elif max >= 1000: dt = 100.
    elif max >= 1: dt = .01
    else: dt = 1.0

    T = '-T%(min)s/%(max)s/%(dt)s' % vars()
    if verbose: print(Core_Util.now(), 'T =', T)

    return T
コード例 #5
0
ファイル: Core_GMT5.py プロジェクト: ojashvirautela/citcoms
def start_postscript(ps):
    '''Start a postscript'''

    if verbose: print(Core_Util.now(), 'start_postscript:')

    arg = 'PS_MEDIA letter PROJ_LENGTH_UNIT inch '
    arg += 'MAP_ORIGIN_X 0 MAP_ORIGIN_Y 0'
    callgmt('gmtset', arg, '', '', '')
    opts = {'K': '', 'T': '', 'R': '0/1/0/1', 'J': 'x1.0'}
    callgmt('psxy', '', opts, '>', ps)
    opts = {'K': '', 'O': ''}

    return opts
コード例 #6
0
ファイル: Core_GMT5.py プロジェクト: ojashvirautela/citcoms
def plot_grid(grid_filename,
              xy_filename=None,
              R_value='g',
              T_value='-T0/1/.1'):
    '''simple function to make a test plot'''
    global verbose
    verbose = True

    # postscript name
    ps = grid_filename.rstrip('.grd') + '.ps'

    # page orientation must be set before start_postscript()
    arg = 'PAGE_ORIENTATION landscape'
    callgmt('gmtset', arg, '', '', '')

    # start postscript
    # the returned dictionary has 'O' and 'K' set
    opts = start_postscript(ps)

    # psbasemap 2
    opts['X'] = apos(3)
    opts['Y'] = apos(3)
    opts['R'] = R_value  # either regional : '0/57/-14/14' ; or global: 'g'
    opts['B'] = 'a30'
    opts['J'] = 'X5/3'  #'R0/6'
    callgmt('psbasemap', '', opts, '>>', ps)

    # create a cpt for this grid
    cpt_file = grid_filename.replace('.grd', '.cpt')

    cmd = '-Cpolar ' + T_value
    callgmt('makecpt', cmd, '', '>', cpt_file)

    # grdimage
    opts['C'] = cpt_file
    callgmt('grdimage', grid_filename, opts, '>>', ps)

    # psxy
    del opts['C']
    opts['m'] = ' '
    callgmt('psxy', xy_filename, opts, '>>', ps)

    # end postscript
    end_postscript(ps)

    # create a .png image file
    #cmd = 'convert -resize 300% -rotate 90 ' + ps + ' ' + ps.replace('.ps', '.png')
    cmd = 'convert -rotate 90 ' + ps + ' ' + ps.replace('.ps', '.png')
    if verbose: print(Core_Util.now(), cmd)
    # call
    subprocess.call(cmd, shell=True)
コード例 #7
0
ファイル: Core_GMT.py プロジェクト: ojashvirautela/citcoms
def start_postscript( ps ):

    '''Start a postscript'''

    if verbose: print( Core_Util.now(), 'start_postscript:' )

    arg = 'PAPER_MEDIA letter MEASURE_UNIT inch '
    arg += 'X_ORIGIN 0 Y_ORIGIN 0'
    callgmt( 'gmtset', arg, '', '', '' )
    opts = {'K':'','T':'','R':'0/1/0/1','J':'x1.0'}
    callgmt( 'psxy', '', opts, '>', ps )
    opts = {'K':'', 'O':''}

    return opts
コード例 #8
0
ファイル: Core_GMT.py プロジェクト: ojashvirautela/citcoms
def callgmt( gmtcmd, arg, opts='', redirect='', out='' ):

    '''Call a generic mapping tools (GMT) command.

The arguments to this function are all single strings, and typically 
constructed from parameters in client code. Only gmtcmd is required,
all other arguments are optional, depending on the GMT command to call.

gmtcmd : the actual GMT command to call, almost always a single string value;
arg : the required arguments for the command (string). 
opts : the optional arguments for the command (in a dictionary).
redirect : the termnal redirect symbol, usually '>', sometimes a pipe '|' or input '<'.
out : the output file name.

'''

    # build list of commands
    cmd_list = [gmtcmd]

    # (required) arguments
    if arg: cmd_list.append( arg )

    # options
    if opts:
        cmd_list.extend('-'+str(k)+str(v) for k, v in opts.items())

    # redirect
    if redirect:
        cmd_list.append(redirect)

    # out file
    if out:
        cmd_list.append(out)

    # create one string
    cmd = ' '.join(cmd_list)

    # always report on calls to GMT for log files 
    print( Core_Util.now(), cmd )

    # capture output (returned as bytes)
    p = subprocess.check_output( cmd, shell=True )

    # convert bytes output to string
    s = bytes.decode(p)

    return s
コード例 #9
0
#                        ALL RIGHTS RESERVED
#=====================================================================
'''This is a test script to show a simple example of using the geodynamic framework modules'''
#=====================================================================
#=====================================================================
import os, sys, datetime, pprint, subprocess

import Core_Util
import Core_Citcom

if not len(sys.argv) == 2:
    print('Run this script like this: ./test_script.py sample.cfg')
    sys.exit(-1)

# create an empty dictionary to hold all the main data
master_d = {}

# get the main data 
master_d = Core_Citcom.get_master_data( sys.argv[1] )

# show the dict
print('\n', Core_Util.now(), 'master_d = ')
Core_Util.tree_print(master_d)

# do something with the data ... 
print()
print('the pid file has nx =', master_d['pid']['nx'], 'nodes')
print('the coor file has', len( master_d['coor']['depth'] ), 'levels')

#=====================================================================