6
6
7
7
import numpy as np
8
8
9
- # from contextlib import contextmanager
9
+ from astropy import units as u
10
10
11
11
from ..mpi import Comm
12
12
20
20
21
21
from ..observation import DetectorData , Observation
22
22
23
+ from .. import future_ops as ops
23
24
24
- ZAXIS = np .array ([0 , 0 , 1.0 ])
25
+
26
+ ZAXIS = np .array ([0.0 , 0.0 , 1.0 ])
25
27
26
28
27
29
# These are helper routines for common operations used in the unit tests.
@@ -78,7 +80,7 @@ def create_comm(mpicomm):
78
80
return toastcomm
79
81
80
82
81
- def create_telescope (group_size ):
83
+ def create_telescope (group_size , sample_rate = 10.0 * u . Hz ):
82
84
"""Create a fake telescope with at least one detector per process."""
83
85
npix = 1
84
86
ring = 1
@@ -90,10 +92,10 @@ def create_telescope(group_size):
90
92
91
93
92
94
def create_distdata (mpicomm , obs_per_group = 1 , samples = 10 ):
93
- """Create a toast communicator and distributed data object.
95
+ """Create a toast communicator and (empty) distributed data object.
94
96
95
97
Use the specified MPI communicator to attempt to create 2 process groups,
96
- each with some observations.
98
+ each with some empty observations.
97
99
98
100
Args:
99
101
mpicomm (MPI.Comm): the MPI communicator (or None).
@@ -119,6 +121,42 @@ def create_distdata(mpicomm, obs_per_group=1, samples=10):
119
121
return data
120
122
121
123
124
+ def create_satellite_data (
125
+ mpicomm , obs_per_group = 1 , sample_rate = 10.0 * u .Hz , obs_time = 5.0 * u .minute
126
+ ):
127
+ """Create a data object with a simple satellite sim.
128
+
129
+ Use the specified MPI communicator to attempt to create 2 process groups. Create
130
+ a fake telescope and run the satellite sim to make some observations for each
131
+ group. This is useful for testing many operators that need some pre-existing
132
+ observations with boresight pointing.
133
+
134
+ Args:
135
+ mpicomm (MPI.Comm): the MPI communicator (or None).
136
+ obs_per_group (int): the number of observations assigned to each group.
137
+ samples (int): number of samples per observation.
138
+
139
+ Returns:
140
+ toast.Data: the distributed data with named observations.
141
+
142
+ """
143
+ toastcomm = create_comm (mpicomm )
144
+ data = Data (toastcomm )
145
+
146
+ tele = create_telescope (toastcomm .group_size , sample_rate = sample_rate )
147
+
148
+ sim_sat = ops .SimSatellite (
149
+ name = "sim_sat" ,
150
+ n_observation = (toastcomm .ngroups * obs_per_group ),
151
+ telescope = tele ,
152
+ hwp_rpm = 10.0 ,
153
+ observation_time = obs_time ,
154
+ )
155
+ sim_sat .apply (data )
156
+
157
+ return data
158
+
159
+
122
160
def uniform_chunks (samples , nchunk = 100 ):
123
161
"""Divide some number of samples into chunks.
124
162
@@ -141,37 +179,3 @@ def uniform_chunks(samples, nchunk=100):
141
179
for r in range (remain ):
142
180
chunks [r ] += 1
143
181
return chunks
144
-
145
-
146
- #
147
- # @contextmanager
148
- # def mpi_guard(comm=MPI.COMM_WORLD):
149
- # """Ensure that if one MPI process raises an exception, all of them do.
150
- #
151
- # Args:
152
- # comm (mpi4py.MPI.Comm): The MPI communicator.
153
- #
154
- # """
155
- # failed = 0
156
- # print(comm.rank, ": guard: enter", flush=True)
157
- # try:
158
- # print(comm.rank, ": guard: yield", flush=True)
159
- # yield
160
- # except:
161
- # print(comm.rank, ": guard: except", flush=True)
162
- # msg = "Exception on process {}:\n".format(comm.rank)
163
- # exc_type, exc_value, exc_traceback = sys.exc_info()
164
- # lines = traceback.format_exception(exc_type, exc_value,
165
- # exc_traceback)
166
- # msg += "\n".join(lines)
167
- # print(msg, flush=True)
168
- # failed = 1
169
- # print(comm.rank, ": guard: except done", flush=True)
170
- #
171
- # print(comm.rank, ": guard: failcount reduce", flush=True)
172
- # failcount = comm.allreduce(failed, op=MPI.SUM)
173
- # if failcount > 0:
174
- # raise RuntimeError("One or more MPI processes raised an exception")
175
- # print(comm.rank, ": guard: done", flush=True)
176
- #
177
- # return
0 commit comments