class Object

Public Instance Methods

SampleDBstore() click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-11-21

Deprecated

Use SampleDBstore3.rb instead.

– Function –

This is a sample procedure for using the LABCOM system's dbStore.

Data name to be registered:

LABCOM

Shot number to be registered:

90000001

Sub-Shot number to be registered:

1

– Usage –

$ SampleDBstore.rb

# File bin/SampleDBstore.rb, line 22
def SampleDBstore()
  p 'START SampleDBstore.rb'
  begin
    p Labcom::Retriever.version()
    p Labcom::DBstorer.version()
    r = Labcom::Retriever.new()
    p 'get with retrieve'
    x = r.get("RADH",117576,1,[2,3,9])
    p 'put by dbstore'
    d = Labcom::DBstorer.new()
    d.puts(90000001,1,"LABCOM","imazu@nifs.ac.jp","raw",x)
      
  rescue => ex
    p 'SampleDBstore ',ex.message
  end
  p 'END SampleDBstore.rb'
end
SampleDBstore3() click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-11-21

– Function –

This is a sample procedure for using the LABCOM system's dbStore.

Data name to be registered:

LABCOM

Shot number to be registered:

90000001

Sub-Shot number to be registered:

3

– Usage –

$ SampleDBstore3.rb

# File bin/SampleDBstore3.rb, line 22
def SampleDBstore3()
  p 'START SampleDBstore3.rb'
  begin
    p Labcom3::DBstorer.version()
    r = Labcom3::Retriever.new()
    p 'get with retrieve'
    x = r.get("RADH",117576,1,[2,3,9])
    p 'put by dbstore( LABCOM 90000001 3 ) '
    d = Labcom3::DBstorer.new()
    d.puts(90000001,3,"LABCOM","imazu@nifs.ac.jp","ana",x)
      
  rescue => ex
    p 'SampleDBstore3 ',ex.message
  end
  p 'END SampleDBstore.rb'
end
SampleImage(diag, shot, subshot, channel, frame, host=nil, path=nil) click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-11-21

Deprecated

Use SampleImage3.rb instead.

– Function –

This is a sample procedure that draws image data stored in the LABCOM system.

– Usage –

$ SampleImage.rb [options] diag shot subshot channel frame

diag

Diagnostics name

shot

Shot number

subshot

Sub-Shot number

frame

frame number

options:
- - host hostname :

host name for direct connection.

- - path pathname :

path name for direct connection.

# File bin/SampleImage.rb, line 28
def SampleImage(diag, shot, subshot, channel, frame, host=nil, path=nil)
  begin
    Warning[:deprecated] = true
    warn("Deprecated SampleImage.rb !", category: :deprecated)
    p Labcom::Retriever.version()+" "+Magick::Version
    magick_ver=Magick::Version.split(/[.| ]/)
    r = Labcom::Retriever.new(0, host, path, 0)
#   ad = r.get("ECH_2Occd",112000,1,1)
#   ad = r.get_frames("ECH_2Occd",112000,1,1,50)
#   fidx = 0
#   ad = r.get("ECH_2Occd",110000,1,1)
#   fidx = 100
    ad = r.get(diag, shot, subshot, channel)
    fidx = frame - 1
    width     = ad.parameters['AcquisitionWindowWidth'] 
    height    = ad.parameters['AcquisitionWindowHeight']
    imagetype = ad.parameters['ImageType']
    sampledframe = ad.parameters['SampledFrame']
    if( sampledframe != nil ) then
       if( Integer(sampledframe) < frame ) then
         p "Not found frame number "+frame.to_s+" (Max:"+sampledframe.to_s+")"
         return
       end
    end
    if( imagetype == 'YUV422' or imagetype == 'YUY2' ) then
      pxls = ad.converted_rgb()  
      if( Integer(magick_ver[1]) < 6 ) then 
        img = Magick::Image.new(width,height){self.background_color = 'white' }
      else
        img = Magick::Image.new(width,height){|options| options.background_color = "white" }
      end
      img.colorspace = Magick::RGBColorspace
      if defined?(Magick::MAGICKCORE_QUANTUM_DEPTH)
        q_depth = Magick::MAGICKCORE_QUANTUM_DEPTH
      else
        q_depth = Magick::QuantumDepth
      end

      if( q_depth == 16 ) then
        for y in 0...img.rows
          for x in 0...img.columns
            img.pixel_color( x,y,Magick::Pixel.new(pxls[0, x, y, fidx]<<8,pxls[1, x, y, fidx]<<8,pxls[2, x, y, fidx]<<8) )
          end
        end
      else
        for y in 0...img.rows
          for x in 0...img.columns
            img.pixel_color( x,y,Magick::Pixel.new(pxls[0, x, y, fidx],pxls[1, x, y, fidx],pxls[2, x, y, fidx]) )
          end
        end
      end
      img.display 
    else
      pxl = ad.val()  
      if( Integer(magick_ver[1]) < 6 ) then 
        img = Magick::Image.new(width,height){self.background_color = 'white' }
      else
        img = Magick::Image.new(width,height){|options| options.background_color = "white" }
      end
      img.colorspace = Magick::GRAYColorspace
      psizes = pxl.sizes
      pmax = pxl[0..psizes[0]-1,0..psizes[1]-1,fidx].max
      puts "max pixel ="+pmax.to_s

      shift_n = 0
      if( pmax > 0 ) then
        if defined?(Magick::MAGICKCORE_QUANTUM_DEPTH)
           q_depth = Magick::MAGICKCORE_QUANTUM_DEPTH
        else
           q_depth = Magick::QuantumDepth
        end
        if( q_depth == 16 ) then
          max_bit_pattern = 0b1000000000000000
        else
          max_bit_pattern = 0b10000000
        end

        while( shift_n < 16 ) do
          break if (pmax & max_bit_pattern ) != 0
          pmax <<= 1
          shift_n += 1
        end
      end

      for y in 0...img.rows
        for x in 0...img.columns
