refactoring and read more avm data
This commit is contained in:
parent
88ded74b76
commit
1e3080ddc7
18
lib/avm/controlled_vocabulary.rb
Normal file
18
lib/avm/controlled_vocabulary.rb
Normal file
@ -0,0 +1,18 @@
|
||||
module AVM
|
||||
module ControlledVocabulary
|
||||
class << self
|
||||
def included(klass)
|
||||
klass::TERMS.each do |type|
|
||||
new_klass = Class.new do
|
||||
def to_s
|
||||
self.class.to_s.split('::').last
|
||||
end
|
||||
end
|
||||
|
||||
klass.const_set(type.to_sym, new_klass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
10
lib/avm/coordinate_frame.rb
Normal file
10
lib/avm/coordinate_frame.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'avm/controlled_vocabulary'
|
||||
|
||||
module AVM
|
||||
module CoordinateFrame
|
||||
TERMS = %w{ICRS FK5 FK4 ECL GAL SGAL}
|
||||
|
||||
include ControlledVocabulary
|
||||
end
|
||||
end
|
||||
|
10
lib/avm/coordinate_system_projection.rb
Normal file
10
lib/avm/coordinate_system_projection.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'avm/controlled_vocabulary'
|
||||
|
||||
module AVM
|
||||
module CoordinateSystemProjection
|
||||
TERMS = %w{TAN SIN ARC AIT CAR CEA}
|
||||
|
||||
include ControlledVocabulary
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,9 @@ require 'avm/creator'
|
||||
require 'avm/xmp'
|
||||
require 'avm/image_type'
|
||||
require 'avm/image_quality'
|
||||
require 'avm/spatial_quality'
|
||||
require 'avm/coordinate_system_projection'
|
||||
require 'avm/coordinate_frame'
|
||||
require 'avm/observation'
|
||||
|
||||
module AVM
|
||||
@ -16,7 +19,20 @@ module AVM
|
||||
'Date',
|
||||
'ID',
|
||||
'Type',
|
||||
'Image.ProductQuality'
|
||||
'Image.ProductQuality',
|
||||
'Spatial.Equinox',
|
||||
'Spatial.Rotation',
|
||||
'Spatial.Notes',
|
||||
'Spatial.FITSheader',
|
||||
'Spatial.Quality',
|
||||
'Spatial.CoordsystemProjection',
|
||||
'Spatial.CDMatrix',
|
||||
'Spatial.Scale',
|
||||
'Spatial.ReferencePixel',
|
||||
'Spatial.ReferenceDimension',
|
||||
'Spatial.ReferenceValue',
|
||||
'Spatial.Equinox',
|
||||
'Spatial.CoordinateFrame'
|
||||
]
|
||||
|
||||
AVM_SINGLE_METHODS = [
|
||||
@ -27,7 +43,20 @@ module AVM
|
||||
:date,
|
||||
:id,
|
||||
:type,
|
||||
:quality
|
||||
:quality,
|
||||
:spatial_equinox,
|
||||
:spatial_rotation,
|
||||
:spatial_notes,
|
||||
:fits_header,
|
||||
:spatial_quality,
|
||||
:coordinate_system_projection,
|
||||
:spatial_cd_matrix,
|
||||
:spatial_scale,
|
||||
:reference_pixel,
|
||||
:reference_dimension,
|
||||
:reference_value,
|
||||
:equinox,
|
||||
:coordinate_frame
|
||||
]
|
||||
|
||||
AVM_SINGLE_MESSAGES = [
|
||||
@ -38,16 +67,50 @@ module AVM
|
||||
:string_date,
|
||||
:id,
|
||||
:image_type,
|
||||
:image_quality
|
||||
:image_quality,
|
||||
:spatial_equinox,
|
||||
:spatial_rotation,
|
||||
:spatial_notes,
|
||||
:fits_header,
|
||||
:spatial_quality,
|
||||
:coordinate_system_projection,
|
||||
:spatial_cd_matrix,
|
||||
:spatial_scale,
|
||||
:reference_pixel,
|
||||
:reference_dimension,
|
||||
:reference_value,
|
||||
:equinox,
|
||||
:coordinate_frame
|
||||
]
|
||||
|
||||
AVM_SINGLES = AVM_SINGLE_FIELDS.zip(AVM_SINGLE_METHODS)
|
||||
|
||||
AVM_TO_FLOAT = [
|
||||
:spatial_rotation,
|
||||
:spatial_cd_matrix,
|
||||
:spatial_scale,
|
||||
:reference_pixel,
|
||||
:reference_dimension,
|
||||
:reference_value
|
||||
]
|
||||
|
||||
attr_reader :creator, :observations
|
||||
|
||||
def initialize(options = {})
|
||||
@creator = AVM::Creator.new(self)
|
||||
@options = options
|
||||
|
||||
AVM_TO_FLOAT.each do |field|
|
||||
if @options[field]
|
||||
case @options[field]
|
||||
when Array
|
||||
@options[field].collect!(&:to_f)
|
||||
else
|
||||
@options[field] = @options[field].to_f
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@observations = []
|
||||
end
|
||||
|
||||
@ -95,11 +158,23 @@ module AVM
|
||||
end
|
||||
|
||||
def image_type
|
||||
(AVM::ImageType.const_get(@options[:type].to_sym).new rescue nil)
|
||||
cv_class_instance_for(AVM::ImageType, :type)
|
||||
end
|
||||
|
||||
def image_quality
|
||||
(AVM::ImageQuality.const_get(@options[:quality].to_sym).new rescue nil)
|
||||
cv_class_instance_for(AVM::ImageQuality, :quality)
|
||||
end
|
||||
|
||||
def spatial_quality
|
||||
cv_class_instance_for(AVM::SpatialQuality, :spatial_quality)
|
||||
end
|
||||
|
||||
def coordinate_frame
|
||||
cv_class_instance_for(AVM::CoordinateFrame, :coordinate_frame)
|
||||
end
|
||||
|
||||
def coordinate_system_projection
|
||||
cv_class_instance_for(AVM::CoordinateSystemProjection, :coordinate_system_projection)
|
||||
end
|
||||
|
||||
def date
|
||||
@ -129,9 +204,13 @@ module AVM
|
||||
|
||||
AVM_SINGLES.each do |tag, field|
|
||||
if node = refs[:avm].at_xpath("./avm:#{tag}")
|
||||
if !(list_items = node.search('.//rdf:li')).empty?
|
||||
options[field] = list_items.collect(&:text)
|
||||
else
|
||||
options[field] = node.text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if node = refs[:photoshop].at_xpath('./photoshop:Headline')
|
||||
options[:headline] = node.text
|
||||
@ -168,6 +247,10 @@ module AVM
|
||||
def rdf_li(text)
|
||||
%{<rdf:li>#{text}</rdf:li>}
|
||||
end
|
||||
|
||||
def cv_class_instance_for(mod, field)
|
||||
(mod.const_get(@options[field].to_sym).new rescue nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
require 'avm/controlled_vocabulary'
|
||||
|
||||
module AVM
|
||||
module ImageQuality
|
||||
%w{Good Moderate Poor}.each do |type|
|
||||
klass = Class.new do
|
||||
def to_s
|
||||
self.class.to_s.split('::').last
|
||||
end
|
||||
end
|
||||
TERMS = %w{Good Moderate Poor}
|
||||
|
||||
AVM::ImageQuality.const_set(type.to_sym, klass)
|
||||
end
|
||||
include AVM::ControlledVocabulary
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
require 'avm/controlled_vocabulary'
|
||||
|
||||
module AVM
|
||||
module ImageType
|
||||
%w{Observation Artwork Photographic Planetary Simulation Chart Collage}.each do |type|
|
||||
klass = Class.new do
|
||||
def to_s
|
||||
self.class.to_s.split('::').last
|
||||
end
|
||||
end
|
||||
TERMS = %w{Observation Artwork Photographic Planetary Simulation Chart Collage}
|
||||
|
||||
AVM::ImageType.const_set(type.to_sym, klass)
|
||||
end
|
||||
include ControlledVocabulary
|
||||
end
|
||||
end
|
||||
|
||||
|
10
lib/avm/spatial_quality.rb
Normal file
10
lib/avm/spatial_quality.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'avm/controlled_vocabulary'
|
||||
|
||||
module AVM
|
||||
module SpatialQuality
|
||||
TERMS = %w{Full Position}
|
||||
|
||||
include AVM::ControlledVocabulary
|
||||
end
|
||||
end
|
||||
|
@ -21,6 +21,21 @@ describe AVM::Image do
|
||||
let(:redshift) { 'Redshift' }
|
||||
let(:light_years) { 'Light years' }
|
||||
|
||||
let(:coordinate_frame) { 'ICRS' }
|
||||
let(:equinox) { '100' }
|
||||
let(:reference_value) { [ 100, 50 ] }
|
||||
let(:reference_dimension) { [ 200, 150 ] }
|
||||
let(:reference_pixel) { [ 25, 15 ] }
|
||||
let(:spatial_scale) { [ 40, 35 ] }
|
||||
let(:spatial_rotation) { 10 }
|
||||
let(:coordinate_system_projection) { 'TAN' }
|
||||
let(:spatial_quality) { 'Full' }
|
||||
let(:spatial_notes) { 'Spatial Notes' }
|
||||
let(:fits_header) { 'FITS header' }
|
||||
let(:spatial_cd_matrix) { [ 1, 2, 3, 4 ] }
|
||||
|
||||
it "should have spatial information"
|
||||
|
||||
def self.with_all_options
|
||||
let(:options) { {
|
||||
:title => title,
|
||||
@ -35,7 +50,19 @@ describe AVM::Image do
|
||||
:type => type,
|
||||
:quality => image_quality,
|
||||
:redshift => redshift,
|
||||
:light_years => light_years
|
||||
:light_years => light_years,
|
||||
:coordinate_frame => coordinate_frame,
|
||||
:equinox => equinox,
|
||||
:reference_value => reference_value,
|
||||
:reference_dimension => reference_dimension,
|
||||
:reference_pixel => reference_pixel,
|
||||
:spatial_scale => spatial_scale,
|
||||
:spatial_rotation => spatial_rotation,
|
||||
:coordinate_system_projection => coordinate_system_projection,
|
||||
:spatial_quality => spatial_quality,
|
||||
:spatial_notes => spatial_notes,
|
||||
:fits_header => fits_header,
|
||||
:spatial_cd_matrix => spatial_cd_matrix,
|
||||
} }
|
||||
end
|
||||
|
||||
@ -52,6 +79,19 @@ describe AVM::Image do
|
||||
its(:id) { should == id }
|
||||
its(:image_type) { should be_a_kind_of eval("AVM::ImageType::#{type}") }
|
||||
its(:image_quality) { should be_a_kind_of eval("AVM::ImageQuality::#{image_quality}") }
|
||||
|
||||
its(:coordinate_frame) { should be_a_kind_of eval("AVM::CoordinateFrame::#{coordinate_frame}") }
|
||||
its(:equinox) { should == equinox }
|
||||
its(:reference_value) { should == reference_value }
|
||||
its(:reference_dimension) { should == reference_dimension }
|
||||
its(:reference_pixel) { should == reference_pixel }
|
||||
its(:spatial_scale) { should == spatial_scale }
|
||||
its(:spatial_rotation) { should == spatial_rotation }
|
||||
its(:coordinate_system_projection) { should be_a_kind_of eval("AVM::CoordinateSystemProjection::#{coordinate_system_projection}") }
|
||||
its(:spatial_quality) { should be_a_kind_of eval("AVM::SpatialQuality::#{spatial_quality}") }
|
||||
its(:spatial_notes) { should == spatial_notes }
|
||||
its(:fits_header) { should == fits_header }
|
||||
its(:spatial_cd_matrix) { should == spatial_cd_matrix }
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
@ -72,19 +112,16 @@ describe AVM::Image do
|
||||
context "nothing in it" do
|
||||
let(:file_path) { 'spec/sample_files/image/nothing.xmp' }
|
||||
|
||||
its(:title) { should be_nil }
|
||||
its(:headline) { should be_nil }
|
||||
its(:description) { should be_nil }
|
||||
its(:distance_notes) { should be_nil }
|
||||
its(:spectral_notes) { should be_nil }
|
||||
its(:reference_url) { should be_nil }
|
||||
its(:credit) { should be_nil }
|
||||
its(:date) { should be_nil }
|
||||
its(:id) { should be_nil }
|
||||
its(:image_type) { should be_nil }
|
||||
its(:image_quality) { should be_nil }
|
||||
its(:redshift) { should be_nil }
|
||||
its(:light_years) { should be_nil }
|
||||
[ :title, :headline, :description, :distance_notes,
|
||||
:spectral_notes, :reference_url, :credit, :date,
|
||||
:id, :image_type, :image_quality, :redshift,
|
||||
:light_years, :coordinate_frame, :equinox, :reference_value,
|
||||
:reference_dimension, :reference_pixel, :spatial_scale,
|
||||
:spatial_rotation, :coordinate_system_projection, :spatial_quality, :spatial_notes,
|
||||
:fits_header, :spatial_cd_matrix
|
||||
].each do |field|
|
||||
its(field) { should be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
context "image in it" do
|
||||
|
@ -39,6 +39,45 @@
|
||||
<rdf:li>Redshift</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Distance>
|
||||
<avm:Spatial.CoordinateFrame>ICRS</avm:Spatial.CoordinateFrame>
|
||||
<avm:Spatial.Equinox>100</avm:Spatial.Equinox>
|
||||
<avm:Spatial.ReferenceValue>
|
||||
<rdf:Seq>
|
||||
<rdf:li>100</rdf:li>
|
||||
<rdf:li>50</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceValue>
|
||||
<avm:Spatial.ReferenceDimension>
|
||||
<rdf:Seq>
|
||||
<rdf:li>200</rdf:li>
|
||||
<rdf:li>150</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceDimension>
|
||||
<avm:Spatial.ReferencePixel>
|
||||
<rdf:Seq>
|
||||
<rdf:li>25</rdf:li>
|
||||
<rdf:li>15</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferencePixel>
|
||||
<avm:Spatial.Scale>
|
||||
<rdf:Seq>
|
||||
<rdf:li>40</rdf:li>
|
||||
<rdf:li>35</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.Scale>
|
||||
<avm:Spatial.Rotation>10</avm:Spatial.Rotation>
|
||||
<avm:Spatial.CoordsystemProjection>TAN</avm:Spatial.CoordsystemProjection>
|
||||
<avm:Spatial.Quality>Full</avm:Spatial.Quality>
|
||||
<avm:Spatial.Notes>Spatial Notes</avm:Spatial.Notes>
|
||||
<avm:Spatial.FITSheader>FITS header</avm:Spatial.FITSheader>
|
||||
<avm:Spatial.CDMatrix>
|
||||
<rdf:Seq>
|
||||
<rdf:li>1</rdf:li>
|
||||
<rdf:li>2</rdf:li>
|
||||
<rdf:li>3</rdf:li>
|
||||
<rdf:li>4</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.CDMatrix>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
@ -12,7 +12,6 @@
|
||||
<rdf:li xml:lang="x-default">Description</rdf:li>
|
||||
</rdf:Alt>
|
||||
</dc:description>
|
||||
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/">
|
||||
@ -34,6 +33,45 @@
|
||||
<avm:Type>Observation</avm:Type>
|
||||
<avm:Image.ProductQuality>Good</avm:Image.ProductQuality>
|
||||
<avm:Distance><rdf:Seq><rdf:li>Light years</rdf:li></rdf:Seq></avm:Distance>
|
||||
<avm:Spatial.CoordinateFrame>ICRS</avm:Spatial.CoordinateFrame>
|
||||
<avm:Spatial.Equinox>100</avm:Spatial.Equinox>
|
||||
<avm:Spatial.ReferenceValue>
|
||||
<rdf:Seq>
|
||||
<rdf:li>100</rdf:li>
|
||||
<rdf:li>50</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceValue>
|
||||
<avm:Spatial.ReferenceDimension>
|
||||
<rdf:Seq>
|
||||
<rdf:li>200</rdf:li>
|
||||
<rdf:li>150</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceDimension>
|
||||
<avm:Spatial.ReferencePixel>
|
||||
<rdf:Seq>
|
||||
<rdf:li>25</rdf:li>
|
||||
<rdf:li>15</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferencePixel>
|
||||
<avm:Spatial.Scale>
|
||||
<rdf:Seq>
|
||||
<rdf:li>40</rdf:li>
|
||||
<rdf:li>35</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.Scale>
|
||||
<avm:Spatial.Rotation>10</avm:Spatial.Rotation>
|
||||
<avm:Spatial.CoordsystemProjection>TAN</avm:Spatial.CoordsystemProjection>
|
||||
<avm:Spatial.Quality>Full</avm:Spatial.Quality>
|
||||
<avm:Spatial.Notes>Spatial Notes</avm:Spatial.Notes>
|
||||
<avm:Spatial.FITSheader>FITS header</avm:Spatial.FITSheader>
|
||||
<avm:Spatial.CDMatrix>
|
||||
<rdf:Seq>
|
||||
<rdf:li>1</rdf:li>
|
||||
<rdf:li>2</rdf:li>
|
||||
<rdf:li>3</rdf:li>
|
||||
<rdf:li>4</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.CDMatrix>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
@ -39,6 +39,45 @@
|
||||
<rdf:li>Redshift</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Distance>
|
||||
<avm:Spatial.CoordinateFrame>ICRS</avm:Spatial.CoordinateFrame>
|
||||
<avm:Spatial.Equinox>100</avm:Spatial.Equinox>
|
||||
<avm:Spatial.ReferenceValue>
|
||||
<rdf:Seq>
|
||||
<rdf:li>100</rdf:li>
|
||||
<rdf:li>50</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceValue>
|
||||
<avm:Spatial.ReferenceDimension>
|
||||
<rdf:Seq>
|
||||
<rdf:li>200</rdf:li>
|
||||
<rdf:li>150</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferenceDimension>
|
||||
<avm:Spatial.ReferencePixel>
|
||||
<rdf:Seq>
|
||||
<rdf:li>25</rdf:li>
|
||||
<rdf:li>15</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.ReferencePixel>
|
||||
<avm:Spatial.Scale>
|
||||
<rdf:Seq>
|
||||
<rdf:li>40</rdf:li>
|
||||
<rdf:li>35</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.Scale>
|
||||
<avm:Spatial.Rotation>10</avm:Spatial.Rotation>
|
||||
<avm:Spatial.CoordsystemProjection>TAN</avm:Spatial.CoordsystemProjection>
|
||||
<avm:Spatial.Quality>Full</avm:Spatial.Quality>
|
||||
<avm:Spatial.Notes>Spatial Notes</avm:Spatial.Notes>
|
||||
<avm:Spatial.FITSheader>FITS header</avm:Spatial.FITSheader>
|
||||
<avm:Spatial.CDMatrix>
|
||||
<rdf:Seq>
|
||||
<rdf:li>1</rdf:li>
|
||||
<rdf:li>2</rdf:li>
|
||||
<rdf:li>3</rdf:li>
|
||||
<rdf:li>4</rdf:li>
|
||||
</rdf:Seq>
|
||||
</avm:Spatial.CDMatrix>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
Loading…
Reference in New Issue
Block a user