Skip to content

GMT crashes when grdcut a tiff file #3992

Closed

Description

@seisman
$ 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

Activity

  1. PaulWessel commented on Aug 18, 2020

    @PaulWessel
    Contributor

    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]]
    
    
  2. seisman commented on Aug 18, 2020

    @seisman
    MemberAuthor

    Tried both GDAL 2.4.4 and 3.1.2. They both crash.

  3. PaulWessel commented on Aug 18, 2020

    @PaulWessel
    Contributor

    OK, after dinner and movie...

  4. joa-quim commented on Aug 18, 2020

    @joa-quim
    Member

    It doesn't crash for me neither.

  5. PaulWessel commented on Sep 3, 2020

    @PaulWessel
    Contributor

    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?

  6. PaulWessel commented on Sep 3, 2020

    @PaulWessel
    Contributor

    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.

  7. joa-quim commented on Sep 3, 2020

    @joa-quim
    Member

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

  8. seisman commented on Sep 3, 2020

    @seisman
    MemberAuthor

    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.

  9. stale commented on Dec 4, 2020

    @stale

    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.

  10. added
    stale
    on Dec 4, 2020
  11. removed
    stale
    on Dec 4, 2020
  12. joa-quim commented on Mar 15, 2021

    @joa-quim
    Member

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

  13. PaulWessel commented on Mar 15, 2021

    @PaulWessel
    Contributor

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

  14. seisman commented on Mar 15, 2021

    @seisman
    MemberAuthor

    It still crashes for me.

  15. joa-quim commented on Mar 15, 2021

    @joa-quim
    Member

    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.

  16. stale commented on Jun 16, 2021

    @stale

    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.

  17. added
    stale
    on Jun 16, 2021
  18. removed
    stale
    on Jun 17, 2021
  19. added
    bug
    on Sep 22, 2021
  20. added this to the milestone on Sep 22, 2021
  21. maxrjones commented on Sep 27, 2021

    @maxrjones
    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.

  22. seisman commented on Sep 27, 2021

    @seisman
    MemberAuthor

    Yes, it works with PR #5798.

  23. maxrjones commented on Sep 27, 2021

    @maxrjones
    Member

    Yes, it works with PR #5798.

    Great, thanks!

  24. maxrjones commented on Sep 28, 2021

    @maxrjones
    Member

    Fixed by #5798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions