Some utility functions for experimenting in Dyalog APL.
Clone this repository and add the path to your APL SALT path (replacing the path below with the actual path to the repository location):
⎕SE.SALT.Settings 'workdir ',(⎕SE.SALT.Settings 'workdir'),':/Users/s/dev/apllib'
Make the settings permanent (not just for this session):
⎕SE.SALT.Settings '-permanent'
Save a new namespace, called foo
in this example, to the location of this
repository (again, replace the path with the actual work directory):
⎕SE.SALT.Save #.foo '/Users/s/dev/apllib/'
or simply
]save #.foo '/Users/s/dev/apllib/'
You can now load foo
either by specifying the full path to the foo.dyalog
object created or by simply specifying foo
(since this working copy should be
in your SALT workdir
path):
⎕SE.SALT.Load 'foo'
or simply
]load foo
Dyalog SALT Reference Guide PowerPoint intro to SALT (2008)
See Appendix 2 of the User Commands User Guide
Load the fits
library:
]load fits
Set ⎕IO
to 0 (zero-indexing):
⎕IO←0
Load headers from a LIGO fits file:
fitspath←'/Users/s/papers/2020-06-01-thesis_healtree_chapter/S200302c.multiorder.fits'
h←fits.headers fitspath
Display the first fits header (dropping the history and comment columns), which should always look like this:
)copy util DISP
DISP ⍪¨¯2↓h[0;]
┌────┬────────┬──────────────────────────┬─┬─┬───┬─┬─┐
│ 0│SIMPLE │conforms to FITS standard │7│0│┌─┐│ │ │
│2880│BITPIX │array data type │6│0││ ││8│1│
│ 0│NAXIS │number of array dimensions│6│1│└─┘│0│1│
│ │EXTEND │ │7│1│ │ │ │
└────┴────────┴──────────────────────────┴─┴─┴───┴─┴─┘
View the raw shapes of the data associated with each header in the file (in bytes):
)copy util DISPLAY
DISPLAY fits.shape¨↓h
┌→───────────────┐
│ ┌⊖┐ ┌→───────┐ │
│ │0│ │19200 40│ │
│ └~┘ └~───────┘ │
└∊───────────────┘
View the metadata fields on the second header, which defines the actual image:
h[1;1 2]
XTENSION binary table extension
BITPIX array data type
NAXIS number of array dimensions
NAXIS1 length of dimension 1
NAXIS2 length of dimension 2
PCOUNT number of group parameters
GCOUNT number of groups
TFIELDS number of table fields
TTYPE1
TFORM1
TTYPE2
TFORM2
TUNIT2
TTYPE3
TFORM3
TUNIT3
TTYPE4
TFORM4
TUNIT4
TTYPE5
TFORM5
TUNIT5
MOC
PIXTYPE HEALPIX pixelisation
ORDERING Pixel ordering scheme: RING, NESTED, or NUNIQ
COORDSYS Ecliptic, Galactic or Celestial (equatorial)
MOCORDER MOC resolution (best order)
INDXSCHM Indexing: IMPLICIT or EXPLICIT
OBJECT Unique identifier for this event
REFERENC URL of this event
INSTRUME Instruments that triggered this event
DATE-OBS UTC date of the observation
MJD-OBS modified Julian date of the observation
DATE UTC date of file creation
CREATOR Program that created this file
ORIGIN Organization responsible for this FITS file
RUNTIME Runtime in seconds of the CREATOR program
DISTMEAN Posterior mean distance (Mpc)
DISTSTD Posterior standard deviation of distance (Mpc)
LOGBCI Log Bayes factor: coherent vs. incoherent
LOGBSN Log Bayes factor: signal vs. noise
VCSVERS Software version
VCSREV Software revision (Git)
DATE-BLD Software build date
Load the DISTMEAN and DISTSTD values:
h[1;] fits.readhead 'DISTMEAN' 'DISTSTD'
1737.414538 500.2420472
View the BINTABLE fields on the second header:
⍪¨fits.binfields h[1;]
UNIQ 0 8 1 K
PROBDENSITY sr-1 8 8 1 D
DISTMU Mpc 16 8 1 D
DISTSIGMA Mpc 24 8 1 D
DISTNORM Mpc-2 32 8 1 D
We want the UNIQ
and PROBDENSITY
or PROB
fields. Besides looking at the
BINTABLE fields as above, we can check for membership with binnames
:
'UNIQ' 'PROBDENSITY' 'PROB'∊fits.binnames h[1;]
1 1 0
Load a single column, UNIQ
, and view its first 10 elements:
10↑⊃'UNIQ'(fitspath fits.binread)h[1;]
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
Load UNIQ
and PROBDENSITY
and display their first 10 elements:
DISP 10↑¨'UNIQ' 'PROBDENSITY'(fitspath fits.binread)h[1;]
┌────┬───────────────┐
│1024│0.0007709143604│
│1025│0.0009595176541│
│1026│0.001926238858 │
│1027│0.002484437434 │
│1028│0.001501028836 │
│1029│0.003074934707 │
│1030│0.003692214647 │
│1031│0.006983876737 │
│1032│0.003647436636 │
│1033│0.005124141247 │
└────┴───────────────┘