Exemplo n.º 1
0
    def test_statics(self):
        self.start(gsys.func_name())

        app = gsys.app_name()
        self.assertTrue(len(app) > 0)
        func = gsys.func_name()
        self.assertEqual(func, 'test_statics')
Exemplo n.º 2
0
    def test_func(self):
        self.start()

        f = gsys.func_name()
        p = gsys.func_name(1)
        self.assertEqual(f, "test_func")
        self.assertEqual(p, "run")
Exemplo n.º 3
0
    def test_func(self):
        self.start()

        f = gsys.func_name()
        p = gsys.func_name(2) # This may change with Python upgrades if the unittest.case code changes 
        self.assertEqual(f, "test_func")
        self.assertEqual(p, "run")
Exemplo n.º 4
0
    def test_strings(self):
        self.start(gsys.func_name())

        fidvv = (99, 0.1)
        npdata = np.array(["name", "maki", "neil", "rider"])
        with gxvv.GXvv(npdata, fid=fidvv) as vv:
            self.assertEqual(vv.fid, fidvv)
            self.assertEqual(vv.length, len(npdata))
            self.assertEqual(vv.gxtype, -5)
            self.assertTrue(vv.dtype.type is np.str_)
            self.assertEqual(str(vv.dtype), '<U5')

            npd, fid = vv.get_np(vv.dtype)
            self.assertEqual(npd[0], "name")
            self.assertEqual(npd[1], "maki")
            self.assertEqual(npd[2], "neil")
            self.assertEqual(npd[3], "rider")

            npd, fid = vv.get_np(vv.dtype, start=2, n=2)
            self.assertEqual(npd[0], "neil")
            self.assertEqual(npd[1], "rider")
            self.assertEqual(fid, (99.2, 0.1))

        npdata = np.array(["1", "2", "3", "4000", "*"])
        with gxvv.GXvv(npdata, fid=fid) as vv:
            npd, fid = vv.get_np(np.float)
            self.assertEqual(npd[0], 1.0)
            self.assertEqual(npd[1], 2.0)
            self.assertEqual(npd[2], 3.0)
            self.assertEqual(npd[3], 4000.0)
            self.assertEqual(npd[4], gxapi.rDUMMY)

        npdata = np.array(["1", "2", "3", "4000", "40000", "*"])
        with gxvv.GXvv(npdata, fid=fid) as vv:
            npd, fid = vv.get_np(np.int)
            self.assertEqual(npd[0], 1)
            self.assertEqual(npd[1], 2)
            self.assertEqual(npd[2], 3)
            self.assertEqual(npd[3], 4000)
            self.assertEqual(npd[4], 40000)
            self.assertEqual(npd[5], gxapi.iDUMMY)

        npdata = np.array(["1", "2", "3", "4000", "40000", "*"])
        with gxvv.GXvv(npdata, fid=fid) as vv:
            npd, fid = vv.get_np(np.int, start=2, n=3)
            self.assertEqual(npd[0], 3)
            self.assertEqual(npd[1], 4000)
            self.assertEqual(npd[2], 40000)

        npdata = np.array(["make_it_big enough"])
        with gxvv.GXvv(npdata, fid=fid) as vv:
            npd, fid = vv.get_np(np.int, start=0, n=1)
            self.assertEqual(npd[0], gxapi.iDUMMY)

            npdata = np.array([1., 2., -30., -87.66662])
            vv.set_np(npdata)
            npd, fid = vv.get_np(start=0, n=4)
            self.assertEqual(npd[0], "1.0")
            self.assertEqual(npd[2], "-30.0")
            self.assertEqual(npd[3], "-87.66662")
Exemplo n.º 5
0
    def test_name_parts(self):
        self.start(gsys.func_name())

        namep = gxgrd.GXgrd.name_parts(
            "f:/someFolder/name.grd(GRD;TYPE=SHORT)")
        self.assertEqual(
            namep,
            ('f:\\someFolder', 'name.grd', 'name', '.grd', 'GRD;TYPE=SHORT'))

        namep = gxgrd.GXgrd.name_parts(".\\name.grd(GRD;TYPE=SHORT)")
        self.assertEqual(namep[0], os.getcwd())
        self.assertEqual(namep[1:],
                         ('name.grd', 'name', '.grd', 'GRD;TYPE=SHORT'))

        namep = gxgrd.GXgrd.name_parts(".\\name.grd")
        self.assertEqual(namep[0], os.getcwd())
        self.assertEqual(namep[1:], ('name.grd', 'name', '.grd', ''))

        ref = 'billybob(decs;more)'
        name = gxgrd.GXgrd.decorate_name('billybob', '(decs;more)')
        self.assertEqual(name, ref)
        name = gxgrd.GXgrd.decorate_name('billybob', 'decs;more')
        self.assertEqual(name, ref)
        name = gxgrd.GXgrd.decorate_name('billybob', '(decs;more')
        self.assertEqual(name, ref)
        name = gxgrd.GXgrd.decorate_name('billybob', 'decs;more)')
        self.assertEqual(name, ref)
        name = gxgrd.GXgrd.decorate_name('billybob', 'decs;more)(and more)')
        self.assertEqual(name, ref)
        name = gxgrd.GXgrd.decorate_name(ref)
        self.assertEqual(name, ref)