#         val = pxl[x,y,fidx]*256
          val = pxl[x,y,fidx] << shift_n
          img.pixel_color(x,y,Magick::Pixel.new(val,val,val))
        end
      end
      puts "shift bits="+shift_n.to_s
      puts "max pixel ="+pmax.to_s
      img.display 
    end

  rescue => ex
    p ex.message
  end
  p "Stop" # TODO
end
SampleImage3(diag, shot, subshot, channel, frame, host=nil, path=nil, img_title=nil, img_file=nil) click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-12-02

– Function –

This is a sample procedure that draws image data stored in the LABCOM system.

– Usage –

$ SampleImage3.rb [options] diag shot subshot channel frame

diag

Diagnostics name

shot

Shot number

subshot

Sub-Shot number

frame

frame number

options:
- - write filename :

Writes the image to the specified file. Determines image format from the prefix or extension.

- - notitle :

without titile

- - host hostname :

host name for direct connection.

- - path pathname :

path name for direct connection.

- - display :

to display ( Windows only, May be not supported by ImageMagick. )

# File bin/SampleImage3.rb, line 29
def SampleImage3(diag, shot, subshot, channel, frame, host=nil, path=nil, img_title=nil, img_file=nil)
  begin
    p Labcom3::Retriever.version()+" "+Magick::Version
    magick_ver=Magick::Version.split(/[.| ]/)
    r = Labcom3::Retriever.new(0, host, path, 0)
#   ad = r.get("ECH_2Occd",112000,1,1)
#   ad = r.get_frames("ECH_2Occd",112000,1,1,50)
#   fidx = 0
#   ad = r.get("ECH_2Occd",110000,1,1)
#   fidx = 100
    ad = r.get(diag, shot, subshot, channel)
    fidx = frame - 1
    width     = ad.parameters['AcquisitionWindowWidth'] 
    height    = ad.parameters['AcquisitionWindowHeight']
    imagetype = ad.parameters['ImageType']
    sampledframe = ad.parameters['SampledFrame']
    if( sampledframe != nil ) then
       if( Integer(sampledframe) < frame ) then
         p "Not found frame number "+frame.to_s+" (Max:"+sampledframe.to_s+")"
         return
       end
    end
    if( imagetype == 'YUV422' or imagetype == 'YUY2' ) then
      pxls = ad.converted_rgb()  
      if( Integer(magick_ver[1]) < 6 ) then 
        img = Magick::Image.new(width,height){self.background_color = 'white' }
      else
        img = Magick::Image.new(width,height){|options| options.background_color = "white" }
      end
      img.colorspace = Magick::RGBColorspace
      if defined?(Magick::MAGICKCORE_QUANTUM_DEPTH)
        q_depth = Magick::MAGICKCORE_QUANTUM_DEPTH
      else
        q_depth = Magick::QuantumDepth
      end

      if( q_depth == 16 ) then
        for y in 0...img.rows
          for x in 0...img.columns
            img.pixel_color( x,y,Magick::Pixel.new(pxls[fidx, y, x, 0]<<8,pxls[fidx, y, x, 1]<<8,pxls[fidx, y, x, 2]<<8) )
          end
        end
      else
        for y in 0...img.rows
          for x in 0...img.columns
            img.pixel_color( x,y,Magick::Pixel.new(pxls[fidx, y, x, 0],pxls[fidx, y, x, 1],pxls[fidx, y, x, 2]) )
          end
        end
      end
      if( nil != img_title )then
        gc = Magick::Draw.new
        gc.fill('white')
        gc.text(width-(img_title.length+2)*8, height-20, img_title)
        gc.draw(img)
      end
      if( nil == img_file ) then
        img.display
      else
        img.write(img_file)
        puts 'save to '+img_file+ ' .'
      end 
    else
      pxl = ad.val()  
      if( Integer(magick_ver[1]) < 6 ) then 
        img = Magick::Image.new(width,height){self.background_color = 'white' }
      else
        img = Magick::Image.new(width,height){|options| options.background_color = "white" }
      end
      img.colorspace = Magick::GRAYColorspace
      psizes = pxl.shape
      pmax = pxl[fidx,0..psizes[1]-1,0..psizes[2]-1].max
      puts "max pixel ="+pmax.to_s

      shift_n = 0
      if( pmax > 0 ) then
        if defined?(Magick::MAGICKCORE_QUANTUM_DEPTH)
           q_depth = Magick::MAGICKCORE_QUANTUM_DEPTH
        else
           q_depth = Magick::QuantumDepth
        end
        if( q_depth == 16 ) then
          max_bit_pattern = 0b1000000000000000
        else
          max_bit_pattern = 0b10000000
        end

        while( shift_n < 16 ) do
          break if (pmax & max_bit_pattern ) != 0
          pmax <<= 1
          shift_n += 1
        end
      end

      for y in 0...img.rows
        for x in 0...img.columns
