Package upoints :: Module cellid :: Class Cells
[hide private]
[frames] | no frames]

Class Cells

   object --+        
            |        
         dict --+    
                |    
point.KeyedPoints --+
                    |
                   Cells

Class for representing a group of Cell objects

Since: 0.11.0

Instance Methods [hide private]
new empty dictionary

__init__(self, cells_file=None)
Initialise a new Cells object
str
__str__(self)
Cells objects rendered as export from OpenCellID.org
dict
import_locations(self, cells_file)
Parse OpenCellID.org data files

Inherited from point.KeyedPoints: __repr__, bearing, destination, distance, final_bearing, forward, inverse, midpoint, range, sun_events, sunrise, sunset, to_grid_locator

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __setitem__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, cells_file=None)
(Constructor)

 
Initialise a new Cells object
Parameters:
  • points - Point objects to wrap
  • parse - Whether to attempt import of points
  • units - Unit type to be used for distances when parsing string locations
Returns:
new empty dictionary

Overrides: object.__init__

__str__(self)
(Informal representation operator)

 

Cells objects rendered as export from OpenCellID.org

>>> cells = Cells(open("cells"))
>>> print(cells)
22747,52.0438995361328,-0.224637001752853,234,33,2319,647,0,1,2008-04-05 21:32:40,2008-04-05 21:32:40
22995,52.3305015563965,-0.225562006235123,234,10,20566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59
23008,52.3506011962891,-0.223410993814468,234,10,10566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59
Returns: str
OpenCellID.org formatted output
Overrides: object.__str__

import_locations(self, cells_file)

 

Parse OpenCellID.org data files

import_locations() returns a dictionary with keys containing the OpenCellID database identifier, and values consisting of a Cell objects.

It expects cell files in the following format:

22747,52.0438995361328,-0.224637001752853,234,33,2319,647,0,1,2008-04-05 21:32:40,2008-04-05 21:32:40
22995,52.3305015563965,-0.225562006235123,234,10,20566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59
23008,52.3506011962891,-0.223410993814468,234,10,10566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59

The above file processed by import_locations() will return the following dict object:

{23008: Cell(23008, 52.3506011963, -0.223410993814, 234, 10, 10566,
             4068, 0, 1, datetime.datetime(2008, 4, 5, 21, 32, 59),
             datetime.datetime(2008, 4, 5, 21, 32, 59)),
 22747: Cell(22747, 52.0438995361, -0.224637001753, 234, 33, 2319,
             647, 0, 1, datetime.datetime(2008, 4, 5, 21, 32, 40),
             datetime.datetime(2008, 4, 5, 21, 32, 40)),
 22995: Cell(22995, 52.3305015564, -0.225562006235, 234, 10, 20566,
             4068, 0, 1, datetime.datetime(2008, 4, 5, 21, 32, 59),
             datetime.datetime(2008, 4, 5, 21, 32, 59))}
>>> cells = Cells(open("cells"))
>>> for value in sorted(cells.values(), key=lambda x: x.ident):
...     print(value)
22747,52.0438995361328,-0.224637001752853,234,33,2319,647,0,1,2008-04-05 21:32:40,2008-04-05 21:32:40
22995,52.3305015563965,-0.225562006235123,234,10,20566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59
23008,52.3506011962891,-0.223410993814468,234,10,10566,4068,0,1,2008-04-05 21:32:59,2008-04-05 21:32:59
Parameters:
  • cells_file (file, list or str) - Cell data to read
Returns: dict
Cell data with their associated database identifier
Overrides: point.KeyedPoints.import_locations