qpoint 1.13.0__cp313-cp313-macosx_10_13_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
qpoint/_libqpoint.py ADDED
@@ -0,0 +1,1286 @@
1
+ # ctypes wrapper for libqpoint
2
+
3
+ import ctypes as ct
4
+ import numpy as np
5
+ import os
6
+
7
+ libqp = np.ctypeslib.load_library("libqpoint", os.path.dirname(__file__))
8
+
9
+ # **********************************************************************
10
+ # Types
11
+ # **********************************************************************
12
+
13
+ NDP = np.ctypeslib.ndpointer
14
+
15
+ quat_t = NDP(np.double, ndim=1, shape=(4,), flags=["A", "C"])
16
+ quat_t_p = NDP(np.double, ndim=2, flags=["A", "C"])
17
+ mueller_t = NDP(np.double, ndim=1, shape=(4,), flags=["A", "C"])
18
+ mueller_t_p = NDP(np.double, ndim=2, flags=["A", "C"])
19
+ vec3_t = NDP(np.double, ndim=1, shape=(3,), flags=["A", "C"])
20
+ vec3_t_p = NDP(np.double, ndim=2, flags=["A", "C"])
21
+
22
+ wquat_t = NDP(np.double, ndim=1, shape=(4,), flags=["A", "C", "W"])
23
+ wquat_t_p = NDP(np.double, ndim=2, flags=["A", "C", "W"])
24
+ wvec3_t = NDP(np.double, ndim=1, shape=(3,), flags=["A", "C", "W"])
25
+ wvec3_t_p = NDP(np.double, ndim=2, flags=["A", "C", "W"])
26
+
27
+ arr = NDP(np.double, ndim=1, flags=["A", "C"])
28
+ arrf = NDP(np.uint8, ndim=1, flags=["A", "C"])
29
+ warr = NDP(np.double, ndim=1, flags=["A", "C", "W"])
30
+ warri = NDP(int, ndim=1, flags=["A", "C", "W"])
31
+
32
+ arr2 = NDP(np.uintp, ndim=1, flags=["A", "C"])
33
+ larr = NDP(int, ndim=1, flags=["A", "C"])
34
+
35
+ QP_DO_ALWAYS = ct.c_int.in_dll(libqp, "QP_DO_ALWAYS").value
36
+ QP_DO_ONCE = ct.c_int.in_dll(libqp, "QP_DO_ONCE").value
37
+ QP_DO_NEVER = ct.c_int.in_dll(libqp, "QP_DO_NEVER").value
38
+
39
+
40
+ class qp_state_t(ct.Structure):
41
+ _fields_ = [("update_rate", ct.c_double), ("ctime_last", ct.c_double)]
42
+
43
+
44
+ class qp_weather_t(ct.Structure):
45
+ _fields_ = [
46
+ ("temperature", ct.c_double),
47
+ ("pressure", ct.c_double),
48
+ ("humidity", ct.c_double),
49
+ ("frequency", ct.c_double),
50
+ ]
51
+
52
+
53
+ class qp_bulletina_entry_t(ct.Structure):
54
+ _fields_ = [
55
+ ("x", ct.c_float),
56
+ ("y", ct.c_float),
57
+ ("dut1", ct.c_float),
58
+ ]
59
+
60
+
61
+ class qp_bulletina_t(ct.Structure):
62
+ _fields_ = [
63
+ ("entries", ct.POINTER(qp_bulletina_entry_t)),
64
+ ("mjd_min", ct.c_int),
65
+ ("mjd_max", ct.c_int),
66
+ ]
67
+
68
+
69
+ class qp_memory_t(ct.Structure):
70
+ _fields_ = [
71
+ ("init", ct.c_int),
72
+ ("state_daber", qp_state_t),
73
+ ("state_lonlat", qp_state_t),
74
+ ("state_wobble", qp_state_t),
75
+ ("state_dut1", qp_state_t),
76
+ ("state_erot", qp_state_t),
77
+ ("state_npb", qp_state_t),
78
+ ("state_aaber", qp_state_t),
79
+ ("state_ref", qp_state_t),
80
+ ("state_daber_inv", qp_state_t),
81
+ ("state_lonlat_inv", qp_state_t),
82
+ ("state_wobble_inv", qp_state_t),
83
+ ("state_dut1_inv", qp_state_t),
84
+ ("state_erot_inv", qp_state_t),
85
+ ("state_npb_inv", qp_state_t),
86
+ ("state_aaber_inv", qp_state_t),
87
+ ("state_ref_inv", qp_state_t),
88
+ ("weather", qp_weather_t),
89
+ ("ref_delta", ct.c_double),
90
+ ("q_ref", ct.c_double * 4),
91
+ ("q_ref_inv", ct.c_double * 4),
92
+ ("dut1", ct.c_double),
93
+ ("q_lonlat", ct.c_double * 4),
94
+ ("q_lonlat_inv", ct.c_double * 4),
95
+ ("q_wobble", ct.c_double * 4),
96
+ ("q_wobble_inv", ct.c_double * 4),
97
+ ("q_npb", ct.c_double * 4),
98
+ ("q_npb_inv", ct.c_double * 4),
99
+ ("q_erot", ct.c_double * 4),
100
+ ("q_erot_inv", ct.c_double * 4),
101
+ ("q_gal", ct.c_double * 4),
102
+ ("q_gal_inv", ct.c_double * 4),
103
+ ("gal_init", ct.c_int),
104
+ ("v_dipole", ct.c_double * 3),
105
+ ("dipole_init", ct.c_int),
106
+ ("beta_earth", ct.c_double * 3),
107
+ ("beta_rot", ct.c_double * 3),
108
+ ("bulletinA", qp_bulletina_t),
109
+ ("accuracy", ct.c_int),
110
+ ("mean_aber", ct.c_int),
111
+ ("fast_aber", ct.c_int),
112
+ ("fast_math", ct.c_int),
113
+ ("polconv", ct.c_int),
114
+ ("pix_order", ct.c_int),
115
+ ("interp_pix", ct.c_int),
116
+ ("fast_pix", ct.c_int),
117
+ ("error_missing", ct.c_int),
118
+ ("nan_missing", ct.c_int),
119
+ ("interp_missing", ct.c_int),
120
+ ("num_threads", ct.c_int),
121
+ ("thread_num", ct.c_int),
122
+ ]
123
+
124
+
125
+ qp_memory_t_p = ct.POINTER(qp_memory_t)
126
+
127
+ QP_STRUCT_INIT = 1
128
+ QP_STRUCT_MALLOC = 2
129
+ QP_ARR_INIT_PTR = 4
130
+ QP_ARR_MALLOC_1D = 8
131
+ QP_ARR_MALLOC_2D = 16
132
+
133
+
134
+ class qp_det_t(ct.Structure):
135
+ _fields_ = [
136
+ ("init", ct.c_int),
137
+ ("q_off", ct.c_double * 4),
138
+ ("weight", ct.c_double),
139
+ ("gain", ct.c_double),
140
+ ("mueller", ct.c_double * 4),
141
+ ("n", ct.c_size_t),
142
+ ("tod_init", ct.c_int),
143
+ ("tod", ct.POINTER(ct.c_double)),
144
+ ("flag_init", ct.c_int),
145
+ ("flag", ct.POINTER(ct.c_uint8)),
146
+ ("weights_init", ct.c_int),
147
+ ("weights", ct.POINTER(ct.c_double)),
148
+ ]
149
+
150
+
151
+ qp_det_t_p = ct.POINTER(qp_det_t)
152
+
153
+
154
+ class qp_detarr_t(ct.Structure):
155
+ _fields_ = [
156
+ ("init", ct.c_int),
157
+ ("n", ct.c_size_t),
158
+ ("arr_init", ct.c_int),
159
+ ("diff", ct.c_size_t),
160
+ ("arr", qp_det_t_p),
161
+ ]
162
+
163
+
164
+ qp_detarr_t_p = ct.POINTER(qp_detarr_t)
165
+
166
+
167
+ class qp_point_t(ct.Structure):
168
+ _fields_ = [
169
+ ("init", ct.c_int),
170
+ ("n", ct.c_size_t),
171
+ ("q_bore_init", ct.c_int),
172
+ ("q_bore", ct.POINTER(ct.c_double * 4)),
173
+ ("ctime_init", ct.c_int),
174
+ ("ctime", ct.POINTER(ct.c_double)),
175
+ ("q_hwp_init", ct.c_int),
176
+ ("q_hwp", ct.POINTER(ct.c_double * 4)),
177
+ ]
178
+
179
+
180
+ qp_point_t_p = ct.POINTER(qp_point_t)
181
+
182
+ qp_vec_mode = ct.c_uint
183
+ QP_VEC_NONE = 0
184
+ QP_VEC_TEMP = 1
185
+ QP_VEC_POL = 2
186
+ QP_VEC_VPOL = 3
187
+ QP_VEC_D1 = 4
188
+ QP_VEC_D1_POL = 5
189
+ QP_VEC_D2 = 6
190
+ QP_VEC_D2_POL = 7
191
+ vec_modes = {
192
+ 1: QP_VEC_TEMP,
193
+ 3: {True: QP_VEC_POL, False: QP_VEC_D1},
194
+ 4: QP_VEC_VPOL,
195
+ 6: QP_VEC_D2,
196
+ 9: QP_VEC_D1_POL,
197
+ 18: QP_VEC_D2_POL,
198
+ }
199
+
200
+ qp_proj_mode = ct.c_uint
201
+ QP_PROJ_NONE = 0
202
+ QP_PROJ_TEMP = 1
203
+ QP_PROJ_POL = 2
204
+ QP_PROJ_VPOL = 3
205
+ proj_modes = {1: QP_PROJ_TEMP, 6: QP_PROJ_POL, 10: QP_PROJ_VPOL}
206
+
207
+
208
+ class qp_map_t(ct.Structure):
209
+ _fields_ = [
210
+ ("init", ct.c_int),
211
+ ("partial", ct.c_int),
212
+ ("nside", ct.c_size_t),
213
+ ("npix", ct.c_size_t),
214
+ ("pixinfo_init", ct.c_int),
215
+ ("pixinfo", ct.c_void_p),
216
+ ("pixhash_init", ct.c_int),
217
+ ("pixhash", ct.c_void_p),
218
+ ("num_vec", ct.c_size_t),
219
+ ("vec_mode", qp_vec_mode),
220
+ ("vec1d_init", ct.c_int),
221
+ ("vec1d", ct.POINTER(ct.c_double)),
222
+ ("vec_init", ct.c_int),
223
+ ("vec", ct.POINTER(ct.POINTER(ct.c_double))),
224
+ ("num_proj", ct.c_size_t),
225
+ ("proj_mode", qp_proj_mode),
226
+ ("proj1d_init", ct.c_int),
227
+ ("proj1d", ct.POINTER(ct.c_double)),
228
+ ("proj_init", ct.c_int),
229
+ ("proj", ct.POINTER(ct.POINTER(ct.c_double))),
230
+ ]
231
+
232
+
233
+ qp_map_t_p = ct.POINTER(qp_map_t)
234
+
235
+
236
+ def pointer_2d(d):
237
+ return (
238
+ d.__array_interface__["data"][0] + np.arange(d.shape[0]) * d.strides[0]
239
+ ).astype(np.uintp)
240
+
241
+
242
+ def as_ctypes(d):
243
+ return np.ctypeslib.as_ctypes(d)
244
+
245
+
246
+ def setargs(fname, arg=None, res=None):
247
+ func = getattr(libqp, fname)
248
+ if arg is not None and not isinstance(arg, (tuple, list)):
249
+ arg = (arg,)
250
+ func.argtypes = arg
251
+ func.restype = res
252
+
253
+
254
+ # **********************************************************************
255
+ # Functions
256
+ # **********************************************************************
257
+
258
+ setargs("qp_init_memory", res=qp_memory_t_p)
259
+ setargs("qp_free_memory", arg=qp_memory_t_p)
260
+ setargs("qp_print_memory", arg=qp_memory_t_p)
261
+
262
+ setargs("qp_reset_rates", arg=qp_memory_t_p)
263
+ setargs("qp_reset_inv_rates", arg=qp_memory_t_p)
264
+
265
+ setargs("qp_get_error_code", arg=qp_memory_t_p, res=ct.c_int)
266
+ setargs("qp_get_error_string", arg=qp_memory_t_p, res=ct.c_char_p)
267
+
268
+ setargs(
269
+ "qp_azel2radec",
270
+ arg=(
271
+ qp_memory_t_p, # params
272
+ ct.c_double,
273
+ ct.c_double,
274
+ ct.c_double, # offset
275
+ arr,
276
+ arr,
277
+ arr,
278
+ arr,
279
+ arr,
280
+ arr,
281
+ arr, # a/e/p/r/l/l/t
282
+ warr,
283
+ warr,
284
+ warr,
285
+ warr,
286
+ ct.c_int,
287
+ ),
288
+ )
289
+ setargs(
290
+ "qp_azelpsi2radec",
291
+ arg=(
292
+ qp_memory_t_p, # params
293
+ ct.c_double,
294
+ ct.c_double,
295
+ ct.c_double, # offset
296
+ arr,
297
+ arr,
298
+ arr,
299
+ arr,
300
+ arr,
301
+ arr,
302
+ arr,
303
+ arr, # a/e/p/p/r/l/l/t
304
+ warr,
305
+ warr,
306
+ warr,
307
+ warr,
308
+ ct.c_int,
309
+ ),
310
+ )
311
+ setargs(
312
+ "qp_azel2radecpa",
313
+ arg=(
314
+ qp_memory_t_p, # params
315
+ ct.c_double,
316
+ ct.c_double,
317
+ ct.c_double, # offset
318
+ arr,
319
+ arr,
320
+ arr,
321
+ arr,
322
+ arr,
323
+ arr,
324
+ arr, # a/e/p/r/l/l/t
325
+ warr,
326
+ warr,
327
+ warr,
328
+ ct.c_int,
329
+ ),
330
+ )
331
+ setargs(
332
+ "qp_azelpsi2radecpa",
333
+ arg=(
334
+ qp_memory_t_p, # params
335
+ ct.c_double,
336
+ ct.c_double,
337
+ ct.c_double, # offset
338
+ arr,
339
+ arr,
340
+ arr,
341
+ arr,
342
+ arr,
343
+ arr,
344
+ arr,
345
+ arr, # a/e/p/p/r/l/l/t
346
+ warr,
347
+ warr,
348
+ warr,
349
+ ct.c_int,
350
+ ),
351
+ )
352
+ setargs(
353
+ "qp_radec2azel",
354
+ arg=(
355
+ qp_memory_t_p, # params
356
+ arr,
357
+ arr,
358
+ arr,
359
+ arr,
360
+ arr,
361
+ arr,
362
+ arr,
363
+ arr,
364
+ arr, # r/d/p/l/l/t/a/e/p
365
+ ct.c_int,
366
+ ),
367
+ )
368
+ setargs(
369
+ "qp_azel2radec_hwp",
370
+ arg=(
371
+ qp_memory_t_p, # params
372
+ ct.c_double,
373
+ ct.c_double,
374
+ ct.c_double, # offset
375
+ arr,
376
+ arr,
377
+ arr,
378
+ arr,
379
+ arr,
380
+ arr,
381
+ arr,
382
+ arr, # a/e/p/r/l/l/t/hwp
383
+ warr,
384
+ warr,
385
+ warr,
386
+ warr,
387
+ ct.c_int,
388
+ ),
389
+ )
390
+ setargs(
391
+ "qp_azelpsi2radec_hwp",
392
+ arg=(
393
+ qp_memory_t_p, # params
394
+ ct.c_double,
395
+ ct.c_double,
396
+ ct.c_double, # offset
397
+ arr,
398
+ arr,
399
+ arr,
400
+ arr,
401
+ arr,
402
+ arr,
403
+ arr,
404
+ arr,
405
+ arr, # a/e/p/p/r/l/l/t/hwp
406
+ warr,
407
+ warr,
408
+ warr,
409
+ warr,
410
+ ct.c_int,
411
+ ),
412
+ )
413
+ setargs(
414
+ "qp_azel2radecpa_hwp",
415
+ arg=(
416
+ qp_memory_t_p, # params
417
+ ct.c_double,
418
+ ct.c_double,
419
+ ct.c_double, # offset
420
+ arr,
421
+ arr,
422
+ arr,
423
+ arr,
424
+ arr,
425
+ arr,
426
+ arr,
427
+ arr, # a/e/p/r/l/l/t/hwp
428
+ warr,
429
+ warr,
430
+ warr,
431
+ ct.c_int,
432
+ ),
433
+ )
434
+ setargs(
435
+ "qp_azelpsi2radecpa_hwp",
436
+ arg=(
437
+ qp_memory_t_p, # params
438
+ ct.c_double,
439
+ ct.c_double,
440
+ ct.c_double, # offset
441
+ arr,
442
+ arr,
443
+ arr,
444
+ arr,
445
+ arr,
446
+ arr,
447
+ arr,
448
+ arr,
449
+ arr, # a/e/p/p/r/l/l/t/hwp
450
+ warr,
451
+ warr,
452
+ warr,
453
+ ct.c_int,
454
+ ),
455
+ )
456
+ setargs(
457
+ "qp_azel2rasindec",
458
+ arg=(
459
+ qp_memory_t_p, # params
460
+ ct.c_double,
461
+ ct.c_double,
462
+ ct.c_double, # offset
463
+ arr,
464
+ arr,
465
+ arr,
466
+ arr,
467
+ arr,
468
+ arr,
469
+ arr, # a/e/p/r/l/l/t
470
+ warr,
471
+ warr,
472
+ warr,
473
+ warr,
474
+ ct.c_int,
475
+ ),
476
+ )
477
+ setargs(
478
+ "qp_azelpsi2rasindec",
479
+ arg=(
480
+ qp_memory_t_p, # params
481
+ ct.c_double,
482
+ ct.c_double,
483
+ ct.c_double, # offset
484
+ arr,
485
+ arr,
486
+ arr,
487
+ arr,
488
+ arr,
489
+ arr,
490
+ arr,
491
+ arr, # a/e/p/p/r/l/l/t
492
+ warr,
493
+ warr,
494
+ warr,
495
+ warr,
496
+ ct.c_int,
497
+ ),
498
+ )
499
+ setargs(
500
+ "qp_azel2rasindec_hwp",
501
+ arg=(
502
+ qp_memory_t_p, # params
503
+ ct.c_double,
504
+ ct.c_double,
505
+ ct.c_double, # offset
506
+ arr,
507
+ arr,
508
+ arr,
509
+ arr,
510
+ arr,
511
+ arr,
512
+ arr,
513
+ arr, # a/e/p/r/l/l/t/hwp
514
+ warr,
515
+ warr,
516
+ warr,
517
+ warr,
518
+ ct.c_int,
519
+ ),
520
+ )
521
+ setargs(
522
+ "qp_azelpsi2rasindec_hwp",
523
+ arg=(
524
+ qp_memory_t_p, # params
525
+ ct.c_double,
526
+ ct.c_double,
527
+ ct.c_double, # offset
528
+ arr,
529
+ arr,
530
+ arr,
531
+ arr,
532
+ arr,
533
+ arr,
534
+ arr,
535
+ arr,
536
+ arr, # a/e/p/p/r/l/l/t/hwp
537
+ warr,
538
+ warr,
539
+ warr,
540
+ warr,
541
+ ct.c_int,
542
+ ),
543
+ )
544
+ setargs(
545
+ "qp_azel2bore",
546
+ arg=(
547
+ qp_memory_t_p, # params
548
+ arr,
549
+ arr,
550
+ arr,
551
+ arr,
552
+ arr,
553
+ arr,
554
+ arr, # a/e/p/r/l/l/t
555
+ wquat_t_p,
556
+ ct.c_int,
557
+ ),
558
+ )
559
+ setargs(
560
+ "qp_azelpsi2bore",
561
+ arg=(
562
+ qp_memory_t_p, # params
563
+ arr,
564
+ arr,
565
+ arr,
566
+ arr,
567
+ arr,
568
+ arr,
569
+ arr,
570
+ arr, # a/e/p/p/r/l/l/t
571
+ wquat_t_p,
572
+ ct.c_int,
573
+ ),
574
+ )
575
+
576
+ setargs("qp_det_offsetn", arg=(arr, arr, arr, wquat_t_p, ct.c_int))
577
+ setargs(
578
+ "qp_bore_offset", arg=(qp_memory_t_p, wquat_t_p, arr, arr, arr, ct.c_int, ct.c_int)
579
+ )
580
+ setargs("qp_hwp_quatn", arg=(arr, wquat_t_p, ct.c_int))
581
+ setargs("qp_gmstn", arg=(qp_memory_t_p, arr, warr, ct.c_int))
582
+ setargs("qp_lmstn", arg=(qp_memory_t_p, arr, arr, warr, ct.c_int))
583
+ setargs("qp_dipolen", arg=(qp_memory_t_p, arr, arr, arr, warr, ct.c_int))
584
+ setargs("qp_bore2dipole", arg=(qp_memory_t_p, quat_t, arr, quat_t_p, warr, ct.c_int))
585
+
586
+ setargs(
587
+ "qp_bore2radec",
588
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, warr, warr, warr, warr, ct.c_int),
589
+ )
590
+ setargs(
591
+ "qp_bore2radec_hwp",
592
+ arg=(
593
+ qp_memory_t_p,
594
+ quat_t,
595
+ arr,
596
+ quat_t_p,
597
+ quat_t_p,
598
+ warr,
599
+ warr,
600
+ warr,
601
+ warr,
602
+ ct.c_int,
603
+ ),
604
+ )
605
+ setargs(
606
+ "qp_bore2rasindec",
607
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, warr, warr, warr, warr, ct.c_int),
608
+ )
609
+ setargs(
610
+ "qp_bore2rasindec_hwp",
611
+ arg=(
612
+ qp_memory_t_p,
613
+ quat_t,
614
+ arr,
615
+ quat_t_p,
616
+ quat_t_p,
617
+ warr,
618
+ warr,
619
+ warr,
620
+ warr,
621
+ ct.c_int,
622
+ ),
623
+ )
624
+ setargs(
625
+ "qp_bore2radecpa",
626
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, warr, warr, warr, ct.c_int),
627
+ )
628
+ setargs(
629
+ "qp_bore2radecpa_hwp",
630
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, quat_t_p, warr, warr, warr, ct.c_int),
631
+ )
632
+
633
+ setargs("qp_radecpa2quatn", arg=(qp_memory_t_p, arr, arr, arr, wquat_t_p, ct.c_int))
634
+ setargs("qp_quat2radecpan", arg=(qp_memory_t_p, quat_t_p, warr, warr, warr, ct.c_int))
635
+
636
+ setargs("qp_radec2pixn", arg=(qp_memory_t_p, arr, arr, ct.c_int, warri, ct.c_int))
637
+
638
+ setargs("qp_radec2gal_quatn", arg=(qp_memory_t_p, wquat_t_p, ct.c_int))
639
+ setargs("qp_gal2radec_quatn", arg=(qp_memory_t_p, wquat_t_p, ct.c_int))
640
+
641
+ setargs("qp_radec2galn", arg=(qp_memory_t_p, warr, warr, warr, warr, ct.c_int))
642
+ setargs("qp_gal2radecn", arg=(qp_memory_t_p, warr, warr, warr, warr, ct.c_int))
643
+ setargs("qp_radecpa2galn", arg=(qp_memory_t_p, warr, warr, warr, ct.c_int))
644
+ setargs("qp_gal2radecpan", arg=(qp_memory_t_p, warr, warr, warr, ct.c_int))
645
+ setargs(
646
+ "qp_rotate_map", arg=(qp_memory_t_p, ct.c_int, arr2, ct.c_char, arr2, ct.c_char)
647
+ )
648
+
649
+ setargs(
650
+ "qp_quat2pixn", arg=(qp_memory_t_p, quat_t_p, ct.c_int, warri, warr, warr, ct.c_int)
651
+ )
652
+ setargs(
653
+ "qp_quat2pixpan", arg=(qp_memory_t_p, quat_t_p, ct.c_int, warri, warr, ct.c_int)
654
+ )
655
+ setargs(
656
+ "qp_bore2pix",
657
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, ct.c_int, warri, warr, warr, ct.c_int),
658
+ )
659
+ setargs(
660
+ "qp_bore2pix_hwp",
661
+ arg=(
662
+ qp_memory_t_p,
663
+ quat_t,
664
+ arr,
665
+ quat_t_p,
666
+ quat_t_p,
667
+ ct.c_int,
668
+ warri,
669
+ warr,
670
+ warr,
671
+ ct.c_int,
672
+ ),
673
+ )
674
+ setargs(
675
+ "qp_bore2pixpa",
676
+ arg=(qp_memory_t_p, quat_t, arr, quat_t_p, ct.c_int, warri, warr, ct.c_int),
677
+ )
678
+ setargs(
679
+ "qp_bore2pixpa_hwp",
680
+ arg=(
681
+ qp_memory_t_p,
682
+ quat_t,
683
+ arr,
684
+ quat_t_p,
685
+ quat_t_p,
686
+ ct.c_int,
687
+ warri,
688
+ warr,
689
+ ct.c_int,
690
+ ),
691
+ )
692
+
693
+ setargs(
694
+ "qp_get_interp_valn", arg=(qp_memory_t_p, ct.c_int, arr, arr, arr, warr, ct.c_int)
695
+ )
696
+
697
+ setargs(
698
+ "qp_set_iers_bulletin_a",
699
+ arg=(qp_memory_t_p, ct.c_int, ct.c_int, arr, arr, arr),
700
+ res=ct.c_int,
701
+ )
702
+ setargs(
703
+ "qp_get_iers_bulletin_a",
704
+ arg=(
705
+ qp_memory_t_p,
706
+ ct.c_double,
707
+ ct.POINTER(ct.c_double),
708
+ ct.POINTER(ct.c_double),
709
+ ct.POINTER(ct.c_double),
710
+ ),
711
+ res=ct.c_int,
712
+ )
713
+
714
+
715
+ def qp_get_bulletin_a(mem, mjd):
716
+ dut1 = ct.c_double()
717
+ x = ct.c_double()
718
+ y = ct.c_double()
719
+
720
+ libqp.qp_get_iers_bulletin_a(mem, mjd, ct.byref(dut1), ct.byref(x), ct.byref(y))
721
+ return dut1.value, x.value, y.value
722
+
723
+
724
+ setargs("qp_refraction", arg=(ct.c_double,) * 5, res=ct.c_double)
725
+ setargs("qp_update_ref", arg=(qp_memory_t_p, quat_t), res=ct.c_double)
726
+
727
+
728
+ def get_vec_mode(map_in=None, pol=True, vpol=False):
729
+ if pol is None:
730
+ pol = True
731
+ if map_in is False:
732
+ return QP_VEC_NONE
733
+ if map_in is None:
734
+ return QP_VEC_VPOL if vpol else QP_VEC_POL if pol else QP_VEC_TEMP
735
+ n = len(map_in)
736
+ if n not in vec_modes:
737
+ raise ValueError("Unrecognized map")
738
+ mode = vec_modes[n]
739
+ if isinstance(mode, dict):
740
+ mode = mode[bool(pol)]
741
+ return mode
742
+
743
+
744
+ def get_proj_mode(proj_in=None, pol=True, vpol=False):
745
+ if pol is None:
746
+ pol = True
747
+ if proj_in is False:
748
+ return QP_PROJ_NONE
749
+ if proj_in is None:
750
+ return QP_PROJ_VPOL if vpol else QP_PROJ_POL if pol else QP_PROJ_TEMP
751
+ n = len(proj_in)
752
+ if n not in proj_modes:
753
+ raise ValueError("Unrecognized proj")
754
+ mode = proj_modes[n]
755
+ if isinstance(mode, dict):
756
+ mode = mode[bool(pol)]
757
+ return mode
758
+
759
+
760
+ # **********************************************************************
761
+ # Mapping functions
762
+ # **********************************************************************
763
+
764
+ # initialize detectors
765
+ setargs(
766
+ "qp_init_det", arg=(quat_t, ct.c_double, ct.c_double, mueller_t), res=qp_det_t_p
767
+ )
768
+ setargs("qp_default_det", res=qp_det_t_p)
769
+ setargs("qp_init_det_tod", arg=(qp_det_t_p, ct.c_size_t))
770
+ setargs("qp_init_det_tod_from_array", arg=(qp_det_t_p, arr, ct.c_size_t, ct.c_int))
771
+ setargs("qp_init_det_flag", arg=(qp_det_t_p, ct.c_size_t))
772
+ setargs("qp_init_det_flag_from_array", arg=(qp_det_t_p, arrf, ct.c_size_t, ct.c_int))
773
+ setargs("qp_free_det", arg=qp_det_t_p)
774
+ setargs(
775
+ "qp_init_detarr",
776
+ arg=(quat_t_p, arr, arr, mueller_t_p, ct.c_size_t),
777
+ res=qp_detarr_t_p,
778
+ )
779
+ setargs("qp_init_detarr_tod", arg=(qp_detarr_t_p, ct.c_size_t))
780
+ setargs(
781
+ "qp_init_detarr_tod_from_array_1d", arg=(qp_detarr_t_p, arr, ct.c_size_t, ct.c_int)
782
+ )
783
+ setargs("qp_init_detarr_flag", arg=(qp_detarr_t_p, ct.c_size_t))
784
+ setargs(
785
+ "qp_init_detarr_flag_from_array_1d", arg=(qp_detarr_t_p, arr, ct.c_size_t, ct.c_int)
786
+ )
787
+ setargs("qp_free_detarr", arg=qp_detarr_t_p)
788
+
789
+ # initialize pointing
790
+ setargs("qp_init_point", arg=(ct.c_size_t, ct.c_int, ct.c_int), res=qp_point_t_p)
791
+ setargs(
792
+ "qp_init_point_from_arrays",
793
+ arg=(quat_t_p, arr, quat_t_p, ct.c_size_t, ct.c_int),
794
+ res=qp_point_t_p,
795
+ )
796
+ setargs("qp_free_point", arg=qp_point_t_p)
797
+
798
+ # initialize maps
799
+ setargs(
800
+ "qp_init_map",
801
+ arg=(ct.c_size_t, ct.c_size_t, qp_vec_mode, qp_proj_mode),
802
+ res=qp_map_t_p,
803
+ )
804
+ setargs(
805
+ "qp_init_map_from_arrays_1d",
806
+ arg=(arr, arr, ct.c_size_t, ct.c_size_t, qp_vec_mode, qp_proj_mode, ct.c_int),
807
+ res=qp_map_t_p,
808
+ )
809
+ setargs("qp_init_map_from_map", arg=(qp_map_t_p, ct.c_int, ct.c_int), res=qp_map_t_p)
810
+ setargs("qp_free_map", arg=qp_map_t_p)
811
+ setargs("qp_reshape_map", arg=qp_map_t_p, res=ct.c_int)
812
+ setargs("qp_init_map_pixhash", arg=(qp_map_t_p, larr, ct.c_size_t), res=ct.c_int)
813
+
814
+ # tod -> map
815
+ setargs("qp_add_map", arg=(qp_map_t_p, qp_map_t_p), res=ct.c_int)
816
+ setargs(
817
+ "qp_tod2map1",
818
+ arg=(qp_memory_t_p, qp_det_t_p, qp_point_t_p, qp_map_t_p),
819
+ res=ct.c_int,
820
+ )
821
+ setargs(
822
+ "qp_tod2map",
823
+ arg=(qp_memory_t_p, qp_detarr_t_p, qp_point_t_p, qp_map_t_p),
824
+ res=ct.c_int,
825
+ )
826
+
827
+ # map -> tod
828
+ setargs(
829
+ "qp_map2tod1",
830
+ arg=(qp_memory_t_p, qp_det_t_p, qp_point_t_p, qp_map_t_p),
831
+ res=ct.c_int,
832
+ )
833
+ setargs(
834
+ "qp_map2tod",
835
+ arg=(qp_memory_t_p, qp_detarr_t_p, qp_point_t_p, qp_map_t_p),
836
+ res=ct.c_int,
837
+ )
838
+
839
+ # **********************************************************************
840
+ # Parameters
841
+ # **********************************************************************
842
+
843
+
844
+ def check_set_float(val):
845
+ if not np.isscalar(val):
846
+ raise TypeError("val must be a scalar value")
847
+ return float(val)
848
+
849
+
850
+ def check_set_int(val):
851
+ if not np.isscalar(val):
852
+ raise TypeError("val must be a scalar value")
853
+ return int(val)
854
+
855
+
856
+ def check_pass(val):
857
+ return val
858
+
859
+
860
+ def set_rfunc(state):
861
+ f = libqp["qp_set_rate_%s" % state]
862
+ f.argtypes = (qp_memory_t_p, ct.c_double)
863
+ f.restype = None
864
+ return f
865
+
866
+
867
+ def reset_rfunc(state):
868
+ f = libqp["qp_reset_rate_%s" % state]
869
+ f.argtypes = (qp_memory_t_p,)
870
+ f.restype = None
871
+ return f
872
+
873
+
874
+ def get_rfunc(state):
875
+ f = libqp["qp_get_rate_%s" % state]
876
+ f.argtypes = (qp_memory_t_p,)
877
+ f.restype = ct.c_double
878
+ return f
879
+
880
+
881
+ def check_set_state(state):
882
+ rdict = {"always": QP_DO_ALWAYS, "once": QP_DO_ONCE, "never": QP_DO_NEVER}
883
+ state = rdict.get(state, state)
884
+ return check_set_float(state)
885
+
886
+
887
+ def check_get_state(state):
888
+ rdict = {QP_DO_ALWAYS: "always", QP_DO_ONCE: "once", QP_DO_NEVER: "never"}
889
+ state = rdict.get(state, state)
890
+ return state
891
+
892
+
893
+ states = ["lonlat", "npb", "erot", "daber", "aaber", "wobble", "dut1", "ref"]
894
+ inv_states = [k + "_inv" for k in states]
895
+ state_funcs = dict()
896
+ for s in states + inv_states:
897
+ k = "rate_%s" % s
898
+ state_funcs[k] = dict()
899
+ state_funcs[k]["set"] = set_rfunc(s)
900
+ state_funcs[k]["reset"] = reset_rfunc(s)
901
+ state_funcs[k]["get"] = get_rfunc(s)
902
+ state_funcs[k]["check_set"] = check_set_state
903
+ state_funcs[k]["check_get"] = check_get_state
904
+
905
+
906
+ def set_wfunc(par):
907
+ f = libqp["qp_set_weather_%s" % par]
908
+ f.argtypes = (qp_memory_t_p, ct.c_double)
909
+ f.restype = None
910
+ return f
911
+
912
+
913
+ def get_wfunc(par):
914
+ f = libqp["qp_get_weather_%s" % par]
915
+ f.argtypes = (qp_memory_t_p,)
916
+ f.restype = ct.c_double
917
+ return f
918
+
919
+
920
+ weather_params = ["temperature", "pressure", "humidity", "frequency"]
921
+ weather_funcs = dict()
922
+ for w in weather_params:
923
+ weather_funcs[w] = dict()
924
+ weather_funcs[w]["set"] = set_wfunc(w)
925
+ weather_funcs[w]["get"] = get_wfunc(w)
926
+ weather_funcs[w]["check_set"] = check_set_float
927
+ weather_funcs[w]["check_get"] = check_pass
928
+
929
+
930
+ def set_ofunc(option):
931
+ f = libqp["qp_set_opt_%s" % option]
932
+ f.argtypes = (qp_memory_t_p, ct.c_int)
933
+ f.restype = None
934
+ return f
935
+
936
+
937
+ def get_ofunc(option):
938
+ f = libqp["qp_get_opt_%s" % option]
939
+ f.argtypes = (qp_memory_t_p,)
940
+ f.restype = ct.c_int
941
+ return f
942
+
943
+
944
+ opts = {
945
+ "accuracy": {0: "high", 1: "low"},
946
+ "polconv": {0: ["cosmo", "healpix"], 1: "iau"},
947
+ "pix_order": {0: "ring", 1: ["nest", "nested"]},
948
+ }
949
+ defaults = {"accuracy": 0, "polconv": 0, "pix_order": 0}
950
+
951
+
952
+ def check_set_dict(opt):
953
+ def func(val):
954
+ if val is None:
955
+ return defaults[opt]
956
+ if isinstance(val, str):
957
+ val = val.lower()
958
+ for k in opts[opt]:
959
+ v = opts[opt][k]
960
+ if isinstance(v, list):
961
+ if val in v:
962
+ return k
963
+ else:
964
+ if val == v:
965
+ return k
966
+ if val == k:
967
+ return k
968
+ return defaults[opt]
969
+
970
+ return func
971
+
972
+
973
+ def check_get_dict(opt):
974
+ def func(val):
975
+ for k in opts[opt]:
976
+ v = opts[opt][k]
977
+ if val == k:
978
+ if isinstance(v, list):
979
+ return v[0]
980
+ return v
981
+ raise ValueError("unrecognized value {} for option {}".format(val, opt))
982
+
983
+ return func
984
+
985
+
986
+ check_set_accuracy = check_set_dict("accuracy")
987
+ check_get_accuracy = check_get_dict("accuracy")
988
+
989
+ check_set_polconv = check_set_dict("polconv")
990
+ check_get_polconv = check_get_dict("polconv")
991
+
992
+ check_set_pix_order = check_set_dict("pix_order")
993
+ check_get_pix_order = check_get_dict("pix_order")
994
+
995
+
996
+ def check_get_bool(val):
997
+ return bool(val)
998
+
999
+
1000
+ def check_set_bool(val):
1001
+ return int(bool(val))
1002
+
1003
+
1004
+ check_set_mean_aber = check_set_bool
1005
+ check_get_mean_aber = check_get_bool
1006
+
1007
+ check_set_fast_aber = check_set_bool
1008
+ check_get_fast_aber = check_get_bool
1009
+
1010
+ check_set_fast_math = check_set_bool
1011
+ check_get_fast_math = check_get_bool
1012
+
1013
+ check_set_fast_pix = check_set_bool
1014
+ check_get_fast_pix = check_get_bool
1015
+
1016
+ check_set_error_missing = check_set_bool
1017
+ check_get_error_missing = check_get_bool
1018
+
1019
+ check_set_nan_missing = check_set_bool
1020
+ check_get_nan_missing = check_get_bool
1021
+
1022
+ check_set_interp_missing = check_set_bool
1023
+ check_get_interp_missing = check_get_bool
1024
+
1025
+ check_set_interp_pix = check_set_bool
1026
+ check_get_interp_pix = check_get_bool
1027
+
1028
+
1029
+ def check_set_num_threads(nt):
1030
+ if nt is None:
1031
+ return 0
1032
+ return int(nt)
1033
+
1034
+
1035
+ def check_get_num_threads(nt):
1036
+ return nt
1037
+
1038
+
1039
+ def check_set_thread_num(tn):
1040
+ if tn is None:
1041
+ return 0
1042
+ return int(nt)
1043
+
1044
+
1045
+ def check_get_thread_num(tn):
1046
+ return tn
1047
+
1048
+
1049
+ options = [
1050
+ "accuracy",
1051
+ "mean_aber",
1052
+ "fast_aber",
1053
+ "fast_math",
1054
+ "polconv",
1055
+ "pix_order",
1056
+ "interp_pix",
1057
+ "fast_pix",
1058
+ "error_missing",
1059
+ "nan_missing",
1060
+ "interp_missing",
1061
+ "num_threads",
1062
+ "thread_num",
1063
+ ]
1064
+ option_funcs = dict()
1065
+ for p in options:
1066
+ option_funcs[p] = dict()
1067
+ option_funcs[p]["set"] = set_ofunc(p)
1068
+ option_funcs[p]["get"] = get_ofunc(p)
1069
+ option_funcs[p]["check_set"] = globals()["check_set_%s" % p]
1070
+ option_funcs[p]["check_get"] = globals()["check_get_%s" % p]
1071
+
1072
+
1073
+ def set_pfunc(par):
1074
+ f = libqp["qp_set_%s" % par]
1075
+ f.argtypes = (qp_memory_t_p, ct.c_double)
1076
+ f.restype = None
1077
+ return f
1078
+
1079
+
1080
+ def get_pfunc(par):
1081
+ f = libqp["qp_get_%s" % par]
1082
+ f.argtypes = (qp_memory_t_p,)
1083
+ f.restype = ct.c_double
1084
+ return f
1085
+
1086
+
1087
+ double_params = ["ref_delta", "dut1"]
1088
+ double_funcs = dict()
1089
+ for p in double_params:
1090
+ double_funcs[p] = dict()
1091
+ double_funcs[p]["set"] = set_pfunc(p)
1092
+ double_funcs[p]["get"] = get_pfunc(p)
1093
+ double_funcs[p]["check_set"] = check_set_float
1094
+ double_funcs[p]["check_get"] = check_pass
1095
+
1096
+ qp_funcs = dict()
1097
+ qp_funcs["rates"] = state_funcs
1098
+ qp_funcs["options"] = option_funcs
1099
+ qp_funcs["weather"] = weather_funcs
1100
+ qp_funcs["params"] = double_funcs
1101
+
1102
+ # **********************************************************************
1103
+ # Argument checking
1104
+ # **********************************************************************
1105
+
1106
+
1107
+ def check_flags(arg):
1108
+ return (
1109
+ arg.flags["C_CONTIGUOUS"]
1110
+ | arg.flags["OWNDATA"] << 1
1111
+ | arg.flags["WRITEABLE"] << 2
1112
+ | arg.flags["ALIGNED"] << 3
1113
+ )
1114
+
1115
+
1116
+ def check_input(
1117
+ name,
1118
+ arg,
1119
+ shape=None,
1120
+ quat=False,
1121
+ dtype=np.double,
1122
+ inplace=True,
1123
+ fill=0,
1124
+ allow_transpose=True,
1125
+ allow_tuple=True,
1126
+ output=False,
1127
+ ):
1128
+ """
1129
+ Ensure input argument is an aligned array of the right type and shape.
1130
+
1131
+ Arguments
1132
+ ---------
1133
+ name : string
1134
+ Name of the argument
1135
+ arg : array_like
1136
+ The argument itself
1137
+ shape : tuple, optional
1138
+ If supplied, ensure `arg` has this shape.
1139
+ quat : bool, optional
1140
+ If True, ensure that the last dimension of the array has length 4.
1141
+ dtype : numpy.dtype, optional
1142
+ Ensure `arg` is of this dtype. Default: numpy.double.
1143
+ inplace : bool, optional
1144
+ If False make sure that a copy of the input `arg` is made prior to
1145
+ returning. Otherwise, the output `arg` may share memory with the
1146
+ input.
1147
+ fill : scalar, optional
1148
+ If the input is missing or empty, fill with this value.
1149
+ If None, leave the array empty.
1150
+ allow_transpose : bool, optional
1151
+ If True, transpose the input array if the transposed shape matches
1152
+ `shape`.
1153
+ allow_tuple : bool, optional
1154
+ If True, `numpy.vstack` the input `arg` if it is a tuple.
1155
+ output : bool, optional
1156
+ If True, ensure that the output `arg` is a writeable array.
1157
+ Otherwise, the array is only ensured to be aligned and
1158
+ C-contiguous.
1159
+
1160
+ Returns
1161
+ -------
1162
+ arg :
1163
+ Aligned, contiguous and properly typed and shaped array for
1164
+ passing to the C library.
1165
+ """
1166
+ if arg is None:
1167
+ if shape is None:
1168
+ raise ValueError("need shape to initialize input!")
1169
+ if fill is None:
1170
+ arg = np.empty(shape, dtype=dtype)
1171
+ else:
1172
+ arg = fill * np.ones(shape, dtype=dtype)
1173
+ if isinstance(arg, tuple) and allow_tuple:
1174
+ arg = np.vstack(arg)
1175
+ if np.isscalar(arg):
1176
+ arg = np.array(arg)
1177
+ if not isinstance(arg, np.ndarray):
1178
+ raise TypeError("input {} must be of type numpy.ndarray".format(name))
1179
+ if quat and arg.shape[-1] != 4:
1180
+ raise ValueError("input {} is not a valid quaternion array")
1181
+ if shape is not None:
1182
+ if arg.shape != shape:
1183
+ if arg.T.shape == shape and allow_transpose:
1184
+ arg = arg.T
1185
+ else:
1186
+ try:
1187
+ _, arg = np.broadcast_arrays(np.empty(shape), arg)
1188
+ # ensure writeable flag is set properly if necessary
1189
+ # broadcast arrays will not be writable in the future
1190
+ if inplace or output:
1191
+ arg = arg.copy()
1192
+ else:
1193
+ arg.flags["WRITEABLE"] = False
1194
+ except ValueError:
1195
+ s = "input {} of shape {} cannot be broadcast to shape {}"
1196
+ raise ValueError(s.format(name, arg.shape, shape))
1197
+ istat = check_flags(arg)
1198
+ arg = np.require(arg, dtype, list("AC" + "W" * output))
1199
+ ostat = check_flags(arg)
1200
+ if (output is True or istat == ostat) and inplace is False:
1201
+ return arg.copy()
1202
+ return arg
1203
+
1204
+
1205
+ def check_inputs(*args, **kwargs):
1206
+ """
1207
+ Ensure that a group of input arguments have the same shape by broadcasting.
1208
+
1209
+ Arguments
1210
+ ---------
1211
+ args :
1212
+ A list of broadcastable array_like arguments.
1213
+ kwargs :
1214
+ Dictionary of arguments to pass to `check_input`.
1215
+
1216
+ Returns
1217
+ -------
1218
+ args :
1219
+ A list of broadcast and properly aligned/shaped/typed arrays for
1220
+ passing to the C library as a set of timestreams.
1221
+ """
1222
+ args = [arg if arg is not None else 0 for arg in args]
1223
+ if "shape" not in kwargs:
1224
+ kwargs["shape"] = np.broadcast(*args).shape
1225
+ return [
1226
+ check_input("argument {}".format(ix), np.atleast_1d(x), **kwargs)
1227
+ for ix, x in enumerate(args)
1228
+ ]
1229
+
1230
+
1231
+ def check_output(
1232
+ name,
1233
+ arg=None,
1234
+ shape=None,
1235
+ quat=False,
1236
+ dtype=np.double,
1237
+ inplace=True,
1238
+ fill=None,
1239
+ allow_transpose=True,
1240
+ allow_tuple=True,
1241
+ **kwargs,
1242
+ ):
1243
+ """
1244
+ Ensure that the output argument is properly aligned/shaped/typed.
1245
+ Check input kwargs to see if a pointer to the output array
1246
+ has been passed in.
1247
+
1248
+ Arguments
1249
+ ---------
1250
+ name : string
1251
+ Name of the argument
1252
+ arg : array_like, optional
1253
+ The argument itself. If not supplied, kwargs is checked.
1254
+ shape : tuple, optional
1255
+ If supplied, ensure `arg` has this shape. If `arg` is None,
1256
+ this argument is required.
1257
+ dtype : numpy.dtype, optional
1258
+ Ensure `arg` is of this dtype. Default: numpy.double.
1259
+ inplace : bool, optional
1260
+ If False make sure that a copy of the input `arg` is made prior to
1261
+ returning. Otherwise, the output `arg` may share memory with the
1262
+ input.
1263
+ fill : scalar, optional
1264
+ If the input is missing or empty, fill with this value.
1265
+ If None, leave the array empty.
1266
+ allow_transpose : bool, optional
1267
+ If True, transpose the input array if the transposed shape matches
1268
+ `shape`.
1269
+ allow_tuple : bool, optional
1270
+ If True, `numpy.vstack` the input `arg` if it is a tuple.
1271
+ kwargs :
1272
+ Any remaining input arguments. If `arg` is None,
1273
+ `kwargs` is searched for the `name` key. If not found, a
1274
+ an empty array is created of the appropriate shape.
1275
+
1276
+ Returns
1277
+ -------
1278
+ arg :
1279
+ Aligned, contiguous, writeable and properly typed and shaped array
1280
+ for passing to the C library.
1281
+ """
1282
+ if arg is None:
1283
+ arg = kwargs.pop(name, None)
1284
+ return check_input(
1285
+ name, arg, shape, quat, dtype, inplace, fill, allow_transpose, allow_tuple, True
1286
+ )