def combine_grids(mode, inpath1, inpath2, outpath):

    from VolumeData import fileformats

    grids = []
    failed_paths = []
    for path in (inpath1, inpath2):
        try:
            glist = fileformats.open_file(path)
            grids.append(glist)
        except fileformats.Unknown_File_Type:
            failed_paths.append(path)

    if failed_paths:
        warning = fileformats.suffix_warning(failed_paths)
        sys.stderr.write(warning)
        sys.exit(1)

    combined = map(lambda g1, g2: Combined_Grid(mode, g1, g2), grids[0],
                   grids[1])

    from VolumeData.netcdf import write_grid_as_netcdf
    write_grid_as_netcdf(combined, outpath)
Beispiel #2
0
# -----------------------------------------------------------------------------
#
def apply_function(array_func, inpath, outpath):

    from VolumeData import fileformats
    try:
        grids = fileformats.open_file(inpath)
    except fileformats.Unknown_File_Type, e:
        sys.stderr.write(str(e))
        sys.exit(1)

    fvalues = [Mapped_Grid(g, array_func) for g in grids]

    from VolumeData.netcdf import write_grid_as_netcdf
    write_grid_as_netcdf(fvalues, outpath)


# -----------------------------------------------------------------------------
#
class Mapped_Grid(Grid_Data):
    def __init__(self, grid_data, array_func):

        self.array_func = array_func
        Grid_Data.__init__(self,
                           grid_data.size,
                           grid_data.value_type,
                           grid_data.origin,
                           grid_data.step,
                           name=grid_data.name,
                           default_color=grid_data.rgba)
# -----------------------------------------------------------------------------
#
def gaussian_convolve(inpath, linewidth, outpath):

    from VolumeData import fileformats
    try:
        glist = fileformats.open_file(inpath)
    except fileformats.Unknown_File_Type, e:
        sys.stderr.write(str(e))
        sys.exit(1)

    gaussian_data = [Gaussian_Convolution(g, linewidth) for g in glist]

    from VolumeData.netcdf import write_grid_as_netcdf
    write_grid_as_netcdf(gaussian_data, outpath)


