utils
formatting
chapter(title)
Formats a chapter header with bold magenta text, uppercase, and padding.
Source code in src/easydiffraction/utils/formatting.py
11 12 13 14 15 16 17 18 19 |
|
error(title)
Formats an error message with red text.
Source code in src/easydiffraction/utils/formatting.py
43 44 45 |
|
info(title)
Formats an info message with cyan text.
Source code in src/easydiffraction/utils/formatting.py
53 54 55 |
|
paragraph(title)
Formats a subsection header with bold blue text while keeping quoted text unformatted.
Source code in src/easydiffraction/utils/formatting.py
28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
section(title)
Formats a section header with bold green text.
Source code in src/easydiffraction/utils/formatting.py
22 23 24 25 |
|
warning(title)
Formats a warning message with yellow text.
Source code in src/easydiffraction/utils/formatting.py
48 49 50 |
|
utils
General utilities and helpers for easydiffraction.
download_from_repository(file_name, branch=None, destination='data', overwrite=False)
Download a data file from the EasyDiffraction repository on GitHub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
The file name to fetch (e.g., "NaCl.gr"). |
required |
branch
|
str | None
|
Branch to fetch from. If None, uses DATA_REPO_BRANCH. |
None
|
destination
|
str
|
Directory to save the file into (created if missing). |
'data'
|
overwrite
|
bool
|
Whether to overwrite the file if it already exists. Defaults to False. |
False
|
Source code in src/easydiffraction/utils/utils.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
get_value_from_xye_header(file_path, key)
Extracts a floating point value from the first line of the file, corresponding to the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the input file. |
required |
key
|
str
|
The key to extract ('DIFC' or 'two_theta'). |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The extracted value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the key is not found. |
Source code in src/easydiffraction/utils/utils.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
is_github_ci()
Determines if the current process is running in GitHub Actions CI.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the environment variable |
bool
|
(Always "true" on GitHub Actions), False otherwise. |
Source code in src/easydiffraction/utils/utils.py
104 105 106 107 108 109 110 111 112 |
|
is_notebook()
Determines if the current environment is a Jupyter Notebook.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running inside a Jupyter Notebook, False otherwise. |
Source code in src/easydiffraction/utils/utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
is_pycharm()
Determines if the current environment is PyCharm.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running inside PyCharm, False otherwise. |
Source code in src/easydiffraction/utils/utils.py
94 95 96 97 98 99 100 101 |
|
render_cif(cif_text, paragraph_title)
Display the CIF text as a formatted table in Jupyter Notebook or terminal.
Source code in src/easydiffraction/utils/utils.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
render_table(columns_data, columns_alignment, columns_headers=None, show_index=False, display_handle=None)
Renders a table either as an HTML (in Jupyter Notebook) or ASCII (in terminal), with aligned columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns_data
|
list
|
List of lists, where each inner list represents a row of data. |
required |
columns_alignment
|
list
|
Corresponding text alignment for each column (e.g., 'left', 'center', 'right'). |
required |
columns_headers
|
list
|
List of column headers. |
None
|
show_index
|
bool
|
Whether to show the index column. |
False
|
Source code in src/easydiffraction/utils/utils.py
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 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 |
|
tof_to_d(tof, offset, linear, quad, quad_eps=1e-20)
Convert time-of-flight (TOF) to d-spacing using a quadratic calibration.
Model
TOF = offset + linear * d + quad * d²
The function
- Uses a linear fallback when the quadratic term is effectively zero.
- Solves the quadratic for d and selects the smallest positive, finite root.
- Returns NaN where no valid solution exists.
- Expects
tof
as a NumPy array; output matches its shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tof
|
ndarray
|
Time-of-flight values (µs). Must be a NumPy array. |
required |
offset
|
float
|
Calibration offset (µs). |
required |
linear
|
float
|
Linear calibration coefficient (µs/Å). |
required |
quad
|
float
|
Quadratic calibration coefficient (µs/Ų). |
required |
quad_eps
|
float
|
Threshold to treat |
1e-20
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: d-spacing values (Å), NaN where invalid. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Source code in src/easydiffraction/utils/utils.py
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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
twotheta_to_d(twotheta, wavelength)
Convert 2-theta to d-spacing using Bragg's law.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
twotheta
|
float or ndarray
|
2-theta angle in degrees. |
required |
wavelength
|
float
|
Wavelength in Å. |
required |
Returns:
Name | Type | Description |
---|---|---|
d |
float or ndarray
|
d-spacing in Å. |
Source code in src/easydiffraction/utils/utils.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|