Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly allow for either pixel or gridline registered grids #476

Merged
merged 41 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ebd3e00
Add registration (r) to common options
weiji14 Jun 10, 2020
bb7afdc
Allow virtualfile_from_grid to accept a registration argument
weiji14 Jun 10, 2020
08edf6f
Try using GMT_GRID_PIXEL_REG as default instead of GMT_GRID_NODE_REG
weiji14 Jun 19, 2020
8ce734d
Merge branch 'master' into grid_registration
seisman Jun 22, 2020
47b5b68
Let pygmt know about geographic grids
weiji14 Jun 22, 2020
522ceba
Revert back to using Cartesian mode, but be explicit this time
weiji14 Jun 22, 2020
d203cd5
Set valid GMT data mode as GMT_IS_OUTPUT
weiji14 Jun 22, 2020
90b22a4
Revert "Try using GMT_GRID_PIXEL_REG as default instead of GMT_GRID_N…
weiji14 Jun 19, 2020
6d4ece4
Automatically detect grid registration from xarray data source
weiji14 Jun 23, 2020
b252b9d
Prevent segfault crash when passing pixel registered grids on GMT < 6.1
weiji14 Jun 23, 2020
93881c5
Merge branch 'master' into grid_registration
weiji14 Jun 23, 2020
572b499
Have `grdinfo` and `grdtrack` autodetect registration type too
weiji14 Jun 23, 2020
0812c50
Put autodetect_registration code directly inside virtualfile_from_grid
weiji14 Jun 23, 2020
5cb2cee
Lint
weiji14 Jun 23, 2020
16d9240
Autodetect grid type as Cartesian or Geographic coordinate system
weiji14 Jun 25, 2020
046a5e3
Merge branch 'master' into grid_registration
weiji14 Jun 25, 2020
3215b0c
Patch to fix crash when registration is GMT_GRID_PIXEL_REG in GMT 6.0
weiji14 Jun 25, 2020
88ceba2
Separate input and output registration
weiji14 Jun 25, 2020
bc2c2f0
Merge branch 'master' into grid_registration
weiji14 Jun 28, 2020
bff3254
Remove unused-import, silence redefined-outer-name warning
weiji14 Jun 28, 2020
1fc91f8
Expect registration type in dataarray's node_offset attribute
weiji14 Jun 28, 2020
6892e4b
Simplify grid region extent calculation
weiji14 Jun 28, 2020
d8fd6b5
Merge branch 'master' into grid_registration
weiji14 Jun 29, 2020
0e593d8
Expect gtype in dataarray's geocoord_type attribute
weiji14 Jun 29, 2020
00a46ca
Merge branch 'master' into grid_registration
weiji14 Jul 11, 2020
0f84f04
Refactor virtualfile_from_grid and dataarray_to_matrix to use accessor
weiji14 Jul 12, 2020
5c5be94
Fix tests where virtual grid had wrong region, registration and gtype
weiji14 Jul 12, 2020
22dfe74
Expect failures from two grdview tests that used wrong coordinate system
weiji14 Jul 12, 2020
53dc9c9
Fix test_grdimage_over_dateline by using gridline instead of pixel reg
weiji14 Jul 12, 2020
0a73114
Run test_grdimage_over_dateline with debug mode on
weiji14 Jul 12, 2020
fe0fbc5
Replace unnecessary comprehension with generator
weiji14 Jul 12, 2020
5a0c639
Flip grid array left right in xarray instead of in numpy
weiji14 Jul 12, 2020
5a685b2
Deep copy grid using xarray.DataArray.copy instead of numpy.copy
weiji14 Jul 12, 2020
40bc7f9
Merge branch 'master' into grid_registration
weiji14 Jul 15, 2020
d0be1c5
Reduce image size from 1 inch to 1 cm
weiji14 Jul 15, 2020
46c8471
Test with a grid that does not reach the North Pole
weiji14 Jul 15, 2020
3499047
Try just running test_grdimage_over_dateline first before other tests
weiji14 Jul 15, 2020
bf03e5b
Don't use pytest --no-summary which is a pytest 6.0.0rc1 feature
weiji14 Jul 15, 2020
60c791d
Revert "Deep copy grid using xarray.DataArray.copy instead of numpy.c…
weiji14 Jul 12, 2020
c411a95
Say why we need to run test_grdimage_over_dateline before other tests
weiji14 Jul 16, 2020
217a7d7
Register the custom runfirst pytest marker
weiji14 Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ test:
@echo ""
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
@echo ""
cd $(TESTDIR); pytest $(PYTEST_ARGS) $(PROJECT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some comments here, explain why we need two pytest.

# There are two steps to the test here because `test_grdimage_over_dateline`
# passes only when it runs before the other tests.
# See also https://github.com/GenericMappingTools/pygmt/pull/476
cd $(TESTDIR); pytest -m runfirst $(PYTEST_ARGS) $(PROJECT)
cd $(TESTDIR); pytest -m 'not runfirst' $(PYTEST_ARGS) $(PROJECT)
cp $(TESTDIR)/coverage.xml .
cp -r $(TESTDIR)/htmlcov .
rm -r $(TESTDIR)
Expand Down
17 changes: 11 additions & 6 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def dataarray_to_matrix(grid):
>>> grid = load_earth_relief(resolution='01d')
>>> matrix, region, inc = dataarray_to_matrix(grid)
>>> print(region)
[-179.5, 179.5, -89.5, 89.5]
[-180.0, 180.0, -90.0, 90.0]
>>> print(inc)
[1.0, 1.0]
>>> type(matrix)
Expand All @@ -67,7 +67,7 @@ def dataarray_to_matrix(grid):
>>> print(matrix.shape)
(31, 71)
>>> print(region)
[-149.5, -79.5, -79.5, -49.5]
[-150.0, -79.0, -80.0, -49.0]
>>> print(inc)
[1.0, 1.0]
>>> # but not if only taking every other grid point.
Expand All @@ -77,7 +77,7 @@ def dataarray_to_matrix(grid):
>>> print(matrix.shape)
(16, 36)
>>> print(region)
[-149.5, -79.5, -79.5, -49.5]
[-150.5, -78.5, -80.5, -48.5]
>>> print(inc)
[2.0, 2.0]

Expand All @@ -102,14 +102,19 @@ def dataarray_to_matrix(grid):
dim
)
)
region.extend([coord.min(), coord.max()])
region.extend(
[
coord.min() - coord_inc / 2 * grid.gmt.registration,
coord.max() + coord_inc / 2 * grid.gmt.registration,
]
)
inc.append(coord_inc)