Exemplo n.º 6
0
    def test_memoryGrid(self):
        self.start(gsys.func_name())

        with gxgrd.GXgrd.new(
                properties={
                    'dtype': np.int16,
                    'nx': 100,
                    'ny': 50,
                    'x0': 4,
                    'y0': 8,
                    'dx': 0.1,
                    'dy': 0.2,
                    'rot': 5,
                    'cs': gxcs.GXcs('NAD27 / UTM zone 18N')
                }) as grd:
            properties = grd.properties()
            self.assertEqual(properties.get('dx'), 0.1)
            self.assertEqual(properties.get('dy'), 0.2)
            self.assertEqual(properties.get('x0'), 4.0)
            self.assertEqual(properties.get('y0'), 8.0)
            self.assertEqual(properties.get('rot'), 5.0)
            self.assertEqual(properties.get('nx'), 100)
            self.assertEqual(properties.get('ny'), 50)
            self.assertEqual(str(properties.get('cs')), 'NAD27 / UTM zone 18N')
            self.assertEqual(properties.get('dtype'), np.int16)
Exemplo n.º 7
0
    def test_orientation(self):
        self.start(gsys.func_name())

        s = "WGS 84 / UTM zone 32N <0, 0, 0, 10, 15, 32>"
        with gxcs.GXcs(s) as cs:
            self.assertEqual(
                str(cs),
                "WGS 84 / UTM zone 32N (0,0,0) <32 deg,15 deg,10 deg>")

        s = "WGS 84 / UTM zone 32N <0, 0, 0, 0, 0, 0>"
        with gxcs.GXcs(s) as cs:
            self.assertEqual(str(cs), "WGS 84 / UTM zone 32N")

        s = "WGS 84 / UTM zone 32N <150, 8.5, 0, 0, 0, 32>"
        with gxcs.GXcs(s) as cs:
            self.assertEqual(str(cs),
                             'WGS 84 / UTM zone 32N (150,8.5,0) <32 deg>')

        gxfs = ('"*AMMP/SAMMP grid"<-4933250,0,0,-90,0,-90>',
                '"*AMMP/SAMMP grid",6378249.145,0,0',
                '"Mercator (1SP)",0,0,1,0,0', '', '')
        with gxcs.GXcs(gxfs) as cs:
            self.assertEqual(
                str(cs),
                '*AMMP/SAMMP grid (-4933250,0,0) <-90 deg,0 deg,-90 deg>')
            self.assertEqual(
                cs.cs_name(),
                '*AMMP/SAMMP grid (-4933250,0,0) <-90 deg,0 deg,-90 deg>')

            grid_xyz = (-2359492.188, -27936.43719, 0.0)
            xyz = cs.xyz_from_oriented(grid_xyz)
            xyz = cs.oriented_from_xyz(xyz)
            self.assertAlmostEqual(xyz, grid_xyz)
Exemplo n.º 8
0
    def test_compare(self):
        self.start(gsys.func_name())

        cs = gxcs.GXcs('NAD27 / UTM zone 18N')
        cs2 = gxcs.GXcs('NAD27 / UTM zone 18N')
        self.assertTrue(cs.same_as(cs2))
        cs2 = gxcs.GXcs('NAD83 / UTM zone 18N')
        self.assertFalse(cs.same_as(cs2))

        with gxcs.GXcs("wgs 84 [geoid]") as cs1:
            with gxcs.GXcs("WGS 84 [geoid]") as cs2:
                self.assertTrue(cs1.same_as(cs2))

        with gxcs.GXcs("wgs 84 / UTM zone 32N", ) as cs1:
            with gxcs.GXcs("WGS 84 [geoid]") as cs2:
                self.assertFalse(cs1.same_as(cs2))

        self.assertTrue(gxcs.GXcs("nad83").same_as(gxcs.GXcs("NAD83")))
        self.assertTrue(
            gxcs.GXcs("nad83 [NAVD92]").same_as(gxcs.GXcs("NAD83 [NAVD92]")))
        self.assertTrue(
            gxcs.GXcs("nad83 [NAVD92]").same_as(gxcs.GXcs("NAD83")))
        self.assertTrue(
            gxcs.GXcs("nad83").same_as(gxcs.GXcs("NAD83 [NAVD92]")))
        self.assertTrue(
            gxcs.GXcs("nad83 [NAVD92]").same_vcs(gxcs.GXcs("NAD27 [NAVD92]")))
        self.assertTrue(
            gxcs.GXcs("nad83").same_vcs(gxcs.GXcs("NAD27 [NAVD92]")))
        self.assertTrue(
            gxcs.GXcs("nad27 [geoid]").same_hcs(gxcs.GXcs("NAD27 [NAVD92]")))

        self.assertFalse(
            gxcs.GXcs("nad83 / UTM zone 35N").same_as(gxcs.GXcs("NAD83")))
        #TODO self.assertFalse(gxcs.GXcs("nad83 [NAVD92]").same_as(gxcs.GXcs("NAD83 [geodetic]")))
        self.assertFalse(gxcs.GXcs("nad83").same_as(gxcs.GXcs("NAD27")))
