add docstring for initial function
# See the License for the specific language governing permissions and
# limitations under the License.
+import pathlib
+from typing import Dict, Tuple
from pymedphys._imports import numpy as np
+from pymedphys._imports import pandas as pd
from pymedphys._streamlit.utilities import config as _config
from pymedphys._streamlit.utilities import misc
@@ -30,14 +33,51 @@ def expand_border_events(mask):
return combined
-def get_directories_and_initial_database(config, refresh_cache):
+def get_directories_and_initial_database(
+ config, refresh_cache
+) -> Tuple[
+ pathlib.Path,
+ pathlib.Path,
+ "pd.DataFrame",
+ "pd.Timestamp",
+ Dict[str, Dict[str, str]],
+]:
+ """Load up paths from configuration, and pull in the primary
+ database structure before further filtering.
+
+ Requests the user to select a site, a date, and a machine id before
+ and then provides an initial database table for these selections
+ as well as the relevant directories.
+
+ Parameters
+ ----------
+ config : Dict
+ refresh_cache : bool
+ Whether or not to utilise the streamlit cache, or to pull
+ directly from the database.
+
+ Returns
+ -------
+ database_directory : pathlib.Path
+ The directory of the iView database for the chosen site.
+ icom_directory : pathlib.Path
+ The directory of the iCom records for the chosen site.
+ database_table : pandas.DataFrame
+ An initial table for the iView database. The column definitions
+ for this table can be found within
+ ``pymedphys._experimental.streamlit.utilities.iview._dbf.load_and_merge_dbfs``.
+ selected_date : pandas.Timestamp
+ The date selected by the user.
+ linac_to_directories_map : Dict[str, Dict[str, str]]
+ A mapping from Linac name/ids through to the configuration
+ directories for that Linac.
+ """
+
site_directories = _config.get_site_directories(config)
chosen_site = misc.site_picker(config, "Site")
database_directory = site_directories[chosen_site]["iviewdb"]
-
icom_directory = site_directories[chosen_site]["icom"]
-
database_table = _load_database_with_cache(database_directory, refresh_cache)
linac_map = {site["name"]: site["linac"] for site in config["site"]}
@@ -49,9 +89,6 @@ def get_directories_and_initial_database(config, refresh_cache):
except KeyError:
alias_map[linac["name"]] = linac["name"]
- # st.write(database_table)
- # st.write(alias_map)
-
database_table["machine_id"] = database_table["machine_id"].apply(
lambda x: alias_map[x]
)
