miriad 4.1.0.0 → 4.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  --
2
2
 
3
- $Id: README 903 2008-04-17 23:05:44Z davidm $
3
+ $Id: README 7 2008-04-18 07:21:10Z davidm $
4
4
 
5
5
  This file includes an RDoc hack so that links can be made to open up into a new
6
6
  frame rather then the current frame.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # $Id: Rakefile 10 2008-04-21 19:51:41Z davidm $
2
+
1
3
  require 'rubygems'
2
4
  require 'rake/gempackagetask'
3
5
 
@@ -12,7 +14,7 @@ run_swig unless test ?e, 'ext/miriad_wrap.c'
12
14
  spec = Gem::Specification.new do |s|
13
15
  # Basics
14
16
  s.name = 'miriad'
15
- s.version = '4.1.0.0'
17
+ s.version = '4.1.0.2'
16
18
  s.summary = 'Ruby interface to MIRIAD'
17
19
  s.description = <<-EOS
18
20
  The MIRIAD-Ruby package...
@@ -25,7 +27,7 @@ spec = Gem::Specification.new do |s|
25
27
  EOS
26
28
 
27
29
  #s.platform = Gem::Platform::Ruby
28
- s.required_ruby_version = '>= 1.8.6'
30
+ s.required_ruby_version = '>= 1.8.4'
29
31
  #s.requirements << 'a prerequisite'
30
32
  s.add_dependency('narray', '>= 0.5.9')
31
33
 
@@ -58,7 +60,7 @@ spec = Gem::Specification.new do |s|
58
60
  s.extensions << 'ext/extconf.rb'
59
61
 
60
62
  # Documentation
61
- s.rdoc_options = ['-x', 'ext/.*.c', '-m', 'README', '-t', "MIRIAD-Ruby Documentation"]
63
+ s.rdoc_options = ['-S', '-x', 'ext/.*.c', '-m', 'README', '-t', "MIRIAD-Ruby Documentation"]
62
64
  s.has_rdoc = true
63
65
  s.extra_rdoc_files = %w[README ext/miriad_ruby.c]
64
66
 
data/ext/bug.c CHANGED
@@ -34,7 +34,7 @@
34
34
  #ifdef MIRIAD_RUBY
35
35
  #include "ruby.h"
36
36
 
37
- extern VALUE mirlib_eMirlibError;
37
+ extern VALUE mirlib_eWrappedMirlibError;
38
38
 
39
39
  #define fprintf(io,fmt,...) \
40
40
  do { \
@@ -44,7 +44,7 @@ extern VALUE mirlib_eMirlibError;
44
44
  fprintf(io,fmt,__VA_ARGS__); \
45
45
  break; \
46
46
  default: \
47
- rb_raise(mirlib_eMirlibError,fmt,__VA_ARGS__); \
47
+ rb_raise(mirlib_eWrappedMirlibError,fmt,__VA_ARGS__); \
48
48
  } \
49
49
  } while(0)
50
50
 
data/ext/extconf.rb CHANGED
@@ -1,4 +1,4 @@
1
- #$Id: extconf.rb 895 2008-04-17 21:30:28Z davidm $
1
+ # $Id: extconf.rb 7 2008-04-18 07:21:10Z davidm $
2
2
  #
3
3
  # Usage: ruby extconf.rb --with-narray-include=/path/to/narray.h
4
4
 
data/ext/miriad.i CHANGED
@@ -1,4 +1,4 @@
1
- /* $Id: miriad.i 899 2008-04-17 21:51:06Z davidm $ */
1
+ /* $Id: miriad.i 11 2008-04-21 20:31:15Z davidm $ */
2
2
 
3
3
  /* MIRIAD Swig wrapper */
4
4
 
@@ -309,6 +309,12 @@ typedef struct {} uvio;
309
309
  }
310
310
  #endif
311
311
 
312
+ unsigned int visno() {
313
+ double visno = 0.0;
314
+ uvinfo_c(self->fd, "visno", &visno);
315
+ return (unsigned int)visno;
316
+ }
317
+
312
318
  // void uvflgwr_c (int tno, Const int *flags);