if any([i < 0 for i in inc]): # Sort grid when there are negative increments
if any(i < 0 for i in inc): # Sort grid when there are negative increments
inc = [abs(i) for i in inc]
grid = grid.sortby(variables=list(grid.dims), ascending=True)

matrix = as_c_contiguous(grid.values[::-1])
matrix = as_c_contiguous(grid[::-1].values)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we practically always create a memory copy here because the numpy view on a flipped grid grid[::-1] is never (or hardly ever?) c_contiguous. I don't know if there's a way around this, but if we need to switch to use GMT_IS_DUPLICATE for stability in #517, wouldn't that mean we create 2 memory copies?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try using xarray.DataArray.copy at 5a685b2 to force a deep copy (that should return a c_contiguous array) before it enters the as_c_contiguous function (which may or may not return a numpy copy). It seems to give a more consistent black image, rather than the reddish-brown one 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted 5a685b2 at 60c791d, will stick to just grid[::-1].values for now (i.e. flipping the grid left right in xarray rather than in numpy).

return matrix, region, inc


Expand Down
35 changes: 23 additions & 12 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"GMT_IS_SURFACE",
]

MODES = ["GMT_CONTAINER_ONLY", "GMT_OUTPUT"]
MODES = ["GMT_CONTAINER_ONLY", "GMT_IS_OUTPUT"]

REGISTRATIONS = ["GMT_GRID_PIXEL_REG", "GMT_GRID_NODE_REG"]

Expand Down Expand Up @@ -113,7 +113,7 @@ class Session:
... )
... # Read the contents of the temp file before it's deleted.
... print(fout.read().strip())
-179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1
"""

# The minimum version of GMT required
Expand Down Expand Up @@ -511,13 +511,13 @@ def create_data(self, family, geometry, mode, **kwargs):
----------
family : str
A valid GMT data family name (e.g., ``'GMT_IS_DATASET'``). See the
``data_families`` attribute for valid names.
``FAMILIES`` attribute for valid names.
geometry : str
A valid GMT data geometry name (e.g., ``'GMT_IS_POINT'``). See the
``data_geometries`` attribute for valid names.
``GEOMETRIES`` attribute for valid names.
mode : str
A valid GMT data mode (e.g., ``'GMT_OUTPUT'``). See the
``data_modes`` attribute for valid names.
A valid GMT data mode (e.g., ``'GMT_IS_OUTPUT'``). See the
``MODES`` attribute for valid names.
dim : list of 4 integers
The dimensions of the dataset. See the documentation for the GMT C
API function ``GMT_Create_Data`` (``src/gmt_api.c``) for the full
Expand All @@ -530,7 +530,7 @@ def create_data(self, family, geometry, mode, **kwargs):
inc : list of 2 floats
The increments between points of the dataset. See the C function
documentation.
registration : int
registration : str
The node registration (what the coordinates mean). Can be
``'GMT_GRID_PIXEL_REG'`` or ``'GMT_GRID_NODE_REG'``. Defaults to
``'GMT_GRID_NODE_REG'``.
Expand Down Expand Up @@ -563,7 +563,9 @@ def create_data(self, family, geometry, mode, **kwargs):

family_int = self._parse_constant(family, valid=FAMILIES, valid_modifiers=VIAS)
mode_int = self._parse_constant(
mode, valid=MODES, valid_modifiers=["GMT_GRID_IS_GEO"]
mode,
valid=MODES,
valid_modifiers=["GMT_GRID_IS_CARTESIAN", "GMT_GRID_IS_GEO"],
)
geometry_int = self._parse_constant(geometry, valid=GEOMETRIES)
registration_int = self._parse_constant(
Expand Down Expand Up @@ -856,12 +858,12 @@ def write_data(self, family, geometry, mode, wesn, output, data):
----------
family : str
A valid GMT data family name (e.g., ``'GMT_IS_DATASET'``). See the
``data_families`` attribute for valid names. Don't use the
``FAMILIES`` attribute for valid names. Don't use the
``GMT_VIA_VECTOR`` or ``GMT_VIA_MATRIX`` constructs for this. Use
``GMT_IS_VECTOR`` and ``GMT_IS_MATRIX`` instead.
geometry : str
A valid GMT data geometry name (e.g., ``'GMT_IS_POINT'``). See the
``data_geometries`` attribute for valid names.
``GEOMETRIES`` attribute for valid names.
mode : str
How the data is to be written to the file. This option varies
depending on the given family. See the GMT API documentation for
Expand Down Expand Up @@ -1243,21 +1245,30 @@ def virtualfile_from_grid(self, grid):
... args = '{} -L0 -Cn ->{}'.format(fin, fout.name)
... ses.call_module('grdinfo', args)
... print(fout.read().strip())
-179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
-180 180 -90 90 -8182 5651.5 1 1 360 180 1 1
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype

"""
_gtype = {0: "GMT_GRID_IS_CARTESIAN", 1: "GMT_GRID_IS_GEO"}[grid.gmt.gtype]
_reg = {0: "GMT_GRID_NODE_REG", 1: "GMT_GRID_PIXEL_REG"}[grid.gmt.registration]

# Conversion to a C-contiguous array needs to be done here and not in
# put_matrix because we need to maintain a reference to the copy while
# it is being used by the C API. Otherwise, the array would be garbage
# collected and the memory freed. Creating it in this context manager
# guarantees that the copy will be around until the virtual file is
# closed. The conversion is implicit in dataarray_to_matrix.
matrix, region, inc = dataarray_to_matrix(grid)