Exemplo n.º 9
0
    def test_names_cs(self):
        self.start(gsys.func_name())

        with gxcs.GXcs(
                '{"type": "Geosoft", "name":"NAD83 / UTM zone 26N", "orientation":"1000,500,0,0,0,15"}'
        ) as cs:
            csd = cs.coordinate_dict()
            self.assertEqual(csd["type"], 'Geosoft')
            self.assertEqual(csd["name"],
                             'NAD83 / UTM zone 26N <1000,500,0,0,0,15>')
            self.assertEqual(csd["datum"],
                             'NAD83,6378137,0.0818191910428158,0')
            self.assertEqual(csd["projection"],
                             '"Transverse Mercator",0,-27,0.9996,500000,0')
            self.assertEqual(csd["units"], 'm,1')
            self.assertEqual(csd["orientation"], '1000,500,0,0,0,15')
            self.assertEqual(csd["vcs"], '')

        with gxcs.GXcs(
                '{"type": "Geosoft", "datum":"NAD83,6378137,0.0818191910428158,0", "projection":"Oblique Stereographic,61.40.00,-128.10.00,1,0,0", "units":"m,1", "local_datum":"NAD83 to WGS 84 (1),0,0,0,0,0,0,0"}'
        ) as cs:
            csd = cs.coordinate_dict()
            self.assertEqual(csd["type"], 'Geosoft')
            self.assertEqual(csd["name"], 'NAD83 / *Oblique Stereographic')
            self.assertEqual(csd["datum"],
                             'NAD83,6378137,0.0818191910428158,0')
            self.assertEqual(csd["local_datum"],
                             '"NAD83 to WGS 84 (1)",0,0,0,0,0,0,0')
            self.assertEqual(
                csd["projection"],
                '"Oblique Stereographic",61.6666666666667,-128.166666666667,1,0,0'
            )
            self.assertEqual(csd["units"], 'm,1')
            self.assertEqual(csd["orientation"], '')
            self.assertEqual(csd["vcs"], '')
Exemplo n.º 10
0
    def test_MAPINFO_cs(self):
        self.start(gsys.func_name())

        stref1 = gxapi.str_ref()
        stref2 = gxapi.str_ref()

        #test IPJ creation using GXF strings
        cs = gxcs.GXcs(['', 'DHDN', 'Okarito 2000', '', ''])
        cs.gxipj.get_mi_coord_sys(stref1, stref2)
        self.assertEqual(
            stref1.value,
            'CoordSys Earth Projection 8,1000,"m",170.2608333333,-43.1100000000,1,400000,800000'
        )
        self.assertEqual(stref2.value, 'Units "m"')

        cs.gxipj.set_mi_coord_sys(stref1.value, stref2.value)
        gxfs = cs.get_gxf()
        self.assertEqual(gxfs[0], 'DHDN / Okarito 2000')
        self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0')
        self.assertEqual(
            gxfs[2],
            '"Transverse Mercator",-43.11,170.2608333333,1,400000,800000')
        self.assertEqual(gxfs[3], 'm,1')
        self.assertEqual(
            gxfs[4],
            '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.29999999996112'
        )
Exemplo n.º 11
0
    def test_ESRI_cs(self):
        self.start(gsys.func_name())

        stref = gxapi.str_ref()

        #test IPJ creation using GXF strings
        cs = gxcs.GXcs(['', 'DHDN', 'Okarito 2000', '', ''])
        cs.gxipj.get_esri(stref)
        self.assertTrue('PROJCS["Okari' in stref.value)
        self.assertTrue(
            'GEOGCS["GCS_Deutsches_Hauptdreiecksnetz"' in stref.value)

        wkt = gxcs.Wkt(stref.value)
        self.assertEqual(wkt.name, 'Okarito_2000')

        cs = gxcs.GXcs(stref.value)
        gxfs = cs.get_gxf()
        self.assertEqual(gxfs[0], 'DHDN / *Okarito 2000')
        self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225274,0')
        self.assertEqual(
            gxfs[2],
            '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000')
        self.assertEqual(gxfs[3], 'm,1')
        self.assertEqual(
            gxfs[4],
            '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.29999999996112'
        )

        gxcs.GXcs("WGS 84 / UTM zone 32N").gxipj.get_esri(stref)
        wkt = gxcs.Wkt(stref.value)
        self.assertEqual(wkt.name, 'WGS_1984_UTM_Zone_32N')

        gxcs.GXcs("WGS 84").gxipj.get_esri(stref)
        wkt = gxcs.Wkt(stref.value)
        self.assertEqual(wkt.name, 'GCS_WGS_1984')
