This function takes the name of a file in grid_task format and returns
    the dimensions of the world it represents.
544478
def get_world_dimensions(gridfile, delim=" "):
    
    infile = open(gridfile)
    lines = infile.readlines()
    infile.close()
    world_x = len(lines[0].strip().split(delim))
    world_y = len(lines)
    return (world_x, world_y)
66839
def _getImageSize(filename):
    """"""
    result = None
    file = open(filename, 'rb')
    if file.read(8) == b'\x89PNG\r\n\x1a\n': # PNG
        while 1:
            length, = _struct.unpack('>i', file.read(4))
            chunkID = file.read(4)
            if chunkID == '': # EOF
                break
            if chunkID == b'IHDR':
                # return width, height
                result = _struct.unpack('>ii', file.read(8))
                break
            file.seek(4 + length, 1)
        file.close()
        return result
    file.seek(0)
    if file.read(8) == b'BM': # Bitmap
        file.seek(18, 0) # skip to size data
        result = _struct.unpack('<ii', file.read(8))
    file.close()
    return result
292202
def compute_plot_size(plot):
    
    if isinstance(plot, GridBox):
        ndmapping = NdMapping({(x, y): fig for fig, y, x in plot.children}, kdims=['x', 'y'])
        cols = ndmapping.groupby('x')
        rows = ndmapping.groupby('y')
        width = sum([max([compute_plot_size(f)[0] for f in col]) for col in cols])
        height = sum([max([compute_plot_size(f)[1] for f in row]) for row in rows])
        return width, height
    elif isinstance(plot, (Div, ToolbarBox)):
        # Cannot compute size for Div or ToolbarBox
        return 0, 0
    elif isinstance(plot, (Row, Column, WidgetBox, Tabs)):
        if not plot.children: return 0, 0
        if isinstance(plot, Row) or (isinstance(plot, ToolbarBox) and plot.toolbar_location not in ['right', 'left']):
            w_agg, h_agg = (np.sum, np.max)
        elif isinstance(plot, Tabs):
            w_agg, h_agg = (np.max, np.max)
        else:
            w_agg, h_agg = (np.max, np.sum)
        widths, heights = zip(*[compute_plot_size(child) for child in plot.children])
        return w_agg(widths), h_agg(heights)
    elif isinstance(plot, (Figure, Chart)):
        if plot.plot_width:
            width = plot.plot_width
        else:
            width = plot.frame_width + plot.min_border_right + plot.min_border_left
        if plot.plot_height:
            height = plot.plot_height
        else:
            height = plot.frame_height + plot.min_border_bottom + plot.min_border_top
        return width, height
    elif isinstance(plot, (Plot, DataTable, Spacer)):
        return plot.width, plot.height
    else:
        return 0, 0
956768
def get_file_name(latitude, longitude)
            north_south = latitude >= 0 ? 'N' : 'S'
            east_west = longitude >= 0 ? 'E' : 'W'

            lat = latitude.floor.to_i.abs.to_s.rjust(2, '0')
            lon = longitude.floor.to_i.abs.to_s.rjust(3, '0')

            "#{north_south}#{lat}#{east_west}#{lon}.hgt"
        end
629966
def get_term_size():
        ''''''
        rows, columns = os.popen('stty size', 'r').read().split()
        return int(rows), int(columns)
1107751
def get_dimensions(filenames):
    """"""

    dims = []
    for filename in filenames:
        implemented = False
        with open(filename, 'rb') as fp:

            img_types = (PNGFile, GIFFile, JPEGFile)
            for img_type in img_types:
                sig = str(getattr(img_type, 'SIGNATURE')[0])
                magic = fp.read(len(sig))
                fp.seek(0)
                if magic == sig:
                    cls = img_type.__name__.split('.')[-1]
                    img = getattr(img_type, cls)(fp)
                    x, y = img.size
                    dims.append((x, y, img.content_type, filename))
                    implemented = True
                    break
            if not implemented:
                # might want to fail silently, or print error to stdout...
                print('cannot handle file: %s' % filename)
                raise NotImplementedError
    return dims
367278
def get_grid_dimensions(current_problem_size, params, grid_div, block_size_names):
    """"""
    def get_dimension_divisor(divisor_list, default, params):
        if divisor_list is None:
            if default in params:
                divisor_list = [default]
            else:
                return 1
        return numpy.prod([int(eval(replace_param_occurrences(s, params))) for s in divisor_list])
    divisors = [get_dimension_divisor(d, block_size_names[i], params) for i, d in enumerate(grid_div)]
    return tuple(int(numpy.ceil(float(current_problem_size[i]) / float(d))) for i, d in enumerate(divisors))
535289
def get_dimension(self):
        """"""
        return int(round(float(self.strokes**2)/2 + float(self.strokes)/2))
1356133
def _get_instance_dimensions(self, ds):
        '''
        
        '''
        ret_val = []
        for variable in ds.get_variables_by_attributes(cf_role=lambda x: isinstance(x, basestring)):
            if variable.ndim > 0:
                ret_val.append(variable.dimensions[0])
        return ret_val
890981
def dimensionNames(self):
        
        mainArrayDims = ['Dim{}'.format(dimNr) for dimNr in range(self._array.ndim)]
        nSubDims = len(self._subArrayShape)
        subArrayDims = ['SubDim{}'.format(dimNr) for dimNr in range(nSubDims)]
        return mainArrayDims + subArrayDims
1201976
def _get_grid_files(self):
        """"""
        grid_file_paths = self.grid_file_paths
        datasets = []
        if isinstance(grid_file_paths, str):
            grid_file_paths = [grid_file_paths]
        for path in grid_file_paths:
            try:
                ds = xr.open_dataset(path, decode_times=False)
            except (TypeError, AttributeError):
                ds = xr.open_mfdataset(path, decode_times=False).load()
            except (RuntimeError, OSError) as e:
                msg = str(e) + ': {}'.format(path)
                raise RuntimeError(msg)
            datasets.append(ds)
        return tuple(datasets)
666349
def filename_to_task_id(fname):
  """"""
  # This matches the order and size in WikisumBase.out_filepaths
  fname = os.path.basename(fname)
  shard_id_increment = {
      "train": 0,
      "dev": 800,
      "test": 900,
  }
  parts = fname.split("-")
  split = parts[1]
  shard_id = parts[2]
  task_id = int(shard_id) + shard_id_increment[split]
  return task_id
132120
def size(filename, format='decimal'):
    '''
    

    '''
    if isinstance(filename, file):
        filename = filename.name

    return filesize(os.stat(filename)[stat.ST_SIZE], format)
1159274
def dimensions(path):
    """"""
    pdf = PdfFileReader(path)
    size = pdf.getPage(0).mediaBox
    return {'w': float(size[2]), 'h': float(size[3])}
1364199
def dimensions(self):
        """"""
        size = self.pdf.getPage(0).mediaBox
        return {'w': float(size[2]), 'h': float(size[3])}
1106253
def get_file_size(filename):
    
    if os.path.isfile(filename):
        return convert_size(os.path.getsize(filename))
    return None
268220
def dimensions(self):
        
        return ImageDimensions(self._info.file.width, self._info.file.height)