Commits
Sandra M Castro authored a56bda9fc13
13 13 | |
14 14 | ctsys_resolve = ctsys.resolve |
15 15 | |
16 16 | _ia = image( ) |
17 17 | else: |
18 18 | from recipes.pixelmask2cleanmask import * |
19 19 | from tasks import * |
20 20 | from taskinit import * |
21 21 | from __main__ import default |
22 22 | |
23 - | dataRoot = os.path.join(os.environ.get('CASAPATH').split()[0],'data') |
23 + | dataRoot = os.path.join(os.environ.get('CASAPATH').split()[0],'casatestdata/') |
24 24 | def ctsys_resolve(apath): |
25 25 | return os.path.join(dataRoot,apath) |
26 26 | |
27 27 | _ia = iatool( ) |
28 28 | |
29 29 | """ |
30 30 | Unit tests for task makemask |
31 31 | |
32 32 | """ |
33 33 | |
34 - | datapath = 'regression/unittest/makemask' |
34 + | datapath = ctsys_resolve('unittest/makemask/') |
35 35 | |
36 36 | #debug=True |
37 37 | debug=False |
38 38 | |
39 39 | class makemaskTestBase(unittest.TestCase): |
40 40 | """ base class for makemask unit test""" |
41 41 | def compareimpix(self,refimage,inimage,evalmask=False): |
42 42 | """ |
43 43 | do pixel by pixel comparison of the cube image |
44 44 | returns true if identical in terms of pixel values |
74 74 | inimage6='3x3.image' |
75 75 | inimage_all = [inimage, inimage2, inimage3, inimage4, inimage5, inimage6] |
76 76 | |
77 77 | outimage1='ngc5921.cube1.copy.mask' |
78 78 | outimage2='ngc5921.cube1.copyinimage.mask' |
79 79 | outimage3='ngc5921.cube2.copyinimage.mask' |
80 80 | outimage4='ngc5921.cube2.copy.mask' |
81 81 | outimage5='3x3b.image' |
82 82 | outimage_all = [outimage1, outimage2, outimage3, outimage4, outimage5] |
83 83 | |
84 - | refimage4=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.copytest4.ref.mask')) |
85 - | refimage6=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.copytest6.ref.mask')) |
84 + | refimage4=os.path.join(datapath,'makemask_reference/ngc5921.copytest4.ref.mask') |
85 + | refimage6=os.path.join(datapath,'makemask_reference/ngc5921.copytest6.ref.mask') |
86 86 | |
87 87 | def setUp(self): |
88 88 | #for img in [self.inimage,self.outimage1,self.outimage2, self.outimage3]: |
89 89 | # if os.path.isdir(img): |
90 90 | # shutil.rmtree(img) |
91 91 | for img in self.inimage_all: |
92 92 | if not os.path.isdir(img): |
93 - | shutil.copytree(ctsys_resolve(os.path.join(datapath,img)),img) |
93 + | shutil.copytree(os.path.join(datapath,img),img) |
94 94 | |
95 95 | def tearDown(self): |
96 96 | if not debug: |
97 97 | for img in self.inimage_all + self.outimage_all: |
98 98 | #pass |
99 99 | if os.path.isdir(img): |
100 100 | shutil.rmtree(img) |
101 101 | else: |
102 102 | print("debugging mode: clean-up did not performed") |
103 103 | |
278 278 | #data in repository |
279 279 | inimage='ngc5921.cube1.mask' |
280 280 | #inimage2='ngc5921.cube1.bmask' |
281 281 | inimage2='ngc5921.cube1.bmask3' |
282 282 | inimage3='ngc5921.cube2.mask' |
283 283 | infile1='ellipse_rg.txt' |
284 284 | |
285 285 | outimage1='ngc5921.cube1.merge.mask' |
286 286 | outimage2='ngc5921.cube1.merge.copyinmage.mask' |
287 287 | |
288 - | refimage1=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.mergetest1.ref.mask')) |
289 - | refimage2=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.mergetest2.ref.mask')) |
290 - | refimage3=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.mergetest3.ref.mask')) |
288 + | refimage1=os.path.join(datapath,'makemask_reference/ngc5921.mergetest1.ref.mask') |
289 + | refimage2=os.path.join(datapath,'makemask_reference/ngc5921.mergetest2.ref.mask') |
290 + | refimage3=os.path.join(datapath,'makemask_reference/ngc5921.mergetest3.ref.mask') |
291 291 | |
292 292 | def setUp(self): |
293 293 | #for img in [self.inimage,self.outimage1,self.outimage2, self.outimage3]: |
294 294 | # if os.path.isdir(img): |
295 295 | # shutil.rmtree(img) |
296 296 | for img in [self.inimage,self.inimage2,self.inimage3]: |
297 297 | if not os.path.isdir(img): |
298 - | shutil.copytree(ctsys_resolve(os.path.join(datapath,img)),img) |
298 + | shutil.copytree(os.path.join(datapath,img),img) |
299 299 | |
300 300 | def tearDown(self): |
301 301 | if not debug: |
302 302 | for img in [self.inimage,self.inimage2,self.inimage3,self.outimage1,self.outimage2, self.infile1, '_tmp_im']: |
303 303 | #pass |
304 304 | if os.path.isdir(img): |
305 305 | shutil.rmtree(img) |
306 306 | elif os.path.isfile(img): |
307 307 | os.system('rm '+img) |
308 308 | else: |
339 339 | self.assertTrue(self.compareimpix(self.refimage2,self.outimage1)) |
340 340 | #shutil.rmtree(self.outimage1) |
341 341 | |
342 342 | def test3_mergemasks(self): |
343 343 | """ (copy mode) mergetest3: merging multiple masks (image mask, boolean mask, regions)""" |
344 344 | try: |
345 345 | #To test for existing outfile |
346 346 | # Note: if make a copy of outfile from inimage, comparison with the current ref image will fail .... |
347 347 | #shutil.copytree(self.inimage,self.outimage1) |
348 348 | if not os.path.exists(self.infile1): |
349 - | shutil.copy(ctsys_resolve(os.path.join(datapath,self.infile1)), self.infile1) |
349 + | shutil.copy(os.path.join(datapath,self.infile1), self.infile1) |
350 350 | makemask(mode='copy',inpimage=self.inimage,\ |
351 351 | # inpmask=[self.inimage3, self.inimage2+':maskoo','ellipse_rg.txt','box[[130pix,135pix],[160pix,165pix]]'],\ |
352 352 | inpmask=[self.inimage3, self.inimage2+':maskformergetest','ellipse_rg.txt','box[[130pix,135pix],[160pix,165pix]]'],\ |
353 353 | output=self.outimage1, overwrite=True) |
354 354 | except: |
355 355 | print("\nError running makemask") |
356 356 | raise |
357 357 | |
358 358 | self.assertTrue(os.path.exists(self.outimage1)) |
359 359 | self.assertTrue(self.compareimpix(self.refimage3,self.outimage1)) |
360 360 | #shutil.rmtree(self.outimage1) |
361 361 | |
362 362 | |
363 363 | def test4_mergemasks(self): |
364 364 | """ (copy mode) mergetest4: merging multiple masks (image mask, boolean mask, regions) to a new internal mask""" |
365 365 | # T/F mask converted to 1/0 image would be the same as the test3 output |
366 366 | # but the output image itself different as the input image is copied to output and T/F mask is applied on it. |
367 367 | try: |
368 368 | #shutil.copytree(self.inimage,self.outimage1) |
369 369 | if not os.path.exists(self.infile1): |
370 - | shutil.copy(ctsys_resolve(os.path.join(datapath,self.infile1)), self.infile1) |
370 + | shutil.copy(os.path.join(datapath,self.infile1), self.infile1) |
371 371 | makemask(mode='copy',inpimage=self.inimage,\ |
372 372 | #inpmask=[self.inimage3, self.inimage2+':maskoo','ellipse_rg.txt','box[[130pix,135pix],[160pix,165pix]]'],\ |
373 373 | inpmask=[self.inimage3, self.inimage2+':maskformergetest','ellipse_rg.txt','box[[130pix,135pix],[160pix,165pix]]'],\ |
374 374 | output=self.outimage1+":newmask") |
375 375 | except: |
376 376 | print("\nError running makemask") |
377 377 | raise |
378 378 | |
379 379 | self.assertTrue(os.path.exists(self.outimage1)) |
380 380 | if os.path.exists(self.outimage1): |
417 417 | #data in repository |
418 418 | inimage='ngc5921.cont.mask' |
419 419 | inimage2='ngc5921.cube1.mask' |
420 420 | inimage3='ngc5921.cube2.mask' |
421 421 | inimage4='ngc5921.cube1.bmask' #T/F mask |
422 422 | |
423 423 | outimage='ngc5921.cube1.expand.mask' |
424 424 | outimage2='ngc5921.cube1.copyinmage.mask' |
425 425 | outimage3='ngc5921.cube2.expand.mask' |
426 426 | |
427 - | refimage1=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest1.ref.mask')) |
428 - | refimage2=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest2.ref.mask')) |
429 - | refimage3=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest5.ref.mask')) |
430 - | refimage4=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest6.ref.mask')) |
431 - | refimage5=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest2b.ref.mask')) |
432 - | refimage6=ctsys_resolve(os.path.join(datapath,'reference/ngc5921.expandtest7.ref.mask')) |
427 + | refimage1=os.path.join(datapath,'makemask_reference/ngc5921.expandtest1.ref.mask') |
428 + | refimage2=os.path.join(datapath,'makemask_reference/ngc5921.expandtest2.ref.mask') |
429 + | refimage3=os.path.join(datapath,'makemask_reference/ngc5921.expandtest5.ref.mask') |
430 + | refimage4=os.path.join(datapath,'makemask_reference/ngc5921.expandtest6.ref.mask') |
431 + | refimage5=os.path.join(datapath,'makemask_reference/ngc5921.expandtest2b.ref.mask') |
432 + | refimage6=os.path.join(datapath,'makemask_reference/ngc5921.expandtest7.ref.mask') |
433 433 | |
434 434 | def setUp(self): |
435 435 | #for img in [self.inimage,self.outimage1,self.outimage2, self.outimage3]: |
436 436 | # if os.path.isdir(img): |
437 437 | # shutil.rmtree(img) |
438 438 | for img in [self.inimage,self.inimage2,self.inimage3,self.inimage4]: |
439 439 | if not os.path.isdir(img): |
440 - | shutil.copytree(ctsys_resolve(os.path.join(datapath,img)),img) |
440 + | shutil.copytree(os.path.join(datapath,img),img) |
441 441 | |
442 442 | def tearDown(self): |
443 443 | if not debug: |
444 444 | for img in [self.inimage,self.inimage2,self.inimage3,self.inimage4, |
445 445 | self.outimage,self.outimage2,self.outimage3, '_tmp_im']: |
446 446 | if os.path.isdir(img): |
447 447 | shutil.rmtree(img) |
448 448 | #pass |
449 449 | else: |
450 450 | print("debugging mode: clean-up did not performed") |
597 597 | |
598 598 | class test_inmask(makemaskTestBase): |
599 599 | """internal mask manupilations""" |
600 600 | |
601 601 | #data in repository |
602 602 | inimage='ngc5921.cube1.bmask2' #T/F mask |
603 603 | |
604 604 | def setUp(self): |
605 605 | for img in [self.inimage]: |
606 606 | if not os.path.isdir(img): |
607 - | shutil.copytree(ctsys_resolve(os.path.join(datapath,img)),img) |
607 + | shutil.copytree(os.path.join(datapath,img),img) |
608 608 | |
609 609 | def tearDown(self): |
610 610 | if not debug: |
611 611 | for img in [self.inimage]: |
612 612 | if os.path.isdir(img): |
613 613 | shutil.rmtree(img) |
614 614 | else: |
615 615 | print("debugging mode: clean-up did not performed") |
616 616 | |
617 617 | def test_deletemask(self): |