# -----------------------------------------------------------------------------
# Convolve a grid with a Gaussian.  Linewidth is specified in xyz units
# (not ijk indices).
#
class Gaussian_Convolution(Grid_Data):
    def __init__(self, grid_data, linewidth):

        self.grid_data = grid_data
        self.linewidth = linewidth

        Grid_Data.__init__(self,
                           grid_data.size,
                           origin=grid_data.origin,
# -----------------------------------------------------------------------------
#
if len(sys.argv) != 9:
    syntax()

inpath = sys.argv[1]
try:
    imin = int(sys.argv[2])
    imax = int(sys.argv[3])
    jmin = int(sys.argv[4])
    jmax = int(sys.argv[5])
    kmin = int(sys.argv[6])
    kmax = int(sys.argv[7])
except:
    syntax()

outpath = sys.argv[8]

from VolumeData import fileformats
try:
    glist = fileformats.open_file(inpath)
except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

from VolumeData import Grid_Subregion
r = [Grid_Subregion(g, (imin, jmin, kmin), (imax, jmax, kmax)) for g in glist]

from VolumeData.netcdf import write_grid_as_netcdf
write_grid_as_netcdf(r, outpath)
Beispiel #5
0
# -----------------------------------------------------------------------------
#
def count_neighbors(inpath, outpath):

  from VolumeData import fileformats
  try:
    glist = fileformats.open_file(inpath)
  except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

  counts = [Lower_Neighbor_Counts(g) for g in glist]

  from VolumeData.netcdf import write_grid_as_netcdf
  write_grid_as_netcdf(counts, outpath)

# -----------------------------------------------------------------------------
#
class Lower_Neighbor_Counts(Grid_Data):
  
  def __init__(self, grid_data):

    from numpy import int8
    size = map(lambda s: s-2, grid_data.size)
    xyz_origin = map(lambda o, s: o + s,
                     grid_data.origin, grid_data.step)
    Grid_Data.__init__(self, size, int8, xyz_origin, grid_data.step,
                       default_color = grid_data.rgba)
    
  # ---------------------------------------------------------------------------
Beispiel #6
0
# -----------------------------------------------------------------------------
#
def gaussian_convolve(inpath, linewidth, outpath):

  from VolumeData import fileformats
  try:
    glist = fileformats.open_file(inpath)
  except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

  gaussian_data = [Gaussian_Convolution(g, linewidth) for g in glist]

  from VolumeData.netcdf import write_grid_as_netcdf
  write_grid_as_netcdf(gaussian_data, outpath)

# -----------------------------------------------------------------------------
# Convolve a grid with a Gaussian.  Linewidth is specified in xyz units
# (not ijk indices).
#
class Gaussian_Convolution(Grid_Data):
  
  def __init__(self, grid_data, linewidth):

    self.grid_data = grid_data
    self.linewidth = linewidth
    
    Grid_Data.__init__(self, grid_data.size,
                       origin = grid_data.origin, step = grid_data.step)
    
Beispiel #7
0
    
  del args[i:i+4]

  return values

# -----------------------------------------------------------------------------
#
def write_netcdf(inpath, outpath, xyz_origin, xyz_step):

  from VolumeData import fileformats
  try:
    glist = fileformats.open_file(inpath)
  except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

  if xyz_origin:
    for g in glist:
      g.origin = xyz_origin
  if xyz_step:
    for g in glist:
      g.step = xyz_step
    
  from VolumeData.netcdf import write_grid_as_netcdf
  write_grid_as_netcdf(glist, outpath)

# -----------------------------------------------------------------------------
#
inpath, outpath, xyz_origin, xyz_step = parse_arguments(sys.argv)
write_netcdf(inpath, outpath, xyz_origin, xyz_step)
    return values


# -----------------------------------------------------------------------------
#
def write_netcdf(inpath, outpath, xyz_origin, xyz_step):

    from VolumeData import fileformats
    try:
        glist = fileformats.open_file(inpath)
    except fileformats.Unknown_File_Type, e:
        sys.stderr.write(str(e))
        sys.exit(1)

    if xyz_origin:
        for g in glist:
            g.origin = xyz_origin
    if xyz_step:
        for g in glist:
            g.step = xyz_step

    from VolumeData.netcdf import write_grid_as_netcdf
    write_grid_as_netcdf(glist, outpath)


# -----------------------------------------------------------------------------
#
inpath, outpath, xyz_origin, xyz_step = parse_arguments(sys.argv)
write_netcdf(inpath, outpath, xyz_origin, xyz_step)
# -----------------------------------------------------------------------------
#
def downsize(mode, cell_size, inpath, outpath):

    from VolumeData import fileformats
    try:
        glist = fileformats.open_file(inpath)
    except fileformats.Unknown_File_Type, e:
        sys.stderr.write(str(e))
        sys.exit(1)

    reduced = [Reduced_Grid(g, mode, cell_size) for g in glist]

    from VolumeData.netcdf import write_grid_as_netcdf
    write_grid_as_netcdf(reduced, outpath)


# -----------------------------------------------------------------------------
# Average over cells to produce reduced size grid object.
#
# If the grid data sizes are not multiples of the cell size then the
# final data values along the dimension are not included in the reduced
# data (ie ragged blocks are not averaged).
#
class Reduced_Grid(Grid_Data):
    def __init__(self, grid_data, mode, cell_size):

        self.grid_data = grid_data
        self.mode = mode
        self.cell_size = cell_size
Beispiel #10
0
# -----------------------------------------------------------------------------
#
def downsize(mode, cell_size, inpath, outpath):

  from VolumeData import fileformats
  try:
    glist = fileformats.open_file(inpath)
  except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)
    
  reduced = [Reduced_Grid(g, mode, cell_size) for g in glist]

  from VolumeData.netcdf import write_grid_as_netcdf
  write_grid_as_netcdf(reduced, outpath)

# -----------------------------------------------------------------------------
# Average over cells to produce reduced size grid object.
#
# If the grid data sizes are not multiples of the cell size then the
# final data values along the dimension are not included in the reduced
# data (ie ragged blocks are not averaged).
#
class Reduced_Grid(Grid_Data):
  
  def __init__(self, grid_data, mode, cell_size):

    self.grid_data = grid_data
    self.mode = mode
    self.cell_size = cell_size
Beispiel #11
0
# -----------------------------------------------------------------------------
#
def apply_function(array_func, inpath, outpath):

  from VolumeData import fileformats
  try:
    grids = fileformats.open_file(inpath)
  except fileformats.Unknown_File_Type, e:
    sys.stderr.write(str(e))
    sys.exit(1)

  fvalues = [Mapped_Grid(g, array_func) for g in grids]

  from VolumeData.netcdf import write_grid_as_netcdf
  write_grid_as_netcdf(fvalues, outpath)

# -----------------------------------------------------------------------------
#
class Mapped_Grid(Grid_Data):
  
  def __init__(self, grid_data, array_func):

    self.array_func = array_func
    Grid_Data.__init__(self, grid_data.size, grid_data.value_type,
                       grid_data.origin, grid_data.step,
                       name = grid_data.name, default_color = grid_data.rgba)
    
  # ---------------------------------------------------------------------------
  #
  def read_matrix(self, ijk_origin, ijk_size, ijk_step, progress):