313
319
  void flagwr(int *flags) {
314
320
  uvflgwr_c(self->fd, flags);
data/ext/miriad_ruby.c CHANGED
@@ -1,4 +1,6 @@
1
1
  /*
2
+ * $Id: miriad_ruby.c 16 2008-04-22 05:40:33Z davidm $
3
+ *
2
4
  * This file is just to document the classes/methods from the SWIG wrappers
3
5
  * that we want to document. It is for rdoc, not gcc. At least for now.
4
6
  * Eventually, it might be nice to dump SWIG since I seem to spend more time
@@ -10,26 +12,18 @@
10
12
 
11
13
  /*
12
14
  * Document-class: Miriad
15
+ *
16
+ * In addition to the Uvio and Visibility classes, the Miriad module also
17
+ * provides some utility methods.
13
18
  */
14
19
 
15
20
  /*
16
21
  * Document-class: Miriad::Uvio
17
- */
18
-
19
- /*
20
- * Document-method: initialize
21
- *
22
- * call-seq: Uvio.new(name, status)
23
- *
24
- * <b>NOTE: This method provides lower-level access than the open() method. It
25
- * may disappear in future versions.</b>
26
22
  *
27
- * Opens a uv dataset and readies it for access. Here +name+ is the dataset's
28
- * name. +status+ can be: <tt>'old'</tt> or <tt>'read'</tt> to open an
29
- * existing dataset for reading, <tt>'new'</tt> or <tt>'write'</tt> to create a
30
- * new dataset, or <tt>'append'</tt> to add to an existing dataset
23
+ * The Uvio class is mostly a SWIG wrapper around the UVIO C routines from
24
+ * MIRIAD. Some convenience methods are added in
25
+ * miriad.rb[link:files/lib/miriad_rb.html].
31
26
  */
32
- static VALUE uvio_initialize();
33
27
 
34
28
  /*
35
29
  * Document-method: close
@@ -144,6 +138,12 @@ static VALUE uvio_scan;
144
138
  * complex data points. This will be either half as many elements as +data+
145
139
  * (if +data+ has real and imaginary components in consecutive elements) or the
146
140
  * same number of elements as +data+ (if +data+ is NArray::SCOMPLEX).
141
+ *
142
+ * The +flags+ indicate whether the corresponding +data+ value has been deemed
143
+ * good or bad:
144
+ *
145
+ * * <tt>1</tt> means good
146
+ * * <tt>0</tt> means bad
147
147
  */
148
148
  static VALUE uvio_write;
149
149
 
@@ -352,8 +352,8 @@ static VALUE uvio_set;
352
352
  *
353
353
  * * +flags+
354
354
  *
355
- * The flags indicate whether the corresponding data value has been deemed
356
- * good or bad. A +1+ means good; a +0+ means bad.
355
+ * The +flags+ indicate whether the corresponding data value has been deemed
356
+ * good or bad. A <tt>1</tt> means good; a <tt>0</tt> means bad.
357
357
  *
358
358
  * * If a Fixnum or Bignum is passed in as +flags+, an NArray that long of
359
359
  * type NArray::LINT is created, populated with +nread+ flag values, and
@@ -395,6 +395,19 @@ static VALUE uvio_uvread;
395
395
  */
396
396
  static VALUE uvio_uvwread;
397
397
 
398
+ /*
399
+ * Document-method: visno
400
+ *
401
+ * call-seq: visno(name) -> Integer
402
+ *
403
+ * Returns the number of the last visibility read. Note that MIRIAD currently
404
+ * increments the visibiliity number on every read, including reads at (or
405
+ * beyond) the end of file. This means that after looping through a dataset
406
+ * with <tt>while vis = uvio.read(vis)</tt>, +visno+ will return one more than
407
+ * the visibility number of the last visibility.
408
+ */
409
+ static VALUE uvio_visno;
410
+
398
411
  /*
399
412
  * Document-method: getvr
400
413
  *
@@ -543,7 +556,12 @@ static VALUE uvio_select;
543
556
  * file), thus overwriting the old flags.
544
557
  *
545
558
  * +flags+ is either an Array or NArray (of type NArray::LINT) and will
546
- * typically have been returned by uvread and subsequently modified.
559
+ * typically have been returned by uvread and subsequently modified. The
560
+ * +flags+ indicate whether the corresponding data value has been deemed good
561
+ * or bad:
562
+ *
563
+ * * <tt>1</tt> means good
564
+ * * <tt>0</tt> means bad
547
565
  */
548
566
  static VALUE uvio_flagwr;
549
567
 
@@ -575,7 +593,6 @@ static VALUE uvio_hiswrite;
575
593
  void Init_Uvio() {
576
594
  VALUE mMiriad = rb_define_module("Miriad");
577
595
  VALUE cUvio = rb_define_class_under(mMiriad,"Uvio",rb_cObject);
578
- rb_define_method(cUvio, "initialize", uvio_initialize, 0);
579
596
  rb_define_method(cUvio, "close", uvio_close, 0);
580
597
  rb_define_method(cUvio, "flush", uvio_flush, 0);
581
598
  rb_define_method(cUvio, "uvnext", uvio_uvnext, 0);
@@ -588,6 +605,7 @@ void Init_Uvio() {
588
605
  rb_define_method(cUvio, "set", uvio_set, 0);
589
606
  rb_define_method(cUvio, "uvread", uvio_uvread, 0);
590
607
  rb_define_method(cUvio, "uvwread", uvio_uvwread, 0);
608
+ rb_define_method(cUvio, "visno", uvio_visno, 0);
591
609
  rb_define_method(cUvio, "getvr", uvio_getvr, 0);
592
610
  rb_define_method(cUvio, "updated?", uvio_updated, 0);
593
611
  rb_define_method(cUvio, "track", uvio_track, 0);
data/ext/miriad_ruby.i CHANGED
@@ -1,13 +1,18 @@
1
- /* Ruby specific typemaps for MIRIAD Swig wrapper */
1
+ /*
2
+ * $Id: miriad_ruby.i 15 2008-04-22 05:26:51Z davidm $
3
+ *
4
+ * Ruby specific typemaps for MIRIAD Swig wrapper
5
+ */
2
6
 
3
7
  #if defined SWIGRUBY
4
8
 
5
9
  %{
6
- VALUE mirlib_eMirlibError;
10
+ VALUE mirlib_eWrappedMirlibError;
7
11
  %}
8
12
 
9
13
  %init %{
10
- mirlib_eMirlibError = rb_define_class("MirlibError", rb_eStandardError);
14
+ mirlib_eWrappedMirlibError =
15
+ rb_define_class("WrappedMirlibError", rb_eStandardError);
11
16
  %}
12
17
 
13
18
  // Requires NArray Ruby extension
@@ -301,8 +306,13 @@ PUTVRX_TYPEMAP(NA_DFLOAT,double,NUM2DBL);
301
306
  }
302
307
  break;
303
308
  case H_BYTE:
304
- $1 = RSTRING(rb_ary_entry(vinput3,0))->ptr;
305
- $2 = RSTRING(rb_ary_entry(vinput3,0))->len;
309
+ {
310
+ // Make sure we have a string!
311
+ VALUE val = rb_ary_entry(vinput3,0);
312
+ Check_Type(val, T_STRING);
313
+ $1 = RSTRING(val)->ptr;
314
+ $2 = RSTRING(val)->len;
315
+ }
306
316
  break;
307
317
  default:
308
318
  rb_raise(rb_eArgError,
data/ext/miriad_wrap.c CHANGED
@@ -1791,7 +1791,7 @@ typedef struct {
1791
1791
  } uvio;
1792
1792
 
1793
1793
 
1794
- VALUE mirlib_eMirlibError;
1794
+ VALUE mirlib_eWrappedMirlibError;
1795
1795
 
1796
1796
 
1797
1797
  #include "narray.h"
@@ -2095,6 +2095,28 @@ SWIGINTERN void uvio_sela(uvio *self,char *object,int datasel,char *string){
2095
2095
  SWIGINTERN void uvio_select(uvio *self,char *object,int datasel,double p1,double p2){
2096
2096
  uvselect_c(self->fd, object, p1, p2, datasel);
2097
2097
  }
2098
+ SWIGINTERN unsigned int uvio_visno(uvio *self){
2099
+ double visno = 0.0;
2100
+ uvinfo_c(self->fd, "visno", &visno);
2101
+ return (unsigned int)visno;
2102
+ }
2103
+
2104
+ #define SWIG_From_long LONG2NUM
2105
+
2106
+
2107
+ SWIGINTERNINLINE VALUE
2108
+ SWIG_From_unsigned_SS_long (unsigned long value)
2109
+ {
2110
+ return ULONG2NUM(value);
2111
+ }
2112
+
2113
+
2114
+ SWIGINTERNINLINE VALUE
2115
+ SWIG_From_unsigned_SS_int (unsigned int value)
2116
+ {
2117
+ return SWIG_From_unsigned_SS_long (value);
2118
+ }
2119
+
2098
2120
  SWIGINTERN void uvio_flagwr(uvio *self,int *flags){
2099
2121
  uvflgwr_c(self->fd, flags);
2100
2122
  }
@@ -2132,9 +2154,6 @@ SWIGINTERN int uvio_haccess(uvio *self,char *keyword,char *status){
2132
2154
  return ihandle;
2133
2155
  }
2134
2156
 
2135
- #define SWIG_From_long LONG2NUM
2136
-
2137
-
2138
2157
  SWIGINTERNINLINE VALUE
2139
2158
  SWIG_From_int (int value)
2140
2159
  {
@@ -2535,8 +2554,13 @@ _wrap_Uvio_putvr(int argc, VALUE *argv, VALUE self) {
2535
2554
  }
2536
2555
  break;
2537
2556
  case H_BYTE:
2538
- arg3 = RSTRING(rb_ary_entry(vinput3,0))->ptr;
2539
- arg4 = RSTRING(rb_ary_entry(vinput3,0))->len;
2557
+ {
2558
+ // Make sure we have a string!
2559
+ VALUE val = rb_ary_entry(vinput3,0);
2560
+ Check_Type(val, T_STRING);
2561
+ arg3 = RSTRING(val)->ptr;
2562
+ arg4 = RSTRING(val)->len;
2563
+ }
2540
2564
  break;
2541
2565
  default:
2542
2566
  rb_raise(rb_eArgError,
@@ -3546,6 +3570,30 @@ fail:
3546
3570
  }
3547
3571
 
3548
3572
 
3573
+ SWIGINTERN VALUE
3574
+ _wrap_Uvio_visno(int argc, VALUE *argv, VALUE self) {
3575
+ uvio *arg1 = (uvio *) 0 ;
3576
+ unsigned int result;
3577
+ void *argp1 = 0 ;
3578
+ int res1 = 0 ;
3579
+ VALUE vresult = Qnil;
3580
+
3581
+ if ((argc < 0) || (argc > 0)) {
3582
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
3583
+ }
3584
+ res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_uvio, 0 | 0 );
3585
+ if (!SWIG_IsOK(res1)) {
3586
+ SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "uvio *","visno", 1, self ));
3587
+ }
3588
+ arg1 = (uvio *)(argp1);
3589
+ result = (unsigned int)uvio_visno(arg1);
3590
+ vresult = SWIG_From_unsigned_SS_int((unsigned int)(result));
3591
+ return vresult;
3592
+ fail:
3593
+ return Qnil;
3594
+ }
3595
+
3596
+
3549
3597
  SWIGINTERN VALUE
3550
3598
  _wrap_Uvio_flagwr(int argc, VALUE *argv, VALUE self) {
3551
3599
  uvio *arg1 = (uvio *) 0 ;
@@ -4168,7 +4216,8 @@ SWIGEXPORT void Init_miriad(void) {
4168
4216
  buglabel_c("mirlib");
4169
4217
 
4170
4218
 
4171
- mirlib_eMirlibError = rb_define_class("MirlibError", rb_eStandardError);
4219
+ mirlib_eWrappedMirlibError =
4220
+ rb_define_class("WrappedMirlibError", rb_eStandardError);
4172
4221
 
4173
4222
 
4174
4223
  rb_require("narray");
@@ -4195,6 +4244,7 @@ SWIGEXPORT void Init_miriad(void) {
4195
4244
  rb_define_method(cUvio.klass, "track", _wrap_Uvio_track, -1);
4196
4245
  rb_define_method(cUvio.klass, "sela", _wrap_Uvio_sela, -1);
4197
4246
  rb_define_method(cUvio.klass, "select", _wrap_Uvio_select, -1);
4247
+ rb_define_method(cUvio.klass, "visno", _wrap_Uvio_visno, -1);
4198
4248
  rb_define_method(cUvio.klass, "flagwr", _wrap_Uvio_flagwr, -1);
4199
4249
  rb_define_method(cUvio.klass, "wflagwr", _wrap_Uvio_wflagwr, -1);
4200
4250
  rb_define_method(cUvio.klass, "haccess", _wrap_Uvio_haccess, -1);
data/ext/narray_ruby.swg CHANGED
@@ -1,3 +1,5 @@
1
+ // $Id: narray_ruby.swg 7 2008-04-18 07:21:10Z davidm $
2
+ //
1
3
  // Common setup for NArray typemaps
2
4
  //
3
5
  // Requires NArray Ruby extension
data/lib/miriad.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  # astronomy related methods to Ruby classes.
8
8
  #
9
9
  #--
10
- #$Id: miriad.rb 901 2008-04-17 22:44:07Z davidm $
10
+ # $Id: miriad.rb 15 2008-04-22 05:26:51Z davidm $
11
11
  #++
12
12
 
13
13
  require 'rbconfig'
@@ -16,7 +16,7 @@ require 'date'
16
16
  require 'narray'
17
17
  miriad_shared_lib = 'miriad.' + Config::CONFIG['DLEXT']
18
18
  require miriad_shared_lib
19
- require 'miriad_ruby_shared_library' if false # Fake out RDoc
19
+ require 'miriad_gem' if false # Fake out RDoc
20
20
  #require 'fftw3'
21
21
 
22
22
  # Add CKMS constant to Math module
@@ -67,7 +67,7 @@ module Math
67
67
  def self.h2d(h) h*15.0; end
68
68
  end
69
69
 
70
- # Th MIRIAD package adds angle conversion and angle formatting methods to
70
+ # The MIRIAD package adds angle conversion and angle formatting methods to
71
71
  # Numeric class.
72
72
  class Numeric
73
73
  # Convert +self+ to [degrees, minutes, seconds] where degrees and minutes are
@@ -112,7 +112,7 @@ end
112
112
 
113
113
  # The MIRIAD package adds angle parsing methods to String class.
114
114
  class String
115
- # Parse a "dd:mm:ss.sss" String to Float degrees.
115
+ # Parse a "dd:mm:ss.sss" String to Numeric degrees.
116
116
  # <b>NOT</b> the inverse of Numeric#to_dmsstr (but may become so).
117
117
  def dms_to_d; Math::dms_to_d(*split(':').map{|s| s.to_f}); end
118
118
  # Parse a "hh:mm:ss.sss" String to Float hours.
@@ -138,9 +138,11 @@ class DateTime
138
138
  2000+(amjd-51544.5)/365.242189813
139
139
  end
140
140
 
141
+ # UT2-UT1 (unit is seconds) at the time represented by +self+
142
+ #
143
+ # Taken from
144
+ # http://www.iers.org/products/6/11136/orig/bulletina-xx-042.txt
141
145
  def ut2_ut1
142
- # Taken from
143
- # http://www.iers.org/products/6/11136/orig/bulletina-xx-042.txt
144
146
  pi2t=Math::PI*2*(by%1)
145
147
  ENV['UT2_UT1'] || 0.022 * Math::sin(pi2t) \
146
148
  - 0.012 * Math::cos(pi2t) \
@@ -260,7 +262,7 @@ class DateTime
260
262
  end
261
263
 
262
264
  # A subclass of StandardError raised by wrapped MIRIAD code.
263
- class MirlibError < StandardError
265
+ class WrappedMirlibError < StandardError
264
266
  end
265
267
 
266
268
  # In addition to the Uvio and Visibility classes, the Miriad module also
@@ -270,35 +272,59 @@ module Miriad
270
272
  # The version of mirlib on which this package is based.
271
273
  MIRLIB_VERSION = "4.1.0"
272
274
 
273
- # Contains Polarization code constants. The values follow the AIPS/FITS
274
- # conventions.
275
- module Pol
276
- # Stokes I
277
- I = 1
278
- # Stokes Q
279
- Q = 2
280
- # Stokes U
281
- U = 3
282
- # Stokes V
283
- V = 4
284
- # Circular RR
285
- RR = -1
286
- # Circular LL
287
- LL = -2
288
- # Circular RL
289
- RL = -3
290
- # Circular LR
291
- LR = -4
292
- # Linear XX
293
- XX = -5
294
- # Linear YY
295
- YY = -6
296
- # Linear XY
297
- XY = -7
298
- # Linear YX
299
- YX = -8
300
- end
301
-
275
+ polarization_code_lookup_table = {
276
+ 1 => 'I' ,
277
+ 2 => 'Q' ,
278
+ 3 => 'U' ,
279
+ 4 => 'V' ,
280
+ -1 => 'RR',
281
+ -2 => 'LL',
282
+ -3 => 'RL',
283
+ -4 => 'LR',
284
+ -5 => 'XX',
285
+ -6 => 'YY',
286
+ -7 => 'XY',
287
+ -8 => 'YX',
288
+ 'I' => 1, 'i' => 1,
289
+ 'Q' => 2, 'q' => 2,
290
+ 'U' => 3, 'u' => 3,
291
+ 'V' => 4, 'v' => 4,
292
+ 'RR' => -1, 'rr' => -1,
293
+ 'LL' => -2, 'll' => -2,
294
+ 'RL' => -3, 'rl' => -3,
295
+ 'LR' => -4, 'lr' => -4,
296
+ 'XX' => -5, 'xx' => -5,
297
+ 'YY' => -6, 'yy' => -6,
298
+ 'XY' => -7, 'xy' => -7,
299
+ 'YX' => -8, 'yx' => -8,
300
+ }.freeze
301
+
302
+ # POLMAP is a Hash that can be used to map polarization codes to strings and
303
+ # vice versa.
304
+ #
305
+ # * Whem mapping from codes (i.e. numbers), uppercase strings are returned.
306
+ #
307
+ # * Whem mapping from strings, either uppercase or lowercase (but *not* mixed
308
+ # case) can be used.
309
+ #
310
+ # The values follow the AIPS/FITS conventions. Here is the mapping:
311
+ #
312
+ # 1:: 'I' (Stokes I)
313
+ # 2:: 'Q' (Stokes Q)
314
+ # 3:: 'U' (Stokes U)
315
+ # 4:: 'V' (Stokes V)
316
+ # -1:: 'RR' (Circular RR)
317
+ # -2:: 'LL' (Circular LL)
318
+ # -3:: 'RL' (Circular RL)
319
+ # -4:: 'LR' (Circular LR)
320
+ # -5:: 'XX' (Linear XX)
321
+ # -6:: 'YY' (Linear YY)
322
+ # -7:: 'XY' (Linear XY)
323
+ # -8:: 'YX' (Linear YX)
324
+ POLMAP = polarization_code_lookup_table
325
+
326
+ # call-seq: Miriad.xyz2uvw(xyz1, xyz2, obsra, obsdec, lst) -> [u, v, w]
327
+ #
302
328
  # Compute the [u,v,w] projection of a baseline with endpoints <tt>xyz1</tt>
303
329
  # and <tt>xyz2</tt> in the direction of +obsra+, +obsdec+ (i.e. right
304
330
  # ascension and declination in the current epoch) at the local apparent
@@ -329,6 +355,128 @@ module Miriad
329
355
  [u,v,w]
330
356
  end
331
357
 
358
+ # call-seq:
359
+ # Miriad.neu2xyz(n, e, u, latitude) -> [x, y, z]
360
+ #
361
+ # Convert topoceptric coordinates to geocentric coordinates. If given,
362
+ # +latitude+ should be in radians. If +latitude+ is not given, the value
363
+ # from <tt>ENV['LATITUDE']</tt> (which should be in degrees in
364
+ # <tt>dd:mm:ss.sss</tt> or <tt>dd.ddd</tt> format) will be used.
365
+ #
366
+ # Output coordinates will be in the same units as the input coordinates.
367
+ #
368
+ # See also Miriad.xyz2neu
369
+ def self.neu2xyz(n, e, u, latitude=String(ENV['LATITUDE']).dms_to_d.d2r)
370
+ sinlat = Math.sin(latitude)
371
+ coslat = Math.cos(latitude)
372
+ [
373
+ u * coslat - n * sinlat,
374
+ e,
375
+ n * coslat + u * sinlat
376
+ ]
377
+ end
378
+
379
+ # :stopdoc:
380
+ class << self
381
+ alias :xyz2neu :neu2xyz
382
+ end
383
+ # :startdoc:
384
+ # RDoc xyz2neu as a method rather than an alias
385
+ if false
386
+ # call-seq:
387
+ # Miriad.xyz2nue(x, y, z, latitude) -> [n, e, u]
388
+ #
389
+ # Convert geocentric coordinates to topocentric coordinates. If given,
390
+ # +latitude+ should be in radians. If +latitude+ is not given, the value
391
+ # from <tt>ENV['LATITUDE']</tt> (which should be in degrees in
392
+ # <tt>dd:mm:ss.sss</tt> or <tt>dd.ddd</tt> format) will be used.
393
+ #
394
+ # Output coordinates will be in the same units as the input coordinates.
395
+ #
396
+ # See also Miriad.neu2xyz
397
+ def self.xyz2neu(x, y, z, latitude=String(ENV['LATITUDE']).dms_to_d.d2r)
398
+ sinlat = Math.sin(latitude)
399
+ coslat = Math.cos(latitude)
400
+ [
401
+ u * coslat - n * sinlat,
402
+ e,
403
+ n * coslat + u * sinlat
404
+ ]
405
+ end
406
+ end
407
+
408
+ # call-seq: Miriad.azel(obsra, obsdec, lst, latitude) -> [azimuth, elevation]
409
+ #
410
+ # Compute +azimuth+ and +elevation+ from +obsra+, +obsdec+, +lst+,
411
+ # +latitude+.
412
+ #
413
+ # NOTE: This calculation is based on a spherical model for the earth, and
414
+ # does not include any atmospheric effects (e.g. refraction).
415
+ #
416
+ # Input:
417
+ #
418
+ # +obsra+:: Apparent RA of the source of interest (radians).
419
+ # +obsdec+:: Apparent DEC of the source of interest (radians).
420
+ # +lst+:: Local sidereal time (radians).
421
+ # +latitude+:: Observatory geodetic latitude (radians). If not given, the
422
+ # value from <tt>ENV['LATITUDE']</tt> (which should be in
423
+ # degrees in <tt>dd:mm:ss.sss</tt> or <tt>dd.ddd</tt> format)
424
+ # will be used.
425
+ #
426
+ # Output:
427
+ #
428
+ # +azimuth+:: Azimuth from north (radians).
429
+ # +elevation+:: Elevation from horizon (radians).
430
+ #
431
+ # The body of this method was transcribed from the miriad source file
432
+ # <tt>ephem.for</tt> originally created by Bob Sault.
433
+ def self.azel(obsra, obsdec, lst, latitude=String(ENV['LATITUDE']).dms_to_d.d2r)
434
+ ha = lst - obsra
435
+ cosha = Math.cos(ha)
436
+ sinha = Math.sin(ha)
437
+ cosd = Math.cos(obsdec)
438
+ sind = Math.sin(obsdec)
439
+ cosl = Math.cos(latitude)
440
+ sinl = Math.sin(latitude)
441
+
442
+ az = Math.atan2(-cosd*sinha, cosl*sind - sinl*cosd*cosha)
443
+
444
+ el = Math.asin(sinl*sind + cosl*cosd*cosha)
445
+
446
+ [az, el]
447
+ end
448
+
449
+ # call-seq: Miriad.parang(obsra, obsdec, lst, latitude) -> parallactic_angle
450
+ #
451
+ # Compute parallactic angle of an altitude-azimuth telescope. Accuracy is
452
+ # about 0.0003 radians.
453
+ #
454
+ # Input:
455
+ #
456
+ # +obsra+:: Apparent RA of the source of interest (radians).
457
+ # +obsdec+:: Apparent DEC of the source of interest (radians).
458
+ # +lst+:: Local sidereal time (radians).
459
+ # +latitude+:: Observatory geodetic latitude (radians). If not given, the
460
+ # value from <tt>ENV['LATITUDE']</tt> (which should be in
461
+ # degrees in <tt>dd:mm:ss.sss</tt> or <tt>dd.ddd</tt> format)
462
+ # will be used.
463
+ #
464
+ # Output:
465
+ #
466
+ # +parang+:: Parallactic angle (radians).
467
+ #
468
+ # The body of this method was transcribed from the miriad source file
469
+ # <tt>ephem.for</tt> originally created by Bob Sault.
470
+ def self.parang(obsra, obsdec, lst, latitude=String(ENV['LATITUDE']).dms_to_d.d2r)
471
+ ha = lst - obsra
472
+ sinq = Math.cos(latitude) * Math.sin(ha)
473
+ cosq = Math.sin(latitude) * Math.cos(obsdec) -
474
+ Math.cos(latitude) * Math.sin(obsdec) * Math.cos(ha)
475
+ Math.atan2(sinq, cosq)
476
+ end
477
+
478
+ # call-seq: Miriad.precess(ra, dec, to_jd, from_jd) -> [ra, dec]
479
+ #
332
480
  # Precess from one mean RA,DEC to another.
333
481
  #
334
482
  # A simple precession routine, to precess from one set of mean
@@ -336,18 +484,22 @@ module Miriad
336
484
  # This is accurate to order 0.3 arcsec over 50 years.
337
485
  #
338
486
  # Reference:
339
- # Explanatory Supplement to the Astronomical Almanac, 1993. p 105-106.
487
+ #
488
+ # <em>Explanatory Supplement to the Astronomical Almanac</em>, 1993. p
489
+ # 105-106.
340
490
  #
341
491
  # NOTE: This does not take account of atmospheric refraction,
342
492
  # nutation, aberration nor gravitational deflection.
343
493
  #
344
494
  # Input:
345
- # ra,dec RA,DEC at the from_jd epoch (radians).
346
- # to_jd Julian day of the new epoch. (defaults to current time)
347
- # from_jd Julian day of the known epoch. (defaults to J2000)
495
+ #
496
+ # +ra+, +dec+:: RA,DEC at the from_jd epoch (radians).
497
+ # +to_jd+:: Julian day of the new epoch. (defaults to current time)
498
+ # +from_jd+:: Julian day of the known epoch. (defaults to J2000)
348
499
  #
349
500
  # Output:
350
- # [ra+,dec] Precessed coordinates (radians).
501
+ #
502
+ # <tt>[ra, dec]</tt>:: Precessed coordinates (radians).
351
503
  #
352
504
  # The body of this method was transcribed from the miriad source file
353
505
  # <tt>ephem.for</tt> originally created by Bob Sault.
@@ -377,24 +529,32 @@ module Miriad
377
529
  [ra, dec]
378
530
  end
379
531
 
380
- # Format a MIRIAD baseline number as "A1-A2".
381
- def self.basstr(baseline)
532
+ # call-seq: Miriad.basstr(baseline, format='%d-%d') -> "A1-A2"
533
+ #
534
+ # Format a MIRIAD baseline number as a String according to +format+.
535
+ def self.basstr(baseline, format='%d-%d')
382
536
  baseline = baseline.to_i
383
- "%d-%d" % basant(baseline)
537
+ format % basant(baseline)
384
538
  end
385
539
 
540
+ # call-seq: Miriad.basant(baseline) -> [a1, a2]
541
+ #
386
542
  # Convert a MIRIAD baseline number into two antenna numbers.
387
543
  def self.basant(baseline)
388
544
  baseline = baseline.to_i
389
545
  [baseline/256, baseline%256]
390
546
  end
391
547
 
548
+ # call-seq: Miriad.antbas(a1, a2) -> baseline_number
549
+ #
392
550
  # Convert two antenna numbers into a MIRIAD baseline number
393
551
  def self.antbas(a1,a2)
394
552
  a1, a2 = a2, a1 if a2 < a1
395
553
  a1.to_i*256 + a2.to_i
396
554
  end
397
555
 
556
+ # call-seq: Miriad.basidx(a1, a2, n) -> baseline_index
557
+ #
398
558
  # Convert two antenna numbers, <tt>a1</tt> and <tt>a2</tt>, into a baseline
399
559
  # index (NOT a MIRIAD baseline number) using +n+ as the maximum antenna
400
560
  # number.
@@ -403,6 +563,8 @@ module Miriad
403
563
  return a1 + ((2*n+1)*(a2-a1) - (a2-a1)**2) / 2
404
564
  end
405
565
 
566
+ # call-seq: Miriad.idxbas(baseline_index, n) -> [a1, a2]
567
+ #
406
568
  # Convert a baseline index (NOT a MIRIAD baseline number) +i+ into two
407
569
  # antenna numbers using +n+ as the maximum antenna number.
408
570
  def self.idxbas(i,n)
@@ -439,21 +601,29 @@ module Miriad
439
601
  def self.[](preamble, data, flags)
440
602
  self.new(preamble, data, flags)
441
603
  end
442
- # Returns the [u,v,w] coordinates from the preamble.
604
+ # call-seq: coord() -> [u, v, w]
605
+ #
606
+ # Returns the [u,v,w] coordinates from this Visibility's preamble. Note
607
+ # that the returned array could be an Array or an NArray, depending on how
608
+ # Uvio#read was called. If you want to use multiple assignment, be sure to
609
+ # call +to_a+ on the returned value (otherwise your +u+ variable might end
610
+ # up as a three element NArray and +v+ and +w+ nil.)
443
611
  def coord() preamble[0..2]; end
444
- # Returns the Julian date from the preamble.
612
+ # Computes the uv distance from this Visibility's preamble.
613
+ def uvdist() Math.sqrt(preamble[0]**2+preamble[1]**2); end
614
+ # Returns the Julian date from this Visibility's preamble.
445
615
  def jd() preamble[3]; end
446
- # Returns the baseline number from the preamble.
616
+ # Returns the baseline number from this Visibility's preamble.
447
617
  def baseline() preamble[4].to_i; end
448
- # Returns a DateTime object corresponding to the Julian date from the
449
- # preamble.
618
+ # Returns a DateTime object corresponding to the Julian date from this
619
+ # Visibility's preamble.
450
620
  def time() DateTime.ajd(jd); end
451
621
  # Returns the two antenna numbers corresponding to the baseline number
452
- # from the preamble.
453
- def ants() Miriad.basant(baseline); end
454
- # True if the baseline is an autocorrelation.
622
+ # from this Visibility's preamble.
623
+ def basant() Miriad.basant(baseline); end
624
+ # True if this Visibility's baseline is an autocorrelation.
455
625
  def auto?() a1,a2=Miriad.basant(baseline); a1 == a2; end
456
- # True if the baseline is a cross correlation.
626
+ # True if this Visibility's baseline is a cross correlation.
457
627
  def cross?() a1,a2=Miriad.basant(baseline); a1 != a2; end
458
628
  ## TODO Make this more robust (i.e. less hard-coded)
459
629
  #def lags()
@@ -478,9 +648,33 @@ module Miriad
478
648
  # Calls <tt>putvr(var, data, ?d)</tt>
479
649
  def putvrd(var,data) putvr(var, data, ?d); end
480
650
 
481
- # Convenience wrapper around self.new. Self.new may become private, so use
482
- # this method instead.
483
- def self.open(name,mode='r')
651
+ # Make new protected
652
+ class << self
653
+ protected :new
654
+ end
655
+
656
+ # call-seq:
657
+ # Uvio.open(name, mode='r') -> uvio
658
+ # Uvio.open(name, mode='r') {|uvio| ...}
659
+ #
660
+ # Opens a uv dataset and readies it for access.
661
+ #
662
+ # +name+:: The dataset's name
663
+ # +mode+:: Specifies how to open the dataset. Valid values are:
664
+ # * <tt>'r'</tt> for reading an existing dataset,
665
+ # * <tt>'w'</tt> for writing a new dataset, or
666
+ # * <tt>'a'</tt> for appending to an existing dataset.
667
+ #
668
+ # Note that datsets opened for reading may still be modified in some ways
669
+ # (e.g. writing new flags).
670
+ #
671
+ # If a block is given, dataset +name+ is opened according to +mode+ and the
672
+ # resulting Uvio object is passed into the block. The dataset will be
673
+ # automatically closed when the block terminates. In this case, the return
674
+ # value of Uvio.open is the return value of the block.
675
+ #
676
+ # If no block is given, the new Uvio object is returned.
677
+ def self.open(name, mode='r')
484
678
  raise 'invalid dataset name' if name.nil? or name.empty?
485
679
  case mode[0]
486
680
  when ?r then
@@ -491,7 +685,15 @@ module Miriad
491
685
  raise 'invalid dataset given' unless test ?d, name
492
686
  end
493
687
 
494
- self.new(name,mode)
688
+ uvio = self.new(name,mode)
689
+
690
+ return uvio unless block_given?
691
+
692
+ begin
693
+ return yield(uvio)
694
+ ensure
695
+ uvio.close() rescue nil
696
+ end
495
697
  end
496
698
 
497
699
  # call-seq:
@@ -510,6 +712,7 @@ module Miriad
510
712
  # future versions!</b>
511
713
  def read(*args)
512
714
  if args.length == 0 || args[0].nil?
715
+ nchan = getvr('nchan') || 0
513
716
  n, p, d, f = uvread(5,nchan,nchan)
514
717
  elsif args.length == 1 && Visibility === args[0]
515
718
  n, p, d, f = uvread(args[0].preamble,args[0].data,args[0].flags)
@@ -520,44 +723,128 @@ module Miriad
520
723
  # Return nil on EOF
521
724
  return nil if n == 0
522
725
 
523
- # FIXME for Array inputs
524
726
  # If nread is different than what was passed in
525
- if n != d.length
526
- # Shorten data and flags
527
- d = d[0...n]
528
- f = f[0...n]
529
- end
727
+ dlen = flen = n
728
+ dlen *= 2 if Array === d
729
+ # Shorten data and flags
730
+ d = d[0...dlen] if dlen != d.length
731
+ f = f[0...flen] if flen != f.length
530
732
 
531
733
  # Return Visibility
532
734
  return args[0] if Visibility === args[0]
533
735
  Visibility[p,d,f]
534
736
  end
535
737
 
536
- # call-seq: baseline -> [ant1, ant2]
738
+ # call-seq: polstr -> String
739
+ #
740
+ # Format the current value of the _pol_ uv variable as a String according
741
+ # to <tt>Miriad::POLMAP</tt>.
742
+ def polstr
743
+ Miriad::POLMAP[getvr('pol')]
744
+ end
745
+
746
+ # call-seq: basstr(format='%d-%d') -> "A1-A2"
537
747
  #
538
- # Decodes the value of the +baseline+ uv variable and returns a two element
748
+ # Format the current value of the _baseline_ uv variable as a String
749
+ # according to +format+.
750
+ def basstr(format='%d-%d')
751
+ format % basant(getvr('baseline'))
752
+ end
753
+
754
+ # call-seq: basant -> [ant1, ant2]
755
+ #
756
+ # Decodes the value of the _baseline_ uv variable and returns a two element
539
757
  # array containing the two antenna numbers.
540
- def baseline
758
+ def basant
541
759
  bl = getvr('baseline')
542
760
  bl = [bl.to_i/256, bl.to_i%256] if bl
543
761
  end
544
762
 
545
- # Uvio.foo, if foo is not a predefined attribute or method, will return the
546
- # current value of the MIRIAD UV variable +foo+ or +nil+ if it doesn't
547
- # (yet) exist.
763
+ # Computes hour angle (in radians) as <tt>lst - obsra</tt>.
764
+ # Returns 0.0 if either one (or both) is undefined.
765
+ def ha
766
+ getvr('lst') - getvr('obsra') rescue 0.0
767
+ end
768
+
769
+ # Computes the uv distance from the current value of the _coord_ uv
770
+ # variable. Returns 0.0 if _coord_ is undefined or maldefined.
771
+ def uvdist
772
+ u, v, w = getvr('coord')
773
+ (u && v) ? Math.sqrt(u**2+v**2) : 0.0
774
+ end
775
+
776
+ # Computes the azimuth and elevation from the current values of _lst_,
777
+ # _obsra_, _obsdec_, and _latitude_. Missing components are assumed to be
778
+ # 0.0.
548
779
  #
549
- # Uvio.foo=bar, if foo= is not a predefined attribute or method, will set
550
- # the value of the MIRIAD UV variable +foo+ to +bar+. Only valid for
551
- # datasets opened in write mode. [SETTER FUNCTIONALITY NOT YET
552
- # IMPLEMENTED!]
553
- def method_missing(sym,*args)
554
- val = nil
555
- var = sym.to_s
556
- case var
557
- when /=$/: break
558
- else val = getvr(var)
559
- end
560
- val
780
+ # See Miriad.azel for more details.
781
+ def azel
782
+ obsra = getvr('obsra') || 0.0
783
+ obsdec = getvr('obsdec') || 0.0
784
+ lst = getvr('lst') || 0.0
785
+ latitude = getvr('latitud') || 0.0
786
+ Miriad.azel(obsra, obsdec, lst, latitude)
787
+ end
788
+
789
+ # Computes the current parallactic angle from the current values of _lst_,
790
+ # _obsra_, _obsdec_, and _latitude_. Missing components are assumed to be
791
+ # 0.0.
792
+ #
793
+ # See Miriad.parang for more details.
794
+ def parang
795
+ obsra = getvr('obsra') || 0.0
796
+ obsdec = getvr('obsdec') || 0.0
797
+ lst = getvr('lst') || 0.0
798
+ latitude = getvr('latitud') || 0.0
799
+ Miriad.parang(obsra, obsdec, lst, latitude)
800
+ end
801
+
802
+ # Returns the value of the uv variable _chi_. If _chi_ is not defined,
803
+ # return <tt>parang()</tt> plus the value of the _evector_ uv variable
804
+ # if it is defined.
805
+ def chi
806
+ getvr('chi') || (parang + (getvr('evector') || 0.0))
807
+ end
808
+
809
+ # call-seq:
810
+ # uvio['name'] -> value or nil
811
+ # uvio[:name] -> value or nil
812
+ #
813
+ # Returns the current value of the uv variable named +name+ or +nil+ if the
814
+ # named variable does not (yet) exist.
815
+ #
816
+ # This provides a Hash-like interface to the uv variables.
817
+ #
818
+ # It is implemented as <tt>getvr(name.to_s)</tt>.
819
+ def [](name)
820
+ getvr(name.to_s)
821
+ end
822
+
823
+ # call-seq:
824
+ # uvio['name'] = value -> value
825
+ # uvio[:name] = value -> value
826
+ # uvio['name', type] = value -> value
827
+ # uvio[:name, type] = value -> value
828
+ #
829
+ # Sets the uv variable +name+ to +value+. If +type+ is not given, the
830
+ # MIRIAD type will be autodetected from +value+. Generally, this works
831
+ # well only for Strings and NArrays, but not for Numeric types. For full
832
+ # control, specify +type+ as one of...
833
+ #
834
+ # * <tt>?a</tt> - ASCII data
835
+ # * <tt>?i</tt> - Integer data
836
+ # * <tt>?r</tt> - Single precision real data
837
+ # * <tt>?d</tt> - Double precision real data
838
+ def []=(*args)
839
+ n, t, v = case args.length
840
+ when 2: [args[0], -1, args[1]]
841
+ when 3: [args[0], args[1], args[2]]
842
+ else
843
+ raise ArgumentError.new(
844
+ "wrong number of arguments (#{args.length} for 3)")
845
+ end
846
+ putvr(n.to_s, v, t)
847
+ v
561
848
  end
562
849
  end
563
850
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miriad
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.0
4
+ version: 4.1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David MacMahon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-17 00:00:00 -07:00
12
+ date: 2008-04-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ has_rdoc: true
61
61
  homepage: http://miriad.rubyforge.org/
62
62
  post_install_message:
63
63
  rdoc_options:
64
+ - -S
64
65
  - -x
65
66
  - ext/.*.c
66
67
  - -m
@@ -74,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
75
  requirements:
75
76
  - - ">="
76
77
  - !ruby/object:Gem::Version
77
- version: 1.8.6
78
+ version: 1.8.4
78
79
  version:
79
80
  required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements: