nenupy.schedule.schedule


Schedule

class nenupy.schedule.schedule.Schedule(time_min, time_max, dt=<TimeDelta object: scale='None' format='sec' value=3600.0>)[source]

Bases: _TimeSlots

Foundation class of observation scheduling.

Parameters:
  • time_min (Time) – Schedule time range lower edge.

  • time_max (Time) – Schedule time range upper edge.

  • dt (TimeDelta) – Schedule granularity (or time slot duration). Default is 1 hour.

Example:
>>> from nenupy.schedule import Schedule
>>> from astropy.time import Time, TimeDelta
>>> schedule = Schedule(
>>>     time_min=Time('2021-01-11 00:00:00'),
>>>     time_max=Time('2021-01-15 00:00:00'),
>>>     dt=TimeDelta(3600, format='sec')
>>> )

Attributes Summary

time_min

Start time of the shedule.

time_max

Stop time of the shedule.

dt

Schedule granularity (time slot duration).

observation_blocks

Observation blocks included in the schedule.

reserved_blocks

Reserved blocks included in the schedule.

Methods Summary

set_free_slots(start_times, stop_times)

Assign a ReservedBlock to every Schedule time interval that is not comprised bewteen start_times and stop_times.

match_booking(booking_file, key_program)

insert(*blocks)

Inserts observation blocks or reserved blocks in the schedule.

plot([days_per_line])

Plots the current schedule.

plot_range(start_time, stop_time, **kwargs)

Plots the current schedule.

book([optimize])

Distributes the observation_blocks over the schedule time slots.

export([score_min])

Exports the current schedule once book() has been called.

Attributes and Methods Documentation

book(optimize=False, **kwargs)[source]

Distributes the observation_blocks over the schedule time slots. The observing constraints are evaluated over the whole schedule.

Parameters:

optimize (bool) – If set to False an heuristic algorithm is used to perfom the booking. However faster, this could result in sub-optimized time slots filling. If set to True, a genetic algorithm is used (see below the configuration keywords). This method delivers more optimized scheduling solutions. However, due to the random nature of genetic algorithm behaviors, the results may not be reproducible and may vary from one run to the other. Default is False.

Genetic algorithm configuration keywords

Parameters:
  • population_size (int) – Size of the solution population, i.e., how many distinct soluttions are evolving at the same time. Default is 20.

  • random_individuals (int) – At each generation, the population of solutions will replace its lower-score random_individuals solutions by random genome ones. This allows for genetic diversity. Default is 1.

  • score_threshold (float) – Score value (between 0 and 1) at which the evolution may stop. Default is 0.8.

  • generation_max (int) – Maximum generation number at which the evolution has to stop (even if score_threshold is not reached). Default is 1000.

  • max_stagnating_generations (int) – If the score does not evolve after max_stagnating_generations generations, the evolution is stopped. Default is 100.

  • selection (str) – At each generation, pairs of individuals (solutions) are selected to give birth to new children with a mix of their genomes (see crossover). This selection can be perfomed according to three methods. 'FPS' (Fitness Proportionate Selection): parents are as likely to be picked as their score is high. 'TNS' (Tournament Selection): \(k\) individuals from the population are selected, the best becomes a parent (where \(k = \max( 2, \rm{population\ size}/10 )\)). 'RKS' (Rank Selection): individuals are ranked according to their scores, and are more likely to be picked according to their rank. The amplitude of score differences doesn’t count. Default is 'FPS'.

  • crossover – Whenever parents give birth to children, their genome (i.e., time slot indices for each observation block) is mixed. This cross-over can be performed according to three methods. 'SPCO' (Single-point crossover): genes from ‘parent1’ and ‘parent2’ are interverted after a random index. 'TPCO' (Two-point crossover): genes from ‘parent1’ and ‘parent2’ are interverted between two random indices. 'UNCO' (Uniform crossover): every genes from ‘parent1’ and ‘parent2’ are interverted with a uniform probability. Default is 'SPCO'.

Returns:

If optimize is set to False, nothing is returned. If optimize is set to True, the GeneticAlgorithm instance is returned. The method plot can then be called to visualize the evolution of the solution populations.

Return type:

None or GeneticAlgorithm

export(score_min=0)[source]

Exports the current schedule once book() has been called. Every observation with a score higher than score_min is included in the export.

Parameters:

score_min – Minimal obervation_blocks’s score to be exported. Default is 0.

Returns:

Scheduled observation blocks as a Table. This object can further be converted to any user requirements using the astropy.io.ascii.write() method (see the list of supported formats).

Return type:

Table

extend_scheduled_observations(relative_score_threshold=0.8)[source]
fine_tune(max_it=1000)[source]
insert(*blocks)[source]

Inserts observation blocks or reserved blocks in the schedule.

Parameters:

*blocks (Block, ObsBlock or ReservedBlock) – Observation blocks or reserved blocks.

Example:
from nenupy.schedule import Schedule, ESTarget, ObsBlock
from astropy.time import Time, TimeDelta

schedule = Schedule(
    time_min=Time('2021-01-11 00:00:00'),
    time_max=Time('2021-01-15 00:00:00'),
    dt=TimeDelta(3600, format='sec')
)

cas_a = ObsBlock(
    name="Cas A",
    program="ES00",
    target=ESTarget.fromName("Cas A"),
    duration=TimeDelta(2*3600, format='sec'),
)

schedule.insert(cas_a)
match_booking(booking_file, key_program)[source]
property observation_blocks

Observation blocks included in the schedule.

Setter:

Observation blocks.

Getter:

Observation blocks.

Type:

ScheduleBlocks

plot(days_per_line=1, **kwargs)[source]

Plots the current schedule.

Data display keywords

Parameters:

days_per_line (int) – Number of days to plots per line. Default is 1.

Plotting layout keywords

Parameters:
  • grid (bool) – If set to True, the time slots are separated by vertical lines. Default is True.

  • figname (str) – Name of the file (absolute or relative path) to save the figure. Default is '' (i.e., only show the figure).

  • figsize (tuple) – Set the figure size. Default is (15, 3*lines).

plot_range(start_time, stop_time, **kwargs)[source]

Plots the current schedule.

Data display keywords

Parameters:
  • start_time (Time) – Minimal time to display.

  • stop_time (Time) – Maximal time to display.

Plotting layout keywords

Parameters:
  • grid (bool) – If set to True, the time slots are separated by vertical lines. Default is True.

  • figname (str) – Name of the file (absolute or relative path) to save the figure. Default is '' (i.e., only show the figure).

  • figsize (tuple) – Set the figure size. Default is (15, 3).

property reserved_blocks

Reserved blocks included in the schedule. No observation can be planned on these time slots.

Setter:

Reserved blocks.

Getter:

Reserved blocks.

Type:

ReservedBlock

property score

Returns the current schedule score.

set_free_slots(start_times, stop_times)[source]

Assign a ReservedBlock to every Schedule time interval that is not comprised bewteen start_times and stop_times.