ipyvasp 0.9.86__py2.py3-none-any.whl → 0.9.87__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ipyvasp/__init__.py +1 -1
- ipyvasp/_version.py +1 -1
- ipyvasp/utils.py +37 -15
- ipyvasp/widgets.py +3 -3
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/METADATA +1 -1
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/RECORD +10 -10
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/LICENSE +0 -0
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/WHEEL +0 -0
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/entry_points.txt +0 -0
- {ipyvasp-0.9.86.dist-info → ipyvasp-0.9.87.dist-info}/top_level.txt +0 -0
ipyvasp/__init__.py
CHANGED
ipyvasp/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.9.
|
|
1
|
+
__version__ = "0.9.87"
|
ipyvasp/utils.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
__all__ = [
|
|
2
2
|
"get_file_size",
|
|
3
|
-
"
|
|
3
|
+
"take",
|
|
4
4
|
"set_dir",
|
|
5
5
|
"interpolate_data",
|
|
6
6
|
"rolling_mean",
|
|
@@ -36,36 +36,58 @@ def get_file_size(path: str):
|
|
|
36
36
|
else:
|
|
37
37
|
return ""
|
|
38
38
|
|
|
39
|
-
def
|
|
40
|
-
"""Read
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
def take(f, rows, cols=None, dtype=str, sep=None):
|
|
40
|
+
"""Read data from an opened file pointer `f` by indexing. Negative indexing is supported to read lines from end.
|
|
41
|
+
Negative indexing is not supported in cols because of variable length of each line.
|
|
42
|
+
If `cols=None`, returns a single str of line if one integer given, otherwise a list of lines.
|
|
43
|
+
If `cols` is int ot sequence of int, each line is splitted by `sep` (default all whitespaces) and `dtype` is applied over resulting fields.
|
|
43
44
|
|
|
45
|
+
`take(f, -1, 1, float) == float(f.readlines()[-1].split()[1])` with advantage for consuming almost no memory as compared to `f.readlines()` on a huge file.
|
|
46
|
+
|
|
47
|
+
Note: For more robust reading of structured files like `PROCAR` use `ipyvasp.parse_text` function.
|
|
48
|
+
|
|
49
|
+
Tip: If your output is matrix-like, you can cast it to numpy array like `take(...)*np.array(1)`.
|
|
50
|
+
|
|
44
51
|
>>> with open('some_file','r') as f:
|
|
45
|
-
>>>
|
|
46
|
-
>>>
|
|
47
|
-
>>>
|
|
52
|
+
>>> take(f, -1, 1, float) # read last line, second column as float
|
|
53
|
+
>>> take(f, range(5)) # first 5 lines
|
|
54
|
+
>>> take(f, range(-5,0)) # last 5 lines
|
|
48
55
|
"""
|
|
49
56
|
if not isinstance(f, io.TextIOWrapper):
|
|
50
57
|
raise TypeError(f"f should be file-like object. got {type(f)}")
|
|
51
58
|
|
|
52
59
|
return_line = False
|
|
53
|
-
if isinstance(
|
|
54
|
-
|
|
60
|
+
if isinstance(rows, int):
|
|
61
|
+
rows = [rows]
|
|
55
62
|
return_line = True
|
|
56
63
|
|
|
57
|
-
if not isinstance(
|
|
58
|
-
raise TypeError(f"
|
|
64
|
+
if not isinstance(rows, (tuple,list, range)):
|
|
65
|
+
raise TypeError(f"rows should int/list/tuple/range, got {type(rows)}")
|
|
59
66
|
|
|
60
67
|
f.seek(0)
|
|
61
|
-
if min(
|
|
68
|
+
if min(rows) < 0:
|
|
62
69
|
if not hasattr(f, '_nlines'): # do this once, assuming file is not changed while reading
|
|
63
70
|
f._nlines = sum(1 for _ in enumerate(f))
|
|
64
71
|
f.seek(0)
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
rows = [i + (f._nlines if i < 0 else 0) for i in rows] # make all positive
|
|
67
74
|
|
|
68
|
-
lines = [l for i, l in enumerate(f) if i in
|
|
75
|
+
lines = [l for i, l in enumerate(f) if i in rows]
|
|
76
|
+
|
|
77
|
+
if cols:
|
|
78
|
+
return_col = False
|
|
79
|
+
if isinstance(cols, int):
|
|
80
|
+
cols = [cols]
|
|
81
|
+
return_col = True
|
|
82
|
+
|
|
83
|
+
if not isinstance(cols, (list,tuple, range)):
|
|
84
|
+
raise TypeError(f"cols should be a sequce of integers or single int, got {type(cols)}")
|
|
85
|
+
|
|
86
|
+
lines = [[dtype(v) for i, v in enumerate(l.split(sep)) if i in cols] for l in lines]
|
|
87
|
+
|
|
88
|
+
if return_col:
|
|
89
|
+
lines = [line[0] for line in lines]
|
|
90
|
+
|
|
69
91
|
return lines[0] if return_line else lines
|
|
70
92
|
|
|
71
93
|
|
ipyvasp/widgets.py
CHANGED
|
@@ -448,9 +448,9 @@ class Files:
|
|
|
448
448
|
>>> import ipyvasp as ipv
|
|
449
449
|
>>> files = ipv.Files(...)
|
|
450
450
|
>>> files.mapf(lambda fp: json.load(fp,cls=ipv.DecodeToNumpy),to_df=True) # or use ipv.load(path) in map
|
|
451
|
-
>>> files.mapf(lambda fp: ipv.
|
|
452
|
-
>>> files.mapf(lambda fp: ipv.
|
|
453
|
-
>>> files.mapf(lambda fp: ipv.
|
|
451
|
+
>>> files.mapf(lambda fp: ipv.take(fp, range(5)) # read first five lines
|
|
452
|
+
>>> files.mapf(lambda fp: ipv.take(fp, range(-5,0)) # read last five lines
|
|
453
|
+
>>> files.mapf(lambda fp: ipv.take(fp, -1, 1, float) # read last line, second column as float
|
|
454
454
|
"""
|
|
455
455
|
if not mode in 'rb':
|
|
456
456
|
raise ValueError("Only 'r'/'rb' mode is allowed in this context!")
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
ipyvasp/__init__.py,sha256=
|
|
1
|
+
ipyvasp/__init__.py,sha256=mV4WksglB6ZwUV30NnWVBmWWjF7fSZ0dB-7eyhJrWtw,1423
|
|
2
2
|
ipyvasp/__main__.py,sha256=eJV1TZSiT8mC_VqAeksNnBI2I8mKMiPkEIlwikbtOjI,216
|
|
3
3
|
ipyvasp/_enplots.py,sha256=D38paN8zqZgluNAwmCwcocd7-_h_T0HTGolI1eBkDes,37484
|
|
4
4
|
ipyvasp/_lattice.py,sha256=kOseNCIWt-VCnkhFQZEcsXhyNYobjfqNfAl3seXHiVU,105584
|
|
5
|
-
ipyvasp/_version.py,sha256=
|
|
5
|
+
ipyvasp/_version.py,sha256=Iig1hTfzlTrB9madAdxIjYYENfEZu438RjihVQ7fLT0,24
|
|
6
6
|
ipyvasp/bsdos.py,sha256=JvYvHLqMp3eVaJ0amD-9kxp7FehQIFq3WFUxsO5dj0Q,31794
|
|
7
7
|
ipyvasp/cli.py,sha256=aWFEVhNmnW8eSOp5uh95JaDwLQ9K9nlCQcbnOSuhWgw,6844
|
|
8
8
|
ipyvasp/evals_dataframe.py,sha256=-sqxK7LPV6sYDO_XXmZ80FznOaXTkVdbqJKKvTUtMak,20637
|
|
@@ -10,16 +10,16 @@ ipyvasp/lattice.py,sha256=VfyhmbpRHA3nePWUmaoMmCiAehby_VvDuDcp34OK3rA,33685
|
|
|
10
10
|
ipyvasp/misc.py,sha256=gPA-71V_fuzyvinHR4P1kYMm90lJYdt24733pA5_4Kk,2340
|
|
11
11
|
ipyvasp/potential.py,sha256=tzA73c5lkp6ahLSJchMrU043-QWaOV0nIOUA7VMmfKQ,11408
|
|
12
12
|
ipyvasp/surface.py,sha256=MjE5oB0wW6Pca_C-xu8rN6OMH7lUEeNPNyM7Kz_Im-8,23766
|
|
13
|
-
ipyvasp/utils.py,sha256=
|
|
14
|
-
ipyvasp/widgets.py,sha256=
|
|
13
|
+
ipyvasp/utils.py,sha256=yPKMaqNKw0uCBO_RE3XWrY7MH8cJ8Jtoj1bqAaNU70g,16649
|
|
14
|
+
ipyvasp/widgets.py,sha256=yNTCmVPQgnIOFLxB8FwG9UhsInIE-g2sFhlS9qcQ5IU,49228
|
|
15
15
|
ipyvasp/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
ipyvasp/core/parser.py,sha256=if5DsBpDS7qCIlWsl6JD0ovRBk01h0CdKYa4vE9SSzw,38945
|
|
17
17
|
ipyvasp/core/plot_toolkit.py,sha256=V-IQo7MrOhmNCGpWHIMtV04TmmubgFvGgH_yd4YmoX4,36158
|
|
18
18
|
ipyvasp/core/serializer.py,sha256=v0ma4htirybtQo_wFhIEjkRoZMQk9ETDz85iloaq3YY,38427
|
|
19
19
|
ipyvasp/core/spatial_toolkit.py,sha256=dXowREhiFzBvvr5f_bApzFhf8IzjH2E2Ix90oCBUetY,14885
|
|
20
|
-
ipyvasp-0.9.
|
|
21
|
-
ipyvasp-0.9.
|
|
22
|
-
ipyvasp-0.9.
|
|
23
|
-
ipyvasp-0.9.
|
|
24
|
-
ipyvasp-0.9.
|
|
25
|
-
ipyvasp-0.9.
|
|
20
|
+
ipyvasp-0.9.87.dist-info/LICENSE,sha256=F3SO5RiAZOMfmMGf1KOuk2g_c4ObvuBJhd9iBLDgXoQ,1263
|
|
21
|
+
ipyvasp-0.9.87.dist-info/METADATA,sha256=I_GtZBZi2Se6P0wNJsrZsme1D74507cjcbpScMdMIpM,2421
|
|
22
|
+
ipyvasp-0.9.87.dist-info/WHEEL,sha256=iYlv5fX357PQyRT2o6tw1bN-YcKFFHKqB_LwHO5wP-g,110
|
|
23
|
+
ipyvasp-0.9.87.dist-info/entry_points.txt,sha256=C7m0Sjmr14wFjflCkWXLzr5N6-cQj8uJC9n82mUtzt8,44
|
|
24
|
+
ipyvasp-0.9.87.dist-info/top_level.txt,sha256=ftziWlMWu_1VpDP1sRTFrkfBnWxAi393HYDVu4wRhUk,8
|
|
25
|
+
ipyvasp-0.9.87.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|