Skip to content

Category: IDL hints

IDL Color Plot Procedure Problems and Tentative Solutions

In our galactic magnetic field project,  color plots seem to fail sporadically, leaving plots with blank places where there should be colored symbols or lines.  Very frustrating!  I am finding this with AO_ATNF_Pulsars_RM_Sag_Region1a.pro

So I tried manually to play around with this from the IDL command line, basically trying to duplicate it.  Note that the above program uses cgcolor multiple times to set up definitions of say red to then be used in plot procedure (without quotes, e.g. plot,x,y,red ). Note comments in above
say we needed to use cgcolor because regular idl colors
were not working. Note all this is with plot procedure, and
newer plot function may not have any of these probs! New programs should use the latter.

From command line, if I do the following:

x=findgen(10)
y=findgen(10)
set_plot,’ps’  (I think needs it only once)
device,filename=’help.ps’ (puts the file in home directory)
Red =cgColor(“Red”, !D.Table_Size-4)  (stolen from pgm, and cgcolor is a coyote routine [there are such calls for every color used])
plot, x, y, color=red (makes every bit of plot red)
device,/close

The above made a red plot in the file ~help.ps .

And then FWIW when I reran the AO_ATNF . . . Sag..1a.pro,
the two plots’ colors were there. I’m not saying cause and
effect, but at least in this case a rerun after above jimmying
brought the colors back.  I am guessing that somehow I
am not properly totally initializing colors when I run the
program, so if something color-related  is left in a funny
state by a previous run, then the next program run does
not automatically fix it.

Coyote has some suggestions at
http://www.idlcoyote.com/color_tips/redps.html   ,
including:

    Set_Plot, 'PS'    
Device, DECOMPOSED=1, COLOR=1, BITS_PER_PIXEL=8, filename='help.ps' 
(Joel added the filename part.)

and he claims that all the above are needed for color to
work, so maybe the program’s lack of such a full Device command is the problem. However the above advice is old and I’m not
sure if today’s idl might need say 24 bits per pixel???? But
the color=1 command sounds like it is turning on color!  Decomposed=1 turns on decomposed colors which I think means R,G,B are expressed separately. That is documented here and there but I’m not sure if our cgcolor routines expect that value, so, be careful!

Sorry I don’t have the definitive fix but hopefully the user can create a workaround with some subset of above, if she suddenly loses color on plots that were colored in previous program runs!

–Joel

For new/upgraded idl, manually set up at least one link updated 20241105 for antares

I needed to put a “version” of idl_setup into the new host’s /usr/local/bin/   :
Obsolete from 2021:
{canopus.physics.carleton.edu}:{jweisber}:/usr/local/bin>
sudo ln -s /usr/local/harris/idl/bin/idl_setup .
New for 20241105 for antares, idl90:
{antares.physics.carleton.edu}:{jweisber}:/usr/local/bin>
sudo ln -s /usr/local/nv5/idl90/bin/idl_setup .
The final dot means link it into the current directory.
–Joel
There are lots of similar links and maybe they were also all manually created:
{canopus.physics.carleton.edu}:{jweisber}:/usr/local/bin> ls -als idl*
0 lrwxrwxrwx. 1 root root 29 Apr 6 12:39 idl -> /usr/local/harris/idl/bin/idl*
0 lrwxrwxrwx. 1 root root 31 Apr 6 12:39 idl86 -> /usr/local/harris/idl86/bin/idl*
0 lrwxrwxrwx. 1 root root 31 Apr 6 12:39 idlde -> /usr/local/harris/idl/bin/idlde*
0 lrwxrwxrwx. 1 root root 33 Apr 6 12:39 idlde86 -> /usr/local/harris/idl86/bin/idlde*
0 lrwxrwxrwx. 1 root root 33 Apr 6 12:39 idlhelp -> /usr/local/harris/idl/bin/idlhelp*
0 lrwxrwxrwx. 1 root root 35 Apr 6 12:39 idlhelp86 -> /usr/local/harris/idl86/bin/idlhelp*
0 lrwxrwxrwx. 1 root root 32 Apr 6 12:39 idlrpc -> /usr/local/harris/idl/bin/idlrpc*
0 lrwxrwxrwx. 1 root root 34 Apr 6 12:39 idlrpc86 -> /usr/local/harris/idl86/bin/idlrpc*
0 lrwxrwxrwx. 1 root root 35 May 14 23:36 idl_setup -> /usr/local/harris/idl/bin/idl_setup*
0 lrwxrwxrwx. 1 root root 39 Apr 6 12:39 idltaskengine -> /usr/local/harris/idl/bin/idltaskengine*
0 lrwxrwxrwx. 1 root root 41 Apr 6 12:39 idltaskengine86 -> /usr/local/harris/idl86/bin/idltaskengine*

idl unix-like commands – see also 2023 11 03

OK.  idl has some built-in unix-like commands, but then others require a ‘$’ beforehand  which I think summons the unix shell.  The various unix-like commands that an idl user might like are a mixture thereof, so see below whether or not there is a $  (See also a third option, spawn, below.):

cd, ‘/data/psrdata/   note no $ : this is a native idl command made to look like its unix cousin

