Exemplo n.º 1
0
    def test_parameters(self):
        self.start()

        p = {'a': 'string', 'list': [1, 2, 3], 'tup': (['a', 'b'], {'q': 1.5})}
        gxu.save_parameters('param_test', p)
        r = gxu.get_parameters('param_test')
        self.assertEqual(r['A'], p['a'])
        self.assertEqual(r['LIST'], p['list'])
        self.assertEqual(r['TUP'][0][1], 'b')
        self.assertEqual(r['TUP'][1]['q'], 1.5)

        s = gxu.get_parameters('param_test', ['a', 'tup', 'not_there'])
        self.assertEqual(s['a'], 'string')
        self.assertEqual(s['tup'][1]['q'], 1.5)
        self.assertEqual(s.get('not_there', None), None)

        q = gxu.get_parameters('param_test', ['not_there'], default="yes I am")
        self.assertEqual(q['not_there'], "yes I am")

        t = {
            '1': '\\',
            '2': '\\\\',
            '3': '\\\\\\',
            '4': '\\\\\\\\',
            '5': '\\\\\\\\\\'
        }
        gxu.save_parameters('escape', t)
        tt = gxu.get_parameters('escape')
        self.assertEqual(t, tt)
Exemplo n.º 2
0
    def test_parameters_2(self):
        self.start()

        self.assertRaises(gxu.UtilityException, gxu.save_parameters)
        self.assertRaises(gxu.UtilityException, gxu.save_parameters,
                          self._test_case_filename)
        group = os.path.basename(self._test_case_filename).split('.')[0]
        self.assertRaises(gxu.UtilityException, gxu.save_parameters, group,
                          {'bad.parameter': ''})

        parameter = 'GRID_NAME'
        p = {parameter: ''}
        gxu.save_parameters(group, p)
        r = gxu.get_parameters(group)
        self.assertEqual(r[parameter], '')

        r = gxu.get_parameters(group, {parameter: 'bogus'})
        self.assertEqual(r[parameter], '')
        r = gxu.get_parameters(group, {'test': 'bogus'})
        self.assertEqual(r['test'], 'bogus')

        r = gxu.get_parameters(group, (parameter, 'test1', 'test2'))
        self.assertEqual(r[parameter], '')
        self.assertEqual(r['test1'], None)
        self.assertEqual(r['test2'], None)

        r = gxu.get_parameters(group, (parameter, 'test1', 'test2'), 99)
        self.assertEqual(r[parameter], '')
        self.assertEqual(r['test1'], 99)
        self.assertEqual(r['test2'], 99)

        gxu.save_parameters(group, r)
        r = gxu.get_parameters(group)
        self.assertEqual(r[parameter], '')
        self.assertEqual(r['TEST1'], 99)
        self.assertEqual(r['TEST2'], 99)

        gxu.save_parameters(parms={
            'test_file': '.\\some_file',
            't2': 'c:\\abc\\def'
        })
        r = gxu.get_parameters()
        self.assertEqual(r['TEST_FILE'], '.\\some_file')
        self.assertEqual(r['T2'], 'c:\\abc\\def')
Exemplo n.º 3
0
def rungx():

    gxu.check_version('9.2')

    with gxpj.Geosoft_project() as pj:
        gdb_name = pj.current_database
        if not gdb_name:
            gxpj.message(_('No current database'),
                         _('An open database is required.'))
        state = pj.current_db_state()

    # settings
    settings = gxu.get_parameters('SOM_OM')

    # if different database, reset database-dependent settings
    if not _same(gdb_name, settings.get('GDB_NAME', '')):
        settings['GDB_NAME'] = os.path.normpath(gdb_name)
        with gxgdb.Geosoft_gdb() as gdb:
            chans = state['disp_chan_list']
        channorm = {}
        for c in chans:
            channorm[c] = 0
        settings['INPUT_DATA'] = channorm
        settings.pop('FILTER', None)

    # analyse data
    gxapi.GXEDB.un_load(gdb_name)
    try:
        script = os.path.join(os.path.split(__file__)[0], 'som_om_qt5.py')
        results = gxu.run_external_python(script, '', '', settings)
    except:
        gxapi.GXEDB.load(gdb_name)
        raise

    # save results
    gxu.save_parameters('SOM_OM', results)

    gxapi.GXEDB.load(gdb_name)
Exemplo n.º 4
0
def rungx():

    # parameter 'GRID_FILE' is the last-specified grid file name for this script.
    grid_parameter = 'GRID_FILE'
    group = os.path.basename(__file__).split('.')[0]
    parms = gxu.get_parameters(group, {grid_parameter: ''})

    # get the name of a grid from the user
    grid_file = gxproj.get_user_input(title='Grid statistics',
                                      prompt='Grid file',
                                      default=parms.get(grid_parameter),
                                      kind='file',
                                      filemask='*.grd')

    # save the grid file name as the default the next time this script is run
    parms[grid_parameter] = grid_file
    gxu.save_parameters(group, parms)

    stats = grid_stats(grid_file)

    gxproj.user_message(
        grid_file, 'min: {}\nmax: {}\nmean: {}\nstd_dev: {}'.format(
            stats.get_info(gxapi.ST_MIN), stats.get_info(gxapi.ST_MAX),
            stats.get_info(gxapi.ST_MEAN), stats.get_info(gxapi.ST_STDDEV)))
Exemplo n.º 5
0
def rungx():

    # api version
    gxpy.utility.check_version('9.2')

    # get the current database
    db = gxpy.gdb.Geosoft_gdb.open()

    # project parameters
    group = 'CHANADD'
    p_chan = 'CHANNEL'
    p_addval = 'ADDVAL'

    # get previous parameters from the parameter block, initializing to start-up defaults '' and 0.0
    parms = gxu.get_parameters(group, {p_chan: '', p_addval: 0.0})

    # if interactive, get user input
    if not gxprj.running_script():

        try:
            # get channel to process from list of database channels
            chan = gxprj.get_user_input(
                    'Channel to process',
                    'Channel:',
                    kind='list',
                    default=parms.get(p_chan),
                    items=sorted([k for k in db.list_channels().keys()]))

            # value to add to the channel
            addval = gxprj.get_user_input(
                    'Value to add to the data',
                    'value to add:',
                    kind='float',
                    default=parms.get(p_addval))
        except gxprj.ProjectException:
            exit()

        # save parameters to new user settings
        parms[p_chan] = chan
        parms[p_addval] = addval
        gxu.save_parameters(group, parms)

    # work through the data a line at a time - get a list of selected lines
    lines = db.list_lines()

    # for each line, get the data, add a value, return the data to the line
    for l in lines:

        # print to the console to reflect progress
        print('line {}...'.format(str(l)))

        # get the data and determine the dummy to the data type
        data, ch, fid = db.read_line(l, channels=chan)
        dummy = gxu.gx_dummy(data.dtype)

        # make a dummy mask so we can replace dummies after processing
        dMask = gxu.dummy_mask(data)

        # process - add the value, then replace the dummies
        sum = data + addval
        sum[dMask] = dummy

        # write the data back to the database
        db.write_channel(l, chan, sum, fid)

    # pause the console so user can review
    input("Press return to continue...")