Skip to content

Commit 47c6ed9

Browse files
committed
break some check from run_uvdata_uvsim into a separate function
1 parent e36435d commit 47c6ed9

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

pyuvsim/mpi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232

3333
class Tags(enum.IntEnum):
34+
"""Tags for MPI computations where worker nodes communicate with a main distribution node."""
35+
3436
READY = enum.auto()
3537
START = enum.auto()
3638
DONE = enum.auto()

pyuvsim/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ def __init__(self, maxval=None):
4444
self.remain = None
4545

4646
def __enter__(self):
47+
"""Enter a context manager."""
4748
return self
4849

4950
def __exit__(self, exc_type, exc_value, traceback):
51+
"""Exit a context manager."""
5052
self.finish()
5153

5254
def update(self, count):

pyuvsim/uvsim.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,41 @@ def _set_nsky_parts(Nsrcs, cat_nfreqs, Nsky_parts):
887887
return Nsky_parts
888888

889889

890+
def _check_uvdata(input_uv):
891+
"""Perform UVData checks for run_uvdata_uvsim.
892+
893+
Moved checks to reduce complexity.
894+
895+
Parameters
896+
-----------
897+
input_uv : :class:`pyuvdata.UVData` instance
898+
Provides baseline/time/frequency information.
899+
900+
Returns
901+
-------
902+
the UVData ordering convention
903+
"""
904+
if not isinstance(input_uv, UVData):
905+
raise TypeError("input_uv must be UVData object")
906+
907+
if not (
908+
(input_uv.Npols == 4)
909+
and (input_uv.polarization_array.tolist() == [-5, -6, -7, -8])
910+
):
911+
raise ValueError("input_uv must have XX,YY,XY,YX polarization")
912+
913+
if not input_uv.future_array_shapes:
914+
input_uv.use_future_array_shapes()
915+
916+
input_order = input_uv.blt_order
917+
if input_order != ("time", "baseline"):
918+
input_uv.reorder_blts(order="time", minor_order="baseline")
919+
920+
return input_order
921+
922+
923+
# this function is very complex according to flake8.
924+
# too many ifs, we can swing back to this later.
890925
def run_uvdata_uvsim(
891926
input_uv,
892927
beam_list,
@@ -986,21 +1021,7 @@ def run_uvdata_uvsim(
9861021
beam_dict = comm.bcast(beam_dict, root=0)
9871022
catalog.share(root=0)
9881023

989-
if not isinstance(input_uv, UVData):
990-
raise TypeError("input_uv must be UVData object")
991-
992-
if not (
993-
(input_uv.Npols == 4)
994-
and (input_uv.polarization_array.tolist() == [-5, -6, -7, -8])
995-
):
996-
raise ValueError("input_uv must have XX,YY,XY,YX polarization")
997-
998-
if not input_uv.future_array_shapes:
999-
input_uv.use_future_array_shapes()
1000-
1001-
input_order = input_uv.blt_order
1002-
if input_order != ("time", "baseline"):
1003-
input_uv.reorder_blts(order="time", minor_order="baseline")
1024+
input_order = _check_uvdata(input_uv)
10041025

10051026
# The root node will initialize our simulation
10061027
# Read input file and make uvtask list

0 commit comments

Comments
 (0)