Skip to content

Commit b8164ea

Browse files
committed
docs: revise docstrings
1 parent 6bf93f8 commit b8164ea

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

wakis/sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def __init__(self, field='E', component='z',
262262
phase=0):
263263
'''
264264
Updates the fields E and H every timestep
265-
to introduce a planewave excitation at the given
265+
to introduce a dipole excitation at the given
266266
xs, ys slice, moving in z+ direction
267267
268268
Parameters

wakis/wakeSolver.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,55 @@ def read_txt(self, txt, skiprows=2, delimiter=None, usecols=None):
793793
d[i] = load[:, i]
794794

795795
return d
796+
797+
def save_txt(self, f_name, x_data=None, y_data=None, x_name='X [-]', y_name='Y [-]'):
798+
"""
799+
Saves x and y data to a text file in a two-column format.
800+
801+
This function exports the provided `x_data` and `y_data` to a `.txt` file,
802+
formatting the output with a header that includes custom column names.
803+
804+
Parameters
805+
----------
806+
f_name : str
807+
Name of the output file (without the `.txt` extension).
808+
x_data : numpy.ndarray, optional
809+
Array containing x-axis data. If None, the file is not saved.
810+
y_data : numpy.ndarray, optional
811+
Array containing y-axis data. If None, the file is not saved.
812+
x_name : str, optional
813+
Label for the x-axis column in the output file. Default is `"X [-]"`.
814+
y_name : str, optional
815+
Label for the y-axis column in the output file. Default is `"Y [-]"`.
816+
817+
Notes
818+
-----
819+
- The data is saved in a two-column format where `x_data` and `y_data`
820+
are combined column-wise.
821+
- If `x_data` or `y_data` is missing, the function prints a warning and does not save a file.
822+
823+
Examples
824+
--------
825+
Save two NumPy arrays to `data.txt`:
826+
827+
>>> x = np.linspace(0, 10, 5)
828+
>>> y = np.sin(x)
829+
>>> save_txt("data", x, y, x_name="Time [s]", y_name="Amplitude")
830+
831+
The saved file will look like:
832+
833+
Time [s] Amplitude
834+
--------------------------------
835+
0.00 0.00
836+
2.50 0.59
837+
5.00 -0.99
838+
7.50 0.94
839+
10.00 -0.54
840+
"""
841+
if x_data is not None and y_data is not None:
842+
np.savetxt(f_name+'.txt', np.c_[x_data, y_data], header=' '+x_name+' '*20+y_name+'\n'+'-'*48)
843+
else:
844+
print('txt not saved, please provide x_data and y_data')
796845

797846
def load_results(self, folder):
798847
'''Load all txt from a given folder

0 commit comments

Comments
 (0)