Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add write_cal_table #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions nenupy/instru/instrument_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,50 @@ def read_cal_table(calibration_file: str = None) -> np.ndarray:
# ============================================================= #


# ============================================================= #
# ---------------------- write_cal_table ---------------------- #
# ============================================================= #
def write_cal_table(
table: np.ndarray,
calibration_file: str = None,
header: str = None,
) -> np.ndarray:
""" Write NenuFAR antenna delays calibration file.

:param table:
Calibration table complex128 shaped as
(frequency, mini-arrays, polarizations).
:type: :class:`~numpy.ndarray`

:param calibration_file:
Name of the calibration file to write.
:type calibration_file: `str`

:param header:
String header to add on top of file
:type header: `str`

:returns:
None
:type: None
"""
assert calibration_file is not None, "You must provide a filename"
assert table.shape == (512, 96, 2), f"Table has wrong shape {table.shape}. Expecting (512, 96, 2)"
assert table.dtype == np.dtype("complex128"), "Table dtype should be complex128"

with open(calibration_file, 'wb') as f:
log.info(f"Writing calibration table {calibration_file}")

f.write(b"HeaderStart\n")
f.write(header.encode())
if header[-1] != "\n":
f.write(b"\n")
f.write(b"HeaderStop\n")
f.write(table.tobytes())
# ============================================================= #
# ============================================================= #


# ============================================================= #
# ---------------- generate_nenufar_subarrays ----------------- #
# ============================================================= #
Expand Down
Loading