Commits
147 147 | 1-17. height() test |
148 148 | 1-18. pop() when height is 1 |
149 149 | """ |
150 150 | |
151 151 | def setUp(self): |
152 152 | self._create_dummy_folders() |
153 153 | if os.path.exists(UNEXISTS): |
154 154 | shutil.rmtree(UNEXISTS) |
155 155 | |
156 156 | def test_1_1(self): |
157 + | """1-1. Create Stack with exist file""" |
157 158 | stack = CasaImageStack(UnerasableFolder(DUMMY_FOLDERS[0])) |
158 159 | self.assertTrue(stack.height() == 1) |
159 160 | |
160 161 | exception_case(ValueError, f'file {UNEXISTS} is not found') | .
161 162 | def test_1_2(self): |
163 + | """1-2. Create Stack with unexist file""" |
162 164 | CasaImageStack(UnerasableFolder(UNEXISTS)) |
163 165 | |
164 166 | def test_1_3(self): |
167 + | """1-3. push() exist file""" |
165 168 | stack = CasaImageStack() |
166 169 | stack.push(UnerasableFolder(DUMMY_FOLDERS[0])) |
167 170 | self.assertTrue(stack.height() == 1) |
168 171 | |
169 172 | exception_case(ValueError, f'file {UNEXISTS} is not found') | .
170 173 | def test_1_4(self): |
174 + | """1-4. push() unexist file""" |
171 175 | stack = CasaImageStack() |
172 176 | stack.push(UnerasableFolder(UNEXISTS)) |
173 177 | |
174 178 | def test_1_5(self): |
179 + | """1-5. pop() exist stuff""" |
175 180 | stack = CasaImageStack() |
176 181 | stack.push(UnerasableFolder(DUMMY_FOLDERS[0])) |
177 182 | obj = UnerasableFolder(DUMMY_FOLDERS[1]) |
178 183 | stack.push(obj) |
179 184 | tmp = stack.pop() |
180 185 | self.assertEqual(obj, tmp) |
181 186 | self.assertTrue(stack.height() == 1) |
182 187 | |
183 188 | exception_case(RuntimeError, 'the stack cannot pop') | .
184 189 | def test_1_6(self): |
190 + | """1-6. pop() unexist stuff""" |
185 191 | stack = CasaImageStack() |
186 192 | stack.pop() |
187 193 | |
188 194 | def test_1_7(self): |
195 + | """1-7. peak() exist stuff""" |
189 196 | stack = CasaImageStack() |
190 197 | obj1 = UnerasableFolder(DUMMY_FOLDERS[0]) |
191 198 | stack.push(obj1) |
192 199 | obj2 = UnerasableFolder(DUMMY_FOLDERS[1]) |
193 200 | stack.push(obj2) |
194 201 | obj3 = UnerasableFolder(DUMMY_FOLDERS[2]) |
195 202 | stack.push(obj3) |
196 203 | self.assertEqual(stack.peak(), obj3) |
197 204 | self.assertEqual(stack.subpeak(), obj2) |
198 205 | self.assertEqual(stack.bottom(), obj1) |
199 206 | |
200 207 | exception_case(RuntimeError, 'the stack is empty') | .
201 208 | def test_1_8(self): |
209 + | """1-8. peak() unexist stuff""" |
202 210 | stack = CasaImageStack() |
203 211 | stack.peak() |
204 212 | |
205 213 | def test_1_9(self): |
214 + | """1-9. subpeak() exist stuff""" |
206 215 | stack = CasaImageStack() |
207 216 | obj1 = UnerasableFolder(DUMMY_FOLDERS[0]) |
208 217 | stack.push(obj1) |
209 218 | obj2 = UnerasableFolder(DUMMY_FOLDERS[1]) |
210 219 | stack.push(obj2) |
211 220 | self.assertEqual(stack.subpeak(), obj1) |
212 221 | self.assertEqual(stack.bottom(), obj1) |
213 222 | obj3 = UnerasableFolder(DUMMY_FOLDERS[2]) |
214 223 | stack.push(obj3) |
215 224 | self.assertEqual(stack.subpeak(), obj2) |
216 225 | self.assertEqual(stack.bottom(), obj1) |
217 226 | |
218 227 | exception_case(RuntimeError, 'the stack has only one stuff') | .
219 228 | def test_1_10(self): |
229 + | """1-10. subpeak() unexist stuff""" |
220 230 | stack = CasaImageStack(UnerasableFolder(DUMMY_FOLDERS[0])) |
221 231 | stack.subpeak() |
222 232 | |
223 233 | def test_1_11(self): |
234 + | """1-11. bottom() exist stuff""" |
224 235 | stack = CasaImageStack() |
225 236 | obj1 = UnerasableFolder(DUMMY_FOLDERS[0]) |
226 237 | stack.push(obj1) |
227 238 | self.assertEqual(stack.bottom(), obj1) |
228 239 | obj2 = UnerasableFolder(DUMMY_FOLDERS[1]) |
229 240 | stack.push(obj2) |
230 241 | self.assertEqual(stack.bottom(), obj1) |
231 242 | self.assertEqual(stack.peak(), obj2) |
232 243 | |
233 244 | exception_case(RuntimeError, 'the stack has not have enough stuff') | .
234 245 | def test_1_12(self): |
246 + | """1-12. bottom() unexist stuff""" |
235 247 | stack = CasaImageStack() |
236 248 | stack.bottom() |
237 249 | |
238 250 | def test_1_13(self): |
251 + | """1-13. clear() exist EraseableFolder file""" |
239 252 | file = EraseableFolder(DUMMY_FOLDERS[0]) |
240 253 | stack = CasaImageStack(file) |
241 254 | stack.clear(False) |
242 255 | self.assertTrue(os.path.exists(DUMMY_FOLDERS[0])) |
243 256 | self.assertEqual(stack.height(), 0) |
244 257 | |
245 258 | def test_1_14(self): |
259 + | """1-14. clear() exist UneraseableFolder file""" |
246 260 | stack = CasaImageStack(UnerasableFolder(DUMMY_FOLDERS[0])) |
247 261 | stack.clear(False) |
248 262 | self.assertTrue(os.path.exists(DUMMY_FOLDERS[0])) |
249 263 | self.assertEqual(stack.height(), 0) |
250 264 | |
251 265 | def test_1_15(self): |
266 + | """1-15. erase EraseableFolder file""" |
252 267 | file = EraseableFolder(DUMMY_FOLDERS[0]) |
253 268 | file.erase(False) |
254 269 | self.assertFalse(os.path.exists(DUMMY_FOLDERS[0])) |
255 270 | |
256 271 | def test_1_16(self): |
272 + | """1-16. erase UneraseableFolder file""" |
257 273 | file = UnerasableFolder(DUMMY_FOLDERS[0]) |
258 274 | file.erase(False) |
259 275 | self.assertTrue(os.path.exists(DUMMY_FOLDERS[0])) |
260 276 | |
261 277 | def test_1_17(self): |
278 + | """1-17. height() test""" |
262 279 | stack = CasaImageStack() |
263 280 | self.assertEqual(stack.height(), 0) |
264 281 | stack.push(UnerasableFolder(DUMMY_FOLDERS[0])) |
265 282 | self.assertEqual(stack.height(), 1) |
266 283 | stack.push(UnerasableFolder(DUMMY_FOLDERS[1])) |
267 284 | self.assertEqual(stack.height(), 2) |
268 285 | stack.push(UnerasableFolder(DUMMY_FOLDERS[2])) |
269 286 | self.assertEqual(stack.height(), 3) |
270 287 | stack.pop() |
271 288 | self.assertEqual(stack.height(), 2) |
272 289 | stack.pop() |
273 290 | self.assertEqual(stack.height(), 1) |
274 291 | |
275 292 | exception_case(RuntimeError, 'the stack cannot pop') | .
276 293 | def test_1_18(self): |
294 + | """1-18. pop() when height is 1""" |
277 295 | stack = CasaImageStack() |
278 296 | stack.push(UnerasableFolder(DUMMY_FOLDERS[0])) |
279 297 | stack.pop() |
280 298 | |
281 299 | |
282 300 | class ImageShape_test(test_base): |
283 301 | """Test ImageShape. |
284 302 | |
285 303 | 2-1. successful case |
286 304 | 2-2. invalid im_nchan |
287 305 | 2-3. invalid dir_shape |
288 306 | """ |
289 307 | |
290 308 | def setUp(self): |
291 309 | pass |
292 310 | |
293 311 | def tearDown(self): |
294 312 | pass |
295 313 | |
296 314 | def test_2_1(self): |
315 + | """2-1. successful case""" |
297 316 | shape = ImageShape(im_shape=np.array([100, 100, 1, 100]), axis_dir=np.array([0, 1]), axis_sp=3, axis_pol=2) |
298 317 | shape.validate() |
299 318 | shape = ImageShape(im_shape=np.array([100, 100, 100, 1]), axis_dir=np.array([0, 1]), axis_sp=2, axis_pol=3) |
300 319 | shape.validate() |
301 320 | # any exceptions are not thrown, its OK |
302 321 | |
303 322 | exception_case(ValueError, 'nchan \\d is too few to perform baseline subtraction') | .
304 323 | def test_2_2(self): |
324 + | """2-2. invalid im_nchan""" |
305 325 | shape = ImageShape(im_shape=np.array([100, 100, 1, 1]), axis_dir=np.array([0, 1]), axis_sp=3, axis_pol=2) |
306 326 | shape.validate() |
307 327 | |
308 328 | exception_case(ValueError, 'invalid value: dir_shape \\[\\d+\\]') | .
309 329 | def test_2_3(self): |
330 + | """2-3. invalid dir_shape""" |
310 331 | shape = ImageShape(np.array([100, 100, 1, 100]), axis_dir=np.array([0]), axis_sp=3, axis_pol=2) |
311 332 | shape.validate() |
312 333 | |
313 334 | |
314 335 | class imsmooth_test(test_base): |
315 336 | """Test imsmooth execution. |
316 337 | |
317 338 | Tests of imsmooth rely on ones of test_imsmooth basically, so we have minimal tests in imbaseline. |
318 339 | |
319 340 | 3-1. simple successful case |
320 341 | 3-2. simple failure case |
321 342 | 3-3. check parameters of ImsmoothParams |
322 343 | """ |
323 344 | |
324 345 | datapath = ctsys_resolve('unittest/imsmooth/') |
325 346 | tiny = 'tiny.im' |
326 347 | |
327 348 | def setUp(self): |
328 349 | self._copy_test_files(self.datapath, self.tiny) |
329 350 | |
330 351 | def test_3_1(self): |
352 + | """3-1. simple successful case""" |
331 353 | major = '2.5arcsec' |
332 354 | minor = '2arcsec' |
333 355 | pa = '0deg' |
334 356 | dirkernel = 'gaussian' |
335 357 | kimage = '' |
336 358 | scale = -1 |
337 359 | |
338 360 | stack = CasaImageStack(top=UnerasableFolder(self.tiny)) |
339 361 | |
340 362 | ImsmoothMethods.execute(dirkernel, major, minor, pa, kimage, scale, stack) |
341 363 | self.assertTrue(os.path.exists(stack.peak().path)) |
342 364 | |
343 365 | exception_case(ValueError, 'Unsupported direction smoothing kernel, foobar') | .
344 366 | def test_3_2(self): |
367 + | """3-2. simple failure case""" |
345 368 | major = '2.5arcsec' |
346 369 | minor = '2arcsec' |
347 370 | pa = '0deg' |
348 371 | dirkernel = 'foobar' |
349 372 | kimage = '' |
350 373 | scale = -1 |
351 374 | |
352 375 | stack = CasaImageStack(top=UnerasableFolder(self.tiny)) |
353 376 | |
354 377 | ImsmoothMethods.execute(dirkernel, major, minor, pa, kimage, scale, stack) |
355 378 | |
356 379 | def test_3_3(self): |
380 + | """3-3. check parameters of ImsmoothParams""" |
357 381 | targetres = stretch = False |
358 382 | mask = region = box = chans = stokes = '' |
359 383 | beam = {} |
360 384 | infile = 'infile' |
361 385 | outfile = 'outfile' |
362 386 | kernel = ('none', 'image', 'gaussian', 'boxcar') |
363 387 | major = '2.5arcsec' |
364 388 | minor = '2arcsec' |
365 389 | pa = '0deg' |
366 390 | kimage = self.tiny |
419 443 | datapath = ctsys_resolve('unittest/imbaseline/') |
420 444 | expected = 'expected.im' |
421 445 | datacolumn = DATACOLUMN |
422 446 | |
423 447 | def setUp(self): |
424 448 | self._create_dummy_folders() |
425 449 | self._copy_test_files(self.datapath, self.expected) |
426 450 | self.image_shape = get_image_shape(os.path.join(self.datapath, self.expected)) |
427 451 | |
428 452 | def test_4_1(self): |
453 + | """4-1. simple successful case""" |
429 454 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected)) |
430 455 | ms_stack = MeasurementSetStack() |
431 456 | Image2MSMethods.execute(self.datacolumn, self.image_shape, image_stack, ms_stack) |
432 457 | self.assertEqual(ms_stack.height(), 1) |
433 458 | ms_path = ms_stack.peak().path |
434 459 | self.assertTrue(os.path.exists(ms_path)) |
435 460 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'table.dat'))) |
436 461 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'ANTENNA'))) |
437 462 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'DATA_DESCRIPTION'))) |
438 463 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'FEED'))) |
442 467 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'OBSERVATION'))) |
443 468 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'POINTING'))) |
444 469 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'POLARIZATION'))) |
445 470 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'PROCESSOR'))) |
446 471 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'SOURCE'))) |
447 472 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'SPECTRAL_WINDOW'))) |
448 473 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'STATE'))) |
449 474 | |
450 475 | exception_case(RuntimeError, 'column INVALID does not exist') | .
451 476 | def test_4_2(self): |
477 + | """4-2. invalid datacolumn""" |
452 478 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected)) |
453 479 | ms_stack = MeasurementSetStack() |
454 480 | Image2MSMethods.execute('INVALID', self.image_shape, image_stack, ms_stack) |
455 481 | |
456 482 | exception_case(RuntimeError, 'Unable to open image dummy1.') | .
457 483 | def test_4_3(self): |
484 + | """4-3. invalid image""" |
458 485 | image_stack = CasaImageStack(top=UnerasableFolder(DUMMY_FOLDERS[0])) |
459 486 | ms_stack = MeasurementSetStack() |
460 487 | Image2MSMethods.execute(self.datacolumn, self.image_shape, image_stack, ms_stack) |
461 488 | |
462 489 | exception_case(RuntimeError, 'the stack is empty') | .
463 490 | def test_4_4(self): |
491 + | """4-4. set empty stack""" |
464 492 | image_stack = CasaImageStack() |
465 493 | ms_stack = MeasurementSetStack() |
466 494 | Image2MSMethods.execute(self.datacolumn, self.image_shape, image_stack, ms_stack) |
467 495 | |
468 496 | def test_4_5(self): |
497 + | """4-5. check Image2MSParams""" |
469 498 | outfile = 'output_4_5.ms' |
470 499 | params = Image2MSParams(self.expected, outfile, self.datacolumn, self.image_shape) |
471 500 | params.validate() |
472 501 | self.assertEqual(params.infile, self.expected) |
473 502 | self.assertEqual(params.outfile, outfile) |
474 503 | self.assertTrue(np.all(params.im_shape == self.image_shape.im_shape)) |
475 504 | self.assertTrue(np.all(params.axis_dir == self.image_shape.axis_dir)) |
476 505 | self.assertTrue(np.all(params.dir_shape == self.image_shape.dir_shape)) |
477 506 | self.assertEqual(params.axis_sp, self.image_shape.axis_sp) |
478 507 | self.assertEqual(params.axis_pol, self.image_shape.axis_pol) |
497 526 | datacolumn = DATACOLUMN |
498 527 | spkenel = 'gaussian' |
499 528 | kwidth = 5 |
500 529 | |
501 530 | def setUp(self): |
502 531 | self._copy_test_files(self.datapath, self.expected_im) |
503 532 | self._copy_test_files(self.datapath, self.expected_ms) |
504 533 | self.image_shape = get_image_shape(os.path.join(self.datapath, self.expected_im)) |
505 534 | |
506 535 | def test_5_1(self): |
536 + | """5-1. simple successful case""" |
507 537 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
508 538 | ms_stack = MeasurementSetStack() |
509 539 | ms_stack.push(EraseableFolder(self.expected_ms)) |
510 540 | SdsmoothMethods.execute(self.datacolumn, self.spkenel, self.kwidth, image_stack, ms_stack, self.image_shape) |
511 541 | self.assertEqual(image_stack.height(), 2) |
512 542 | self.assertEqual(ms_stack.height(), 2) |
513 543 | self.assertTrue(os.path.exists(os.path.join(image_stack.peak().path, 'table.dat'))) |
514 544 | |
515 545 | ms_path = ms_stack.peak().path |
516 546 | self.assertTrue(os.path.exists(ms_path)) |
524 554 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'OBSERVATION'))) |
525 555 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'POINTING'))) |
526 556 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'POLARIZATION'))) |
527 557 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'PROCESSOR'))) |
528 558 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'SOURCE'))) |
529 559 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'SPECTRAL_WINDOW'))) |
530 560 | self.assertTrue(os.path.exists(os.path.join(ms_path, 'STATE'))) |
531 561 | |
532 562 | exception_case(RuntimeError, 'the stack is empty') | .
533 563 | def test_5_2(self): |
564 + | """5-2. invalid ms stack""" |
534 565 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
535 566 | ms_stack = MeasurementSetStack() |
536 567 | SdsmoothMethods.execute(self.datacolumn, self.spkenel, self.kwidth, image_stack, ms_stack, self.image_shape) |
537 568 | |
538 569 | exception_case(RuntimeError, 'the stack has not have enough stuff') | .
539 570 | def test_5_3(self): |
571 + | """5-3. invalid image stack""" |
540 572 | image_stack = CasaImageStack() |
541 573 | ms_stack = MeasurementSetStack() |
542 574 | ms_stack.push(EraseableFolder(self.expected_ms)) |
543 575 | SdsmoothMethods.execute(self.datacolumn, self.spkenel, self.kwidth, image_stack, ms_stack, self.image_shape) |
544 576 | |
545 577 | def test_5_4(self): |
578 + | """5-4. check SdsmoothParams""" |
546 579 | spw = field = antenna = timerange = scan = pol = intent = '' |
547 580 | reindex = overwrite = True |
548 581 | infile = 'infile' |
549 582 | outfile = 'outfile' |
550 583 | datacolumn = DATACOLUMN |
551 584 | kernel = ('none', 'gaussian', 'boxcar') |
552 585 | kwidth = 5 |
553 586 | logorigin = 'imbaseline' |
554 587 | |
555 588 | def compare_params(_kernel): |
596 629 | clipthresh = 2.0 |
597 630 | datacolumn = DATACOLUMN |
598 631 | |
599 632 | def setUp(self): |
600 633 | self._copy_test_files(self.datapath, self.expected_im) |
601 634 | self._copy_test_files(self.datapath, self.expected_ms) |
602 635 | self._copy_test_files(self.datapath, self.blparam) |
603 636 | self.image_shape = get_image_shape(os.path.join(self.datapath, self.expected_im)) |
604 637 | |
605 638 | def test_6_1(self): |
639 + | """6-1. simple successful case""" |
606 640 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
607 641 | ms_stack = MeasurementSetStack() |
608 642 | ms_stack.push(EraseableFolder(self.expected_ms)) |
609 643 | SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, |
610 644 | self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft, |
611 645 | self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh, |
612 646 | image_stack, ms_stack, self.image_shape) |
613 647 | self.assertTrue(os.path.exists(ms_stack.peak().path)) |
614 648 | self.assertTrue(os.path.exists(self.bloutput)) |
615 649 | self.assertTrue(os.path.exists(image_stack.peak().path)) |
616 650 | |
617 651 | exception_case(RuntimeError, 'the stack is empty') | .
618 652 | def test_6_2(self): |
653 + | """6-2. invalid ms stack""" |
619 654 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
620 655 | ms_stack = MeasurementSetStack() |
621 656 | SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, |
622 657 | self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft, |
623 658 | self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh, |
624 659 | image_stack, ms_stack, self.image_shape) |
625 660 | |
626 661 | exception_case(RuntimeError, 'the stack has not have enough stuff') | .
627 662 | def test_6_3(self): |
663 + | """6-3. invalid image stack""" |
628 664 | image_stack = CasaImageStack() |
629 665 | ms_stack = MeasurementSetStack() |
630 666 | ms_stack.push(EraseableFolder(self.expected_ms)) |
631 667 | SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, |
632 668 | self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft, |
633 669 | self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh, |
634 670 | image_stack, ms_stack, self.image_shape) |
635 671 | |
636 672 | def test_6_4(self): |
673 + | """6-4. check SdbaselineParams""" |
637 674 | antenna = field = timerange = scan = pol = intent = bltable = '' |
638 675 | reindex = dosubtract = overwrite = True |
639 676 | updateweight = showprogress = verbose = False |
640 677 | blmode = 'fit' |
641 678 | blformat = 'csv' |
642 679 | sigmavalue = 'stddev' |
643 680 | minnrow = 1000 |
644 681 | fftmethod = 'fft' |
645 682 | |
646 683 | infile = 'infile' |
709 746 | self._copy_test_files(self.datapath, self.expected_im) |
710 747 | self._copy_test_files(self.datapath, self.expected_imsmoothed) |
711 748 | self._copy_test_files(self.datapath, self.expected_bl) |
712 749 | self._create_image(self.input_image[0], self.input_image[1], self.input_image[2]) |
713 750 | self._create_image(self.smoothed_image[0], self.smoothed_image[1], self.smoothed_image[2]) |
714 751 | self._create_image(self.smoothed_and_subtracted_image[0], self.smoothed_and_subtracted_image[1], |
715 752 | self.smoothed_and_subtracted_image[2]) |
716 753 | self._create_image(self.testdata_err[0], self.testdata_err[1], self.testdata_err[2]) |
717 754 | |
718 755 | def test_7_1(self): |
756 + | """7-1. successful test: output = input_image - (smoothed_image - smoothed_and_subtracted_image)""" |
719 757 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
720 758 | image_stack.push(EraseableFolder(self.expected_imsmoothed)) |
721 759 | image_stack.push(EraseableFolder(self.expected_bl)) |
722 760 | output = 'output_7_1.im' |
723 761 | ImageSubtractionMethods.execute(output, image_stack) |
724 762 | self.assertTrue(os.path.exists(output)) |
725 763 | |
726 764 | def test_7_2(self): |
765 + | """7-2. successful test: output = subtracted_image""" |
727 766 | image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im)) |
728 767 | image_stack.push(EraseableFolder(self.expected_bl)) |
729 768 | output = 'output_7_2.im' |
730 769 | ImageSubtractionMethods.execute(output, image_stack) |
731 770 | self.assertTrue(os.path.exists(output)) |
732 771 | |
733 772 | exception_case(ValueError, 'operands could not be broadcast together with shapes') | .
734 773 | def test_7_3(self): |
774 + | """7-3. unmatch shape""" |
735 775 | image_stack = CasaImageStack(top=UnerasableFolder(self.input_image[0])) |
736 776 | image_stack.push(EraseableFolder(self.smoothed_image[0])) |
737 777 | image_stack.push(EraseableFolder(self.testdata_err[0])) |
738 778 | output = 'output_7_3.im' |
739 779 | ImageSubtractionMethods.execute(output, image_stack) |
740 780 | |
741 781 | def test_7_4(self): |
782 + | """7-4. unmatch shape(exception is not thrown)""" |
742 783 | image_stack = CasaImageStack(top=UnerasableFolder(self.input_image[0])) |
743 784 | image_stack.push(EraseableFolder(self.testdata_err[0])) |
744 785 | output = 'output_7_4.im' |
745 786 | ImageSubtractionMethods.execute(output, image_stack) |
746 787 | self.assertTrue(os.path.exists(output)) |
747 788 | self.assertFalse(os.path.exists(self.testdata_err[0])) |
748 789 | |
749 790 | def test_7_5(self): |
791 + | """7-5. three images subtraction test""" |
750 792 | # output = input_image - (smoothed_image - smoothed_and_subtracted_image) |
751 793 | image_stack = CasaImageStack(top=UnerasableFolder(self.input_image[0])) |
752 794 | image_stack.push(EraseableFolder(self.smoothed_image[0])) |
753 795 | image_stack.push(EraseableFolder(self.smoothed_and_subtracted_image[0])) |
754 796 | output = 'output_7_5.im' |
755 797 | ImageSubtractionMethods.execute(output, image_stack) |
756 798 | with tool_manager(output, image) as ia: |
757 799 | arr = ia.getchunk() |
758 800 | self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0))) |
759 801 | |
760 802 | def test_7_6(self): |
803 + | """7-6. two images subtraction test""" |
761 804 | # output = smoothed_image |
762 805 | image_stack = CasaImageStack(top=UnerasableFolder(self.input_image[0])) |
763 806 | image_stack.push(EraseableFolder(self.smoothed_image[0])) |
764 807 | output = 'output_7_6.im' |
765 808 | ImageSubtractionMethods.execute(output, image_stack) |
766 809 | with tool_manager(output, image) as ia: |
767 810 | arr = ia.getchunk() |
768 811 | self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0))) |
769 812 | |
770 813 | |
788 831 | self._copy_test_files(self.datapath, self.expected_bl_ms) |
789 832 | if os.path.exists(self.expected_im): |
790 833 | os.rename(self.expected_im, self.expected_orig_im) |
791 834 | else: |
792 835 | raise RuntimeError('some errors occured in copying files') |
793 836 | if not os.path.exists(self.expected_orig_im): |
794 837 | raise RuntimeError('some errors occured in copying files') |
795 838 | self.image_shape = get_image_shape(self.expected_orig_im) |
796 839 | |
797 840 | def test_8_1(self): |
841 + | """8-1. successful test""" |
798 842 | MS2ImageMethods.convert(base_image=self.expected_orig_im, |
799 843 | input_ms=self.expected_ms, |
800 844 | input_image_shape=self.image_shape, |
801 845 | datacolumn=DATACOLUMN) |
802 846 | self.assertTrue(os.path.exists(self.expected_im)) |
803 847 | with tool_manager(self.expected_im, image) as ia: |
804 848 | arr1 = ia.getchunk() |
805 849 | with tool_manager(self.expected_orig_im, image) as ia: |
806 850 | arr2 = ia.getchunk() |
807 851 | self.assertTrue(np.array_equal(arr1, arr2)) |
808 852 | |
809 853 | exception_case(TypeError, 'stat: path should be string, ') | .
810 854 | def test_8_2(self): |
855 + | """8-2. base image error""" |
811 856 | MS2ImageMethods.convert(base_image=None, |
812 857 | input_ms=self.expected_ms, |
813 858 | input_image_shape=self.image_shape, |
814 859 | datacolumn=DATACOLUMN) |
815 860 | |
816 861 | exception_case(TypeError, 'stat: path should be string, ') | .
817 862 | def test_8_3(self): |
863 + | """8-3. MS error""" |
818 864 | MS2ImageMethods.convert(base_image=self.expected_orig_im, |
819 865 | input_ms=self.expected_bl_ms, |
820 866 | input_image_shape=self.image_shape, |
821 867 | datacolumn=DATACOLUMN) |
822 868 | converted = 'expected.bl.im' |
823 869 | self.assertTrue(os.path.exists(converted)) |
824 870 | with tool_manager(self.expected_orig_im, image) as ia: |
825 871 | arr1 = ia.getchunk() |
826 872 | with tool_manager(converted, image) as ia: |
827 873 | arr2 = ia.getchunk() |
842 888 | """ |
843 889 | datapath = ctsys_resolve('unittest/imbaseline/') |
844 890 | expected_im = 'expected.im' |
845 891 | g192_im = 'g192_a2.image' |
846 892 | |
847 893 | def setUp(self): |
848 894 | self._copy_test_files(self.datapath, self.expected_im) |
849 895 | self._copy_test_files(self.datapath, self.g192_im) |
850 896 | |
851 897 | def test_9_1(self): |
898 + | """9-1. get_image_shape: successful""" |
852 899 | shape = get_image_shape(self.expected_im) |
853 900 | self.assertTrue(np.array_equal(shape.im_shape, [20, 20, 100])) |
854 901 | self.assertTrue(np.array_equal(shape.axis_dir, [0, 1])) |
855 902 | self.assertEqual(shape.axis_sp, 2) |
856 903 | self.assertEqual(shape.axis_pol, -1) |
857 904 | self.assertTrue(np.array_equal(shape.dir_shape, [20, 20])) |
858 905 | self.assertEqual(shape.im_nrow, 400) |
859 906 | self.assertEqual(shape.im_nchan, 100) |
860 907 | self.assertEqual(shape.im_npol, 1) |
861 908 | |
864 911 | self.assertTrue(np.array_equal(shape.axis_dir, [0, 1])) |
865 912 | self.assertEqual(shape.axis_sp, 3) |
866 913 | self.assertEqual(shape.axis_pol, 2) |
867 914 | self.assertTrue(np.array_equal(shape.dir_shape, [512, 512])) |
868 915 | self.assertEqual(shape.im_nrow, 262144) |
869 916 | self.assertEqual(shape.im_nchan, 40) |
870 917 | self.assertEqual(shape.im_npol, 1) |
871 918 | |
872 919 | exception_case(ValueError, 'path \'notexists\' is not found') | .
873 920 | def test_9_2(self): |
921 + | """9-2. get_image_shape: failure""" |
874 922 | get_image_shape('notexists') |
875 923 | |
876 924 | exception_case(ValueError, 'image \'testdata_01.im\' is invalid') | .
877 925 | def test_9_3(self): |
926 + | """9-3. get_image_shape: failure""" |
878 927 | testimage = 'testdata_01.im' |
879 928 | self._create_image(testimage, 1.0, [64, 64]) |
880 929 | get_image_shape(testimage) |
881 930 | |
882 931 | |
883 932 | class imbaseline_test(test_base): |
884 933 | """Test full of imbaseline. |
885 934 | |
886 935 | F-1. maskmode/blfunc/dirkernel/spkernel combination test |
887 936 | F-2. imagefile is None |
888 937 | F-3. output_cont is False |
938 + | F-4. output_cont is True |
889 939 | """ |
890 940 | |
891 941 | datapath = ctsys_resolve('unittest/imbaseline/') |
892 942 | expected = 'ref_multipix.signalband' |
893 943 | blparam = 'analytic_variable_blparam_spw1.txt' |
894 944 | f_1_count = 1 |
895 945 | |
896 946 | def setUp(self): |
897 947 | self._copy_test_files(self.datapath, self.expected) |
898 948 | self._copy_test_files(self.datapath, self.blparam) |
899 949 | |
900 950 | def test_f_1(self): |
951 + | """F-1. maskmode/blfunc/dirkernel/spkernel combination test""" |
901 952 | imagename = self.expected |
902 953 | linefile = 'output_f_1' |
903 954 | output_cont = True |
904 955 | bloutput = self.expected + '.bloutput' |
905 956 | maskmode = ('auto', 'list') |
906 957 | chans = '' |
907 958 | thresh = 5.0 |
908 959 | avg_limit = 5 |
909 960 | minwidth = 5 |
910 961 | edge = [0, 0] |
953 1004 | imbaseline(**params) |
954 1005 | for file in filenames_existance_check: |
955 1006 | self.assertTrue(os.path.exists(file)) |
956 1007 | finally: |
957 1008 | self.f_1_count += 1 |
958 1009 | self.tearDown() |
959 1010 | self.setUp() |
960 1011 | |
961 1012 | exception_case(ValueError, 'Error: file is not found.') | .
962 1013 | def test_f_2(self): |
1014 + | """F-2. imagefile is None""" |
963 1015 | imagefile = '' |
964 1016 | linefile = 'output_f_2' |
965 1017 | dirkernel = 'gaussian' |
966 1018 | spkernel = 'gaussian' |
967 1019 | major = '20arcsec' |
968 1020 | minor = '10arcsec' |
969 1021 | pa = '0deg' |
970 1022 | blfunc = 'sinusoid' |
971 1023 | output_cont = True |
972 1024 | |
973 1025 | imbaseline(imagename=imagefile, |
974 1026 | linefile=linefile, |
975 1027 | dirkernel=dirkernel, |
976 1028 | spkernel=spkernel, |
977 1029 | major=major, |
978 1030 | minor=minor, |
979 1031 | pa=pa, |
980 1032 | blfunc=blfunc, |
981 1033 | output_cont=output_cont) |
982 1034 | |
983 1035 | def test_f_3(self): |
1036 + | """F-3. output_cont is False""" |
984 1037 | imagefile = self.expected |
985 1038 | linefile = 'output_f_3' |
986 1039 | dirkernel = 'gaussian' |
987 1040 | spkernel = 'gaussian' |
988 1041 | major = '20arcsec' |
989 1042 | minor = '10arcsec' |
990 1043 | pa = '0deg' |
991 1044 | blfunc = 'sinusoid' |
992 1045 | output_cont = False |
993 1046 | |
996 1049 | dirkernel=dirkernel, |
997 1050 | spkernel=spkernel, |
998 1051 | major=major, |
999 1052 | minor=minor, |
1000 1053 | pa=pa, |
1001 1054 | blfunc=blfunc, |
1002 1055 | output_cont=output_cont) |
1003 1056 | self.assertFalse(os.path.exists(linefile + '.cont')) |
1004 1057 | |
1005 1058 | def test_f_4(self): |
1059 + | """F-4. output_cont is True""" |
1006 1060 | imagefile = self.expected |
1007 1061 | linefile = 'output_f_4' |
1008 1062 | dirkernel = 'gaussian' |
1009 1063 | spkernel = 'gaussian' |
1010 1064 | major = '20arcsec' |
1011 1065 | minor = '10arcsec' |
1012 1066 | pa = '0deg' |
1013 1067 | blfunc = 'sinusoid' |
1014 1068 | output_cont = True |
1015 1069 | bloutput = self.expected + 'bloutput' |