Exemplo n.º 12
0
    def test_zone_grid(self):
        self.start(gsys.func_name())

        def test_zone(zone, crc, shade=False):
            with gxmap.GXmap.new(map_file, overwrite=True) as gmap:
                mapfile = gmap.filename
                with gxv.GXview(gmap,
                                "data",
                                area=(mn[0], mn[1], mx[0], mx[1]),
                                scale=(mx[0] - mn[0]) / 0.2) as view:
                    with gxagg.GXagg(grid_file, zone=zone, shade=shade) as agg:
                        view.aggregate(agg)

            #gxvwr.map(mapfile)
            self.assertEqual(gxmap.crc_map(mapfile), crc)

        # test grid file
        folder, files = gsys.unzip(os.path.join(os.path.dirname(__file__),
                                                'testgrids.zip'),
                                   folder=self.gx.temp_folder())
        grid_file = os.path.join(folder, 'test_agg_utm.grd')
        with gxgrd.GXgrd(grid_file) as grd:
            mn, mx = grd.extent_2d()
        map_file = os.path.join(self.gx.temp_folder(), "test_agg")

        test_zone(gxagg.ZONE_LINEAR, 3720728838, shade=True)
        test_zone(gxagg.ZONE_EQUALAREA, 1656439979)
        test_zone(gxagg.ZONE_DEFAULT, 1656439979)
        test_zone(gxagg.ZONE_LAST, 1656439979)
        test_zone(gxagg.ZONE_LINEAR, 1901089024)
        test_zone(gxagg.ZONE_NORMAL, 2691213422)
        test_zone(gxagg.ZONE_SHADE, 4087607233)
        test_zone(gxagg.ZONE_LOGLINEAR, 353055968)
Exemplo n.º 13
0
    def test_basic_drawing(self):
        self.start(gsys.func_name())

        testmap = os.path.join(self.gx.temp_folder(), "test")
        with gxmap.GXmap.new(testmap, overwrite=True) as gmap:
            mapfile = gmap.filename
            with gxv.GXview(gmap, "base", area=(0, 0, 25, 20),
                            scale=100.0) as view:
                view.xy_rectangle(((0, 0), (25, 20)),
                                  pen={
                                      'line_thick': 0.1,
                                      'line_color': 'R'
                                  })

            with gxv.GXview(gmap,
                            "data",
                            map_location=(4, 3),
                            area=(0, 0, 1800, 1500),
                            scale=10000) as view:
                view.xy_rectangle(((0, 0), (1800, 1500)),
                                  pen={
                                      'line_thick': 5,
                                      'line_color': 'G'
                                  })

                # TODO - the underlying grid function has a bug - it cannot do dotted lines
                view.graticule(style=gxv.GRATICULE_DOT, pen={'line_thick': 50})

        #gxvwr.map(mapfile)
        self.assertEqual(
            gxmap.crc_map(mapfile),
            2258658382)  # TODO replace with correct crc once fixed
Exemplo n.º 14
0
    def test_elapsed_time(self):
        self.start(gsys.func_name())

        with gx.GXpy() as gxc:
            self.assertTrue(gxc.elapsed_seconds("startup") > 0.0)
            time.sleep(0.25)
            self.assertTrue(gxc.elapsed_seconds("0.25 seconds later") > 0.25)
Exemplo n.º 15
0
    def test_vv(self):
        self.start(gsys.func_name())

        self.assertEqual(gxvv.__version__, geosoft.__version__)

        with gxvv.GXvv(dtype=np.float) as vv:
            self.assertEqual(vv.fid, (0.0, 1.0))

        fid = (10.1, 0.99)
        with gxvv.GXvv(dtype=np.float, fid=fid) as vv:
            self.assertEqual(vv.fid, fid)
            self.assertEqual(vv.length, 0)

            fid = (-45, 7)
            vv.fid = fid
            self.assertEqual(vv.fid, fid)

            vv.reFid((-40, 8), 4)
            self.assertEqual(vv.fid, (-40, 8))
            self.assertEqual(vv.length, 4)

        with gxvv.GXvv([1, 2, 3, 4, 5, 6]) as vv:
            self.assertEqual(vv.fid, (0.0, 1.0))
            self.assertEqual(vv.length, 6)
            self.assertEqual(vv.dtype, np.int32)
            self.assertEqual(vv.gxtype, gxu.gx_dtype(np.int32))

        with gxvv.GXvv([1, 2, 3, 4, 5, 6], dtype=np.int64) as vv:
            self.assertEqual(vv.fid, (0.0, 1.0))
            self.assertEqual(vv.length, 6)
            self.assertEqual(vv.dtype, np.int64)
            self.assertEqual(vv.gxtype, gxu.gx_dtype(np.int64))