pwd                         ”       ”   ”     ”        ”  (This and previous command often go together ,
since this one returns the “present working directory” which should
verify that your cd command did as you wished! (There is supposedly a
way to get the idl prompt to show the pwd but I haven’t yet figured it out.)

printd or popd or pushd are all native idl directory-oriented commands made to look like their unix cousins (or in printd case, just print the current directory name – no unix cousin exists.)

$ls     Needs the dollar sign which I think invoked the unix shell.

The idl spawn command can also be useful: 

spawn,’ls -als | grep arecibowapp’ is a way to do the idl version of the unix  ls with flags, and even then pipe it into another command. This looks like the most flexible!.

spawn,’ps aux’  ditto

 

IDL manual breakpoint operation

using breakpoints on idlde over vncviewer (as opposed to chicken-of-the-vnc) was fraught.  The usual key combinations would not place breakpoints anywhere.  But I eventually learned that:

DOUBLE CLICKING ON GRAY BORDER AT VERY LEFT OF DESIRED LINE TOGGLES BREAKPOINT

Here is a harder way that I learned before above red easy way:

  1. select desired line
  2. shift control b toggles a breakpoint on that line.

Here is an even harder way to do it from keyboard:

help,/breakpoint  will give a list of existing breakpoints

cd, ‘full path to desired directory’ will change idl’s current directory from users home directory (the default) to another. remember apostrophes CASE SENSITIVE

printd   prints the current directory

IDL> printd
Current Directory: /data/psrdata/arecibopuppi/B1913+16/2019Aug
Directory stack is empty.

breakpoint,/set, ‘filename inside of current idl directory path [see printd above to discover current path value] ‘, 150   (use apostrophes, note final value is linenumber) CASE SENSITIVE

i think i did not see the red circle on line 150 of idlde until i recompiled.

check out help,/breakpoint to see a list of current breakpoints, including their “index” which can be used in some other breakpoint commands like breakpoint,/clear,1 (index 1)

IDL> help,/breakpoint
Index Line Attributes                                                 File
1         150      Pro=PLOTADAYSRMTOT       /data/psrdata/arecibopuppi/B1913+16/2019Aug/plotAdaysRMtot.pro

idl status / hosts 2018 Jun

idl 8.3 is on deneb and canopus.  I have no maintenance contract on them any more, so they are frozen at that version.  They reside on local disks on each machine at /usr/local/exelis. . .

i dropped maint on mirzam for about 10 months in 2016(?). When I picked it up again, we loaded idl 8.6 into /usr/local/harris/ . . .

–Joel

calculate weighted (mean and SDM) in IDL

At least for now, function wmeanandsig.pro is in /data/psrdata/rmgalprojs

If you create an array of RM and an equal-sized array of sig_RM (with no ∞ sig_RM’s), then:

wmean_and_sdm=wmeanandsig(RM,sig_RM)

will put the weighted mean and weighted sdm into a two-element array  called wmean_and_sdm

(and the way functions work, you can replace the variable that above i call “wmean_and_sdm”, with

a variable of any name you wish)

Right now there is a “driver” program in the same directory, called, “wmeanandsigDRIVER.pro”  .  It

is a module that tests wmeanandsig.pro  .  I used it extensively to do so, to the point where I can now

call wmeanandsig.pro “ready to go”   .  (Luckily the NIST web pages give sample input/output for weighted

mean and for weighted SDM, which I endeavored to match.)

Caution: In 2018 April, I changed the calculation of the weighted SDM.  Previously, we had used the NIST definition, which changed the data weights so as to achieve reduced χ^2 to 1.  (The NIST webpage gave a formula for wgtd SD but did not note that it included this readjustment. )  In 2018 April, I changed the calculation to be

σ^2_wgtdmean = 1 / [ Σ 1/σ^2_j]. Note that this calculation depends entirely on the σ_j’s of the data points, and nothing else (such as deviation from mean).

–Joel

idl save set query contents

Here’s how to figure out the contents of a save set.

1. This is the classic way:
restore,’filename.sav’,/verbose  will list the variable names in the saveset.

help, variable_name will then give details on any such variable.

2. This  is the modern (object-oriented) way. Note that it does not require a restore:

[After http://northstar-www.dartmouth.edu/doc/idl/html_6.2/IDL_Savefile.html#wp1034474 ] :

Use the IDL_Savefile object to query the contents of a SAVE file containing data and selectively restore variables.

So first, create a savefile object out of of the .sav file:   sObj = obj_new(‘IDL_Savefile’, ‘p2206.B1913+16.wapp4.53958.0004_shifted.sav’)

Typically, IDL_Savefile::Contents is the first method called on a savefile object; the information retrieved indicates the number of different types of items contained in the file (variables, routines, etc.).

sContents = sObj->Contents()

one type of query of sContents is:  print, sContents.N_var
20

Next, a call to IDL_Savefile::Names is used to obtain the names of items of a specific type.

sNames = sObj ->Names()
print,snames
ACTUAL_NRECS BINSHIFT BW DELFREQ IDLFILE LSRK NBIN NCHAN OBSJULDATE OBSTIME PROFILE_VERSION ROUNDBINSHIFT SCANNO SHIFTONOFFA SHIFTONOFFB
SHIFTTOTA SHIFTTOTB SRC VEL WAPPHOST

Then,  IDL_Savefile::Size can be used to determine the size of a given (named) variable in the file:

size_of_shiftonoffa = sObj->Size(‘shiftonoffA’)
print, size_of_shiftonoffA
1    512   4    512,  which means:

If no keywords are set, SIZE returns a vector of integer type. The first element is equal to the number of dimensions of Expression. This value is zero if Expression is scalar or undefined. The next elements contain the size of each dimension, one element per dimension (none if Expression is scalar or undefined). After the dimension sizes, the last two elements contain the type code (zero if undefined) and the number of elements in Expression, respectively. The type codes are listed at https://www.harrisgeospatial.com/docs/size.html.  (the four here means floating point).

 

–Joel

IDL license info

To determine IDL license number on a particular host, I think logging in to idl gives the license number.  But the geeky way is to  look near the top of the following file on a machine hosting an IDL license:

/usr/local/exelis/license/license.dat

(Mirzam is 217420)

–Joel