Class: VORuby::STC::V1_10::STC::AstroCoordSystemType

Inherits:
CoordSysType
  • Object
show all
Defined in:
lib/voruby/stc/1.10/stc.rb

Overview

The astronomical coordinate system definition: spatial coordinate frame and reference position; time frame and reference position; the coordinate flavor; spectral frame and (optionally) Doppler frame; and the planetary ephemeris; an ID is required, since this is how coordinate elements are associated with their coordinate systems

Direct Known Subclasses

AstroCoordSystem

Instance Attribute Summary collapse

Attributes inherited from CoordSysType

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ AstroCoordSystemType

Returns a new instance of AstroCoordSystemType.



1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File 'lib/voruby/stc/1.10/stc.rb', line 1494

def initialize(options={})
  raise_argument_required_error('time frame') if !options.has_key?(:time_frame)
  raise_argument_required_error('space frame') if !options.has_key?(:space_frame)
  
  frames = []
  frames << options[:time_frame] << options[:space_frame]
  frames << options[:spectral_frame] if options.has_key?(:spectral_frame)
  frames << options[:redshift_frame] if options.has_key?(:redshift_frame)
  options[:generic_coord_frames].each { |f| frames << f } if options.has_key?(:generic_coord_frames) and options[:generic_coord_frames]
  options[:coord_frames] = frames
  
  super(options)
end

Instance Attribute Details

#generic_coord_framesObject

Returns the value of attribute generic_coord_frames.



1492
1493
1494
# File 'lib/voruby/stc/1.10/stc.rb', line 1492

def generic_coord_frames
  @generic_coord_frames
end

#redshift_frameObject

Returns the value of attribute redshift_frame.



1492
1493
1494
# File 'lib/voruby/stc/1.10/stc.rb', line 1492

def redshift_frame
  @redshift_frame
end

#space_frameObject

Returns the value of attribute space_frame.



1492
1493
1494
# File 'lib/voruby/stc/1.10/stc.rb', line 1492

def space_frame
  @space_frame
end

#spectral_frameObject

Returns the value of attribute spectral_frame.



1492
1493
1494
# File 'lib/voruby/stc/1.10/stc.rb', line 1492

def spectral_frame
  @spectral_frame
end

#time_frameObject

Returns the value of attribute time_frame.



1492
1493
1494
# File 'lib/voruby/stc/1.10/stc.rb', line 1492

def time_frame
  @time_frame
end

Class Method Details

.from_xml(xml) ⇒ Object



1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
# File 'lib/voruby/stc/1.10/stc.rb', line 1602

def self.from_xml(xml)
  root = element_from(xml)
  
  options = {
    :id => Id.new(root.attributes.get_attribute_ns(obj_ns.uri, 'ID').value),
    :time_frame => TimeFrame.from_xml(REXML::XPath.first(root, 'x:TimeFrame', {'x' => obj_ns.uri})),
    :space_frame => SpaceFrame.from_xml(REXML::XPath.first(root, 'x:SpaceFrame', {'x' => obj_ns.uri}))
  }
  
  spectral_frame = REXML::XPath.first(root, 'x:SpectralFrame', {'x' => obj_ns.uri})
  options[:spectral_frame] = SpectralFrame.from_xml(spectral_frame) if spectral_frame
  
  redshift_frame = REXML::XPath.first(root, 'x:RedshiftFrame', {'x' => obj_ns.uri})
  options[:redshift_frame] = RedshiftFrame.from_xml(redshift_frame) if redshift_frame
  
  generic_coord_frames = REXML::XPath.match(root, 'x:GenericCoordFrame', {'x' => obj_ns.uri})
  if generic_coord_frames
    options[:generic_coord_frames] = GenericCoordFrameList.new(
      generic_coord_frames.collect{ |f| GenericCoordFrame.from_xml(f) }
    )
    options[:generic_coord_frames] = nil if options[:generic_coord_frames].size == 0
  end
  
  self.new(options)
end

Instance Method Details

#==(s) ⇒ Object



1539
1540
1541
1542
1543
1544
1545
1546
# File 'lib/voruby/stc/1.10/stc.rb', line 1539

def ==(s)
  self.id == s.id and
  self.time_frame == s.time_frame and
  self.space_frame == s.space_frame and
  self.spectral_frame == s.spectral_frame and
  self.redshift_frame == s.redshift_frame and
  self.generic_coord_frames == s.generic_coord_frames
end

#coord_framesObject



1548
1549
1550
1551
1552
1553
1554
1555
1556
# File 'lib/voruby/stc/1.10/stc.rb', line 1548

def coord_frames
  frames = CoordFrameList.new([self.time_frame, self.space_frame])
  
  frames << self.spectral_frame if self.spectral_frame
  frames << self.redshift_frame if self.redshift_frame
  self.generic_coord_frames.each { |f| frames << f } if self.generic_coord_frames
  
  frames
end

#coord_frames=(fs) ⇒ Object



1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
# File 'lib/voruby/stc/1.10/stc.rb', line 1558

def coord_frames=(fs)
  raise_argument_required_error('at least TimeFrame and SpaceFrame') if fs.size < 2
  self.spectral_frame = self.redshift_frame = self.generic_coord_frames = nil
  
  raise_type_mismatch_error(fs[0], TimeFrame)
  self.time_frame = fs[0]

  raise_type_mismatch_error(fs[1], SpaceFrame)
  self.space_frame = fs[1]
  
  if fs.size >= 3 
    raise_type_mismatch_error(fs[2], SpectralFrame)
    self.spectral_frame = fs[2]
  end
  
  if fs.size >= 4
    raise_type_mismatch_error(fs[3], RedshiftFrame)
    self.redshift_frame = fs[3]
  end
    
  if fs.size >= 5
    fs[4..-1].each do |f|
      raise_type_mismatch_error(f, GenericCoordFrame)
    end
    self.generic_coord_frames = GenericCoordFrameList.new(fs[4..-1])
  end
  
  super(fs)
end

#to_xml(name = nil) ⇒ Object



1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
# File 'lib/voruby/stc/1.10/stc.rb', line 1588

def to_xml(name=nil)
  el = element(name)
  el.attributes["#{obj_ns.prefix}:ID"] = self.id.to_s
  
  el.add_element(self.time_frame.to_xml)
  el.add_element(self.space_frame.to_xml)
  el.add_element(self.spectral_frame.to_xml) if self.spectral_frame
  el.add_element(self.redshift_frame.to_xml) if self.redshift_frame
  self.generic_coord_frames.each{ |f| el.add_element(f.to_xml) } if self.generic_coord_frames
  
  collapse_namespaces(el)
  el
end