file.py
create_dir
Try to create an output directory if one doesn't exist.
Throws an exception if the directory cannot be created. Returns quietly if the directory already exists.
Parameters:
-
(dirstr) –name of directory
Returns:
-
str–path to directory.
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
create_directories
create_directories(
results_path: Sequence = ("..", "experiments"),
results_dir: str = "Demo",
do_clean: bool = False,
) -> str
Create results parent and target directory.
Parameters:
-
(results_pathSequence, default:('..', 'experiments')) –path to parent results directory (to be created if necessary)
-
(results_dirstr, default:'Demo') –target results directory (to be created)
Returns:
-
str–path to target results directory.
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
export_info
export_info(
info_dir: str,
file_name: str,
source_dict: dict,
module: Any,
suffix: str | None = None,
encoding: str = "utf-8",
) -> tuple[dict, str]
Export results dictionary to JSON file.
Tries to ensure all dictionary entries are
serializable by running latex
on keys and converting values to floats.
Parameters:
-
(info_dirstr) –target parent folder
-
(file_namestr) –name of output JSON file
-
(moduleAny) –dplvn or other class module
-
(source_dictdict) –dictionary of results, possibly requiring conversion from latex form such that serialization into a JSON file is possible
-
(suffixstr | None, default:None) –to append to filename prior to addition of '.json' extension
Returns:
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
export_plot
export_plot(
fig_name: str,
fig: Any,
results_dir: str,
file_type: str = "pdf",
suffix: str = "",
dpi: int | None = None,
) -> None
Export plot to PDF or other format file.
Parameters:
-
(fig_namestr) –name to be used for file (extension auto-appended)
-
(figAny) –figure object
-
(results_dirstr) –name of output directory
-
(file_typestr, default:'pdf') –file format
-
(suffixstr, default:'') –filename suffix
-
(dpiint | None, default:None) –output image resolution
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
export_plots
export_plots(
fig_dict: dict,
results_dir: str,
file_types: list[str] | tuple[str] | str = "png",
suffix: str = "",
dpi: int = 150,
do_verbose: bool = False,
) -> str
Export plots to PDF or other format files.
Parameters:
-
(fig_dictdict) –dictionary of figures
-
(results_dirstr) –name of output directory
-
(file_typeslist[str] | tuple[str] | str, default:'png') –file format (or list of file formats)
-
(suffixstr, default:'') –filename suffix
-
(dpiint, default:150) –output image resolution
-
(do_verbosebool, default:False) –use tqdm progress bar to track
Returns:
-
str–the supplied export directory
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
import_info
Read and adapt parameters specified in a JSON file.
Parameters:
-
(info_dirstr) –parent folder of JSON file
-
(file_namestr) –JSON file name.
-
(moduleAny) –dplvn or other class module
Returns: info as dictionary.
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
read_info
Wrapper around method to import info dictionary.
Parameters:
Returns:
Source code in .venv/lib/python3.14/site-packages/lvn/base/file.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |