open_cp.data¶
Encapsulates input data.
-
class
open_cp.data.
Point
(x=0, y=0)¶ Bases:
object
A simple 2 dimensional point class.
-
x
¶ The x coordinate.
-
y
¶ The y coordinate.
-
-
class
open_cp.data.
RectangularRegion
(xmin=0, xmax=1, ymin=0, ymax=1)¶ Bases:
object
Stores a rectangular region.
-
aspect_ratio
¶ Height divided by width
-
grid_size
(cell_width, cell_height=None)¶ Return the size of grid defined by this region.
Parameters: - cell_width – The width of each cell in the grid.
- cell_height – Optional. The height of each cell in the grid; defaults to a square grid where the height is the same as the width.
Returns: (xsize, ysize) of the grid.
-
height
¶ The height of the region: ymax - ymin
-
max
¶ The pair (xmax, ymax)
-
min
¶ The pair (xmin, ymin)
-
width
¶ The width of the region: xmax - xmin
-
xmax
¶
-
xmin
¶
-
ymax
¶
-
ymin
¶
-
-
class
open_cp.data.
TimedPoints
(timestamps, coords)¶ Bases:
object
Stores a list of timestamped x-y coordinates of events.
Parameters: - timestamps – An array of timestamps (must be convertible to
numpy.datetime64
). - coords – An array of shape (2,n) where n must match the number of timestamps.
-
bounding_box
¶ The smallest (space) box containing all the data points.
Returns: A RectangularRegion
instance.
-
empty
¶ True or False, do we have any events
-
events_before
(cutoff_time=None)¶ Returns just the events with timestamps before (or equal to) the cutoff.
Parameters: cutoff_time – End of the time period we’re interested in. Default is None which means return all the data.
-
static
from_coords
(timestamps, xcoords, ycoords)¶ Static constructor allowing you to pass separate arrays of x and y coordinates.
-
number_data_points
¶ The number of events
-
time_deltas
(time_unit=numpy.timedelta64(1, 'm'))¶ Returns a numpy array of floats, converted from the timestamps, starting from 0, and with the optional unit.
Parameters: time_unit – The unit to measure time by. Defaults to 1 minute, so timestamps an hour apart will be converted to floats 60.0 apart. No rounding occurs, so there is no loss in accuracy by passing a different time unit.
-
time_range
¶ Find the time range.
Returns: A pair (start, end) of timestamps.
-
times_datetime
()¶ Return an array of timestamps using the
datetime.datetime
standard library class. Useful for plotting with matplotlib, for example.
-
to_time_space_coords
(time_unit=numpy.timedelta64(1, 'm'))¶ Returns a single numpy array [t,x,y] where the time stamps are converted to floats, starting from 0, and with the optional unit.
Parameters: time_unit – The unit to measure time by. Defaults to 1 minute, so timestamps an hour apart will be converted to floats 60.0 apart. No rounding occurs, so there is no loss in accuracy by passing a different time unit.
-
xcoords
¶ A one dimensional array representing the x coordinates of events.
-
ycoords
¶ A one dimensional array representing the y coordinates of events.
- timestamps – An array of timestamps (must be convertible to
-
open_cp.data.
points_from_lon_lat
(points, proj=None, epsg=None)¶ Converts longitude / latitude data into x,y coordinates using a projection. The module pyproj must be loaded, otherwise this does nothing.
Parameters: - points – A :class TimedPoints: instance of lon/lat data.
- proj – Optionally, a
pyproj.Proj
instance describing the projection. - epsg – If no proj is given, this must be supplied. A valid EPSG projection reference. For example, 7405 is suitable for UK data. See http://spatialreference.org/ref/epsg/
Returns: A
TimedPoints
instance of projected data with the same timestamps.