organoid_tracker.config package
Module contents
With this package, you can read the organoid_tracker.ini config files.
This will read from the config section called “my_script_name”: >>> config = ConfigFile(“my_script_name”)
This will read an organoid_tracker.ini file from a different folder: >>> config = ConfigFile(“my_script_name”, folder_name=r”C:path o older”)
This will read some settings, or provide default values for them if not found: >>> config.get_or_default(“example_string”, “My default value”, comment=”Some helpful comment”) >>> config.get_or_default(“example_int”, “4”, comment=”Only accepts integers”, type=config_type_int) >>> config.save() # Saves to disk
You can also define custom config types. For that, you need to create a function that takes a string and returns some object. >>> def config_type_complex_number(input: str) -> complex: >>> input = input.replace(” “, “”) # Strip spaces, so that you can write “5 + 3j” instead of “5+3j” >>> input = input.replacE(“i”, “j”) # Allow writing “5+2i” instead of just “5+2j” >>> return complex(input) >>> >>> config.get_or_default(“example_complex”, “8+2j”, comment=”Oooh, complex!”, type=config_type_complex_number)
- class organoid_tracker.config.ConfigFile(section_name: str, *, folder_name: str = './')
Bases:
object
Simple wrapper around ConfigParser
- FILE_NAME = 'organoid_tracker.ini'
- get_or_default(key: str, default_value: ~typing.Any, *, comment: str = '', store_in_defaults: bool = False, type: ~typing.Callable[[str], ~typing.Any] = <function config_type_str>) Any
Gets a string from the config file for the given key. If no such string exists, the default value is stored in the config first. If store_in_defaults is True, then the default value is stored in the DEFAULTS section, otherwise the default value is stored in the section given to __init__.
The default value can be supplied as a string or as the actual type. If it is a string, it will be stored as-is, but ran through the type function before being returned. If it is not a string, it will be stored as str(default_value), and returned as-is.
- get_or_prompt(key: str, question: str, store_in_defaults: bool = False, *, type: ~typing.Callable[[str], ~typing.Any] = <function config_type_str>) Any
Gets a string from the config file for the given key. If no such string exists, the user is asked for a default value, which is then stored in the configuration file. If store_in_defaults is True, then the default value is stored in the DEFAULTS section, otherwise the default value is stored in the section given to __init__.
- save() bool
Saves the configuration file if there are any changes made. Returns True if the config file was saved, False if no save was necessary.
- save_and_exit_if_changed()
If the configuration file was changed, the changes are stored an then the program is exited. This allows the user to see what changes were made, and then restart the program.
- organoid_tracker.config.config_type_csv_file(input: str) str
A string that will automatically have “.csv” appended to it if it hasn’t already (except for empty strings).
- organoid_tracker.config.config_type_image_shape(input: str) Tuple[int, int, int]
Parses a string like “512, 512, 32” as the tuple (32, 512, 512). Note the inversion of order.