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

GMT crashes when grdcut a tiff file #3992

Closed
seisman opened this issue Aug 18, 2020 · 18 comments
Closed

GMT crashes when grdcut a tiff file #3992

seisman opened this issue Aug 18, 2020 · 18 comments
Labels
bug Something isn't working

Comments

@seisman
Copy link
Member

seisman commented Aug 18, 2020

$ gmt grdcut @earth_day_05m -R0/30/0/30 -Gabc.tiff
ERROR: Caught signal number 11 (Segmentation fault) at
0   libgmt.6.dylib                      0x0000000103aa61e9 gmt_gdal_read_grd + 2057
1   ???                                 0x00007ffa8bdf1000 0x0 + 140714065203200
Stack backtrace:
0   libgmt.6.dylib                      0x0000000103a56695 sig_handler + 581
1   libsystem_platform.dylib            0x00007fff685495fd _sigtramp + 29
2   ???                                 0x00007ffa89500000 0x0 + 140714022273024
3   libgmt.6.dylib                      0x0000000103ab9149 gmtlib_read_grd + 185
4   libgmt.6.dylib                      0x0000000103a89445 gmtapi_import_grid + 4885
5   libgmt.6.dylib                      0x0000000103a837c5 gmtapi_import_data + 437
6   libgmt.6.dylib                      0x0000000103a70b2c gmtapi_get_data + 348
7   libgmt.6.dylib                      0x0000000103a68f01 GMT_Read_Data + 4849
8   libgmt.6.dylib                      0x0000000103ccf478 GMT_grdcut + 11640
9   libgmt.6.dylib                      0x0000000103a78b7c GMT_Call_Module + 2156
10  gmt                                 0x0000000103a469a8 main + 2568
11  libdyld.dylib                       0x00007fff68350cc9 start + 1
12  ???                                 0x0000000000000005 0x0 + 5
@PaulWessel
Copy link
Member

Cannot immediately reproduce that:

