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
find_scan_files(scan_file, directory, 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 |
required |
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)
¶
Return dict of {visit: path} for each visible visit in the beamline directory
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