[Thread Prev][Thread Next][Index]

Re: [ferret_users] Is it possible to add a pen color as gray?



Hi Xioyu,

Yes, you can do this.  The usual way is to redefine a pen to temporarily use a different color.  For example change  pen # 2, by specifying the pen number, and red-green-blue values ranging from 0 to 100.  Here is a short script.

  yes? use etopo20
  yes? fill rose

  yes? ppl color,2,75,75,75  ! set pen 2 to a light gray
  yes? go land 2

  yes? ppl color,2,100,0,0  ! return pen 2 to red color

This is not very flexible, but it works well with all versions of Ferret and PyFerret.


If you are using PyFerret, the attached new version of land.jnl allows the arguments for the pens to be given as (r,g,b) colors using the same syntax that may be used for line plots, see https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/commands-reference/PLOT#_VPINDEXENTRY_1468

So, just as in PyFerret you can say

  yes? plot/color=(50,50,50) my_var

The arguments to this new version of land could be

  yes? go land (50,50,50)


Please read the comments at the start of the updated land.jnl.  This version of land.jnl also works fine with the classic ways to send arguments to the script. I expect that this version of land.jnl will be included with future releases of PyFerret.  For now you can try using it by just putting it in your local directory. 

Ansley


On 3/8/2023 4:14 PM, Xiaoyu Bai wrote:
Dear Ferreters,

I am using go land_detail (https://github.com/NOAA-PMEL/PyFerret/blob/master/jnls/go/land_detail.jnl) and am wondering if we can add a pen color as gray. Looks like currently we have "black", "red", "green", "blue", "lightblue" "purple" "white"  colors for land_detail. Let me know if we can change the transparency of black color to obtain a gray base map.
  
Thank you very much and stay healthy,


Xiaoyu (she/her)
\cancel mode verify	! ... now overlaying coastal outline ...
! 1/23 ACM     Allow for (r,g,b) syntax for line-color specifications
!              (Not in the official PyFerret release as of 3/1/2023)
!
! Description: Plot outlines of continents, countries, and/or states
! 
!		        arg 1	      arg 2	   arg 3        arg 4
! usage:   GO land [continent_color] ["basemap"] [country_color] [state_color]
! 
! colors	may be "0"(background), "1"(foreground), "thick"(same as # 7),
!		"black", "red", "green", "blue", "lightblue", "purple" or 2-18.
!		Additionally may be a color (r,g,b) or (r,g,b,a) in parentheses
!
! arg 2 may be "basemap", "overlay", "fast" (fast, 20e:20e overlay) or omitted
!
!	Note 1: A color of "black" or 1 will actually pen number 1, 
!		normally white if the window background is black.
!               To draw a black line in this case, use a color of (0,0,0)
!	Note 2: An "N" for the continent means no continents
!		-- use this for the special case of geo-political
!		   overlay without continents.
!	Note 3: If a color is specified with an (r,g,b) color, then other
!		qualifiers such as /THICK may be added after (r,g,b). This
!		capability is available only in PyFerret

! examples:
!   GO land red        	  - overlay continents using red pen 
!   GO land 10            - overlay continents using pen number 10
!   GO land 1 basemap     - basemap of continents outline in foreground color
!   GO land 1 fast        - overlay continents in region 20e to 380, only
!   GO land 1 " " red     - overlay continents with countries in red
!   GO land thick basemap black black - continents, countries, and states
!   GO land N " " 1 1     - overlay: no continents; yes political boundaries
!
!   GO land (0,55,55)/thick=2 " " (40,20,65)	     ! (r,g,b) for arguments 1 and 3
!   GO land (0,30,0) basemap (100,60,70) (100,75,0)  ! (r,g,b) for arguments 1, 3, 4
!
! Notes:
!  1) If a value is given for the country_color or state_color then the
!	corresponding geopolitical boundaries will be drawn - else
!	they will be omitted
!  2) use  GO line_samples    to view the first 6 pen numbers
!       Higher pen numbers cycle with thicker lines (max 18)
!  3) For more control over basemaps use "GO basemap"
!
!  4) 10/12/2004 ACM
! This script has additions similar to commands in land_detail
! to draw replications  +/-360 degrees longitude beyond the data
! in geo_borders. This gives us -540 to 1100 degrees.

! test argument before performing any actions

query/ignore $2%default|basemap|overlay|fast|<argument 2 can be "basemap", "overlay", or "fast"%

! introduce the outline data set
set data/save
use geo_borders

!*!*
! from land_detail: allow modulo duplications 360 deg beyond 
! data in geo_borders

! Initialize
let landi_subx = 0
let landi_addx = 0
let landi_mapxmin = 0
let landi_mapxmax = 0

let landi_datxmin = 0
let landi_datxmax = 0

let landi_basemap = $2"0|basemap>1|*>0"

IF `landi_basemap EQ 1` THEN
   GO  basemap " " " " " " white
ENDIF

let landi_mapxmin = ($xaxis_min)
let landi_mapxmax = ($xaxis_max)

define region/default save
cancel region