family = "GMT_IS_GRID|GMT_VIA_MATRIX"
geometry = "GMT_IS_SURFACE"
gmt_grid = self.create_data(
family, geometry, mode="GMT_CONTAINER_ONLY", ranges=region, inc=inc
family,
geometry,
mode=f"GMT_CONTAINER_ONLY|{_gtype}",
ranges=region,
inc=inc,
registration=_reg,
)
self.put_matrix(gmt_grid, matrix)
args = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", gmt_grid)
Expand Down
5 changes: 5 additions & 0 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
- 'c' for bicubic [Default]
- 'l' for bilinear
- 'n' for nearest-neighbor""",
"registration": """\
registration : str
``[g|p]``
Force output grid to be gridline (g) or pixel (p) node registered.
Default is gridline (g).""",
}


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test Figure.grdimage
"""
import numpy as np
import xarray as xr
import pytest

from .. import Figure
Expand All @@ -15,6 +16,27 @@ def fixture_grid():
return load_earth_relief(registration="gridline")


@pytest.fixture(scope="module", name="xrgrid")
def fixture_xrgrid():
"""
Create a sample xarray.DataArray grid for testing
"""
longitude = np.arange(0, 360, 1)
latitude = np.arange(-89, 90, 1)
x = np.sin(np.deg2rad(longitude))
y = np.linspace(start=0, stop=1, num=179)
data = y[:, np.newaxis] * x

return xr.DataArray(
data,
coords=[
("latitude", latitude, {"units": "degrees_north"}),
("longitude", longitude, {"units": "degrees_east"}),
],
attrs={"actual_range": [-1, 1]},
)


@pytest.mark.mpl_image_compare
def test_grdimage(grid):
"Plot an image using an xarray grid"
Expand Down Expand Up @@ -51,3 +73,23 @@ def test_grdimage_fails():
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.grdimage(np.arange(20).reshape((4, 5)))


# This test needs to run first before the other tests (on Linux at least) so
# that a black image isn't plotted due to an `inf` value when resampling.
# See also https://github.com/GenericMappingTools/pygmt/pull/476
@pytest.mark.runfirst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a brief comment here, explain why we need "runfirst".