#         val = pxl[fidx,y,x]*256
          val = pxl[fidx,y,x] << shift_n
          img.pixel_color(x,y,Magick::Pixel.new(val,val,val))
        end
      end
      if( nil != img_title )then
        gc = Magick::Draw.new
        gc.fill('white')
        gc.text(width-(img_title.length+2)*8, height-20, img_title)
        gc.draw(img)
      end
      puts "shift bits="+shift_n.to_s
      puts "max pixel ="+pmax.to_s
      if( nil == img_file ) then
        img.display
      else
        img.write(img_file)
        puts 'save to '+img_file+ ' .'
      end 
    end

  rescue => ex
    puts " Cannot save to "+img_file+" ." if( nil != img_file )
    if( nil != ex.message.index('no encode delegate') ) then
      puts " Not supported this image format. Determines image format from the prefix or extension."
    else
      puts ex.message
    end
  end
  p "Stop" # TODO
end
SamplePlot(diag, shot, subshot, channel, range_type=Labcom::Retriever::RANGE_NOSET,range='',op_nsum=0, raw=false, host=nil, path=nil) click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-11-21

Deprecated

Use SamplePlot3.rb instead.

– Function –

This is a sample procedure for plotting measurement data stored in the LABCOM system.

– Usage –

$ SamplePlot.rb [options] diag shot subshot channel [nsum]

diag

Diagnostics name

shot

Shot number

subshot

Sub-Shot number

nsum

Indicates the number of data points to average when plotting.

options:
- - et range :

range by experiment time(s,ms,us) e.g. ‘1.0:2.5s’

- - tt range :

range by relative time(s,ms,us) e.g. ‘1.0:2.5s’

- - ss range :

range by sample number e.g. ‘1000:2000’

- - frame range :

range by frame number e.g. ‘100:200’

- - host hostname :

host name for direct connection.

- - path pathname :

path name for direct connection.

- - raw :

raw mode

# File bin/SamplePlot.rb, line 32
def SamplePlot (diag, shot, subshot, channel, range_type=Labcom::Retriever::RANGE_NOSET,range='',op_nsum=0, raw=false, host=nil, path=nil)
  Warning[:deprecated] = true
  warn("Deprecated SamplePlot.rb !", category: :deprecated)
  begin
    p Labcom::Retriever.version()
    r = Labcom::Retriever.new(0,host,path,0)
#   ad = r.get("RADH",98000,1,[3,4])
#   ad = r.get("MIR3",112000,1,2)
#   ad = r.get("MIR3",112000,1,['MIR3_002(114)'])
#   ad = r.get("MIR3",112000,1,[10,3,'MIR3_002(114)'])
#   ad = r.get("MIR3",112001,1,2..4)
    if raw then
      r.set_raw_mode()      
    end 
    ad = r.get(diag, shot, subshot, channel, range_type, range)
#   num = ad[0].num()
    num = ad.num()
    num_t = ad.num_times()
    if num != num_t then      
      p 'It\'s different from th number of sample and times.' 
      return
    end 
    if 0 == op_nsum then
      if 0 == num then
        return
      elsif 1000000000 < num then
        nsum = 100000
      elsif 100000000 < num then
        nsum = 10000
      elsif 10000000 < num then
        nsum = 1000
      elsif 1000000 < num then
        nsum = 100
      elsif 10000 < num then
        nsum = 10
      else
        nsum = 1
      end
    else
      nsum = op_nsum
    end
    p 'nsum : '+ nsum.to_s
    p 'num : '+ num.to_s
#   art = ad[0].time()
    art = ad.time()
#   arv = ad[0].val()
    arv = ad.val()
    Gnuplot.open do |gp|
        Gnuplot::Plot.new( gp ) do |plot|
            plot.title  'SamplePlot '+diag
            if !raw then 
              plot.ylabel 'V'
            end
            plot.xlabel 'Sec'
#           plot.xrange '[2:8]'
#           plot.yrange '[0:2]'
            r = Range.new(0,(num-(nsum-1)),true)
            x = Array.new()
            r.step(nsum) {|i| x.push(art[i]) }
            y = Array.new()
            r.step(nsum) {|i| 
              rr =  Range.new(i,i+nsum,true)
              avg = 0.0
              rr.step {|j| avg+=arv[j]}
              y.push(avg/nsum) }
         
            p 'Start plot.' # TODO
            plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
              ds.with = "lines"
              ds.notitle
            end
            p 'End plot.'  # TODO
        end
    end
    
  rescue => ex
    p ex.message
  end
  p "Stop." # TODO
end
SamplePlot3(diag, shot, subshot, channel, range_type=Labcom3::Retriever::RANGE_NOSET,range='',op_nsum=0, raw=false, host=nil, path=nil) click to toggle source
Authors

S.imazu

Version

25.2.0

Date

2024-11-21

– Function –

This is a sample procedure for plotting measurement data stored in the LABCOM system.

– Usage –

$ SamplePlot3.rb [options] diag shot subshot channel [nsum]

diag

Diagnostics name

shot

Shot number

subshot

Sub-Shot number

nsum

Indicates the number of data points to average when plotting.

options:
- - et range :

range by experiment time(s,ms,us) e.g. ‘1.0:2.5s’

- - tt range :

range by relative time(s,ms,us) e.g. ‘1.0:2.5s’

- - ss range :

range by sample number e.g. ‘1000:2000’

- - frame range :

range by frame number e.g. ‘100:200’

- - host hostname :

host name for direct connection.

- - path pathname :

path name for direct connection.

- - raw :

raw mode

# File bin/SamplePlot3.rb, line 32
def SamplePlot3 (diag, shot, subshot, channel, range_type=Labcom3::Retriever::RANGE_NOSET,range='',op_nsum=0, raw=false, host=nil, path=nil)

  begin
    p Labcom3::Retriever.version()
    r = Labcom3::Retriever.new(0,host,path,0)
#   ad = r.get("RADH",98000,1,[3,4])
#   ad = r.get("MIR3",112000,1,2)
#   ad = r.get("MIR3",112000,1,['MIR3_002(114)'])
#   ad = r.get("MIR3",112000,1,[10,3,'MIR3_002(114)'])
#   ad = r.get("MIR3",112001,1,2..4)
    if raw then
       r.set_raw_mode()      
    end 
    ad = r.get(diag, shot, subshot, channel, range_type, range)
#   num = ad[0].num()
    num = ad.num()
    num_t = ad.num_times()
    if num != num_t then      
      p 'It\'s different from th number of sample and times.' 
      return
    end 
    if 0 == op_nsum then
      if 0 == num then
        return
      elsif 1000000000 < num then
        nsum = 100000
      elsif 100000000 < num then
        nsum = 10000
      elsif 10000000 < num then
        nsum = 1000
      elsif 1000000 < num then
        nsum = 100
      elsif 10000 < num then
        nsum = 10
      else
        nsum = 1
      end
    else
      nsum = op_nsum
    end
    p 'nsum : '+ nsum.to_s
    p 'num : '+ num.to_s
#   art = ad[0].time()
    art = ad.time()
#   arv = ad[0].val()
    arv = ad.val()
    p 'Start time        : '+ad.start_time_sec().to_s+" sec"
    p 'Sampling Interval : '+ad.sampling_interval_sec().to_s+" sec"
    Gnuplot.open do |gp|
      p 'Start canvas.'  # TODO
      Gnuplot::Plot.new( gp ) do |plot|
          plot.title  'SamplePlot '+diag
          if !raw then 
            plot.ylabel 'V'
          end
          plot.xlabel 'Sec'
#         plot.xrange '[2:8]'
#         plot.yrange '[0:2]'
          r = Range.new(0,(num-(nsum-1)),true)
          x = Array.new()
          r.step(nsum) {|i| x.push(art[i]) }
          y = Array.new()
          r.step(nsum) {|i| 
            rr =  Range.new(i,i+nsum,true)
            avg = 0.0
            rr.step {|j| avg+=arv[j]}
              y.push(avg/nsum) }
         
          p 'Start plot lines.' # TODO
          plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
            ds.with = "lines"
            ds.notitle
          end
          p 'End plot lines.'  # TODO
      end
      p 'End canvas.'  # TODO
    end
    
  rescue => ex
    p ex.message
  end
  p "Stop." # TODO
end