Skip to content

Commit 2e5945c

Browse files
database/opxrd: Fixed order in checking for database exists
1 parent 41e3380 commit 2e5945c

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

opxrd/database/opxrd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
class OpXRD(PatternDB):
1111
@classmethod
1212
def load(cls, root_dirpath : str, download : bool = True, *args, **kwargs) -> PatternDB:
13+
root_dirpath = os.path.expanduser(root_dirpath)
14+
root_dirpath = os.path.abspath(root_dirpath)
15+
16+
if os.path.isdir(root_dirpath) and download:
17+
raise ValueError(f'Cannot download to existing directory {root_dirpath}')
18+
1319
if not os.path.isdir(root_dirpath) and download:
1420
tmp_fpath = tempfile.mktemp(suffix='.zip')
1521
OpXRD._download_zenodo_opxrd(output_fpath=tmp_fpath)
1622
OpXRD._unzip_file(tmp_fpath, output_dir=root_dirpath)
1723

18-
if os.path.isdir(root_dirpath) and download:
19-
raise ValueError(f'Cannot download to existing directory {root_dirpath}')
2024

2125
print(f'- Loading patterns from local files')
2226
return super().load(dirpath=root_dirpath)

opxrd/usage.ipynb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "initial_id",
7+
"metadata": {
8+
"collapsed": true,
9+
"is_executing": true,
10+
"ExecuteTime": {
11+
"start_time": "2024-12-03T23:07:11.865624Z"
12+
}
13+
},
14+
"outputs": [],
15+
"source": [
16+
"from opxrd import OpXRD\n",
17+
"\n",
18+
"opxrd = OpXRD.load(root_dirpath='/tmp/opxrd')\n",
19+
"opxrd.plot_quantity(attr='spacegroup')"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"outputs": [],
25+
"source": [
26+
"pattern = opxrd.patterns[0]\n",
27+
"pattern.plot(title='Example pattern', save_fpath=)"
28+
],
29+
"metadata": {
30+
"collapsed": false
31+
},
32+
"id": "f3f5065b29df5401"
33+
}
34+
],
35+
"metadata": {
36+
"kernelspec": {
37+
"display_name": "Python 3",
38+
"language": "python",
39+
"name": "python3"
40+
},
41+
"language_info": {
42+
"codemirror_mode": {
43+
"name": "ipython",
44+
"version": 2
45+
},
46+
"file_extension": ".py",
47+
"mimetype": "text/x-python",
48+
"name": "python",
49+
"nbconvert_exporter": "python",
50+
"pygments_lexer": "ipython2",
51+
"version": "2.7.6"
52+
}
53+
},
54+
"nbformat": 4,
55+
"nbformat_minor": 5
56+
}

0 commit comments

Comments
 (0)