lib/numru/vttrac.rb
# Conduct tracking
#
# * tid [Integer or integer NArray]: tracking initial t indices.
#   If Numeric, treated as a constant common for all of x,y,etc.
# * x [float/integer NArray]: Tracking initial template-center x location (index-based; non-integer for subgrid)
# * y [float/integer NArray]: Tracking initial template-center y location (index-based; non-integer for subgrid)
# * vxg [optional float NArray]: vx initial guess (if nil, set to 0)
# * vyg [optional float NArray]: vy initial guess (if nil, set to 0)
# * out_subimage: [false: default, or true] if true, returens the
#   subimages along the track zss (see below)
# 
# REMARK
# The shapes of tid, x, y, vxg, vyg must be the same (rank can be > 1).
# This shape shall be expressed as *sh in what follows.
# e.g. if if the shape of the input arrays are [k,l], the shapes of
# the outputs shall be like, count: [k,l], tid: [ntrac+1,k,l]
# 
# RETURN VALUE
# * An Array containing the following
#   * count (int NArray[*sh])  The number of successful tracking for each initial template.
#   * tid (int NArray[ntrac+1,*sh])  time indices of the trajectories (starting from the initial ones)
#   * x (float NArray[ntrac+1,*sh])  x locations of the trajectories (starting from the initial ones)
#   * y (float NArray[ntrac+1,*sh])  y locations of the trajectories (starting from the initial ones)
#   * vx (float NArray[ntrac,*sh])  Derived x-velocity
#   * vy (float NArray[ntrac,*sh])  Derived y-velocity
#   * score (float NArray[ntrac,*sh])  Scores along the trajectory (max values, possibly at subgrid)
#   * zss  (nil if !out_subimage, or 4D NArray[nsx,nsy, ntrac+1,*sh])
#     the entire subimages along the tracks  (including the initial one)
#   * score_ary (nil if !out_subimage, or 4D NArray[(x-sliding size),(y-sliding size), ntrac+1,*sh])
#     the entire scores
# 
Conduct tracking
tid [Integer or integer NArray]: tracking initial t indices.
If Numeric, treated as a constant common for all of x,y,etc.

REMARK
The shapes of tid, x, y, vxg, vyg must be the same (rank can be > 1).
This shape shall be expressed as *sh in what follows.

RETURN VALUE
An Array containing the following
count (int NArray[*sh])  The number of successful tracking for each initial template.
Conduct tracking tid [ Integer or integer NArray ] : tracking initial t indices . If Numeric treated as a constant common for all of x y etc . REMARK The shapes of tid x y vxg vyg must be the same ( rank can be > 1 ) . This shape shall be expressed as * sh in what follows . RETURN VALUE An Array containing the following count ( int NArray [ * sh ] ) The number of successful tracking for each initial template .
def trac(tid, x, y, vxg: nil, vyg: nil,
             out_subimage: false, out_score_ary: false)
      raise(ArgumentError,"Need to call #setup in advance") unless @setup
      sh = x.shape
      if tid.is_a?(Integer)
        tid = NArray.int(*sh).fill!(tid)
      else
        raise(ArgumentError,"Shape miss-match (x)") if tid.shape != sh
      end
      raise(ArgumentError,"Shape miss-match (y)") if y.shape != sh 
      if vxg.nil?
        vxg = NArray.float(*sh)
      else
        raise(ArgumentError,"Shape miss-match (vxg)") if vxg.shape != sh
      end
      if vyg.nil?
        vyg = NArray.float(*sh)
      else
        raise(ArgumentError,"Shape miss-match (vyg)") if vyg.shape != sh
      end
      if !tid.is_a?(NArray) || tid.typecode!=NArray::INT
        raise("tid != int NArray")
      end
      result = super(tid, x, y, vxg, vyg, out_subimage, out_score_ary)
      result[2..6] = result[2..6].map{|na| NArrayMiss.to_nam(na, na.ne(rmiss))}
      if sh.length >= 2
        result[0] = result[0].reshape(*sh)
        result[1..8] = result[1..8].map{|na|
          if na
            newshape = na.shape[0..-2] + sh
            na.reshape(*newshape)
          else
            na
          end
        }
      end
      result
    end
def trac ( tid , x , y , vxg : nil , vyg : nil , out_subimage : false , out_score_ary : false ) raise ( ArgumentError , "Need to call #setup in advance" ) unless @setup sh = x . shape if tid . is_a? ( Integer ) tid = NArray . int ( * sh ) . fill! ( tid ) else raise ( ArgumentError , "Shape miss-match (x)" ) if tid . shape != sh end raise ( ArgumentError , "Shape miss-match (y)" ) if y . shape != sh if vxg . nil? vxg = NArray . float ( * sh ) else raise ( ArgumentError , "Shape miss-match (vxg)" ) if vxg . shape != sh end if vyg . nil? vyg = NArray . float ( * sh ) else raise ( ArgumentError , "Shape miss-match (vyg)" ) if vyg . shape != sh end if ! tid . is_a? ( NArray ) || tid . typecode != NArray :: INT raise ( "tid != int NArray" ) end result = super ( tid , x , y , vxg , vyg , out_subimage , out_score_ary ) result [ 2 .. 6 ] = result [ 2 .. 6 ] . map { | na | NArrayMiss . to_nam ( na , na . ne ( rmiss ) ) } if sh . length >= 2 result [ 0 ] = result [ 0 ] . reshape ( * sh ) result [ 1 .. 8 ] = result [ 1 .. 8 ] . map { | na | if na newshape = na . shape [ 0 .. - 2 ] + sh na . reshape ( * newshape ) else na end } end result end
Conduct tracking
 tid [Integer or integer NArray]: tracking initial t indices.
Conduct tracking tid [ Integer or integer NArray ] : tracking initial t indices .
# reshape outputs based on the shape of inputs
tid
x
y
vxg
vyg
out_subimage
out_score_ary