Class: Cicada::InSituCorrection

Inherits:
Object
  • Object
show all
Defined in:
lib/cicada/correction/in_situ_correction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref_ch, in_situ_ch, corr_ch, iobjs, disable_intercept) ⇒ InSituCorrection

Returns a new instance of InSituCorrection.



29
30
31
32
33
34
35
36
# File 'lib/cicada/correction/in_situ_correction.rb', line 29

def initialize(ref_ch, in_situ_ch, corr_ch, iobjs, disable_intercept)
  self.reference_channel = ref_ch
  self.in_situ_corr_second_channel = in_situ_ch
  self.correction_channel = corr_ch
  @disable_intercept = disable_intercept

  calculate_in_situ_corr(iobjs)
end

Instance Attribute Details

#corr_parametersObject

Returns the value of attribute corr_parameters.



27
28
29
# File 'lib/cicada/correction/in_situ_correction.rb', line 27

def corr_parameters
  @corr_parameters
end

#correction_channelObject

Returns the value of attribute correction_channel.



27
28
29
# File 'lib/cicada/correction/in_situ_correction.rb', line 27

def correction_channel
  @correction_channel
end

#in_situ_corr_second_channelObject

Returns the value of attribute in_situ_corr_second_channel.



27
28
29
# File 'lib/cicada/correction/in_situ_correction.rb', line 27

def in_situ_corr_second_channel
  @in_situ_corr_second_channel
end

#parametersObject

Returns the value of attribute parameters.



27
28
29
# File 'lib/cicada/correction/in_situ_correction.rb', line 27

def parameters
  @parameters
end

#reference_channelObject

Returns the value of attribute reference_channel.



27
28
29
# File 'lib/cicada/correction/in_situ_correction.rb', line 27

def reference_channel
  @reference_channel
end

Instance Method Details

#apply(iobjs) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/cicada/correction/in_situ_correction.rb', line 55

def apply(iobjs)
  corrected_differences = iobjs.map do |iobj|
    corr_diff = iobj.getCorrectedVectorDifferenceBetweenChannels(reference_channel, in_situ_corr_second_channel).toArray.to_a
    expt_diff = iobj.getCorrectedVectorDifferenceBetweenChannels(reference_channel, correction_channel).toArray.to_a
    correction = (corr_diff.ewise * corr_parameters[0]).ewise + corr_parameters[1]
    Vector.elements(expt_diff.ewise - correction, false)
  end

  corrected_differences  
end

#calculate_in_situ_corr(iobjs) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cicada/correction/in_situ_correction.rb', line 42

def calculate_in_situ_corr(iobjs)
  corr_diffs = Matrix.rows(iobjs.map { |iobj| iobj.getCorrectedVectorDifferenceBetweenChannels(reference_channel, in_situ_corr_second_channel).toArray })
  expt_diffs = Matrix.rows(iobjs.map { |iobj| iobj.getCorrectedVectorDifferenceBetweenChannels(reference_channel, correction_channel).toArray })

  bslf = BisquareLinearFit.new
  bslf.disableIntercept if disable_intercept?
  all_parameters = 0.upto(corr_diffs.column_size - 1).collect do |i|
    bslf.fit_rb(corr_diffs.column(i), expt_diffs.column(i)).toArray
  end
 
  self.corr_parameters = all_parameters.transpose
end

#disable_intercept?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cicada/correction/in_situ_correction.rb', line 38

def disable_intercept?
  @disable_intercept
end