Skip to content

Commit

Permalink
Adding support to init from Path objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kartographer committed Feb 20, 2024
1 parent 7d2e4dd commit 4398c75
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

### Added
- Added support for initializing `MirParser` and `MirMetaData` objects from `Path`
objects.
- Added a brief tutorial on how to convert SMA MIR data into MS format (with some notes
on SMA specific keywords than can be used).
- Added the `Mir.generate_sma_antpos_dict` method for reading in SMA-formatted antenna
Expand Down
23 changes: 12 additions & 11 deletions pyuvdata/uvdata/mir_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,14 @@ def __init__(
Parameters
----------
obj : str or ndarray or int
Optional argument used to specify how to initialize the object. If a str is
supplied, then it is treated as the path to the Mir data folder containing
the metadata. If an int is supplied, a "blank" (zero-filled) array of
metadata is generated, with length of `obj`. If an ndarray is supplied, then
the supplied array is used as the underlying data set for the object (where
dtype of the array must match that appropriate for the object).
obj : str or Path or ndarray or int
Optional argument used to specify how to initialize the object. If a str or
Path is supplied, then it is treated as the path to the Mir data folder
containing the metadata. If an int is supplied, a "blank" (zero-filled)
array of metadata is generated, with length of `obj`. If an ndarray is
supplied, then the supplied array is used as the underlying data set for the
object (where dtype of the array must match that appropriate for the
object).
filetype : str
Name of the type MirMetaData object, which is then used as the file name
that is read from/written to within the folder specified by the path.
Expand Down Expand Up @@ -2197,7 +2198,7 @@ def _gen_filepath(self, filepath=None, *, check=True, invert_check=False):
Parameters
----------
filepath : str
filepath : str or Path
Either the file to write to, or if providing the name of an existing folder,
the name of the folder to write in (with the file name set by the _filetype
attribute, which is automatically set for various subclasses of
Expand Down Expand Up @@ -2246,7 +2247,7 @@ def read(self, filepath=None):
Parameters
----------
filepath : str
filepath : str or Path
Path of the folder containing the metadata in question.
"""
self._data = np.fromfile(
Expand Down Expand Up @@ -2881,7 +2882,7 @@ def read(self, filepath=None):
Parameters
----------
filepath : str
filepath : str or Path
Path of the folder containing the metadata in question.
"""
with open(self._gen_filepath(filepath), "r") as antennas_file:
Expand Down Expand Up @@ -3415,7 +3416,7 @@ def read(self, filepath=None):
Parameters
----------
filepath : str
filepath : str or Path
Path of the folder containing the metadata in question.
"""
try:
Expand Down
2 changes: 1 addition & 1 deletion pyuvdata/uvdata/mir_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
Parameters
----------
filepath : str
filepath : str or Path
Filepath is the path to the folder containing the Mir data set.
compass_soln : str
Optional argument, specifying the path of COMPASS-derived flagging and
Expand Down
13 changes: 13 additions & 0 deletions pyuvdata/uvdata/tests/test_mir_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2318,3 +2318,16 @@ def test_mir_remember_me_vis_data(mir_data):
np.all(sp_raw["data"] == check_arr) if (np.mod(idx, 5) == 0) else True
for idx, sp_raw in enumerate(mir_data.raw_data.values())
)


def test_mir_parser_read_path_vs_str():
from pathlib import Path

sma_data_path = str(os.path.join(DATA_PATH, "sma_test.mir"))
sma_str_init = MirParser(
sma_data_path, load_cross=True, load_auto=True, has_auto=True
)
sma_path_init = MirParser(
Path(sma_data_path), load_cross=True, load_auto=True, has_auto=True
)
assert sma_str_init == sma_path_init

0 comments on commit 4398c75

Please sign in to comment.