env_functions¶
Environment functions
check_file_access(filepath, append='_new')
¶
Check path has write access, if not, return appended path with write access
Source code in mmg_toolbox/utils/env_functions.py
contains_filetype(folder, extension='.nxs')
¶
Return True if folder contains filetype
Source code in mmg_toolbox/utils/env_functions.py
find_scan_files(scan_file, directory=None, instrument=None, extension='.nxs')
¶
Recursively search a directory for scan files, returns a generator
fn = find_scan_files(12345, '/dls/i16/data')
filepath = next(fn, None) # returns first filepath with '12345' in the title
all_paths = list(fn)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_file
|
str | int
|
scan number or part of filename |
required |
directory
|
str | None
|
directory to search for scan files, or None to use instrument |
None
|
instrument
|
str | None
|
if directory is None, use instrument to use DLS data directory (None to use current beamline) |
None
|
extension
|
str
|
extension to search for scan files |
'.nxs'
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
generator object for search |
Source code in mmg_toolbox/utils/env_functions.py
get_beamline(default='', filename=None)
¶
Return current beamline from filename/filepath or environment variable
Source code in mmg_toolbox/utils/env_functions.py
get_beamline_from_directory(directory, default='')
¶
Return current beamline from given directory. Finds the last instance of [ijk]##-#.
Source code in mmg_toolbox/utils/env_functions.py
get_data_directory()
¶
Return the default data directory
get_dls_visits(instrument=None, year=None, max_visits=None, omit_empty=False)
¶
Return dict of {visit: path} for each visible visit in the beamline directory
visits = get_dls_visits('i16')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument
|
str | None
|
displays visits for this instrument, or None for current beamline. |
None
|
year
|
str | int | None
|
displays visits in this year, or None for current year. |
None
|
max_visits
|
int | None
|
maximum number of visits to display, nor None for all visits |
None
|
omit_empty
|
bool
|
if True, omits visits containing no scans |
False
|
Source code in mmg_toolbox/utils/env_functions.py
get_dls_visits_str(instrument=None, year=None, max_visits=3, omit_empty=True)
¶
Return str of visits for each visible visit int he beamline directory
print(get_dls_visits_str('i16', 2025))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument
|
str | None
|
displays visits for this instrument, or None for current beamline. |
None
|
year
|
str | int | None
|
displays visits in this year, or None for current year. |
None
|
max_visits
|
int | None
|
maximum number of visits to display, nor None for all visits |
3
|
omit_empty
|
bool
|
if True, omits visits containing no scans |
True
|
Returns:
| Type | Description |
|---|---|
str
|
multiline string |
Source code in mmg_toolbox/utils/env_functions.py
get_first_file(folder, extension='.nxs')
¶
get_last_scan_number(folder)
¶
get_notebook_directory(data_directory)
¶
get_processing_directory(data_directory)
¶
get_scan_notebooks(scan, data_directory=None)
¶
Return list of processed jupyter notebooks for scan
Source code in mmg_toolbox/utils/env_functions.py
get_scan_numbers(folder, extension='.nxs')
¶
Return ordered list of scans numbers from nexus files in directory
Source code in mmg_toolbox/utils/env_functions.py
get_user(default='')
¶
last_folder_update(folder)
¶
open_jupyter_lab(directory=None)
¶
Open a new terminal and start a Jupyter lab terminal (linux only)
Source code in mmg_toolbox/utils/env_functions.py
open_terminal(command)
¶
Open a new terminal window (linux only) and run a command
run_command(command)
¶
Run shell command, print output to terminal
Source code in mmg_toolbox/utils/env_functions.py
run_jupyter_notebook(notebook_filename)
¶
run_python_script(script_filename)
¶
run_python_string(script)
¶
Run shell command, print output to terminal
scan_number_mapping(*folders, extension='.nxs')
¶
Build mapping of scan number to scan file