Skip to content

Month: March 2018

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