read observations
This commit is contained in:
parent
b0cc66969a
commit
a5498624a2
@ -116,6 +116,7 @@ module AVM
|
||||
|
||||
image = new(options)
|
||||
image.creator.from_xml(self, document)
|
||||
Observation.from_xml(image, document)
|
||||
image
|
||||
end
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
module AVM
|
||||
class Observation
|
||||
AVM_SINGLE_FIELDS = %w{Facility Instrument Spectral.ColorAssignment Spectral.Band Spectral.Bandpass Spectral.CentralWavelength Spectral.Notes Temporal.StartTime Temporal.IntegrationTime DatasetID}
|
||||
AVM_SINGLE_METHODS = [ :facility, :instrument, :color_assignment, :band, :bandpass, :wavelength, :notes, :string_start_time, :integration_time, :dataset_id ]
|
||||
AVM_SINGLE_FIELDS = %w{Facility Instrument Spectral.ColorAssignment Spectral.Band Spectral.Bandpass Spectral.CentralWavelength Temporal.StartTime Temporal.IntegrationTime DatasetID}
|
||||
AVM_SINGLE_METHODS = [ :facility, :instrument, :color_assignment, :band, :bandpass, :wavelength, :string_start_time, :integration_time, :dataset_id ]
|
||||
AVM_SINGLES = AVM_SINGLE_FIELDS.zip(AVM_SINGLE_METHODS)
|
||||
|
||||
attr_reader :image, :options
|
||||
|
||||
def initialize(image, options = {})
|
||||
options[:start_time] = options[:string_start_time] if options[:string_start_time]
|
||||
|
||||
@image, @options = image, options
|
||||
end
|
||||
|
||||
@ -14,12 +16,44 @@ module AVM
|
||||
@options[method]
|
||||
end
|
||||
|
||||
def wavelength
|
||||
@options[:wavelength] ? @options[:wavelength].to_f : nil
|
||||
end
|
||||
|
||||
def start_time
|
||||
(Time.parse(@options[:start_time]) rescue nil)
|
||||
end
|
||||
|
||||
def string_start_time
|
||||
start_time.strftime('%Y-%m-%dT%H:%M')
|
||||
if start_time
|
||||
start_time.strftime('%Y-%m-%dT%H:%M')
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.from_xml(image, document)
|
||||
observation_parts = {}
|
||||
|
||||
document.get_refs do |refs|
|
||||
AVM_SINGLES.each do |name, method|
|
||||
if node = refs[:avm].at_xpath(".//avm:#{name}")
|
||||
observation_parts[method] = node.text.split(',').collect(&:strip)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
observation = {}
|
||||
|
||||
observation_parts.each do |method, parts|
|
||||
if part = parts.shift
|
||||
observation[method] = part if part != '-'
|
||||
end
|
||||
end
|
||||
|
||||
image.create_observation(observation) if !observation.empty?
|
||||
end while !observation.empty?
|
||||
end
|
||||
|
||||
def self.add_to_document(document, observations)
|
||||
@ -27,7 +61,7 @@ module AVM
|
||||
AVM_SINGLES.each do |name, method|
|
||||
observations.each do |observation|
|
||||
field_values[name] ||= []
|
||||
field_values[name] << observation.send(method)
|
||||
field_values[name] << (observation.send(method) || '-')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,6 +20,8 @@ describe AVM::Image do
|
||||
let(:redshift) { 'Redshift' }
|
||||
let(:light_years) { 'Light years' }
|
||||
|
||||
it "should have spectral notes"
|
||||
|
||||
def self.with_all_options
|
||||
let(:options) { {
|
||||
:title => title,
|
||||
|
@ -14,7 +14,6 @@ describe AVM::Observation do
|
||||
let(:band) { 'em.opt' }
|
||||
let(:bandpass) { 'B' }
|
||||
let(:wavelength) { 2.5 }
|
||||
let(:notes) { 'Notes' }
|
||||
let(:start_time) { '2010-01-01' }
|
||||
let(:start_time_string) { '2010-01-01T00:00' }
|
||||
let(:integration_time) { '300' }
|
||||
@ -27,32 +26,108 @@ describe AVM::Observation do
|
||||
:band => band,
|
||||
:bandpass => bandpass,
|
||||
:wavelength => wavelength,
|
||||
:notes => notes,
|
||||
:start_time => start_time,
|
||||
:integration_time => integration_time,
|
||||
:dataset_id => dataset_id,
|
||||
} }
|
||||
|
||||
context 'defaults' do
|
||||
let(:second_facility) { 'Chandra' }
|
||||
let(:second_instrument) { 'X-Ray' }
|
||||
let(:second_color_assignment) { 'Green' }
|
||||
let(:second_band) { 'em.x-ray' }
|
||||
let(:second_bandpass) { 'C' }
|
||||
let(:second_wavelength) { nil }
|
||||
let(:second_start_time) { '2010-01-02' }
|
||||
let(:second_start_time_string) { '2010-01-02T00:00' }
|
||||
let(:second_integration_time) { '400' }
|
||||
let(:second_dataset_id) { '23456' }
|
||||
|
||||
let(:second_options) { {
|
||||
:facility => second_facility,
|
||||
:instrument => second_instrument,
|
||||
:color_assignment => second_color_assignment,
|
||||
:band => second_band,
|
||||
:bandpass => second_bandpass,
|
||||
:wavelength => second_wavelength,
|
||||
:start_time => second_start_time,
|
||||
:integration_time => second_integration_time,
|
||||
:dataset_id => second_dataset_id,
|
||||
} }
|
||||
|
||||
def self.check_defaults
|
||||
its(:facility) { should == facility }
|
||||
its(:instrument) { should == instrument }
|
||||
its(:color_assignment) { should == color_assignment }
|
||||
its(:band) { should == band }
|
||||
its(:bandpass) { should == bandpass }
|
||||
its(:wavelength) { should == wavelength }
|
||||
its(:notes) { should == notes }
|
||||
its(:start_time) { should == Time.parse(start_time) }
|
||||
its(:integration_time) { should == integration_time }
|
||||
its(:dataset_id) { should == dataset_id }
|
||||
end
|
||||
|
||||
context 'defaults' do
|
||||
check_defaults
|
||||
end
|
||||
|
||||
describe '.from_xml' do
|
||||
let(:image) { AVM::Image.from_xml(File.read(file_path)) }
|
||||
let(:observations) { image.observations }
|
||||
|
||||
subject { observations }
|
||||
|
||||
context 'no observations' do
|
||||
let(:file_path) { 'spec/sample_files/observation/none.xmp' }
|
||||
|
||||
it { should == [] }
|
||||
end
|
||||
|
||||
context 'one observation' do
|
||||
let(:file_path) { 'spec/sample_files/observation/one.xmp' }
|
||||
|
||||
its(:length) { should == 1 }
|
||||
|
||||
context 'first observation' do
|
||||
subject { observations.first }
|
||||
|
||||
check_defaults
|
||||
end
|
||||
end
|
||||
|
||||
context 'two observations' do
|
||||
let(:file_path) { 'spec/sample_files/observation/two.xmp' }
|
||||
|
||||
its(:length) { should == 2 }
|
||||
|
||||
context 'first observation' do
|
||||
subject { observations.first }
|
||||
|
||||
check_defaults
|
||||
end
|
||||
|
||||
context 'second observation' do
|
||||
subject { observations.last }
|
||||
|
||||
its(:facility) { should == second_facility }
|
||||
its(:instrument) { should == second_instrument }
|
||||
its(:color_assignment) { should == second_color_assignment }
|
||||
its(:band) { should == second_band }
|
||||
its(:bandpass) { should == second_bandpass }
|
||||
its(:wavelength) { should == second_wavelength }
|
||||
its(:start_time) { should == Time.parse(second_start_time) }
|
||||
its(:integration_time) { should == second_integration_time }
|
||||
its(:dataset_id) { should == second_dataset_id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_to_document' do
|
||||
let(:xml) { image.to_xml }
|
||||
let(:avm) { xml.at_xpath('//rdf:Description[@rdf:about="AVM"]') }
|
||||
|
||||
context 'none' do
|
||||
it "should not have any observation information" do
|
||||
%w{Facility Instrument Spectral.ColorAssignment Spectral.Band Spectral.Bandpass Spectral.CentralWavelength Spectral.Notes Temporal.StartTime Temporal.IntegrationTime DatasetID}.each do |name|
|
||||
%w{Facility Instrument Spectral.ColorAssignment Spectral.Band Spectral.Bandpass Spectral.CentralWavelength Temporal.StartTime Temporal.IntegrationTime DatasetID}.each do |name|
|
||||
avm.at_xpath("//avm:#{name}").should be_nil
|
||||
end
|
||||
end
|
||||
@ -69,7 +144,6 @@ describe AVM::Observation do
|
||||
'Spectral.Band' => band,
|
||||
'Spectral.Bandpass' => bandpass,
|
||||
'Spectral.CentralWavelength' => wavelength,
|
||||
'Spectral.Notes' => notes,
|
||||
'Temporal.StartTime' => start_time_string,
|
||||
'Temporal.IntegrationTime' => integration_time,
|
||||
'DatasetID' => dataset_id
|
||||
@ -82,30 +156,6 @@ describe AVM::Observation do
|
||||
context 'two' do
|
||||
let(:second_observation) { image.create_observation(second_options) }
|
||||
|
||||
let(:second_facility) { 'Chandra' }
|
||||
let(:second_instrument) { 'X-Ray' }
|
||||
let(:second_color_assignment) { 'Green' }
|
||||
let(:second_band) { 'em.x-ray' }
|
||||
let(:second_bandpass) { 'C' }
|
||||
let(:second_wavelength) { nil }
|
||||
let(:second_notes) { 'More Notes' }
|
||||
let(:second_start_time) { '2010-01-02' }
|
||||
let(:second_start_time_string) { '2010-01-02T00:00' }
|
||||
let(:second_integration_time) { '400' }
|
||||
let(:second_dataset_id) { '23456' }
|
||||
|
||||
let(:second_options) { {
|
||||
:facility => second_facility,
|
||||
:instrument => second_instrument,
|
||||
:color_assignment => second_color_assignment,
|
||||
:band => second_band,
|
||||
:bandpass => second_bandpass,
|
||||
:wavelength => second_wavelength,
|
||||
:notes => second_notes,
|
||||
:start_time => second_start_time,
|
||||
:integration_time => second_integration_time,
|
||||
:dataset_id => second_dataset_id,
|
||||
} }
|
||||
|
||||
before { observation ; second_observation }
|
||||
|
||||
@ -116,8 +166,7 @@ describe AVM::Observation do
|
||||
'Spectral.ColorAssignment' => [ color_assignment, second_color_assignment ].join(','),
|
||||
'Spectral.Band' => [ band, second_band ].join(','),
|
||||
'Spectral.Bandpass' => [ bandpass, second_bandpass ].join(','),
|
||||
'Spectral.CentralWavelength' => [ wavelength, second_wavelength ].join(','),
|
||||
'Spectral.Notes' => [ notes, second_notes ].join(','),
|
||||
'Spectral.CentralWavelength' => [ wavelength, second_wavelength || '-' ].join(','),
|
||||
'Temporal.StartTime' => [ start_time_string, second_start_time_string ].join(','),
|
||||
'Temporal.IntegrationTime' => [ integration_time, second_integration_time ].join(','),
|
||||
'DatasetID' => [ dataset_id, second_dataset_id ].join(',')
|
||||
@ -125,7 +174,6 @@ describe AVM::Observation do
|
||||
avm.at_xpath("//avm:#{name}").text.should == value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
5
spec/sample_files/observation/none.xmp
Normal file
5
spec/sample_files/observation/none.xmp
Normal file
@ -0,0 +1,5 @@
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:05:41 ">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
17
spec/sample_files/observation/one.xmp
Normal file
17
spec/sample_files/observation/one.xmp
Normal file
@ -0,0 +1,17 @@
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:05:41 ">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:avm="http://www.communicatingastronomy.org/avm/1.0/">
|
||||
<avm:Facility>HST</avm:Facility>
|
||||
<avm:Instrument>ACS</avm:Instrument>
|
||||
<avm:Spectral.ColorAssignment>Blue</avm:Spectral.ColorAssignment>
|
||||
<avm:Spectral.Band>em.opt</avm:Spectral.Band>
|
||||
<avm:Spectral.Bandpass>B</avm:Spectral.Bandpass>
|
||||
<avm:Spectral.CentralWavelength>2.5</avm:Spectral.CentralWavelength>
|
||||
<avm:Temporal.StartTime>2010-01-01T00:00</avm:Temporal.StartTime>
|
||||
<avm:Temporal.IntegrationTime>300</avm:Temporal.IntegrationTime>
|
||||
<avm:DatasetID>12345</avm:DatasetID>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
17
spec/sample_files/observation/two.xmp
Normal file
17
spec/sample_files/observation/two.xmp
Normal file
@ -0,0 +1,17 @@
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:05:41 ">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:avm="http://www.communicatingastronomy.org/avm/1.0/">
|
||||
<avm:Facility>HST,Chandra</avm:Facility>
|
||||
<avm:Instrument>ACS,X-Ray</avm:Instrument>
|
||||
<avm:Spectral.ColorAssignment>Blue,Green</avm:Spectral.ColorAssignment>
|
||||
<avm:Spectral.Band>em.opt,em.x-ray</avm:Spectral.Band>
|
||||
<avm:Spectral.Bandpass>B,C</avm:Spectral.Bandpass>
|
||||
<avm:Spectral.CentralWavelength>2.5,-</avm:Spectral.CentralWavelength>
|
||||
<avm:Temporal.StartTime>2010-01-01T00:00,2010-01-02</avm:Temporal.StartTime>
|
||||
<avm:Temporal.IntegrationTime>300,400</avm:Temporal.IntegrationTime>
|
||||
<avm:DatasetID>12345,23456</avm:DatasetID>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
Loading…
Reference in New Issue
Block a user