Exemplo n.º 16
0
    def test_read_GDB(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.open(self.gdb_name) as gdb:

            npd, ch, fid = gdb.read_line('D578625')
            self.assertEqual(npd.shape[0], 832)
            self.assertEqual(fid[0], 0.0)
            self.assertEqual(fid[1], 1.0)

            ln, ls = gdb.line_name_symb('D578625')
            npd, ch, fid = gdb.read_line(ls,
                                         channels=['X', 'Y', 'Z', 'dx', 'dy'])
            self.assertEqual(npd.shape, (832, 5))
            self.assertEqual(npd[10, :3].tolist(),
                             [578625.0, 7773625.0, -1195.7531280517615])

            npd, ch, fid = gdb.read_line(ls, 'X')
            self.assertEqual(npd.shape, (832, 1))
            self.assertEqual(npd[10], 578625.0)

            npd, ch, fid = gdb.read_line(ls,
                                         channels=['X', 'Y', 'Z'],
                                         dtype='<U32')
            self.assertEqual(npd.shape, (832, 3))
            self.assertEqual(npd[10, :3].tolist(),
                             ['578625.0', '7773625.0', '-1195.8'])

            gdb.discard()
Exemplo n.º 17
0
    def test_array_locations(self):
        self.start(gsys.func_name())

        props = {'x0': 100, 'y0': -25.25, 'dx': 5, 'nx': 101, 'ny': 501}
        a = gxgrd.array_locations(props)
        self.assertEqual(len(a.shape), 3)
        self.assertEqual(a.shape[0], props.get('ny'))
        self.assertEqual(a.shape[1], props.get('nx'))
        self.assertEqual(a.shape[2], 3)
        self.assertEqual(a[0, 0, 0], 100.0)
        self.assertEqual(a[0, 0, 1], -25.25)
        self.assertEqual(a[0, 0, 2], 0.0)
        self.assertEqual(a[0, 1, 0] - a[0, 0, 0], props.get('dx'))
        self.assertEqual(a[1, 0, 1] - a[0, 0, 1], props.get('dx'))
        self.assertEqual(a[0, 0, 2] - a[1, 1, 2], 0.)

        props = {
            'x0': 100,
            'y0': -25.25,
            'dx': 5,
            'dy': 1,
            'nx': 101,
            'ny': 501
        }
        a = gxgrd.array_locations(props, z=10.1)
        self.assertEqual(len(a.shape), 3)
        self.assertEqual(a.shape[0], props.get('ny'))
        self.assertEqual(a.shape[1], props.get('nx'))
        self.assertEqual(a.shape[2], 3)
        self.assertEqual(a[0, 0, 0], 100.0)
        self.assertEqual(a[0, 0, 1], -25.25)
        self.assertEqual(a[0, 0, 2], 10.1)
        self.assertEqual(a[0, 1, 0] - a[0, 0, 0], props.get('dx'))
        self.assertEqual(a[1, 0, 1] - a[0, 0, 1], props.get('dy'))
        self.assertEqual(a[0, 0, 2] - a[1, 1, 2], 0.)
Exemplo n.º 18
0
    def test_newmap(self):
        self.start(gsys.func_name())

        # temp map
        with gxmap.GXmap.new() as gmap:
            mapfile = gmap.filename
            self.assertTrue(os.path.isfile(mapfile))
        self.assertFalse(os.path.isfile(mapfile))

        # test map
        map_name = 'test_newmap'
        gxmap.delete_files(map_name)
        with gxmap.GXmap.new(map_name) as gmap:
            mapfile = gmap.filename
            self.assertEqual(mapfile, os.path.abspath((map_name + '.map')))
        self.assertTrue(os.path.isfile(mapfile))

        # verify can't write on a new map
        self.assertRaises(gxmap.MapException, gxmap.GXmap.new, map_name)
        self.assertRaises(gxmap.MapException, gxmap.GXmap.new, mapfile)
        with gxmap.GXmap.new(map_name, overwrite=True):
            pass

        # but I can open it
        with gxmap.GXmap.open(map_name):
            pass
        with gxmap.GXmap.open(mapfile):
            pass

        gxmap.delete_files(mapfile)
        self.assertFalse(os.path.isfile(mapfile))
Exemplo n.º 19
0
    def test_run_external_python(self):
        self.start(gsys.func_name())

        testpy = os.path.join(os.getcwd(), 'test_python.py')
        with open(testpy, 'w') as py:
            py.write("import sys\n")
            py.write("import geosoft.gxpy as gxpy\n")
            py.write("import geosoft.gxpy.utility as gxu\n")
            py.write("gxc = gxpy.gx.GXpy()\n")
            py.write("d = gxu.get_shared_dict()\n")
            py.write(
                "gxpy.utility.set_shared_dict({'a':'letter a', 'b':'letter b', 'c':[1,2,3], 'argv': sys.argv, 'in_dict':d})\n"
            )
            #py.write("input('RUN_EXTERNAL! Press return to continue...')\n")

        test_result = gxu.run_external_python(testpy,
                                              script_args='test1 test2',
                                              dict={'howdy': 'hey there'},
                                              console=False)
        os.remove(testpy)
        self.assertEqual(test_result['a'], 'letter a')
        l = test_result['c']
        self.assertEqual(len(l), 3)
        self.assertEqual(l[1], 2)
        self.assertEqual(test_result['argv'][1], 'test1')
        self.assertEqual(test_result['argv'][2], 'test2')
        self.assertEqual(test_result['in_dict']['howdy'], 'hey there')

        try:
            gxu.run_external_python(testpy, script_args='test1 test2')
            self.assertTrue(False)
        except gxu.UtilityException:
            pass
        except:
            raise
Exemplo n.º 20
0
    def test_map_delete(self):
        self.start(gsys.func_name())

        with gxmap.GXmap.new(filename='test_geosoft', overwrite=True) as gmap:
            filename = gmap.filename
            self.assertEqual(len(gmap.view_list()), 0)
            self.assertFalse(gmap.has_view('*Data'))
            self.assertFalse(gmap.has_view('*Base'))
        self.assertTrue(os.path.isfile(filename))
        with open(filename, 'rb') as f:
            pass

        with gxmap.GXmap.new_standard_geosoft(filename='test_geosoft',
                                              overwrite=True,
                                              data_area=(1000, 200, 11000,
                                                         5000)) as gmap:
            filename = gmap.filename
            self.assertEqual(len(gmap.view_list()), 2)
            self.assertTrue(gmap.has_view('*Data'))
            self.assertTrue(gmap.has_view('*Base'))
        self.assertTrue(os.path.isfile(filename))
        with open(filename, 'rb') as f:
            pass

        with gxmap.GXmap.new(filename='test_geosoft', overwrite=True) as gmap:
            filename = gmap.filename
            gmap.remove_on_close(True)
        self.assertFalse(os.path.isfile(filename))

        for i in range(3):
            gmap = gxmap.GXmap.new(filename='t{}'.format(i), overwrite=True)
            gmap.remove_on_close(True)
            gmap.close()
Exemplo n.º 21
0
    def test_parameters(self):
        self.start(gsys.func_name())

        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.º 22
0
    def test_new(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.new(os.path.join(self.folder, 'new.gdb')) as gdb:

            #read an image and put it in a new database
            with open(os.path.join(self.folder, 'image.png'),
                      'rb') as im_handle:
                im = Image.open(im_handle)
                im.thumbnail((20, 20), Image.ANTIALIAS)
                imageIn = np.asarray(im, dtype=np.float32)
            gdb.new_channel('R', dtype=np.int)
            gdb.new_channel('G', dtype=np.int)
            gdb.new_channel('B', dtype=np.int)
            gdb.new_channel('A', dtype=np.int)
            for l in range(imageIn.shape[0]):
                gdb.write_line('L{}'.format(l),
                               imageIn[l, :, :],
                               channels=['R', 'G', 'B', 'A'])

            self.assertEqual(len(gdb.list_lines()), imageIn.shape[0])
            self.assertEqual(len(gdb.list_channels()), 4)
            d, c, f = gdb.read_line('L5')
            self.assertEqual(d.shape[0], imageIn.shape[1])
            self.assertEqual(d.shape[1], imageIn.shape[2])
Exemplo n.º 23
0
    def test_read_write_channel_vv_va(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.open(self.gdb_name) as gdb:
            gdb.delete_channel('test_chan_vv')
            vv = gxvv.GXvv(np.array([1., 2., 3.]), fid=(-10, 2.5))
            gdb.write_channel_vv('T46', 'test_chan_vv', vv)
            vv = gdb.read_channel_vv('T46', 'test_chan_vv')
            self.assertEqual(vv.length, 3)
            self.assertEqual(vv.fid, (-10.0, 2.5))
            va = gdb.read_channel_va('T46', 'test_chan_vv')
            self.assertEqual(va.width, 1)
            self.assertEqual(va.length, 3)
            self.assertEqual(va.fid, (-10.0, 2.5))
            gdb.delete_channel('test_chan_vv')

            va = gxva.GXva(np.array([[1., 2., 3.], [8, 9, 10]]),
                           fid=(-10, 2.5))
            gdb.write_channel_va('T46', 'test_chan_va', va)
            self.assertRaises(gxgdb.GDBException, gdb.read_channel_vv, 'T46',
                              'test_chan_va')
            va = gdb.read_channel_va('T46', 'test_chan_va')
            self.assertEqual(va.width, 3)
            self.assertEqual(va.length, 2)
            self.assertEqual(va.fid, (-10.0, 2.5))
            gdb.delete_channel('test_chan_va')
Exemplo n.º 24
0
    def test_newline_vv_GDB(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.open(self.gdb_name) as gdb:

            data = gdb.read_line_vv('D578625', channels=['dx', 'dy', 'vector'])
            ch = [c[0] for c in data]
            datalen = data[0][1].length

            gdb.delete_line('testline')
            gdb.new_line('testline')
            gdb.write_line_vv('testline', data)
            npd2, ch2, fid2 = gdb.read_line('testline', channels=ch)
            self.assertEqual(npd2.shape, (datalen, len(data)))

            gdb.delete_line('testline')
            gdb.new_line('testline', gxgdb.SYMB_LINE_NORMAL)
            gdb.write_line_vv('testline', (("single", data[0][1]), ))
            npd2, ch2, fid2 = gdb.read_line('testline', "single")
            self.assertEqual(npd2.shape, (datalen, 1))

            gdb.delete_line('testline')
            gdb.new_line('testline', gxgdb.SYMB_LINE_GROUP)
            gdb.write_line_vv('testline', [("single", data[0][1])])
            npd2, ch2, fid2 = gdb.read_line('testline', "single")
            self.assertEqual(npd2.shape, (datalen, 1))

            gdb.discard()
Exemplo n.º 25
0
    def test_write_VA_GDB(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.open(self.gdb_name) as gdb:

            gdb.delete_channel('testVA')
            gdb.new_channel('testVA')
            try:
                gdb.write_channel(
                    'D590875', 'testVA',
                    np.array([[1.0, 2.0, 3.0, 4.0], [10.0, 20.0, 30.0, 40.0],
                              [15.0, 25.0, 35.0, 45.0]]))
                self.assertTrue(False)
            except gxgdb.GDBException:
                pass

            gdb.delete_channel('testVA')
            gdb.write_channel(
                'D590875', 'testVA',
                np.array([[1.0, 2.0, 3.0, 4.0], [10.0, 20.0, 30.0, 40.0],
                          [15.0, 25.0, 35.0, 45.0]]))
            npd, ch, fid = gdb.read_line('D590875', channels=['testVA'])
            self.assertEqual(npd.shape, (3, 4))
            self.assertEqual(npd[0, :].tolist(), [1.0, 2.0, 3.0, 4.0])
            self.assertEqual(npd[1, :].tolist(), [10.0, 20.0, 30.0, 40.0])
            self.assertEqual(npd[2, :].tolist(), [15.0, 25.0, 35.0, 45.0])

            gdb.discard()
Exemplo n.º 26
0
    def _test_OBLIQUESTEREO_cs(self):
        self.start(gsys.func_name())

        stref = gxapi.str_ref()

        cs = gxcs.GXcs(
            '{"type": "Geosoft", "datum":"NAD83,6378137,0.0818191910428158,0","projection":"\\"Oblique Stereographic\\",61.40.00,-128.10.00,1,0,0","units":"m,1","gxf5":"\\"NAD83 to WGS 84 (1)\\",0,0,0,0,0,0,0"}'
        )
        cs.gxipj.get_display_name(stref)
        gxfs = cs.get_gxf()
        self.assertEqual(gxfs[0], 'NAD83 / *Oblique Stereographic')
        self.assertEqual(gxfs[1], 'NAD83,6378137,0.0818191910428158,0')
        self.assertEqual(
            gxfs[2],
            '"Oblique Stereographic",61.6666666666667,-128.166666666667,1,0,0')
        self.assertEqual(gxfs[3], 'm,1')
        self.assertEqual(gxfs[4], '"NAD83 to WGS 84 (1)",0,0,0,0,0,0,0')

        cs = gxcs.GXcs(
            '{"type": "Localgrid", "longitude":"-128.10.00","latitude":"61.40.00","azimuth":-15,"units":"ft"}'
        )
        cs.gxipj.get_display_name(stref)
        gxfs = cs.get_gxf()
        self.assertEqual(
            gxfs[0],
            'WGS 84 / *Local grid (61.40.00,-128.10.00) <0,0,0,0,0,-15>')
        self.assertEqual(gxfs[1], '"WGS 84",6378137,0.0818191908426215,0')
        self.assertEqual(
            gxfs[2],
            '"Oblique Stereographic",61.6666666666667,-128.166666666667,0.9996,0,0'
        )
        self.assertEqual(gxfs[3], 'ft,0.3048')
        self.assertEqual(gxfs[4], '"WGS 84",0,0,0,0,0,0,0')

        cs = gxcs.GXcs(
            '{"type": "Localgrid", "longitude":"-128.10.00","latitude":"61.40.00","azimuth":-15,"units":"ft","elevation":133.1567}'
        )
        cs.gxipj.get_display_name(stref)
        gxfs = cs.get_gxf()
        self.assertEqual(
            gxfs[0],
            'WGS 84 / *Local grid [61.40.00,-128.10.00] <0,0,133.1567,0,0,-15>'
        )
        self.assertEqual(gxfs[1], '"WGS 84",6378137,0.0818191908426215,0')
        self.assertEqual(
            gxfs[2],
            '"Oblique Stereographic",61.6666666666667,-128.166666666667,0.9996,0,0'
        )
        self.assertEqual(gxfs[3], 'ft,0.3048')
        self.assertEqual(gxfs[4], '"WGS 84",0,0,0,0,0,0,0')

        cs = gxcs.GXcs('{"type": "Localgrid", "longitude":0,"latitude":0}')
        cs.gxipj.get_display_name(stref)
        gxfs = cs.get_gxf()
        self.assertEqual(gxfs[0], 'WGS 84 / *Local grid [0,0]')
        self.assertEqual(gxfs[1], '"WGS 84",6378137,0.0818191908426215,0')
        self.assertEqual(gxfs[2], '"Oblique Stereographic",0,0,0.9996,0,0')
        self.assertEqual(gxfs[3], 'm,1')
        self.assertEqual(gxfs[4], '"WGS 84",0,0,0,0,0,0,0')
Exemplo n.º 27
0
    def test_rdecode(self):
        self.start(gsys.func_name())

        cDUMMY = "*"
        rDUMMY = gxu.rdecode(cDUMMY)

        def test(s):
            r = gxu.rdecode(s)
            return r

        self.assertEqual(test("1.9"), 1.9)
        self.assertEqual(test("1.o9"), 1.09)
        self.assertEqual(test(""), rDUMMY)
        self.assertEqual(test("*"), rDUMMY)
        self.assertEqual(test("*ab"), rDUMMY)
        self.assertEqual(test("\t"), rDUMMY)
        self.assertEqual(test("    \t   \t"), rDUMMY)
        self.assertEqual(test("\t             000oooOOO45.o0o0   \t\t"), 45)
        self.assertEqual(test("62"), 62)
        self.assertEqual(test("62S"), -62)
        self.assertEqual(test("62 00 00N"), 62)
        self.assertEqual(test("-62 00 00"), -62)
        self.assertEqual(test("62.00.00S"), -62)
        self.assertEqual(test("62N"), 62)
        self.assertEqual(test("62 45S"), -62.75)
        self.assertEqual(test("62 29 60w"), -62.5)
        self.assertEqual(test("62 29 60.00E"), 62.5)
        self.assertEqual(test("-62 29 60.00E"), -62.5)
        self.assertEqual(test("62.45.0.00s"), -62.75)
        self.assertEqual(test("62.30.30.15W"), -62.508375)
        self.assertEqual(test("-62.30.30.15"), -62.508375)
        self.assertEqual(test("-62.30.30.15W"), 62.508375)
        self.assertEqual(test("13:14:60.00"), 13.25)
        self.assertEqual(test("13:14:60.00pm"), 25.25)
        self.assertEqual(test("13:15"), 13.25)
        self.assertEqual(test("2:15PM"), 14.25)
        self.assertEqual(test("2:90pm"), 15.5)
        self.assertEqual(test("\to o o   "), 0.0)
        self.assertEqual(test("\to 59 6O   "), 1.0)
        self.assertEqual(test("bogus"), rDUMMY)
        self.assertEqual(test("2014-01-01"), 2014.0)
        self.assertEqual(test("2014-02-25"), 2014.150684931507)
        self.assertEqual(test("2014/02/25"), 2014.150684931507)
        self.assertEqual(test("2014/2/25"), 2014.150684931507)
        self.assertEqual(test("2014/02/5"), 2014.0958904109589)
        self.assertEqual(test("2014/12/31"), 2014.9972602739726)
        self.assertEqual(test("2016/12/31"), 2016.9972677595629)
        self.assertEqual(test("2017-1-1"), 2017.0)

        try:
            gxu.rdecode_err("bogus")
            self.assertTrue(False)
        except ValueError:
            self.assertTrue(True)
        try:
            gxu.rdecode_err("\t0 o 0 0")
            self.assertTrue(False)
        except ValueError:
            self.assertTrue(True)
Exemplo n.º 28
0
    def test_agg(self):
        self.start(gsys.func_name())

        with gxagg.GXagg() as agg:
            self.assertEqual(str(agg), 'GXagg')

        with gxagg.GXagg(self.g3f) as agg:
            self.assertEqual(str(agg), 'GXagg> test_agg_utm')
Exemplo n.º 29
0
    def test_gxpy(self):
        self.start(gsys.func_name())

        with gx.GXpy(log=print) as gxc:
            self.assertTrue(gxc.gid.find('@') > 0)
            self.assertEqual(gxc.main_wind_id(), 0)
            self.assertEqual(gxc.active_wind_id(), 0)
            self.assertEqual(gx.__version__, geosoft.__version__)
Exemplo n.º 30
0
    def test_read_vv_GDB(self):
        self.start(gsys.func_name())

        with gxgdb.GXdb.open(self.gdb_name) as gdb:

            data = gdb.read_line_vv('D578625')
            for chvv in data:
                self.assertEqual(len(data), 8)
                vv = chvv[1]
                fid = vv.fid
                self.assertEqual(vv.length, 832)
                self.assertEqual(fid[0], 0.0)
                self.assertEqual(fid[1], 1.0)

            data = gdb.read_line_vv('D578625', common_fid=True)
            for chvv in data:
                self.assertEqual(len(data), 8)
                vv = chvv[1]
                fid = vv.fid
                self.assertEqual(vv.length, 832)
                self.assertEqual(fid[0], 0.0)
                self.assertEqual(fid[1], 1.0)

            data = gdb.read_line_vv('D578625', common_fid=True, fid=(0.1, 4.8))
            for chvv in data:
                self.assertEqual(len(data), 8)
                vv = chvv[1]
                fid = vv.fid
                self.assertEqual(vv.length, 175)
                self.assertEqual(fid[0], 0.1)
                self.assertEqual(fid[1], 4.8)

            ln, ls = gdb.line_name_symb('D578625')
            data = gdb.read_line_vv(ls, channels=['X', 'Y', 'Z', 'dx', 'dy'])
            self.assertEqual(len(data), 5)
            self.assertEqual(data[0][0], 'X')
            self.assertEqual(data[4][0], 'dy')
            npd = data[0][1].get_np()[0]
            self.assertEqual(npd[10], 578625.0)
            npd = data[1][1].get_np()[0]
            self.assertEqual(npd[10], 7773625.0)
            npd = data[2][1].get_np()[0]
            self.assertEqual(npd[10], -1195.7531280517615)

            data = gdb.read_line_vv(ls, 'X')
            self.assertEqual(data[0][0], 'X')
            npd = data[0][1].get_np()[0]
            self.assertEqual(npd[10], 578625.0)

            data = gdb.read_line_vv(ls, channels=['X', 'Y', 'Z'], dtype='<U32')
            npd = data[0][1].get_np()[0]
            self.assertEqual(npd[10], '578625.0')
            npd = data[1][1].get_np()[0]
            self.assertEqual(npd[10], '7773625.0')
            npd = data[2][1].get_np()[0]
            self.assertEqual(npd[10], '-1195.8')

            gdb.discard()