Skip to content

Commit

Permalink
Merge pull request #1256 from GenericMappingTools/fix-makecpt-grd
Browse files Browse the repository at this point in the history
Fix case when makecpt.jl(Grid,...) received 2 -C
  • Loading branch information
joa-quim authored Sep 9, 2023
2 parents 6a796af + 803ac84 commit 2cc1d44
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/gmtreadwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When files are multiband or nc files with 3D or 4D arrays, we access them via th
grid, layer can be a scalar (to read 3D arrays) or an array of two elements (to read a 4D array).
If file is an image `layer` can be a 1 or a 1x3 array (to read a RGB image). Not that in this later case
bands do not need to be contiguous. A `band=[1,5,2]`` composes an RGB out of those bands. See more at
bands do not need to be contiguous. A `band=[1,5,2]` composes an RGB out of those bands. See more at
$(GMTdoc)/GMT_Docs.html#modifiers-for-coards-compliant-netcdf-files) but note that we use **1 based** indexing here.
- $(GMT._opt_R)
Expand Down
12 changes: 10 additions & 2 deletions src/makecpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ end
function makecpt(G::GMTgrid; equalize=false, kw...) # A version that works on grids.
# equalize = true uses default grd2cpt. equalize=n uses grd2cpt -Tn
# The kw... are those of makecpt or grd2cpt depending on 'equalize'.
cpt = ((val = find_in_kwargs(kw, CPTaliases)[1]) === nothing) ? (G.cpt != "") ? G.cpt : :turbo : nothing

val, symb = find_in_kwargs(kw, CPTaliases)
cpt = (val === nothing) ? (G.cpt != "") ? G.cpt : :turbo : nothing
d = Dict{Symbol, Any}()
if (equalize == 0 && symb != Symbol() && val === nothing && cpt !== nothing)
# It means kw have a -C, but it can be a C=nothing. Remove the duplicate that was in kw.
d = KW(kw...); delete!(d, symb) # This confusion is due to the crazziness possible in lelandshade()
end
if (equalize == 0)
makecpt(T=@sprintf("%.12g/%.12g/256+n", G.range[5]*(1-0.001), G.range[6]*(1+0.001)), C=cpt, kw...)
t = isempty(d) ? kw : d
makecpt(; T=@sprintf("%.12g/%.12g/256+n", G.range[5]*(1-0.001), G.range[6]*(1+0.001)), C=cpt, t...)
else
(equalize == 1) ? grd2cpt(G, C=cpt, kw...) : grd2cpt(G, T="$equalize", C=cpt, kw...)
end
Expand Down
6 changes: 3 additions & 3 deletions src/rasterpolygonfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ is large (think Russia size) because even at a moderately resultion it can imply
- `img`: the image from which the stats (`fun`) of each color for each polygon will be computed.
- `url`: In case the `img` option is not used, pass the Web Map Server URL (see the `wmsinfo` and `wmsread` functions)
from where the the images covering the BoundingBox of each polygon will be downloaded. Warning, this is a much slower
method but potentially usefull when the images to download risk to be very big.
method but potentially useful when the images to download risk to be very big.
- `layer`: When the `url` option is used this one becomes mandatory and represents the layer number or layer name of
interest from those provided by the WMS service. That is, both of these forms are allowed: `layer=3` or
interest from those provided by the WMS service. That is, both forms are allowed: `layer=3` or
`layer="Invented layer name"`
- `pixelsize`: Sets the requested cell size in meters [default]. Use a string appended with a 'd'
(e.g. `resolution="0.001d"`) if the resolution is given in degrees. This way works only when the layer is in geogs.
- `append`: By default the color assignement to each of the polygons in the `shapes` vector is achieved by
- `append`: By default, the color assignment to each of the polygons in the `shapes` vector is achieved by
appending the fill color to the possibly existing header field. Running the `colorzones` command more than once
keeps adding (now ignored, because only the first is used) colors. Setting `append=false` forces rewriting
the header field at each run and hence the assigned color is always the one used (but the previous header is cleared out).
Expand Down
2 changes: 1 addition & 1 deletion src/utils_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ result (that we easily do with `imshow(mat)`) but return instead a GMTimage obje
- `clim`: Specify clims as a two-element vector of the form [cmin cmax], where values of the scaled image
less than or equal to cmin are assigned that value. The same goes for cmax.
- `cmap`: If provided, `cmap` is a GMTcpt and its contents is converted to the `GMTimage` colormp.
- `cmap`: If provided, `cmap` is a GMTcpt and its contents is converted to the `GMTimage` colormap.
- `GI`: This can be either a GMTgrid or a GMTimage and its contents is used to set spatial contents
(x,y coordinates) and projection info that one may attach to the created image result. This is
a handy alterative to the `x=, y=, proj4=...` options.
Expand Down
1 change: 1 addition & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
getindex(G1,1:2);
setindex!(G1, [-1 -1],1:2)
size(G1)
size(GMT.GMTcpt())
flipud(G)
fliplr(G)
flipdim(G.z,1)
Expand Down

0 comments on commit 2cc1d44

Please sign in to comment.