sim_archive API

class rubin_scheduler.sim_archive.AnomalousOverheadFunc(seed, slew_scale, visit_scale=0.0, slew_loc=0.0, visit_loc=0.0)[source]

Bases: object

Callable to return random overhead.

Parameters:
  • seed (int) – Random number seed.

  • slew_scale (float) – The scale for the scatter in the slew offest (seconds).

  • visit_scale (float, optional) – The scale for the scatter in the visit overhead offset (seconds). Defaults to 0.0.

  • slew_loc (float, optional) – The location of the scatter in the slew offest (seconds). Defaults to 0.0.

  • visit_loc (float, optional) – The location of the scatter in the visit offset (seconds). Defaults to 0.0.

__call__(visittime, slewtime)[source]

Return a randomized offset for the visit overhead.

Parameters:
  • visittime (float) – The visit time (seconds).

  • slewtime (float) – The slew time (seconds).

Returns:

offset – Random offset (seconds).

Return type:

float

rubin_scheduler.sim_archive.check_opsim_archive_resource(archive_uri)[source]

Check the contents of an opsim archive resource.

Parameters:

archive_uri (str) – The URI of the archive resource to be checked.

Returns:

validity – A dictionary of files checked, and their validity.

Return type:

dict

rubin_scheduler.sim_archive.drive_sim(observatory, scheduler, archive_uri=None, label=None, tags=[], script=None, notebook=None, **kwargs)[source]

Run a simulation and archive the results.

Parameters:
  • observatory (ModelObservatory) – The model for the observatory.

  • scheduler (CoreScheduler) – The scheduler to use.

  • archive_uri (str, optional) – The root URI of the archive resource into which the results should be stored. Defaults to None.

  • label (str, optional) – The label for the simulation in the archive. Defaults to None.

  • tags (list of str, optional) – The tags for the simulation in the archive. Defaults to an empty list.

  • script (str) – The filename of the script producing this simulation. Defaults to None.

  • notebook (str, optional) – The filename of the notebook producing the simulation. Defaults to None.

Returns:

  • observatory (ModelObservatory) – The model for the observatory.

  • scheduler (CoreScheduler) – The scheduler used.

  • observations (numpy.recarray) – The observations produced.

  • reward_df (pandas.DataFrame, optional) – The table of rewards. Present if record_rewards or scheduler.keep_rewards is True.

  • obs_rewards (pandas.Series, optional) – The mapping of entries in reward_df to observations. Present if record_rewards or scheduler.keep_rewards is True.

  • resource_path (ResourcePath, optional) – The resource path to the archive of the simulation. Present if archive_uri was set.

Notes

Additional parameters not described above will be passed into sim_runner.

If the archive_uri parameter is not supplied, sim_runner is run directly, so that drive_sim can act as a drop-in replacement of sim-runner.

In a jupyter notebook, the notebook can be saved for the notebook paramater using %notebook $notebook_fname (where notebook_fname is variable holding the filename for the notebook) in the cell prior to calling drive_sim.

rubin_scheduler.sim_archive.make_sim_archive_dir(observations, reward_df=None, obs_rewards=None, in_files={}, sim_runner_kwargs={}, tags=[], label=None, data_path=None, capture_env=True)[source]

Create or fill a local simulation archive directory.

Parameters:
  • observations (numpy.recarray) – The observations data, in the “obs” format as accepted and created by rubin_scheduler.scheduler.utils.SchemaConverter.

  • reward_df (pandas.DataFrame, optional) – The reward data, by default None.

  • obs_rewards (pandas.DataFrame, optional) – The observation rewards data, by default None.

  • in_files (dict, optional) – Additional input files to be included in the archive, by default {}.

  • sim_runner_kwargs (dict, optional) – Additional simulation runner keyword arguments, by default {}.

  • tags (list [str], optional) – A list of tags/keywords to be included in the metadata, by default [].

  • label (str, optional) – A label to be included in the metadata, by default None.

  • data_path (str or pathlib.Path, optional) – The path to the simulation archive directory, by default None.

  • capture_env (bool) – Use the current environment as the sim environment. Defaults to True.

Returns:

data_dir – The temporary directory containing the simulation archive.

Return type:

pathlib.Path or tempfile.TemporaryDirectory

rubin_scheduler.sim_archive.read_archived_sim_metadata(base_uri, latest=None, num_nights=5)[source]

Read metadata for a time range of archived opsim output.

Parameters:
  • base_uri (str) – The base URI of the archive resource to be checked.

  • latest (str, optional) – The date of the latest simulation whose metadata should be loaded. This is the date on which the simulations was added to the archive, not necessarily the date on which the simulation was run, or any of the dates simulated. Default is today.

  • num_nights (int) – The number of nights of the date window to load.

Returns:

sim_metadata – A dictionary of metadata for simulations in the date range.

Return type:

dict

rubin_scheduler.sim_archive.run_prenights(day_obs_mjd, archive_uri, scheduler_file=None, opsim_db=None)[source]

Run the set of scheduler simulations needed to prepare for a night.

Parameters:
  • day_obs_mjd (float) – The starting MJD.

  • archive_uri (str) – The URI of visits completed before this night.

  • scheduler_file (str, optional) – File from which to load the scheduler. None defaults to the example scheduler in rubin_sim, if it is installed. The default is None.

  • opsim_db (str, optional) – The file name of the visit database for visits preceeding the simulation. The default is None.

Return type:

None

rubin_scheduler.sim_archive.transfer_archive_dir(archive_dir, archive_base_uri='s3://rubin-scheduler-prenight/opsim/')[source]

Transfer the contents of an archive directory to an resource.

Parameters:
  • archive_dir (str) – The path to the archive directory containing the files to be transferred.

  • archive_base_uri (str, optional) – The base URI where the archive files will be transferred to. Default is “s3://rubin-scheduler-prenight/opsim/”.

Returns:

resource_rpath – The destination resource.

Return type:

ResourcePath