@pytest.mark.mpl_image_compare
def test_grdimage_over_dateline(xrgrid):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to think that this test is exposing some flaky tests in our test suite (see also #327 (comment)). The test passes pretty much all the time (?) when I just run pytest --verbose --mpl pygmt/tests/test_grdimage.py or even pytest --verbose --mpl pygmt/tests/test_grd*.py, but running make test causes the test to fail 😕

I probably went down the wrong rabbit hole, but I've tried pretty much all of the pytest plugins to test for flakiness including pytest-xdist and pytest-flakefinder, and they pretty much agree that it's not test_grdimage_over_dateline which is the issue, it's one of the tests that precede it, but I'm having trouble tracking it down since the failures are all intermittent and semi-random.

Comment on lines +81 to +83
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running test_grdimage_over_dateline first (before the other tests) makes the tests pass on Linux (see commit 3499047 and bf03e5b). This is a hacky workaround for the flakiness I described at https://github.com/GenericMappingTools/pygmt/pull/476/files#r453429872.

"""
Ensure no gaps are plotted over the 180 degree international dateline.
Specifically checking that `xrgrid.gmt.gtype = 1` sets `GMT_GRID_IS_GEO`,
and that `xrgrid.gmt.registration = 0` sets `GMT_GRID_NODE_REG`. Note that
there would be a gap over the dateline if a pixel registered grid is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to issue #375?

See also https://github.com/GenericMappingTools/pygmt/issues/375.
"""
fig = Figure()
assert xrgrid.gmt.registration == 0 # gridline registration
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dateline test seems to work sometimes, but crashes at other times, reminds me of the black image we got a while ago. Was there a regression in GMT?

baseline-test_grdimage_over_dateline test_grdimage_over_dateline-failed-diff test_grdimage_over_dateline
Expected Diff Generated

Copy link
Member

@seisman seisman Jul 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiji14 Please see if #517 works for you.

You can cherry-pick commit b64f371 to your local branch or this PR and see it can fix the random crashes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, still get the all black image :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the tests 10 times, and always get the expected figure, but I'm using macOS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add V='d' to the grdimage function, and post the output so that I can compare if there are any differences.

Copy link
Member Author

@weiji14 weiji14 Jul 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on, that error message was from one of the successful runs. It seems to work fine in ipython but fails when I run it using make test. Give me a couple of minutes. I've turned on debugging for test_grdimage_over_dateline in 0a73114, let's see the output there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got the failing debug info (not sure why it's not printed in the CI). The main difference seems to be an inf value:

# good
grdimage [INFORMATION]: gmt_grd_project: Output grid extrema [-27.5593/114.589] exceed extrema of input grid [-1/1] due to resampling
# bad
grdimage [INFORMATION]: gmt_grd_project: Output grid extrema [-inf/114.589] exceed extrema of input grid [-inf/1] due to resampling
grdimage [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
grdimage [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
grdimage [DEBUG]: Projected grid is non-orthogonal, nonlinear, or dpi was changed
grdimage [INFORMATION]: Read header from file @GMTAPI@-S-I-G-M-G-N-000000
grdimage [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdimage [DEBUG]: gmtapi_import_grid: Passed ID = 0 and mode = 1
grdimage [DEBUG]: Grid/Image dimensions imply w/e/s/n = 0/359/-89/90, inc = 1/1, gridline registration, n_layers = 1
grdimage [DEBUG]: Geographic input grid, longitudes span less than 360
grdimage [DEBUG]: Chosen boundary condition for all edges: geographic
grdimage [DEBUG]: Geographic input grid, longitude cells span exactly 360
grdimage [DEBUG]: Object ID 1 : Registered Grid Memory Reference 562abb2b9ce0 as an Input resource with geometry Surface [n_objects = 2]
grdimage [DEBUG]: Successfully created a new Grid container
grdimage [DEBUG]: GMT_End_IO: Input resource access is now disabled
grdimage [DEBUG]: Projected values in meters: -9.00996e+06 9.00996e+06 -9.00996e+06 9.00996e+06
grdimage [INFORMATION]: Map scale is 7094.46 km per cm or 1:7.09446e+08.
grdimage [DEBUG]: Running in PS mode modern
grdimage [DEBUG]: Use PS filename /home/user/.gmt/sessions/gmt_session.6871/gmt_68.ps-
grdimage [DEBUG]: Create hidden PS file /home/user/.gmt/sessions/gmt_session.6871/gmt_68.ps-
grdimage [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
grdimage [INFORMATION]: Allocate and read data from file @GMTAPI@-S-I-G-M-G-N-000000
grdimage [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdimage [DEBUG]: gmtapi_import_grid: Passed ID = 0 and mode = 2
grdimage [INFORMATION]: Importing grid data from user matrix memory location
grdimage [DEBUG]: Grid is considered to have a 360-degree longitude range.
grdimage [DEBUG]: Chosen boundary condition for left and right edges: geographic
grdimage [DEBUG]: Chosen boundary condition for bottom edge: natural
grdimage [DEBUG]: Chosen boundary condition for top    edge: geographic
grdimage [INFORMATION]: 359 (of 361) inconsistent grid values at North pole.
grdimage [INFORMATION]: Set boundary condition for top    edge: geographic
grdimage [INFORMATION]: Set boundary condition for bottom edge: natural
grdimage [DEBUG]: GMT_End_IO: Input resource access is now disabled
grdimage [INFORMATION]: project grid files
grdimage [DEBUG]: Object ID 2 : Registered Grid Memory Reference 562abb070e10 as an Input resource with geometry Surface [n_objects = 3]
grdimage [DEBUG]: Successfully duplicated a Grid
grdimage [DEBUG]: gmt_project_init: IN: Inc [0/0] n_columns/n_rows [361/180] dpi = 0 offset = 0
grdimage [DEBUG]: gmt_project_init: OUT: Inc [0/0] n_columns/n_rows [361/180] dpi = 0 offset = 0
grdimage [INFORMATION]: Grid projection from size 361x180 to 361x180
grdimage [DEBUG]: Successfully added data array to previously registered Grid container
grdimage [DEBUG]: gmt_grd_project: In [0/360/-89/90] and out [0/1/0/1]
grdimage [INFORMATION]: gmt_grd_project: Output grid extrema [-inf/114.589] exceed extrema of input grid [-inf/1] due to resampling
grdimage [INFORMATION]: gmt_grd_project: Output grid clipped to input grid extrema
grdimage [DEBUG]: GMT_Destroy_Data: freed memory for a Grid for object 1
grdimage [DEBUG]: gmtlib_unregister_io: Unregistering object no 1 [n_objects = 2]
grdimage [DEBUG]: gmtlib_unregister_io: Object no 1 has non-NULL resource pointer
grdimage [DEBUG]: gmtlib_get_graphics_item: Fig: 68 Subplot: 2 Panel: () Inset: 0
grdimage [DEBUG]: No current cpt file found
grdimage [DEBUG]: gmtlib_get_graphics_item: Fig: 68 Subplot: 2 Panel: () Inset: 0
grdimage [DEBUG]: No current cpt file found
grdimage [DEBUG]: GMT: 0. Will try to find subdir=cpt stem = turbo suffix=.cpt
grdimage [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
grdimage [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR /home/user/.gmt
grdimage [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir /home/user/.gmt/cpt
grdimage [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir /home/user/miniconda3/envs/pygmt/share/gmt/cpt
grdimage [DEBUG]: gmt_get_filename: In: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt Out: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: Given full path to file /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: gmt_get_filename: In: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt Out: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: gmt_get_filename: In: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt Out: /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: Found readable file /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: Object ID 3 : Registered CPT File /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt as an Input resource with geometry Non-Geographical [n_objects = 3]
grdimage [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdimage [DEBUG]: gmtapi_import_palette: Passed ID = 3 and mode = 8
grdimage [INFORMATION]: Reading CPT from File /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: Reading CPT from /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [DEBUG]: GMT_End_IO: Input resource access is now disabled
grdimage [INFORMATION]: Auto-stretching CPT file turbo to fit data range -inf to 1
grdimage [DEBUG]: gmtlib_get_graphics_item: Fig: 68 Subplot: 2 Panel: () Inset: 0
grdimage [DEBUG]: Object ID 4 : Registered CPT File /home/user/.gmt/sessions/gmt_session.6871/gmt.68.cpt as an Output resource with geometry Non-Geographical [n_objects = 4]
grdimage [DEBUG]: gmtapi_begin_io: Output resource access is now enabled [container]
grdimage [DEBUG]: gmtapi_export_palette: Passed ID = 4 and mode = 0
grdimage [INFORMATION]: Write CPT to File /home/user/.gmt/sessions/gmt_session.6871/gmt.68.cpt
grdimage [DEBUG]: Writing CPT to /home/user/.gmt/sessions/gmt_session.6871/gmt.68.cpt
grdimage [DEBUG]: GMT_End_IO: Output resource access is now disabled
grdimage [INFORMATION]: Save current CPT file to /home/user/.gmt/sessions/gmt_session.6871/gmt.68.cpt !
grdimage [INFORMATION]: Evaluate image pixel colors
grdimage [INFORMATION]: Basic z(x,y) with optional illumination and no PostScript colormasking.
grdimage [INFORMATION]: Creating 24-bit color image
PSL: Colormap of 2 colors created
PSL: Image depth reduced to 1 bits
PSL: DEFLATE compressed 8280 to 668 bytes (91.9% savings at compression level 5)
grdimage [DEBUG]: Current size of half-baked PS file /home/user/.gmt/sessions/gmt_session.6871/gmt_68.ps- = 22240.
grdimage (GMT_grdimage): tried to free unallocated memory
grdimage [DEBUG]: GMT_Destroy_Data: freed memory for a Grid for object 2
grdimage [DEBUG]: gmtlib_unregister_io: Unregistering object no 2 [n_objects = 3]
grdimage [DEBUG]: gmtlib_unregister_io: Object no 2 has non-NULL resource pointer
grdimage [DEBUG]: gmtlib_garbage_collection: Destroying object: C=0 A=0 ID=3 W=Input F=CPT M=File S=Used P=562abf53bc60 N=/home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage (gmtsupport_free_range): tried to free unallocated memory
grdimage (gmtsupport_free_range): tried to free unallocated memory
...
grdimage (gmtsupport_free_range): tried to free unallocated memory
grdimage (gmtsupport_free_range): tried to free unallocated memory
grdimage [DEBUG]: GMTAPI_Garbage_Collection freed 1 memory objects
grdimage [DEBUG]: gmtlib_unregister_io: Unregistering object no 3 [n_objects = 2]
grdimage [DEBUG]: gmtlib_unregister_io: Unregistering object no 4 [n_objects = 1]
grdimage (gmtlib_free_tmp_arrays): tried to free unallocated memory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw the similar inf when debugging the shading=True failure in #364. That's why I thought GMT_IN should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be another potential GMT bug, which is usually difficult to debugging from the PyGMT side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this is the output using GMT_IS_DUPLICATE, which generates the reddish-brown image above. Using V="i" for brevity, note that -1.1949e+26 is printed instead of -inf:

grdimage [INFORMATION]: Read header from file @GMTAPI@-S-I-G-M-G-N-000000
grdimage [INFORMATION]: Map scale is 7094.46 km per cm or 1:7.09446e+08.
grdimage [INFORMATION]: Allocate and read data from file @GMTAPI@-S-I-G-M-G-N-000000
grdimage [INFORMATION]: Importing grid data from user matrix memory location
grdimage [INFORMATION]: 359 (of 361) inconsistent grid values at North pole.
grdimage [INFORMATION]: Set boundary condition for top    edge: geographic
grdimage [INFORMATION]: Set boundary condition for bottom edge: natural
grdimage [INFORMATION]: project grid files
grdimage [INFORMATION]: Grid projection from size 361x180 to 361x180
grdimage [INFORMATION]: gmt_grd_project: Output grid extrema [-1.1949e+26/114.589] exceed extrema of input grid [-1.1949e+26/1] due to resampling
grdimage [INFORMATION]: gmt_grd_project: Output grid clipped to input grid extrema
grdimage [INFORMATION]: Reading CPT from File /home/user/miniconda3/envs/pygmt/share/gmt/cpt/turbo.cpt
grdimage [INFORMATION]: Auto-stretching CPT file turbo to fit data range -1.1949e+26 to 1
grdimage [INFORMATION]: Write CPT to File /home/user/.gmt/sessions/gmt_session.12777/gmt.68.cpt
grdimage [INFORMATION]: Save current CPT file to /home/user/.gmt/sessions/gmt_session.12777/gmt.68.cpt !
grdimage [INFORMATION]: Evaluate image pixel colors
grdimage [INFORMATION]: Basic z(x,y) with optional illumination and no PostScript colormasking.
grdimage [INFORMATION]: Creating 24-bit color image
PSL: Colormap of 3 colors created
PSL: Image depth reduced to 2 bits
PSL: DEFLATE compressed 16380 to 779 bytes (95.2% savings at compression level 5)

xrgrid.gmt.gtype = 1 # geographic coordinate system
fig.grdimage(grid=xrgrid, region="g", projection="A0/0/1c", V="i")
return fig
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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 0"
assert result.strip() == "-180 180 -90 90 -8592.5 5559 1 1 361 181 0 1"


def test_grdinfo_file():
Expand Down
6 changes: 6 additions & 0 deletions pygmt/tests/test_grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def fixture_grid():
)


@pytest.mark.xfail(
reason="Baseline image generated using Cartesian instead of Geographic coordinates"
)
@pytest.mark.mpl_image_compare
def test_grdview_grid_dataarray(grid):
"""
Expand Down Expand Up @@ -54,6 +57,9 @@ def test_grdview_wrong_kind_of_grid(grid):
fig.grdview(grid=dataset)


@pytest.mark.xfail(
reason="Baseline image generated using Cartesian instead of Geographic coordinates"
)
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective(grid):
"""
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ exclude =
[tool:pytest]
markers =
mpl_image_compare: compare generated plots with correct baseline version
runfirst: runs the test(s) first before the other ones