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

Figure.solar crashes on Linux when drawing nautical terminator for 2024-04-16T06:00:00 #2959

Closed
MySlientWind opened this issue Jan 6, 2024 · 19 comments
Labels
bug Something isn't working upstream Bug or missing feature of upstream core GMT
Milestone

Comments

@MySlientWind
Copy link

MySlientWind commented Jan 6, 2024

Description of the problem

When I try to draw nautical terminator for year=2024, month=4, day=16, hour=6, minute=0, second=0, I got

malloc(): invalid size (unsorted)
Aborted (core dumped)

There is no problem to draw it for other time, such as year=2024, month=4, day=16, hour=6, minute=1, second=0

Minimal Complete Verifiable Example

import datetime
import pygmt

fig = pygmt.Figure()
fig.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue")

terminator_datetime = datetime.datetime(year=2024,
                                        month=4,
                                        day=16,
                                        hour=6,
                                        minute=0,
                                        second=0)

fig.solar(
    terminator="nautical",
    terminator_datetime=terminator_datetime,
    fill="blue@90",
    pen="0.5p",
)

fig.savefig("demo.png")

Full error message

malloc(): invalid size (unsorted)
Aborted (core dumped)

System information

PyGMT information:
  version: v0.10.0
System information:
  python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
  executable: /home/{my_user_name}/software/anaconda3/envs/pygmt/bin/python
  machine: Linux-4.18.0-477.13.1.el8_8.x86_64-x86_64-with-glibc2.28
Dependency information:
  numpy: 1.26.3
  pandas: 2.1.4
  xarray: 2023.12.0
  netCDF4: 1.6.5
  packaging: 23.2
  contextily: None
  geopandas: None
  IPython: 8.19.0
  rioxarray: None
  ghostscript: 9.56.1
GMT library information:
  binary version: 6.4.0
  cores: 80
  grid layout: rows
  image layout: 
  library path: /work/{my_user_name}/anaconda3/envs/pygmt/lib/libgmt.so
  padding: 2
  plugin dir: /work/{my_user_name}/anaconda3/envs/pygmt/lib/gmt/plugins
  share dir: /home/{my_user_name}/software/anaconda3/envs/pygmt/share/gmt
  version: 6.4.0
@MySlientWind MySlientWind added the bug Something isn't working label Jan 6, 2024
Copy link

welcome bot commented Jan 6, 2024

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

@seisman
Copy link
Member

seisman commented Jan 6, 2024

It works well for me, but I'm using macOS. Could you please add verbose="d" to the Figure.solar method and post the debugging messages?

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Jan 6, 2024

For me, it fails under Linux as reported, but it works under Windows.

Output of verbose="d":

solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
solar [DEBUG]: Reset MAP_ANNOT_OBLIQUE to anywhere
solar [DEBUG]: Projected values in meters: -1.80199e+07 1.80199e+07 -9.00996e+06 9.00996e+06
solar [DEBUG]: Computed automatic parameters using dimension scaling: 0.908088
solar [INFORMATION]: Map scale is 2402.66 km per cm or 1:2.40266e+08.
solar [DEBUG]: Running in PS mode modern
solar [DEBUG]: Use PS filename /home/yfroe/.gmt/sessions/gmt_session.28939/gmt_4.ps-
solar [DEBUG]: Append to hidden PS file /home/yfroe/.gmt/sessions/gmt_session.28939/gmt_4.ps-
solar [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
solar [DEBUG]: Basemap order: Frame = above  Grid = above  Tick/Annot = above
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-90.9771
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0292
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -4.54747e-13 Polygon contains south (CW) pole.
solar [INFORMATION]: Plot small circle with pole at 89.9773/10.0419 and radius 102 degrees
solar [DEBUG]: Polar cap: 1
solar [DEBUG]: Try to include S pole in polar cap path
solar [DEBUG]: West longitude = -180.  East longitude = 180
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -4.54747e-13 Polygon contains south (CW) pole.
solar [DEBUG]: First longitude = 89.9773.  Last longitude = 89.9773
solar [DEBUG]: Crossing at -180,-90
solar [DEBUG]: k at point closest to lon -180 is = 0 [n = 363]
solar [DEBUG]: Created path from 180/-90 to 180/-90 [0 points]
solar [DEBUG]: Add perimeter data from k0->n [0->363], then 0->k0 [0]
solar [DEBUG]: Add path from -180/-90 to -180/-90 [0 points]
solar [DEBUG]: New path has 364 points, we allocated 363 points
malloc(): invalid size (unsorted)


Fatal Python error: Aborted

@yvonnefroehlich
Copy link
Member

It looks like the issue is related to the fill parameter. If specifying a fill color via fill the code fails, but it works if not using fill or fill=None [Default]. The "problematic" date part seems to be hour=6, minute=0.

import datetime
import pygmt

term_datetime = datetime.datetime(
    year=2024,
    month=4,
    day=16,
    hour=6,
    minute=0,  # fails with a fill color
    # minute=1,  # works with a fill color
    second=0,
)
print(term_datetime)

fig = pygmt.Figure()
fig.coast(region="d", projection="W10c", shorelines=True, frame=True)

fig.solar(
    terminator="nautical",
    terminator_datetime=term_datetime,
    # fill=None,  # works
    fill="blue",  # fails
    # pen="1p,red,solid",  # works
)

fig.show()

@seisman
Copy link
Member

seisman commented Jan 6, 2024

The equivalent GMT CLI is:

gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map

Could you please try if it fails for you on Linux?

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Jan 6, 2024

The equivalent GMT CLI is:

gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map

Could you please try if it fails for you on Linux?

Yes, it fails with GMT 6.4 and 6.4.0_965606f_2022.03.14 on Linux.

(gmt_env_dev) yfroe@gpiseis16:~> gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
malloc(): invalid size (unsorted)
Aborted (core dumped)
(gmt_env_dev) yfroe@gpiseis16:~> gmt --version
6.4.0_965606f_2022.03.14

@MySlientWind
Copy link
Author

Output of verbose="d":

solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
solar [DEBUG]: Reset MAP_ANNOT_OBLIQUE to anywhere
solar [DEBUG]: Projected values in meters: -1.80199e+07 1.80199e+07 -9.00996e+06 9.00996e+06
solar [DEBUG]: Computed automatic parameters using dimension scaling: 0.908088
solar [INFORMATION]: Map scale is 2402.66 km per cm or 1:2.40266e+08.
solar [DEBUG]: Running in PS mode modern
solar [DEBUG]: Use PS filename /home/{my_user_name}/.gmt/sessions/gmt_session.852013/gmt_1.ps-
solar [DEBUG]: Append to hidden PS file /home/{my_user_name}/.gmt/sessions/gmt_session.852013/gmt_1.ps-
solar [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
solar [DEBUG]: Basemap order: Frame = above  Grid = above  Tick/Annot = above
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-90.9758
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0332
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -1.27898e-13 Polygon contains south (CW) pole.
solar [INFORMATION]: Plot small circle with pole at 89.9329/10.3111 and radius 102 degrees
solar [DEBUG]: Polar cap: 1
solar [DEBUG]: Try to include S pole in polar cap path
solar [DEBUG]: West longitude = -180.  East longitude = 180
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -1.27898e-13 Polygon contains south (CW) pole.
solar [DEBUG]: First longitude = 89.9329.  Last longitude = 89.9329
solar [DEBUG]: Crossing at -180,-90
solar [DEBUG]: k at point closest to lon -180 is = 0 [n = 363]
solar [DEBUG]: Created path from 180/-90 to 180/-90 [0 points]
solar [DEBUG]: Add perimeter data from k0->n [0->363], then 0->k0 [0]
solar [DEBUG]: Add path from -180/-90 to -180/-90 [0 points]
solar [DEBUG]: New path has 364 points, we allocated 363 points
malloc(): invalid size (unsorted)
Aborted (core dumped)

Output of

gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
malloc(): invalid size (unsorted)
Aborted (core dumped)

@seisman seisman changed the title Crash when draw nautical terminator for year=2024, month=4, day=16, hour=6, minute=0, second=0 Figure.solar crashes on Linux when drawing nautical terminator for 2024-04-16T06:00:00 Jan 6, 2024
@seisman seisman added the upstream Bug or missing feature of upstream core GMT label Jan 6, 2024
@seisman
Copy link
Member

seisman commented Jan 6, 2024

It's likely an upstream bug, although I can't test if it has been fixed in the upcoming GMT 6.5.0 release.

Ping @PaulWessel.

@PaulWessel
Copy link
Member

6.5 master (i.e., release) on macOS arm64:

gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map

map

@yvonnefroehlich
Copy link
Member

Thanks @PaulWessel for immediately looking at this. So far, this issue appears to be OS-dependent: it works on Windows and macOS, but it fails on Linux.

@PaulWessel
Copy link
Member

So we need someone with Linux to run that command in ddd for example and learn what the crash is and why.

@seisman
Copy link
Member

seisman commented Jan 7, 2024

It still crashes with GMT master branch. Trying to debug it, and this is the callstack and shows where it crashes:
Screenshot from 2024-01-07 11-30-52

@PaulWessel
Copy link
Member

So it SEGVs in line 565? That is a calloc call but the message says malloc? What are the values of Belem and size? The message about size is invalid (unsorted) is strange was size is a scalar, no??

@seisman
Copy link
Member

seisman commented Jan 7, 2024

nelem=2048 and size=8.

@seisman
Copy link
Member

seisman commented Jan 7, 2024

Does this debug message make sense to you?

solar [DEBUG]: New path has 364 points, we allocated 363 points

As the OP says, using a slightly different time works:

$ gmt solar -Rd -JW10c -Tn+d2024-04-16T06:01:00 -Gblue -png map
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 180/-86.5149
solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0502
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 1  Residual: 2.27374e-13 Polygon contains south (CCW) pole.
solar [INFORMATION]: Plot small circle with pole at 89.6829/10.3113 and radius 102 degrees
solar [DEBUG]: Polar cap: 1
solar [DEBUG]: Try to include S pole in polar cap path
solar [DEBUG]: West longitude = -180.  East longitude = 180
solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 1  Residual: 2.27374e-13 Polygon contains south (CCW) pole.
solar [DEBUG]: Make polygon to clockwise
solar [DEBUG]: First longitude = 89.6829.  Last longitude = 89.6829
solar [DEBUG]: Crossing at -180,-86.5149
solar [DEBUG]: k at point closest to lon -180 is = 358 [n = 363]
solar [DEBUG]: Created path from 180/-90 to 180/-86.5149 [48 points]
solar [DEBUG]: Add perimeter data from k0->n [358->363], then 0->k0 [358]
solar [DEBUG]: Add path from -180/-86.5149 to -180/-90 [48 points]
solar [DEBUG]: New path has 459 points, we allocated 459 points

@PaulWessel
Copy link
Member

Could you try on Linux to change line 9707 in gmt_plot.c to be

`n_new = 2 * MIN (1, perim_n) + n;`

since perim_n is 0 this is a bit suspect. Does that help?

@PaulWessel
Copy link
Member

Sorry, MAX of course

@seisman
Copy link
Member

seisman commented Jan 7, 2024

Yes, n_new = 2 * MAX (1, perim_n) + n; works.

PaulWessel added a commit to GenericMappingTools/gmt that referenced this issue Jan 7, 2024
See GenericMappingTools/pygmt#2959 for background.  Ensure we add at least 1 point when going to pole.
PaulWessel added a commit to GenericMappingTools/gmt that referenced this issue Jan 7, 2024
See GenericMappingTools/pygmt#2959 for background.  Ensure we add at least 1 point when going to pole.
@seisman seisman added this to the 0.11.0 milestone Jan 7, 2024
@seisman
Copy link
Member

seisman commented Jan 7, 2024

The upstream bug has been fixed in the GMT's master branch and the working version GMT 6.5.0 will be released soon.

@seisman seisman closed this as completed Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream Bug or missing feature of upstream core GMT
Projects
None yet
Development

No branches or pull requests

4 participants