lmpy.data_preparation.occurrence_splitter

Module containing functions for splitting occurrence data.

Module Contents

Classes

OccurrenceSplitter

Constructor.

Functions

get_writer_filename_func(base_dir)

Get a function that returns a filename from a writer key.

get_writer_key_from_fields_func(*fields)

Get a function that returns a writer key from fields of a point.

class lmpy.data_preparation.occurrence_splitter.OccurrenceSplitter(writer_key_func, writer_filename_func, write_fields=None, max_writers=DEFAULT_MAX_WRITERS)[source]

Constructor.

Parameters
  • writer_key_func (Method) – A function for determining a writer to use. It should take a Point as input and return a dictionary key.

  • writer_filename_func (Method) – A function to determine the file location to write data for a particular writer. It should take a dictionary key and return a string.

  • write_fields (list) – A list of fields to write for each writer. If None, use all fields in the first output Point object.

  • max_writers (int) – The maximum number of open writers (files) at any given time.

__enter__(self)[source]

Context manager magic method.

Returns

This instance.

Return type

OccurrenceSplitter

__exit__(self, *args)[source]

Context manager magic method on exit.

Parameters

*args – Position arguments passed to the method.

close(self)[source]

Close all open writers.

flush_writers(self)[source]

Close all open occurrence writers.

open_writer(self, writer_key)[source]

Open an occurrence writer for the provided key.

Parameters

writer_key (object) – Some key that can be used to determine a writer.

process_reader(self, reader, wranglers)[source]

Process an occurrence reader.

Parameters
write_points(self, points)[source]

Write points using the appropriate writer.

Parameters

points (list) – A list of point objects to write to file.

lmpy.data_preparation.occurrence_splitter.get_writer_filename_func(base_dir)[source]

Get a function that returns a filename from a writer key.

Parameters

base_dir (str) – A base directory for all writers.

Returns

A function that returns a filename when given a writer key.

Return type

Method

lmpy.data_preparation.occurrence_splitter.get_writer_key_from_fields_func(*fields)[source]

Get a function that returns a writer key from fields of a point.

Parameters

*fields (list) – A list of fields to use to determine the Point’s writer key.

Returns

A function that takes a Point as an argument and returns a key.

Return type

Method