voruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/LICENSE +339 -0
  2. data/REQUIREMENTS +4 -0
  3. data/Rakefile.rb +296 -0
  4. data/lib/voruby/adql/adql.rb +2735 -0
  5. data/lib/voruby/adql/ext.rb +15 -0
  6. data/lib/voruby/adql/loader.rb +5 -0
  7. data/lib/voruby/adql/operations.rb +54 -0
  8. data/lib/voruby/adql/parser.rb +160 -0
  9. data/lib/voruby/adql/transforms.rb +573 -0
  10. data/lib/voruby/ext.rb +17 -0
  11. data/lib/voruby/loader.rb +4 -0
  12. data/lib/voruby/misc/propertyfile.rb +36 -0
  13. data/lib/voruby/plastic/applications.rb +174 -0
  14. data/lib/voruby/plastic/constants.rb +30 -0
  15. data/lib/voruby/plastic/loader.rb +10 -0
  16. data/lib/voruby/plastic/plastic.rb +1 -0
  17. data/lib/voruby/resources/conesearch/conesearch.rb +9 -0
  18. data/lib/voruby/resources/conesearch/conesearch_v0_2.rb +55 -0
  19. data/lib/voruby/resources/conesearch/conesearch_v0_3.rb +50 -0
  20. data/lib/voruby/resources/conesearch/conesearch_v1_0.rb +72 -0
  21. data/lib/voruby/resources/conesearch/loader.rb +4 -0
  22. data/lib/voruby/resources/loader.rb +50 -0
  23. data/lib/voruby/resources/nodes.rb +190 -0
  24. data/lib/voruby/resources/openskynode/loader.rb +4 -0
  25. data/lib/voruby/resources/openskynode/openskynode.rb +9 -0
  26. data/lib/voruby/resources/openskynode/openskynode_v0_1.rb +54 -0
  27. data/lib/voruby/resources/sia/loader.rb +5 -0
  28. data/lib/voruby/resources/sia/sia.rb +9 -0
  29. data/lib/voruby/resources/sia/sia_v0_6.rb +90 -0
  30. data/lib/voruby/resources/sia/sia_v0_7.rb +89 -0
  31. data/lib/voruby/resources/sia/sia_v1_0.rb +122 -0
  32. data/lib/voruby/resources/stsci.rb +59 -0
  33. data/lib/voruby/resources/vodataservice/coverage_v0_2.rb +195 -0
  34. data/lib/voruby/resources/vodataservice/coverage_v0_3.rb +158 -0
  35. data/lib/voruby/resources/vodataservice/loader.rb +5 -0
  36. data/lib/voruby/resources/vodataservice/vodataservice.rb +9 -0
  37. data/lib/voruby/resources/vodataservice/vodataservice_v0_4.rb +189 -0
  38. data/lib/voruby/resources/vodataservice/vodataservice_v0_5.rb +163 -0
  39. data/lib/voruby/resources/vodataservice/vodataservice_v1_0.rb +221 -0
  40. data/lib/voruby/resources/voregistry/loader.rb +4 -0
  41. data/lib/voruby/resources/voregistry/voregistry.rb +9 -0
  42. data/lib/voruby/resources/voregistry/voregistry_v0_2.rb +40 -0
  43. data/lib/voruby/resources/voregistry/voregistry_v0_3.rb +30 -0
  44. data/lib/voruby/resources/voregistry/voregistry_v1_0.rb +86 -0
  45. data/lib/voruby/resources/voresource/loader.rb +17 -0
  46. data/lib/voruby/resources/voresource/voresource.rb +9 -0
  47. data/lib/voruby/resources/voresource/voresource_v0_10.rb +322 -0
  48. data/lib/voruby/resources/voresource/voresource_v0_9.rb +405 -0
  49. data/lib/voruby/resources/voresource/voresource_v1_0.rb +230 -0
  50. data/lib/voruby/services/ext.rb +11 -0
  51. data/lib/voruby/services/gestalt/footprint.rb +95 -0
  52. data/lib/voruby/services/gestalt/wcs_fixer.rb +105 -0
  53. data/lib/voruby/services/gestalt/wesix.rb +155 -0
  54. data/lib/voruby/services/loader.rb +7 -0
  55. data/lib/voruby/services/registry/registry.rb +53 -0
  56. data/lib/voruby/services/resolver/resolver.rb +35 -0
  57. data/lib/voruby/sesame/loader.rb +6 -0
  58. data/lib/voruby/sesame/sesame_v1_0.rb +64 -0
  59. data/lib/voruby/simple/loader.rb +6 -0
  60. data/lib/voruby/simple/parameters.rb +196 -0
  61. data/lib/voruby/simple/sap.rb +446 -0
  62. data/lib/voruby/spacetime/loader.rb +3 -0
  63. data/lib/voruby/spacetime/spacetime.rb +607 -0
  64. data/lib/voruby/stc/coords_v1_20.rb +900 -0
  65. data/lib/voruby/stc/loader.rb +55 -0
  66. data/lib/voruby/stc/region_v1_20.rb +274 -0
  67. data/lib/voruby/stc/stc_v1_20.rb +1196 -0
  68. data/lib/voruby/util.rb +27 -0
  69. data/lib/voruby/voevent/loader.rb +7 -0
  70. data/lib/voruby/voevent/voevent_v1_0.rb +213 -0
  71. data/lib/voruby/voevent/voevent_v1_1.rb +196 -0
  72. data/lib/voruby/votables/chandra.rb +410 -0
  73. data/lib/voruby/votables/cnoc.rb +393 -0
  74. data/lib/voruby/votables/data.rb +179 -0
  75. data/lib/voruby/votables/galex.rb +390 -0
  76. data/lib/voruby/votables/hst.rb +391 -0
  77. data/lib/voruby/votables/int.rb +391 -0
  78. data/lib/voruby/votables/libxml_parser.rb +411 -0
  79. data/lib/voruby/votables/libxml_votable.rb +67 -0
  80. data/lib/voruby/votables/loader.rb +10 -0
  81. data/lib/voruby/votables/meta.rb +763 -0
  82. data/lib/voruby/votables/misc.rb +51 -0
  83. data/lib/voruby/votables/nsa.rb +393 -0
  84. data/lib/voruby/votables/nsar3.rb +410 -0
  85. data/lib/voruby/votables/rexml_parser.rb +408 -0
  86. data/lib/voruby/votables/rexml_votable.rb +67 -0
  87. data/lib/voruby/votables/sdss.rb +393 -0
  88. data/lib/voruby/votables/transforms.rb +388 -0
  89. data/lib/voruby/votables/tree.rb +45 -0
  90. data/lib/voruby/votables/types.rb +391 -0
  91. data/lib/voruby/votables/votable.rb +630 -0
  92. data/lib/voruby/votables/xmm.rb +394 -0
  93. data/test/adql/test1.adql +49 -0
  94. data/test/adql/test2.adql +51 -0
  95. data/test/adql/test3.adql +81 -0
  96. data/test/adql/test4.adql +53 -0
  97. data/test/adql/test5.adql +55 -0
  98. data/test/adql/test6.adql +18 -0
  99. data/test/adql/test7.adql +48 -0
  100. data/test/adql/unittest.rb +1672 -0
  101. data/test/plastic/test.rb +44 -0
  102. data/test/plastic/test.vot +5385 -0
  103. data/test/plastic/unittest.rb +66 -0
  104. data/test/resources/conesearch/conesearch_v0_3.xml +31 -0
  105. data/test/resources/conesearch/conesearch_v1_0.xml +86 -0
  106. data/test/resources/conesearch/unittest_v0_3.rb +22 -0
  107. data/test/resources/conesearch/unittest_v1_0.rb +24 -0
  108. data/test/resources/openskynode/open_sky_node_v0_1.xml +32 -0
  109. data/test/resources/openskynode/unittest_v0_1.rb +31 -0
  110. data/test/resources/sia/simple_image_access_v0_7.xml +36 -0
  111. data/test/resources/sia/simple_image_access_v1_0.xml +122 -0
  112. data/test/resources/sia/unittest_v0_7.rb +24 -0
  113. data/test/resources/sia/unittest_v1_0.rb +29 -0
  114. data/test/resources/stsci.xml +336 -0
  115. data/test/resources/unittest_stsci.rb +25 -0
  116. data/test/resources/vodataservice/catalog_service_resource_v1_0.xml +128 -0
  117. data/test/resources/vodataservice/data_collection_resource_v0_5.xml +54 -0
  118. data/test/resources/vodataservice/data_collection_resource_v1_0.xml +117 -0
  119. data/test/resources/vodataservice/data_service_resource_v1_0.xml +115 -0
  120. data/test/resources/vodataservice/sky_service_resource_v0_10.xml +45 -0
  121. data/test/resources/vodataservice/table_service_resource_v1_0.xml +122 -0
  122. data/test/resources/vodataservice/tabular_sky_service_resource_v0_10.xml +60 -0
  123. data/test/resources/vodataservice/unittest_v0_5.rb +126 -0
  124. data/test/resources/vodataservice/unittest_v1_0.rb +151 -0
  125. data/test/resources/voregistry/authority_resource_v0_3.xml +20 -0
  126. data/test/resources/voregistry/authority_resource_v1_0.xml +82 -0
  127. data/test/resources/voregistry/registry_service_v0_3.xml +20 -0
  128. data/test/resources/voregistry/registry_service_v1_0.xml +107 -0
  129. data/test/resources/voregistry/unittest_v0_3.rb +31 -0
  130. data/test/resources/voregistry/unittest_v1_0.rb +34 -0
  131. data/test/resources/voresource/organisation_resource_v1_0.xml +90 -0
  132. data/test/resources/voresource/resource_organisation_v0_10.xml +22 -0
  133. data/test/resources/voresource/resource_service_v0_10.xml +19 -0
  134. data/test/resources/voresource/resource_v0_10.xml +19 -0
  135. data/test/resources/voresource/resource_v1_0.xml +79 -0
  136. data/test/resources/voresource/service_resource_v1_0.xml +91 -0
  137. data/test/resources/voresource/unittest_v0_10.rb +61 -0
  138. data/test/resources/voresource/unittest_v0_9.rb +4 -0
  139. data/test/resources/voresource/unittest_v1_0.rb +190 -0
  140. data/test/services/gestalt/unittest.rb +74 -0
  141. data/test/services/registry/unittest.rb +34 -0
  142. data/test/services/resolver/unittest.rb +38 -0
  143. data/test/simple/unittest.rb +46 -0
  144. data/test/spacetime/unittest.rb +39 -0
  145. data/test/stc/catalog_entry_location_v1_20.xml +112 -0
  146. data/test/stc/obs_data_location_v1_20.xml +108 -0
  147. data/test/stc/search_location_v1_20.xml +54 -0
  148. data/test/stc/stc_resource_profile_v1_20.xml +60 -0
  149. data/test/stc/unittest_v1_20.rb +620 -0
  150. data/test/voevent/unittest_v1_0.rb +79 -0
  151. data/test/voevent/unittest_v1_1.rb +70 -0
  152. data/test/voevent/voevent_v1_0.xml +96 -0
  153. data/test/voevent/voevent_v1_1.xml +76 -0
  154. data/test/votables/test.vot +366 -0
  155. data/test/votables/unittest.rb +54 -0
  156. metadata +256 -0