let landi_datxmin = continent_LON[x=@min]
let landi_datxmax = continent_LON[x=@max]
IF `landi_mapxmin LT landi_datxmin` then let landi_subx = `landi_subx - 360`
IF `landi_mapxmax GT landi_datxmax` then let landi_addx = `landi_addx + 360`

!*!*

! always do the continents

define symbol land_setting = $1"1|black>1|red>2|green>3|blue>4|lightblue>5|purple>6|thick>7|\
0>0|1>1|2>2|3>3|4>4|5>5|6>6|7>7|8>8|9>9|10>10|11>11|12>12|13>13|14>14|15>15|16>16|17>17|18>18|N>-1|*>-2"

if `($land_setting) ge 0` then
   define symbol land_colorqual=/color=($land_setting)/line
else
   define symbol land_colorqual=/color=($1)
   IF `strindex("($land_colorqual)", "dash") EQ 0` then define symbol land_colorqual=($land_colorqual)/line
endif

if `($land_setting) ne -1` then 
   plot/set($land_colorqual)/vs/nolab/$2"i=1:22585/overlay|basemap>i=1:22585/overlay|fast>i=4886:13712/overlay|*>i=1:22585/overlay" CONTINENT_LON, CONTINENT_LAT

! set up axis formatting in case it is a basemap
   ppl xfor (I7,''LONE'')
   ppl yfor (I7,''LAT'')

! draw it - as an overlay or as a basemap
   
   define symbol overqual = /overlay
   if ($2"0|basemap>1|*>") then cancel symbol overqual
   ppl plot($overqual)
endif
!*!*
! Draw any lines outside 0 to 360

IF `landi_addx NE 0` THEN 
   plot/set($land_colorqual)/overlay/vs/nolab CONTINENT_LON+landi_addx, CONTINENT_LAT
   ppl plot/overlay
ENDIF

IF `landi_subx NE 0` THEN 
   plot/set($land_colorqual)/overlay/vs/nolab CONTINENT_LON+landi_subx, CONTINENT_LAT
   ppl plot/overlay
ENDIF

! **** now the optional country borders

define symbol land_setting = $3"1|black>1|red>2|green>3|blue>4|lightblue>5|purple>6|thick>7|\
0>0|1>1|2>2|3>3|4>4|5>5|6>6|7>7|8>8|9>9|10>10|11>11|12>12|13>13|14>14|15>15|16>16|17>17|18>18|N>-1|*>-2"

if `($land_setting) ge 0` then
   define symbol land_colorqual=/color=($land_setting)/line
else
   define symbol land_colorqual=/color=($3)
   IF `strindex("($land_colorqual)", "dash") EQ 0` then define symbol land_colorqual=($land_colorqual)/line
endif


$3"query/ignore|*>plot/set($land_colorqual)/vs/nolab/x=1:91083/overlay" COUNTRY_LON, COUNTRY_LAT

! draw it - as an overlay 
$3"query/ignore|*>ppl plot/overlay"

!*!*
! Draw any lines outside 0 to 360
IF `landi_addx NE 0` THEN 
   $3"query/ignore|*>plot/set($land_colorqual)/vs/nolab/overlay" COUNTRY_LON+landi_addx, COUNTRY_LAT
   $3"query/ignore|*>ppl plot/overlay"
ENDIF
IF `landi_subx NE 0` THEN 
   $3"query/ignore|*>plot/set($land_colorqual)/vs/nolab/overlay" COUNTRY_LON+landi_subx, COUNTRY_LAT
   $3"query/ignore|*>ppl plot/overlay"
ENDIF
!*!*

! **** now the optional state borders

define symbol land_setting = $4"1|black>1|red>2|green>3|blue>4|lightblue>5|purple>6|thick>7|\
0>0|1>1|2>2|3>3|4>4|5>5|6>6|7>7|8>8|9>9|10>10|11>11|12>12|13>13|14>14|15>15|16>16|17>17|18>18|N>-1|*>-2"

if `($land_setting) ge 0` then
   define symbol land_colorqual=/color=($land_setting)/line
else
   define symbol land_colorqual=/color=($4)
   IF `strindex("($land_colorqual)", "dash") EQ 0` then define symbol land_colorqual=($land_colorqual)/line
endif


$4"query/ignore|*>plot/set($land_colorqual)/vs/nolab/x=1:7034/overlay" STATE_LON, STATE_LAT

! draw it - as an overlay
$4"query/ignore|*>ppl plot/overlay"

!*!*
IF `landi_addx NE 0` THEN 
   $4"query/ignore|*>plot/set($land_colorqual)/vs/nolab/overlay" STATE_LON+landi_addx, STATE_LAT
   $4"query/ignore|*>ppl plot/overlay"
ENDIF
IF `landi_subx NE 0` THEN 
   $4"query/ignore|*>plot/set($land_colorqual)/vs/nolab/overlay" STATE_LON+landi_subx, STATE_LAT)
   $4"query/ignore|*>ppl plot/overlay"
ENDIF
!*!*

cancel data geo_borders
cancel var landi_*

set region save
set data/restore
set mode/last verify

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement