lib/numru/gphys/assoccoords.rb in gphys-1.2.2.1 vs lib/numru/gphys/assoccoords.rb in gphys-1.4.3

- old
+ new

@@ -1,5 +1,6 @@ +# -*- coding: utf-8 -*- require "narray" #require "numru/gphys_ext" module NumRu @@ -108,10 +109,19 @@ def coord(name) @assoc_crds[name].data # return a VArray end + def replace(gphys) + raise(ArgumentError,"not a GPhys") unless gphys.is_a?(GPhys) + nm = gphys.name + raise("assoc coord '#{nm}' is not found") unless (old=@assoc_crds[nm]) + raise("shapes of the current and new '#{nm}' are different") unless old.shape==gphys.shape + @assoc_crds[nm] = gphys + self + end + def coord_gphys(name) @assoc_crds[name] # return a GPhys end def has_coord?(name) @@ -120,11 +130,11 @@ def coordnames @assoc_crds.keys end - # assoc_crds に関する座標値ベースの切り出し : 引数は Hash のみ + # assoc_crds 縺ォ髢「縺吶k蠎ァ讓吝、繝吶シ繧ケ縺ョ蛻繧雁コ縺 : 蠑墓焚縺ッ Hash 縺ョ縺ソ def cut(hash) cutaxnms = hash.keys newcrds = Array.new slicer_hash = Hash.new @groups.each do |orgaxnms, group| @@ -143,11 +153,11 @@ crdnms.push( nm ) cuts.push( hash[nm] ) anms = @assoc_crds[nm].axnames crdaxexist.push( NArray.to_na( orgaxnms.collect{|a| anms.include?(a) ? 1 : 0} ) ) - v = @assoc_crds[nm].val # 座標値 (NArray or NArrayMiss) + v = @assoc_crds[nm].val # 蠎ァ讓吝、 (NArray or NArrayMiss) if v.is_a?(NArrayMiss) crds.push(v.to_na) masks.push(v.get_mask) else crds.push(v) @@ -219,10 +229,15 @@ else lost_assoc_crds.push( "#{sub.name}=#{sub.val}" ) end end - ret = self.class.new( new_assoc_crds, @axnames ) + axnames = Array.new + args.each_with_index do |a, i| + axnames.push @axnames[i] unless Numeric === a + end + + ret = self.class.new( new_assoc_crds, axnames ) ret.set_lost_coords( lost_assoc_crds ) if !lost_assoc_crds.empty? ret end # make a subset with assoc coords related only to axnames