-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from radionets-project/docstrings
Add docstrings throughout the codebase
- Loading branch information
Showing
13 changed files
with
852 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add/update docstrings throughout the codebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,133 @@ | ||
from pathlib import Path | ||
|
||
import natsort | ||
import numpy as np | ||
from astropy.io import fits | ||
from numpy.typing import ArrayLike | ||
|
||
__all__ = [ | ||
"fits_data", | ||
] | ||
|
||
|
||
class fits_data: | ||
def __init__(self, data_path): | ||
"""Handle h5 files simulated with radiosim package. | ||
"""Class that handles h5 files simulated | ||
with the radiosim package. | ||
Parameters | ||
---------- | ||
data_path: str or :class:`~pathlib.Path` | ||
path to fits data directory | ||
""" | ||
|
||
def __init__(self, data_path: str | Path) -> None: | ||
"""Handle h5 files simulated with the | ||
radiosim package. | ||
Parameters | ||
---------- | ||
data_path: str | ||
data_path: str Path | ||
path to fits data directory | ||
""" | ||
self.path = data_path | ||
self.files = self.get_files(Path(data_path)) | ||
self.num_files = len(self.files) | ||
|
||
def __call__(self): | ||
def __call__(self) -> None: | ||
return print("This is the pyvisgen fits files data set class.") | ||
|
||
def __len__(self): | ||
def __len__(self) -> int: | ||
""" | ||
Returns the total number of fits files in this dataset. | ||
Returns | ||
------- | ||
num_files : int | ||
Number of files in data set. | ||
""" | ||
return self.num_files | ||
|
||
def __getitem__(self, i): | ||
"""Returns the file at index ``i`` of :py:attr:`~self.files`.""" | ||
return self.open_file(i) | ||
|
||
def get_files(self, path): | ||
import natsort | ||
def get_files(self, path: Path) -> list[str]: | ||
"""Returns a list of files in natural ordering. | ||
Parameters | ||
---------- | ||
path : Path | ||
Path to the data directory. | ||
Returns | ||
------- | ||
fits_files_sorted : list | ||
List of files in natural ordering. | ||
""" | ||
fits_files = [str(x) for x in path.iterdir()] | ||
fits_files_sorted = natsort.natsorted(fits_files) | ||
|
||
return fits_files_sorted | ||
|
||
def get_uv_data(self, i): | ||
def get_uv_data(self, i: int) -> ArrayLike: | ||
"""Loads uv data from the file at index ``i`` of | ||
:py:attr:`~self.files`. | ||
Parameters | ||
---------- | ||
i : int | ||
Index of the file in :py:attr:`self.files`. | ||
Returns | ||
------- | ||
uv_data : array_like | ||
Array of uv data. | ||
""" | ||
with fits.open(self.files[i]) as hdul: | ||
uv_data = hdul[0].data | ||
hdul.close() | ||
return uv_data | ||
|
||
def get_freq_data(self, i): | ||
return uv_data | ||
|
||
def get_freq_data(self, i: int) -> ArrayLike: | ||
"""Loads frequency data from the file at index ``i`` of | ||
:py:attr:`~self.files`. | ||
Parameters | ||
---------- | ||
i : int | ||
Index of the file in :py:attr:`~self.files`. | ||
Returns | ||
------- | ||
freq_data : array_like | ||
Array of frequency data. | ||
base_freq : float | ||
Base frequency of the observing antenna array. | ||
""" | ||
with fits.open(self.files[i]) as hdul: | ||
base_freq = hdul[0].header["CRVAL4"] | ||
freq_data = hdul[2].data | ||
hdul.close() | ||
return freq_data, base_freq | ||
|
||
def open_file(self, i): | ||
return freq_data, base_freq | ||
|
||
def open_file(self, i: int) -> ArrayLike: | ||
"""Opens the file and returns the file information. | ||
Parameters | ||
---------- | ||
i : int | ||
Index of the file in :py:attr:`~self.files`. | ||
Returns | ||
------- | ||
:py:func:`~astropy.io.fits.info` | ||
Summary information on the FITS file. | ||
""" | ||
if isinstance(i, np.ndarray): | ||
print("Only one file can be open at the same time!") | ||
return | ||
|
||
with fits.open(self.files[i]) as hdul: | ||
fits_file = hdul | ||
hdul.close() | ||
return fits_file.info() | ||
|
||
return fits_file.info() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.