gmt grdcut @earth_day_05m -R0/30/0/30 -Gabc.tiff
gmt grdinfo abc.tiff
abc.tiff: Title: Produced by grdcut
abc.tiff: Command: grdcut @earth_day_05m_p -R0/30/0/30 -Gabc.tiff
abc.tiff: Remark: 
abc.tiff: Pixel node registration used [Geographic grid]
abc.tiff: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
abc.tiff: x_min: 0 x_max: 30 x_inc: 0.0833333333333 (5 min) name: longitude n_columns: 360
abc.tiff: y_min: 0 y_max: 30 y_inc: 0.0833333333333 (5 min) name: latitude n_rows: 360
abc.tiff: z_min: 0 z_max: 255 name: z
abc.tiff: scale_factor: 1 add_offset: 0
abc.tiff: format: netCDF-4 chunk_size: 180,180 shuffle: on deflation_level: 3
GEOGCS["unknown",
    DATUM["unknown",
        SPHEROID["unknown",6378137,0]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AXIS["Longitude",EAST],
    AXIS["Latitude",NORTH]]

@seisman
Copy link
Member Author

seisman commented Aug 18, 2020

Tried both GDAL 2.4.4 and 3.1.2. They both crash.

@PaulWessel
Copy link
Member

OK, after dinner and movie...

@joa-quim
Copy link
Member

It doesn't crash for me neither.

@PaulWessel
Copy link
Member

Remember that although you ask for -Gabc.tiff, what is written here is a grid (netCDF). And you loose the green and blue layers since a grid is z only. I think you were imagining a subset of an image to be written? Also, you had some other GDAL related troubles so perhaps the crash is part of that?

@PaulWessel
Copy link
Member

If we actually wanted grdcut to work on images like you probably expected, the shortcut to implementation would be

  1. Detect that the input file is an image (simply by examining extensions, possibly by reading header)
  2. If image, set up a series of grdmix calls to split into three grids, cut each of them, then reassmble:
gmt grdmix @earth_day_05m -D -Glayer%c.grd
gmt grdcut layerR.grd -R0/30/0/30 -GR.grd
gmt grdcut layerG.grd -R0/30/0/30 -GG.grd
gmt grdcut layerB.grd -R0/30/0/30 -GB.grd
gmt grdmix R.grd G.grd B.grd -C -Gcut.tif -N

Coded up as a short functions that sets the virtual files stuff it is all done in memory.

@joa-quim
Copy link
Member

joa-quim commented Sep 3, 2020

We talked this before. The solution should go into grdgdal.

@seisman
Copy link
Member Author

seisman commented Sep 3, 2020

Remember that although you ask for -Gabc.tiff, what is written here is a grid (netCDF). And you loose the green and blue layers since a grid is z only. I think you were imagining a subset of an image to be written?

I didn't realize that. I expect to have a subset of an image, written in tiff format.

Also, you had some other GDAL related troubles so perhaps the crash is part of that?

gmt grdinfo @earth_day_05m works well for me. gmt grdcut @earth_day_05m -R0/30/0/30 -Gabc.tiff -Vd shows the following messages before crashing:

grdcut [DEBUG]: gmt_get_filename: In: /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.hdr Out: /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.hdr
grdcut [DEBUG]: Found readable file /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif
grdcut [INFORMATION]: File /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif reads with GDAL driver GTiff
grdcut [DEBUG]: Found readable file /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif
grdcut [DEBUG]: Geographic input grid, longitudes span less than 360
grdcut [DEBUG]: Call gmtgrdio_doctor_geo_increments on a geographic grid
grdcut [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
grdcut [DEBUG]: Geographic input grid, longitudes span exactly 360
grdcut [DEBUG]: GMT_End_IO: Input resource access is now disabled
grdcut [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdcut [DEBUG]: gmtapi_import_grid: Passed ID = 0 and mode = 2
grdcut [INFORMATION]: Reading grid from file /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif
grdcut [INFORMATION]: Read band(s):	1
grdcut [DEBUG]: Found readable file /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif
grdcut [DEBUG]: Found readable file /Users/seisman/.gmt/server/earth/earth_day/earth_day_05m_p.tif
ERROR: Caught signal number 11 (Segmentation fault: 11) at
0   libgmt.6.dylib                      0x0000000104c06439 gmt_gdal_read_grd + 2057
1   ???                                 0x00007ff9778e2000 0x0 + 140709429387264
Stack backtrace:
0   libgmt.6.dylib                      0x0000000104bb5ef2 sig_handler + 578
1   libsystem_platform.dylib            0x00007fff6fe815fd _sigtramp + 29
2   ???                                 0x0000000000000006 0x0 + 6
3   libgmt.6.dylib                      0x0000000104c195a9 gmtlib_read_grd + 185
4   libgmt.6.dylib                      0x0000000104be9635 gmtapi_import_grid + 4885
5   libgmt.6.dylib                      0x0000000104be39b5 gmtapi_import_data + 437
6   libgmt.6.dylib                      0x0000000104bd090c gmtapi_get_data + 348
7   libgmt.6.dylib                      0x0000000104bc8d11 GMT_Read_Data + 4849
8   libgmt.6.dylib                      0x0000000104e35218 GMT_grdcut + 11640
9   libgmt.6.dylib                      0x0000000104bd895c GMT_Call_Module + 2156
10  gmt                                 0x0000000104ba59a8 main + 2568
11  libdyld.dylib                       0x00007fff6fc88cc9 start + 1
12  ???                                 0x0000000000000006 0x0 + 6

Debugging in xcode shows the crash point:
image

head->size is 132694, and j is 131072.

@stale
Copy link

stale bot commented Dec 4, 2020

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Dec 4, 2020
@seisman seisman removed the stale This will not be worked on label Dec 4, 2020
@joa-quim
Copy link
Member

Hmm, but this tiff file is indexed so it should have ~worked (though loose the cpt).

@PaulWessel
Copy link
Member

Does this still crash for @seisman ? Works fine for me.

@seisman
Copy link
Member Author

seisman commented Mar 15, 2021

It still crashes for me.

@joa-quim
Copy link
Member

joa-quim commented Mar 15, 2021

And for me too, but Kristof showed as the example of the land cover file where he was able to do a grdcut on a single band tif file.

@stale
Copy link

stale bot commented Jun 16, 2021

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Jun 16, 2021
@seisman seisman removed the stale This will not be worked on label Jun 17, 2021
@maxrjones maxrjones added the bug Something isn't working label Sep 22, 2021
@maxrjones maxrjones added this to the 6.3.0 milestone Sep 22, 2021
@maxrjones
Copy link
Member

@seisman, would you be able to check whether #5798 fixes this crash? For me, it works fine but it seems that the problem was not easily reproducible to start with.

@seisman
Copy link
Member Author

seisman commented Sep 27, 2021

Yes, it works with PR #5798.

@maxrjones
Copy link
Member

Yes, it works with PR #5798.

Great, thanks!

@maxrjones
Copy link
Member

Fixed by #5798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants