def test_grdinfo(): """ Make sure grd info works as expected. """ grid = load_earth_relief(registration="gridline") result = grdinfo(grid, L=0, C="n") assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1"
def test_grdcut_dataarray_in_file_out(grid): "grdcut an input DataArray, and output to a grid file" with GMTTempFile(suffix=".nc") as tmpfile: result = grdcut(grid, outgrid=tmpfile.name, region="0/180/0/90") assert result is None # grdcut returns None if output to a file result = grdinfo(tmpfile.name, C=True) assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n"
def test_grdinfo_region(grid): """ Check that the region argument works in grdinfo. """ result = grdinfo( grid=grid, force_scan=0, per_column="n", region=[-54, -50, -23, -20] ) assert result.strip() == "-54 -50 -23 -20 284.5 491 1 1 4 3 1 1"
def test_grdfill_file_out(grid): """ grdfill with an outgrid set. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdfill(grid=grid, mode="c20", outgrid=tmpfile.name) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True).strip() assert result == "-5 5 -5 5 -5130.5 inf 1 1 10 10 1 1"
def test_grdcut_file_in_file_out(): """ grdcut an input grid file, and output to a grid file. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region="0/180/0/90") assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, C=True) assert result == "0 180 0 90 -8182 5651.5 1 1 180 90 1 1\n"
def test_grdsample_file_out(grid): """ grdsample with an outgrid set and the spacing is changed. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdsample(grid=grid, outgrid=tmpfile.name, spacing=[1, 0.5]) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True).strip().split() assert float(result[6]) == 1 # x-increment assert float(result[7]) == 0.5 # y-increment
def test_grdinfo_region(): """ Check that the region argument works in grdinfo. """ result = grdinfo( grid="@earth_relief_01d", force_scan=0, per_column="n", region=[-170, 170, -80, 80], ) assert result.strip() == "-170 170 -80 80 -8182 5651.5 1 1 340 160 1 1"
def test_grdfilter_dataarray_in_file_out(grid): """ grdfilter an input DataArray, and output to a grid file. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdfilter(grid, outgrid=tmpfile.name, filter="g600", distance="4") assert result is None # grdfilter returns None if output to a file result = grdinfo(tmpfile.name, per_column=True) assert ( result == "-180 180 -90 90 -6147.49072266 5164.06005859 1 1 360 180 1 1\n" )
def test_xyz2grd_input_array_file_out(ship_data): """ Run xyz2grd by passing in a numpy array and set an outgrid file. """ with GMTTempFile(suffix=".nc") as tmpfile: result = xyz2grd( data=np.array(ship_data), spacing=5, region=[245, 255, 20, 30], outgrid=tmpfile.name, ) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) result = grdinfo(tmpfile.name, per_column=True).strip() assert result == "245 255 20 30 -3651.06079102 -352.379486084 5 5 3 3 0 0"
def test_grdclip_outgrid(grid): """ Test the below and above parameters for grdclip and creates a test outgrid. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdclip(grid=grid, outgrid=tmpfile.name, below=[-1500, -1800], above=[-200, 40]) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = (grdinfo(grid=tmpfile.name, force_scan=0, per_column="n").strip().split()) assert int(result[4]) == -1800 # minimum value assert int(result[5]) == 40 # maximum value
def test_grdproject_file_out(grid): """ grdproject with an outgrid set. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdproject(grid=grid, projection="M10c", outgrid=tmpfile.name) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True).strip().split() npt.assert_allclose(float(result[0]), 0) # x min npt.assert_allclose(float(result[1]), 10) # x max npt.assert_allclose(float(result[2]), 0, atol=1.0e-10) # y min npt.assert_allclose(float(result[3]), 9.94585661273) # y max npt.assert_allclose(float(result[4]), -5130.48193359) # min npt.assert_allclose(float(result[5]), -152.585281372) # max
def test_grdlandmask_outgrid(): """ Creates a grid land mask with an outgrid argument. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdlandmask(outgrid=tmpfile.name, spacing=1, region=[-5, 5, -5, 5]) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = (grdinfo(grid=tmpfile.name, force_scan=0, per_column="n").strip().split()) assert result == [ "-5", "5", "-5", "5", "0", "1", "1", "1", "11", "11", "0", "1" ]
def test_grdfilter_file_in_file_out(): """ grdfilter an input grid file, and output to a grid file. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdfilter( "@earth_relief_01d", outgrid=tmpfile.name, region=[0, 180, 0, 90], filter="g600", distance="4", ) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True) assert result == "0 180 0 90 -6147.49072266 5164.06005859 1 1 180 90 1 1\n"
def test_grdgradient_outgrid(grid): """ Test the azimuth and direction parameters for grdgradient with a set outgrid. """ with GMTTempFile(suffix=".nc") as tmpfile: result = grdgradient(grid=grid, outgrid=tmpfile.name, azimuth=10, direction="c") assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = (grdinfo(grid=tmpfile.name, force_scan="a", per_column="n").strip().split()) npt.assert_allclose(float(result[4]), -0.0045060496) # min npt.assert_allclose(float(result[5]), 0.0575332976) # max # Check spherically weighted statistics below npt.assert_allclose(float(result[10]), 0.000384754501283) # median npt.assert_allclose(float(result[12]), 0.00285958005568) # mean
def test_grdinfo_fails(): "Check that grdinfo fails correctly" with pytest.raises(GMTInvalidInput): grdinfo(np.arange(10).reshape((5, 2)))
def test_grdinfo_file(): "Test grdinfo with file input" result = grdinfo("@earth_relief_01d", L=0, C="n") assert result.strip() == "-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1"
def test_grdinfo_file(): """ Test grdinfo with file input. """ result = grdinfo(grid="@earth_relief_01d", force_scan=0, per_column="n") assert result.strip() == "-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1"
# %% # Gridded plots, and transect plot of slipperiness/velocity/rheologyB pointXY = collections.namedtuple(typename="pointXY", field_names="x y") pointA = pointXY(x=-1590_000, y=-99_000) pointB = pointXY(x=-1580_000, y=-255_000) points = pd.DataFrame(data=np.linspace(start=pointA, stop=pointB, num=250), columns=["x", "y"]) # %% fig = pygmt.Figure() # Same colormap for both grids grids = [ f"Models/{bedname.lower()}_{z_attr.varname}.nc" for bedname in ("DeepBedMap", "BedMachine") ] pygmt.grdinfo(grid=grids[1], T=10)[2:-1] pygmt.makecpt( cmap="hawaii", series=pygmt.grdinfo(grid=" ".join(grids), T=10)[2:-1], reverse=True, continuous=True, ) with pygmt.clib.Session() as session: subplot = lambda args: session.call_module(module="subplot", args=args) # Begin subplot subplot(args="begin 2x3 -BWSne -Bxaf -Byaf -Fs10c/4c,14c -M0c/0.5c -SRl") # Plot transect line graph subplot(args=f"set 0,0") transectproj = "X32c/4c"
def test_grdinfo(grid): """ Make sure grdinfo works as expected. """ result = grdinfo(grid=grid, force_scan=0, per_column="n") assert result.strip() == "-55 -47 -24 -10 190 981 1 1 8 14 1 1"