@@ -0,0 +1,196 @@
1
+ require 'uri'
2
+
3
+ module VORuby
4
+
5
+ module Simple
6
+
7
+ # Classes representing the different sorts of parameters commonly used
8
+ # in the REST-based services like SIAP, SSAP and SCS.
9
+ module Parameters
10
+
11
+ # Represents a search radius.
12
+ class Radius
13
+ def initialize(radius)
14
+ @radius = radius(radius)
15
+ end
16
+
17
+ def radius(radius=nil)
18
+ if radius == nil
19
+ return @radius
20
+ else
21
+ @radius = radius.to_f()
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ URI.escape(sprintf("SR=%.2f", @radius))
27
+ end
28
+ end
29
+
30
+ # Represents astronomical longitude.
31
+ class RightAscension
32
+ def initialize(ra)
33
+ ra(ra)
34
+ end
35
+
36
+ def ra(ra=nil)
37
+ if ra == nil
38
+ return @ra
39
+ else
40
+ if ra.instance_of?(String)
41
+ if ra =~ /[-+]\d+:\d+:\d+(\.\d+)?/
42
+ @ra = RightAscension.convert_to_decimal_degrees(ra)
43
+ else
44
+ @ra = ra.to_f()
45
+ end
46
+ else
47
+ @ra = ra.to_f()
48
+ end
49
+ end
50
+ end
51
+
52
+ def to_s
53
+ URI.escape(sprintf("RA=%.3f", @ra))
54
+ end
55
+
56
+ # Convert an RA in h:m:s format to decimal degrees.
57
+ def self.convert_to_decimal_degrees(ra)
58
+ hours, min, sec = ra.split(':')
59
+
60
+ degrees =
61
+ (hours.to_f() * 15.0) +
62
+ (min.to_f() * 15.0 / 60.0) +
63
+ (sec.to_f() * 15.0 / (60.0 * 60.0))
64
+
65
+ return degrees
66
+ end
67
+ end
68
+
69
+ # Represents astronomical latitude.
70
+ class Declination
71
+ def initialize(dec)
72
+ dec(dec)
73
+ end
74
+
75
+ def dec(dec=nil)
76
+ if dec == nil
77
+ return @dec
78
+ else
79
+ if dec.instance_of?(String)
80
+ @dec = Declination.convert_to_decimal_degrees(dec)
81
+ else
82
+ @dec = dec.to_f()
83
+ end
84
+ end
85
+ end
86
+
87
+ def to_s
88
+ URI.escape(sprintf("DEC=%.3f", @dec))
89
+ end
90
+
91
+ # Convert a Dec in d:m:s format to decimal degrees.
92
+ def self.convert_to_decimal_degrees(dec)
93
+ degree, arcmin, arcsec = dec.split(':')
94
+
95
+ degree_f = degree.to_f()
96
+ arcmin_f = (arcmin.to_f() / 60.0)
97
+ arcsec_f = (arcsec.to_f() / (60.0 * 60.0))
98
+
99
+ return (degree_f - arcmin_f - arcsec_f) if degree_f < 0
100
+ return degree_f + arcmin_f + arcsec_f
101
+ end
102
+ end
103
+
104
+ # Represents an angular size on the sky.
105
+ class Size
106
+ def initialize(ra_width, dec_width=nil)
107
+ if dec_width == nil
108
+ ra_width(ra_width)
109
+ dec_width(ra_width)
110
+ else
111
+ ra_width(ra_width)
112
+ dec_width(dec_width)
113
+ end
114
+ end
115
+
116
+ # Set or get the value of the RA width.
117
+ # The width is specifed in decimal degrees.
118
+ def ra_width(ra_width=nil)
119
+ if ra_width == nil
120
+ return @ra_width
121
+ else
122
+ @ra_width = ra_width.to_f()
123
+ end
124
+ end
125
+
126
+ # Set or get the value of the declination width.
127
+ # The width is specified in decimal degrees.
128
+ def dec_width(dec_width=nil)
129
+ if dec_width == nil
130
+ return @dec_width
131
+ else
132
+ @dec_width = dec_width.to_f()
133
+ end
134
+ end
135
+
136
+ # Convert the size to its SIAP-compliant form.
137
+ def to_s
138
+ if @ra_width == @dec_width
139
+ # size = 0 is a special case--it test whether
140
+ # the given point is in an image.
141
+ if @ra_width == 0.0
142
+ return URI.escape("SIZE=0")
143
+ else
144
+ return URI.escape(sprintf("SIZE=%.4f", @ra_width))
145
+ end
146
+ else
147
+ return URI.escape(sprintf("SIZE=%.4f,%.4f", @ra_width, @dec_width))
148
+ end
149
+ end
150
+ end
151
+
152
+ # Represents a position on the sky.
153
+ class Position
154
+ def initialize(ra, dec)
155
+ ra(ra)
156
+ dec(dec)
157
+ end
158
+
159
+ # Set or get the value of the right ascension.
160
+ # The RA may be a decimal or a string in standard sexigesimal format.
161
+ def ra(ra=nil)
162
+ if ra == nil
163
+ return @ra
164
+ else
165
+ if ra.instance_of?(RightAscension)
166
+ @ra = ra
167
+ else
168
+ @ra = RightAscension.new(ra)
169
+ end
170
+ end
171
+ end
172
+
173
+ # Set or get the value of the declination.
174
+ # The declination may be a decimal or a string in standard sexigesimal format.
175
+ def dec(dec=nil)
176
+ if dec == nil
177
+ return @dec
178
+ else
179
+ if dec.instance_of?(Declination)
180
+ @dec = dec
181
+ else
182
+ @dec = Declination.new(dec)
183
+ end
184
+ end
185
+ end
186
+
187
+ # Convert the position to its SIAP-compliant form.
188
+ def to_s
189
+ URI.escape(sprintf("POS=%.3f,%.3f", @ra.ra(), @dec.dec()))
190
+ end
191
+ end
192
+
193
+ end
194
+ end
195
+
196
+ end
@@ -0,0 +1,446 @@
1
+ require 'voruby/simple/loader'
2
+
3
+ module VORuby
4
+ # A number of classes for dealing with standard VO protocols like SIAP, SSAP and
5
+ # SCS.
6
+ module Simple
7
+ # Executes a series of queries, each in its own thread.
8
+ # Typical use might be something like this:
9
+ # # Convert the query results into an object representation.
10
+ # objectifier = Proc.new { |query|
11
+ # query.marshall().votable().votable()
12
+ # }
13
+ #
14
+ # # Prepare a SIAP query
15
+ # nsa_siap = Simple::ImageAccess.new('http://archive.noao.edu/nvo/sim/voquery.php',
16
+ # '23:00:00, 2:00:00', 7, nil, 30, 'rexml')
17
+ #
18
+ # # Prepare a SSAP query
19
+ # iso_ssap = Simple::SpectralAccess.new('http://pma.iso.vilspa.esa.es:8080/aio/jsp/siap.jsp',
20
+ # '53.084, -27.873', 10, {:format => 'votable'}, 30, 'rexml')
21
+ # # Prepare a cone search query
22
+ # mast_cone = Simple::ConeSearch.new('http://archive.stsci.edu/hst/search.php',
23
+ # 53.084, -27.873, 0.01, nil, 30, 'rexml')
24
+ #
25
+ # # Execute the queries asynchronously.
26
+ # Simple::QueryExecutor.new([nsa_siap, iso_ssap, mast_cone], objectifier).results().each do |query, votable|
27
+ # # Just to prove things are working, output the list of field UCDs for each table.
28
+ # puts "#{query.to_s()}..."
29
+ # votable.fields().each do |field|
30
+ # puts "#{field.id()}, #{field.name()}, #{field.ucd().value() if field.ucd() != nil}"
31
+ # end
32
+ #
33
+ # votable.rows().each do |row|
34
+ # puts row
35
+ # end
36
+ #
37
+ # puts "\n"
38
+ # end
39
+ class QueryExecutor
40
+ attr_accessor :queries, :converter
41
+ attr_reader :results
42
+
43
+ # [_queries_:]
44
+ # A list of valid query objects. Good examples of these are:
45
+ # * Simple::SpectralAccess (Simple Spectral Access Protocol queries)
46
+ # * Simple::ImageAccess (Simple Image Access Protocol queries)
47
+ # * Simple::ConeSearch (Simple Cone Search queries)
48
+ # [_converter_:]
49
+ # An anonymous subroutine that can be used to convert the result of a
50
+ # query into another form--often a VOTABLE::VOTable for our purposes.
51
+ # By default, it simply returns the completed query.
52
+ # [_abort_on_exeception_:]
53
+ # A flag which indicates whether or not if one query fails, the other queries
54
+ # should abort, too.
55
+ # Each query must also have a _fetch_ method. One way to get this is to mixin
56
+ # the Simple::HTTPGetQuery module.
57
+ def initialize(queries=[], converter=Proc.new{|qo| qo}, abort_on_exception=false)
58
+ @queries = queries
59
+ @converter = converter
60
+ Thread::abort_on_exception = abort_on_exception
61
+
62
+ @results = {}
63
+ begin_queries()
64
+ end
65
+
66
+ # Kick off each query into its own thread.
67
+ def begin_queries
68
+ threads = []
69
+
70
+ # Place each query in its own thread.
71
+ queries.each do |query|
72
+ threads << Thread.new(query){ |the_query|
73
+ the_query.fetch()
74
+ # Convert the query into something (maybe itself).
75
+ @results[the_query] = converter.call(the_query)
76
+ }
77
+ end
78
+
79
+ # Make sure each thread finishes before the program
80
+ # exits.
81
+ threads.each{ |thread| thread.join() }
82
+ end
83
+ end
84
+
85
+ # Mixin a generic GET-type HTTP query.
86
+ # Requires that the main object has a query_uri() method defined
87
+ # that returns a valid URI as a string.
88
+ module HTTPGetQuery
89
+ # Using an HTTP get, fetch the response that corresponds to the
90
+ # query parameters.
91
+ def fetch
92
+ uri = URI.parse(query_uri())
93
+
94
+ http = Net::HTTP.new(uri.host, uri.port)
95
+ http.read_timeout = query_timeout()
96
+
97
+ uri_params = required_parameters()
98
+ # Other parameters
99
+ parameters().each do |param, value|
100
+ uri_params.push(URI.escape("#{param.to_s().upcase()}=#{value}"))
101
+ end
102
+
103
+ res = http.start {|http|
104
+ http.get(uri.path + '?' + uri_params.join('&'))
105
+ }
106
+ self.response = res.body
107
+ end
108
+
109
+ # Convert to a form suitable for use in a URL. The required_parameters
110
+ # and parameters methods must exist.
111
+ def query_uri
112
+ uri_params = required_parameters()
113
+
114
+ # Other parameters
115
+ parameters().each do |param, value|
116
+ uri_params.push(URI.escape("#{param.to_s().upcase()}=#{value}"))
117
+ end
118
+
119
+ "#{uri()}?" + uri_params.join('&')
120
+ end
121
+ end
122
+
123
+ # Mixin a method that converts an XML VOTable into an object using
124
+ # a VOTABLE::TreeParsedVOTable.
125
+ module VOTableMarshaller
126
+ # Interpret the response into an object.
127
+ def marshall
128
+ tmp_file = Tempfile.new('response_') # Open a temporary file.
129
+
130
+ # Write the response.
131
+ tmp_file.write(response())
132
+ tmp_file.flush()
133
+
134
+ # Create the votable
135
+ votable = VORuby::VOTables::VOTable::TreeParsedVOTable.new(tmp_file.path(), parser())
136
+
137
+ tmp_file.close()
138
+
139
+ votable
140
+ end
141
+ end
142
+
143
+ # Represents a query to a cone search server.
144
+ # mast_cone = Simple::ConeSearch.new('http://archive.stsci.edu/hst/search.php',
145
+ # 53.084, -27.873, 0.01, nil, 30, 'rexml')
146
+ # mast_cone.fetch()
147
+ # votable = mast_cone.marshall()
148
+ class ConeSearch
149
+ include HTTPGetQuery
150
+ include VOTableMarshaller
151
+
152
+ attr_accessor :uri, :parameters, :query_timeout, :parser, :response
153
+
154
+ # [_uri_:]
155
+ # The base URI of the cone service.
156
+ # [_ra_:]
157
+ # The right ascension search center of the query. May be a floating
158
+ # point number (in degrees), or a full Simple::Parameters::RightAscension
159
+ # object.
160
+ # [_dec_:]
161
+ # The declination search center of the query. May be a floating
162
+ # point number (in degrees), or a full Simple::Parameters::Declination
163
+ # object.
164
+ # [_radius_:]
165
+ # The size of the search radius in degrees.
166
+ # [_parameters_:]
167
+ # A hash of extra parameters to pass to the cone service. Typically
168
+ # this list is empty, but some cone servers permit "extra" parameters
169
+ # to be used.
170
+ # [_:query_timeout_:]
171
+ # Period of time to wait until the remote host don't respond.
172
+ # [_parser_:]
173
+ # A string representing the underlying XML parser to use. Choices
174
+ # right now are 'rexml' and 'libxml'. rexml ships with Ruby, but is
175
+ # slow. libxml is much faster, but of course must be installed
176
+ # separately.
177
+ def initialize(uri, ra, dec, radius, parameters={}, query_timeout=30, parser='rexml')
178
+ parameters ||= {}
179
+
180
+ @uri = uri
181
+ ra(ra)
182
+ dec(dec)
183
+ radius(radius)
184
+ @parameters = parameters
185
+ @query_timeout = query_timeout
186
+ @parser = parser
187
+
188
+ @response = nil
189
+ end
190
+
191
+ # Set or get the value of the RA.
192
+ # Allows a lazy mode where a string representing
193
+ # the right ascension is passed in instead of a full
194
+ # Simple::Parameters::RightAscension object.
195
+ def ra(ra=nil)
196
+ if ra == nil
197
+ return @ra
198
+ else
199
+ if ra.instance_of?(Parameters::RightAscension)
200
+ @ra = ra
201
+ elsif ra.instance_of?(String) or ra.instance_of?(Float) or ra.instance_of?(Fixnum)
202
+ @ra = Parameters::RightAscension.new(ra)
203
+ else
204
+ raise "Right ascension must be RightAscension object or an interparable string."
205
+ end
206
+ end
207
+ end
208
+
209
+ # Set or get the value of the dec.
210
+ # Allows a lazy mode where a string representing
211
+ # the declination is passed in instead of a full
212
+ # Simple::Parameters::Declination object.
213
+ def dec(dec=nil)
214
+ if dec == nil
215
+ return @dec
216
+ else
217
+ if dec.instance_of?(Parameters::Declination)
218
+ @dec = dec
219
+ elsif dec.instance_of?(String) or dec.instance_of?(Float) or dec.instance_of?(Fixnum)
220
+ @dec = Parameters::Declination.new(dec)
221
+ else
222
+ raise "Declination must be a Declination object or an interparable string."
223
+ end
224
+ end
225
+ end
226
+
227
+ # Set or get the value of the search radius (in degrees).
228
+ # Allows a lazy mode where an integer representing the radius
229
+ # is passed in instead of a full
230
+ # Simple::Parameters::Radius object.
231
+ def radius(radius=nil)
232
+ if radius == nil
233
+ return @radius
234
+ else
235
+ if radius.instance_of?(Parameters::Radius)
236
+ @radius = radius
237
+ else
238
+ @radius = Parameters::Radius.new(radius)
239
+ end
240
+ end
241
+ end
242
+
243
+ # Retrieve the list of required parameters. In this case: ra, dec and radius.
244
+ def required_parameters
245
+ [@ra.to_s(), @dec.to_s(), @radius.to_s()]
246
+ end
247
+
248
+ # Convert the query into a valid URL.
249
+ def to_s
250
+ query_uri()
251
+ end
252
+ end
253
+
254
+ # Represents a query to single SSAP server.
255
+ # iso_ssap = Simple::SpectralAccess.new('http://pma.iso.vilspa.esa.es:8080/aio/jsp/siap.jsp',
256
+ # '53.084, -27.873', 10, {:format => 'votable'},
257
+ # 30, 'rexml')
258
+ # iso_ssap.fetch()
259
+ # votable = iso_ssap.marshall()
260
+ class SpectralAccess
261
+ include HTTPGetQuery
262
+ include VOTableMarshaller
263
+
264
+ attr_accessor :uri, :parameters, :query_timeout, :parser, :response
265
+
266
+ # [_uri_:]
267
+ # The base URI of the SSAP service.
268
+ # [_pos_:]
269
+ # The RA and dec position of the search center for the query. May be a string
270
+ # of the form '53.084, -27.873', or a full Simple::Parameters::Position
271
+ # object.
272
+ # [_size_:]
273
+ # The size (in degrees) of the search area.
274
+ # [_parameters_:]
275
+ # A hash of additional parameters to pass to the SSAP service.
276
+ # [_:query_timeout_:]
277
+ # Period of time to wait until the remote host don't respond.
278
+ # [_parser_:]
279
+ # A string representing the underlying XML parser to use. Choices
280
+ # right now are 'rexml' and 'libxml'. rexml ships with Ruby, but is
281
+ # slow. libxml is much faster, but of course must be installed
282
+ # separately.
283
+ def initialize(uri, pos, size, parameters={}, query_timeout=30, parser='rexml')
284
+ parameters ||= {}
285
+
286
+ @uri = uri
287
+ pos(pos)
288
+ size(size)
289
+ @parameters = parameters
290
+ @query_timeout = query_timeout
291
+ @parser = parser
292
+
293
+ @response = nil
294
+ end
295
+
296
+ # Set or get the value of the position.
297
+ # Allows a lazy mode where a string representing
298
+ # the position like '53.084, -27.873'is passed in
299
+ # instead of a full Position object.
300
+ def pos(pos=nil)
301
+ if pos == nil
302
+ return @pos
303
+ else
304
+ # Position. Allow a lazy mode where a string representing
305
+ # the position is passed in instead of a full Position object.
306
+ if pos.instance_of?(Parameters::Position)
307
+ @pos = pos
308
+ elsif pos.instance_of?(String)
309
+ ra_dec, dec_dec = pos.split(/\s*,\s*/)
310
+ @pos = Parameters::Position.new(ra_dec, dec_dec)
311
+ else
312
+ raise "Position must be a Position object or a string like " +
313
+ "'ra_in_decimal_degrees, dec_in_decimal_degrees'"
314
+ end
315
+ end
316
+ end
317
+
318
+ # Set or get the value of the angular size.
319
+ # Allows a lazy mode where a floating point number representing
320
+ # the size is passed in instead of a full Size object.
321
+ def size(size=nil)
322
+ if size == nil
323
+ return @size
324
+ else
325
+ if size.instance_of?(Parameters::Size)
326
+ @size = size
327
+ elsif size.instance_of?(String)
328
+ ra_width, dec_width = size.split(/\s*,\s*/)
329
+ @size = Parameters::Size.new(ra_width, dec_width)
330
+ elsif size.instance_of?(Float) or size.instance_of?(Fixnum)
331
+ @size = Parameters::Size.new(size.to_f())
332
+ else
333
+ raise "Size must be a Size object or a string like " +
334
+ "'ra_width_in_decimal_degrees, dec_width_in_decimal_degrees'"
335
+ end
336
+ end
337
+ end
338
+
339
+ # Retrieve the list of required parameters. In this case: pos and size.
340
+ def required_parameters
341
+ [@pos.to_s(), @size.to_s()]
342
+ end
343
+
344
+ # Convert the query into a valid URL.
345
+ def to_s
346
+ query_uri()
347
+ end
348
+ end
349
+
350
+ # Represents a query to single SIAP server.
351
+ # nsa_siap = Simple::ImageAccess.new('http://archive.noao.edu/nvo/sim/voquery.php',
352
+ # '23:00:00, 2:00:00', 7, nil, 30, 'rexml')
353
+ # nsa_siap.fetch()
354
+ # votable = nsa_siap.marshall()
355
+ class ImageAccess
356
+ include HTTPGetQuery
357
+ include VOTableMarshaller
358
+
359
+ attr_accessor :uri, :parameters, :query_timeout, :parser, :response
360
+
361
+ # [_uri_:]
362
+ # The base URI of the SIAP service.
363
+ # [_pos_:]
364
+ # The RA and dec position of the search center for the query. May be a string
365
+ # of the form '53.084, -27.873', or a full Simple::Parameters::Position
366
+ # object.
367
+ # [_size_:]
368
+ # The size (in degrees) of the search area.
369
+ # [_parameters_:]
370
+ # A hash of additional parameters to pass to the SIAP service.
371
+ # [_:query_timeout_:]
372
+ # Period of time to wait until the remote host don't respond.
373
+ # [_parser_:]
374
+ # A string representing the underlying XML parser to use. Choices
375
+ # right now are 'rexml' and 'libxml'. rexml ships with Ruby, but is
376
+ # slow. libxml is much faster, but of course must be installed
377
+ # separately.
378
+ def initialize(uri, pos, size, parameters={}, query_timeout=30, parser='rexml')
379
+ parameters ||= {}
380
+
381
+ @uri = uri
382
+ pos(pos)
383
+ size(size)
384
+ @parameters = parameters
385
+ @query_timeout = query_timeout
386
+ @parser = parser
387
+
388
+ @response = nil
389
+ end
390
+
391
+ # Set or get the value of the position.
392
+ # Allows a lazy mode where a string representing
393
+ # the position like '53.084, -27.873'is passed in
394
+ # instead of a full Position object.
395
+ def pos(pos=nil)
396
+ if pos == nil
397
+ return @pos
398
+ else
399
+ # Position. Allow a lazy mode where a string representing
400
+ # the position is passed in instead of a full Position object.
401
+ if pos.instance_of?(Parameters::Position)
402
+ @pos = pos
403
+ elsif pos.instance_of?(String)
404
+ ra_dec, dec_dec = pos.split(/\s*,\s*/)
405
+ @pos = Parameters::Position.new(ra_dec, dec_dec)
406
+ else
407
+ raise "Position must be a Position object or a string like " +
408
+ "'ra_in_decimal_degrees, dec_in_decimal_degrees'"
409
+ end
410
+ end
411
+ end
412
+
413
+ # Set or get the value of the angular size.
414
+ # Allows a lazy mode where a floating point number representing
415
+ # the size is passed in instead of a full Size object.
416
+ def size(size=nil)
417
+ if size == nil
418
+ return @size
419
+ else
420
+ if size.instance_of?(Parameters::Size)
421
+ @size = size
422
+ elsif size.instance_of?(String)
423
+ ra_width, dec_width = size.split(/\s*,\s*/)
424
+ @size = Parameters::Size.new(ra_width, dec_width)
425
+ elsif size.instance_of?(Float) or size.instance_of?(Fixnum)
426
+ @size = Parameters::Size.new(size.to_f())
427
+ else
428
+ raise "Size must be a Size object or a string like " +
429
+ "'ra_width_in_decimal_degrees, dec_width_in_decimal_degrees'"
430
+ end
431
+ end
432
+ end
433
+
434
+ # Retrieve the list of required parameters. In this case: pos and size.
435
+ def required_parameters
436
+ [@pos.to_s(), @size.to_s()]
437
+ end
438
+
439
+ # Convert the query into a valid URL.
440
+ def to_s
441
+ query_uri()
442
+ end
443
+ end
444
+
445
+ end
446
+ end
@@ -0,0 +1,3 @@
1
+ require 'voruby/loader'
2
+
3
+ require 'matrix'