Skip to content

Odd makecpt behavior from Julia #7558

Closed

Description

@joa-quim
# Correct

julia> makecpt(cmap=(:red,:green,:blue), range=[0 100 200 450])
Extract of a GMTcpt exposed as a GMTdataset for display. Colors converted to [0-255]
Model: rgb
Color depth: 24
3×9 GMTdataset{Float64, 2}
 Row │      r1       g1       b1       r2       g2       b2    alpha       z1       z2
     │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64
─────┼─────────────────────────────────────────────────────────────────────────────────
   1 │   255.0      0.0      0.0    255.0      0.0      0.0      0.0      0.0    100.0
   2 │     0.0    255.0      0.0      0.0    255.0      0.0      0.0    100.0    200.0
   3 │     0.0      0.0    255.0      0.0      0.0    255.0      0.0    200.0    450.0

# Inventive

julia> makecpt(cmap=(:red,:green,:blue), range=[0 100 200 451])
Extract of a GMTcpt exposed as a GMTdataset for display. Colors converted to [0-255]
Model: rgb
Color depth: 24
3×9 GMTdataset{Float64, 2}
 Row │      r1       g1       b1       r2       g2       b2    alpha       z1       z2
     │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64
─────┼─────────────────────────────────────────────────────────────────────────────────
   1 │   255.0      0.0      0.0    255.0      0.0      0.0      0.0      0.0    100.0
   2 │   255.0      0.0      0.0    255.0      0.0      0.0      0.0    100.0    200.0
   3 │     0.0      0.0    255.0      0.0      0.0    255.0      0.0    200.0    451.0

Activity

  1. added
    bug
    on Jun 19, 2023
  2. PaulWessel commented on Jun 20, 2023

    @PaulWessel
    Contributor

    So CLI has it right:

    gmt makecpt -Cred,green,blue -T0,100,200,450
    0	red	100	red	L
    100	green	200	green	L
    200	blue	450	blue	B
    B	black
    F	white
    N	128
    
    (base) pwessel@MacAttack-> gmt makecpt -Cred,green,blue -T0,100,200,451
    0	red	100	red	L
    100	green	200	green	L
    200	blue	451	blue	B
    B	black
    F	white
    N	128
    
    

    Gotta be something in GMT.jl?

  3. joa-quim commented on Jun 20, 2023

    @joa-quim
    MemberAuthor

    CLI passes a string, not an array. That works fine in GMT.jl too

    julia> makecpt(cmap=(:red,:green,:blue), range="0,100,200,451")
    Extract of a GMTcpt exposed as a GMTdataset for display. Colors converted to [0-255]
    Model: rgb
    Color depth: 24
    3×9 GMTdataset{Float64, 2}
     Row │      r1       g1       b1       r2       g2       b2    alpha       z1       z2
         │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64
    ─────┼─────────────────────────────────────────────────────────────────────────────────
       1 │   255.0      0.0      0.0    255.0      0.0      0.0      0.0      0.0    100.0
       2 │     0.0    255.0      0.0      0.0    255.0      0.0      0.0    100.0    200.0
       3 │     0.0      0.0    255.0      0.0      0.0    255.0      0.0    200.0    451.0
    
  4. PaulWessel commented on Jun 21, 2023

    @PaulWessel
    Contributor

    OK, looking at this but following debug instructions. using GMT gives

    using GMT

    ERROR: InitError: could not load library "/opt/local/lib/libgdal.30.dylib"
    dlopen(/opt/local/lib/libgdal.30.dylib, 0x0001): tried: '/opt/local/lib/libgdal.30.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/local/lib/libgdal.30.dylib' (no such file), '/opt/local/lib/libgdal.30.dylib' (no such file)
    Stacktrace:
     [1] GDALVersionInfo(a1::String)
       @ GMT.Gdal ~/.julia/packages/GMT/qpeq8/src/gdal.jl:331
     [2] __init__()
       @ GMT.Gdal ~/.julia/packages/GMT/qpeq8/src/gdal.jl:2457
     [3] _include_from_serialized(path::String, depmods::Vector{Any})
       @ Base ./loading.jl:768
     [4] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
       @ Base ./loading.jl:854
     [5] _require(pkg::Base.PkgId)
       @ Base ./loading.jl:1097
     [6] require(uuidkey::Base.PkgId)
       @ Base ./loading.jl:1013
     [7] require(into::Module, mod::Symbol)
       @ Base ./loading.jl:997
    during initialization of module Gdal
    

    My GDAL works find for me?

  5. PaulWessel commented on Jun 21, 2023

    @PaulWessel
    Contributor

    I have libgdal.33.dylib - where is the 30 coming from?

  6. joa-quim commented on Jun 21, 2023

    @joa-quim
    MemberAuthor

    Things have changed in GMT.jl land in that we now use a pre-build GMT (remember that paper that I ever finish) and the local GMT installs are now ignored, but you should not have had that error. The fix should come from doing
    import Pkg; Pkg.build("GMT")
    but that will not allow you to do debugging, only normal use. To use a GMT local build, and hence follow the old debug instructions, please try what is explained in https://github.com/GenericMappingTools/GMT.jl#install
    Not 100% sure it will work. It did on Linux when I invented that but never tried Mac ans specially with a debug build.

    Ah, and don't forget to do a ] up before all the rest.

  7. PaulWessel commented on Jun 21, 2023

    @PaulWessel
    Contributor

    You gotta be more precise with us who do not use Julia:

    import Pkg
    ERROR: Could not determine command

  8. joa-quim commented on Jun 21, 2023

    @joa-quim
    MemberAuthor

    All Julia commands must be run from the Julia shell.
    But you should have got an error when running the ] up (to update), which must all be done in the Julia shell.

  9. PaulWessel commented on Jun 21, 2023

    @PaulWessel
    Contributor

    odd

  10. joa-quim commented on Jun 21, 2023

    @joa-quim
    MemberAuthor

    Ah, I see. Hit the backspace key to bring you back to the julia> prompt and than run those commands. When we type ] we are sent to the Pkg mode and probably running build("GMT") would work too, but never tried that way.

  11. PaulWessel commented on Jun 21, 2023

    @PaulWessel
    Contributor

    Not sure, but the CLI -T is a list argument while yours is a -Tmemory file argument. Some bool probably different between the wo cases. If I do the same with a text file -Tt.txt which has those 4 values I get the same as you. So the differences lies in the parsing of the list vs reading a file.

  12. PaulWessel commented on Jun 23, 2023

    @PaulWessel
    Contributor

    Problem seems to be this: You are giving a list of values which we usually flag via -Ta,b,c,d i.e., comma-separated list. This sets T->list = true somewhere. However, when you pass a data file there is no information that says "treat this as a list". It is seen as a regular file with uneven increments and we end up resampling it evenly on the output, thus getting wrong colours.
    You can see in gmt_sample_cpt that we linearly select output nodes and not the 0, 100, 200, 451 as the list would have done. Not sure what a good solution is here. Maybe we have to introduce another MODE flag that would accompany your data set as segment header and it would flag "this is a list" not a data set" or something?

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