population

Defines a population of space objects in the form of a class.

Module summary

Classes

Population([fields, dtypes, …])

Encapsulates a population of space objects as an array and functions for returning instances of space objects.

Contents

Population

class sorts.population.population.Population(fields=None, dtypes=None, space_object_fields=None, state_fields=None, epoch_field=None, propagator=None, propagator_args={}, propagator_options={})[source]

Bases: object

Encapsulates a population of space objects as an array and functions for returning instances of space objects.

Default columns:

  • 0: oid - Object ID

  • 1: a - Semi-major axis in m

  • 2: e - Eccentricity

  • 3: i - Inclination in degrees

  • 4: raan - Right Ascension of ascending node in degrees

  • 5: aop - Argument of perihelion in degrees

  • 6: mu0 - Mean anoamly in degrees

  • 7: mjd0 - Epoch of object given in Modified Julian Days

Any column that is added will have its name used in initializing the Space object.

A population’s column data can also be accessed as a python dictionary or a table according to row number, e.g.

#this returns all Right Ascension of ascending node as a numpy vector
vector = my_population['raan']

#this gets row number 3 (since we use 0 indexing)
row = my_population[2]

but it is also configured to be able to try to convert to uniform type array and perform numpy like slices. If a column data type cannot be converted to the default data type numpy.nan is inserted instead.

#This will convert the internal data structure to a uniform type array and select all rows and columns 4 and onwards. This is time-consuming on large populations as it actually copies to data.
vector = my_population[:,4:]

# This is significantly faster as a single column is easy to extract and no conversion is needed
data_point = my_population[123,2]

This indexing system can also be used for data manipulation:

my_population['raan'] = vector
my_population[2] = row
my_population[:,4:] = matrix
my_population[123,2] = 2.3
my_population[123,11] = 'test'

Notice that in the above example the value to be assigned always has the correct size corresponding to the index and slices, a statement like x[:,3:7] = 3 is not possible, instead one would write x[:,3:7] = np.full((len(pop), 4), 3.0, dtype='f').

#TODO: THESE HAVE CHANGED, UPDATE THEM!!!!

Variables
  • objs (numpy.ndarray) – Array containing population data. Rows correspond to objects and columns to variables.

  • name (str) – Name of population.

  • fields (list) – List of strings containing column descriptions.

  • space_object_uses (list) – List of booleans describing what columns should be included when initializing a space object. This allows for extra data to be stored in the population without passing it to the space object.

  • propagator (PropagatorBase) – Propagator class pointer used for space_object.SpaceObject.

  • propagator_options (dict) – Propagator initialization keyword arguments.

Parameters
  • name (str) – Name of population.

  • fields (list) – List of strings containing column descriptions for addition data besides the default columns.

  • dtypes (list) – List of strings containing numpy data type description. Defaults to ‘f’.

  • space_object_fields (list) – List of booleans describing what columns should be included when initializing a space object. This allows for extra data to be stored in the population without passing it to the space object.

  • propagator (PropagatorBase) – Propagator class pointer used for space_object.SpaceObject.

  • propagator_options (dict) – Propagator initialization keyword arguments.

add_field(name, dtype=None)[source]

Add a field to the population data.

allocate(length)[source]

Allocate the internal data array for assignment of objects.

Warning: This removes all internal data.

Example:

Create a population with two objects. Here the load_data function is a fictional function that creates a row with the needed data.

from population import Population
from my_data_loader import load_data

my_pop = Population(
    name='two objects',
    extra_columns = ['m', 'color'],
    dtypes = ['Float64', 'U20'],
    space_object_uses = [True, False],
)

print(len(my_pop)) #will output 0
my_pop.allocate(2)
print(len(my_pop)) #will output 2

my_pop.data[0] = load_data('obj1')
my_pop.data[1] = load_data('obj2')
copy()[source]

Return a copy of the current Population instance.

delete(inds)[source]

Remove the rows according to the given indices. Supports single index, iterable of indices and slices.

filter(col, fun)[source]

Filters the population using a boolean function, keeping true values.

Parameters
  • col (str) – Column to filter, must match exactly one entry in the header attribute.

  • fun (function) – Function that returns boolean array used for filtering.

Example:

Filter Master population keeping only objects below 45.0 degrees inclination.

from population_library import master_catalog

master = master_catalog()
master.filter(
    col='i',
    fun=lambda inc: inc < 45.0,
)
get_fields(fields, n=None, named=True, dtype=None)[source]

Get the orbital elements for one row from internal data array.

Parameters
  • n (int/slice/list) – Row number(s).

  • fields (list) – List of fields to get data for

  • named (bool) – return a named numpy array or a unnamed one. If True, all dtypes are cast as the first fields.

get_object(n)[source]

Get the one row from the population as a space_object.SpaceObject instance.

get_orbit(n, fields=None, M_cent=5.972169366075844e+24, degrees=True, anomaly='mean')[source]

Get the one row from the population as a pyorb.Orbit instance.

get_states(n=None, named=True, dtype=None)[source]

Use the defined state parameters to get a copy of the states

property shape

This is the shape of the internal data matrix