dmagic.dm

Functions:

make_experiment_name(args)

Build the DM experiment name from proposal metadata.

create_experiment(args)

Create a new DM experiment on Sojourner.

make_dm_username_list(args)

Make DM username sets from the proposal (GUP) and ESAF user lists.

add_users(exp_obj, username_list)

Add a list of DM usernames to an experiment.

make_username_list(args)

Return the list of DM usernames currently on the experiment.

make_user_email_list(username_list)

Convert a list of DM usernames ('d+badge#') to email addresses.

list_users_this_dm_exp(args)

Return the list of DM usernames on the current experiment, or None if not found.

make_pretty_user_name(user_obj)

Format a DM user object as 'FirstName MiddleName LastName'.

make_data_link(args)

Build the Globus file-manager URL for the experiment data directory.

dmagic.dm.add_users(exp_obj, username_list)[source]

Add a list of DM usernames to an experiment.

dmagic.dm.create_experiment(args)[source]

Create a new DM experiment on Sojourner.

Returns the experiment object (new or pre-existing), or None on error.

dmagic.dm.delete_experiment(exp_name)[source]

Delete a DM experiment from Sojourner by name.

Returns True on success, False on error.

dmagic.dm.get_emailed_users(exp_name)[source]

Return the set of DM usernames already emailed for this experiment.

Reads from DM experiment metadata key ‘emailedUsers’. Returns an empty set if the metadata has not been set yet or on any error.

dmagic.dm.get_esaf_doi(esaf_id)[source]

Return the DOI string for the ESAF, or None if unavailable.

dmagic.dm.get_esaf_users(esaf_id)[source]

Return set of ‘d+badge’ strings for users listed in the ESAF.

Uses EsafApsDbApi.getStationEsafById() with the station name from the DM_STATION_NAME environment variable (default ‘2BM’). Returns an empty set if esaf_id is empty, DM is unavailable, or the call fails (e.g. session expired or access denied).

dmagic.dm.get_experiment(exp_name)[source]

Return the DM experiment object for exp_name, or None if not found.

dmagic.dm.get_user(username)[source]

Return the DM user object for a username, or None on error.

dmagic.dm.list_experiments_by_station(station, years=2)[source]

Return DM experiment objects for the station from the last years calendar years.

Uses getExperimentsByStation(stationName=station). Sorted newest first. Returns [] on error or no results.

dmagic.dm.list_users_this_dm_exp(args)[source]

Return the list of DM usernames on the current experiment, or None if not found.

Build the Globus file-manager URL for the experiment data directory.

dmagic.dm.make_dm_username_list(args)[source]

Make DM username sets from the proposal (GUP) and ESAF user lists.

Returns (gup_set, esaf_set) where:

gup_set — ‘d+badge’ strings from proposal experimenters + beamline contacts esaf_set — ‘d+badge’ strings from ESAF experimenters NOT already in gup_set

Returns (None, set()) if the beamtime cannot be found in the scheduling system.

dmagic.dm.make_experiment_name(args)[source]

Build the DM experiment name from proposal metadata.

Format: {year_month}-{pi_last_name}-{gup_number} Example: 2025-03-Smith-123456

dmagic.dm.make_pretty_user_name(user_obj)[source]

Format a DM user object as ‘FirstName MiddleName LastName’.

dmagic.dm.make_user_email_list(username_list)[source]

Convert a list of DM usernames (‘d+badge#’) to email addresses.

dmagic.dm.make_username_list(args)[source]

Return the list of DM usernames currently on the experiment.

dmagic.dm.remove_users(exp_name, username_list)[source]

Remove a list of DM usernames from an experiment.

dmagic.dm.set_emailed_users(exp_name, username_set)[source]

Persist the set of emailed DM usernames as experiment metadata.

Stores under key ‘emailedUsers’ as a comma-separated string.

dmagic.dm.start_daq(exp_name, analysis, analysis_top_dir)[source]
Start two DM DAQs for exp_name:
  • raw data: analysis_top_dir/<exp_name> → DM data directory

  • reconstructed data: analysis_top_dir/<exp_name>_rec → DM analysis directory

The rec DAQ is skipped with a warning if the directory does not yet exist. Returns True if at least the raw DAQ started, False on error.

dmagic.dm.stop_daq(exp_name)[source]

Stop all running DM DAQs for exp_name.

Returns True on success (including no DAQs found), False on error.

dmagic.dm.upload(exp_name, analysis, analysis_top_dir)[source]

One-shot upload of raw and reconstructed data to the DM experiment.

Uploads files that exist at the time the command is issued (unlike DAQ, which monitors for new files continuously). Use this when daq-start was not running while data was being collected. Uses the same source directories as daq-start:

  • raw data: analysis_top_dir/<exp_name> → DM data directory

  • reconstructed data: analysis_top_dir/<exp_name>_rec → DM analysis directory

The rec upload is skipped with a warning if the directory does not exist. Returns True if at least the raw upload started, False on error.