Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_imreframe.py: 12%

59 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 17:39 +0000

1import os 

2import shutil 

3 

4from casatools import image, measures, quanta 

5from casatasks import casalog 

6# this is a local tool 

7qa = quanta() 

8 

9str_lower = str.lower 

10 

11 

12def imreframe(imagename=None, output=None, outframe=None, epoch=None, restfreq=None): 

13 try: 

14 casalog.origin('imreframe') 

15 if(output==imagename): 

16 output='' 

17 needregrid=False 

18 outframe=str_lower(outframe) 

19 if(((outframe == 'topo') or (outframe=='geo')) and (epoch != '')): 

20 needregrid=True 

21 

22 myia = image() 

23 me = measures() 

24 

25 myia.open(imagename) 

26 c=myia.coordsys() 

27 me.doframe(me.observatory(c.telescope())) 

28 me.doframe(c.referencevalue('m', 'direction')['measure']['direction']) 

29 me.doframe(c.epoch()) 

30 myret = c.findcoordinate('spectral') 

31 hasspec = myret['return'] 

32 pixax = myret['pixel'] 

33 worldax = myret['world'] 

34 if(not hasspec): 

35 raise RuntimeError('Could not find spectral axis') 

36 if(outframe != ''): 

37 c.setconversiontype(spectral=outframe) 

38 if(restfreq != ''): 

39 c.setrestfrequency(value=qa.quantity(restfreq, 'Hz')) 

40 if(epoch != ''): 

41 c.setepoch(me.epoch('utc', epoch)) 

42 me.doframe(me.epoch('utc', epoch)) 

43 if(not needregrid): 

44 if(output != ''): 

45 myia.fromimage(outfile=output, infile=imagename, overwrite=True) 

46 myia.close() 

47 myia.open(output) 

48 myia.setcoordsys(c.torecord()) 

49 myia.done() 

50 else: 

51 c.setreferencecode(outframe, 'spectral', True) 

52 reffreq=c.referencevalue('m', 'spectral')['measure']['spectral']['frequency'] 

53 newreffreq=me.measure(reffreq, outframe) 

54 c.setreferencevalue(qa.tos(newreffreq['m0']), 'spectral') 

55 outname='_temp_regrid_image' if(output=='') else output 

56 shp=myia.shape() 

57 ib=myia.regrid(outfile=outname, shape=shp, csys=c.torecord(), 

58 axes=pixax, overwrite=True, asvelocity=False) 

59 ib.setcoordsys(c.torecord()) 

60 if(output==''): 

61 myia.done() 

62 ib.rename(name=imagename, overwrite=True) 

63 myia.done() 

64 ib.done() 

65 

66 finally: 

67 if('myia' in locals()): 

68 myia.close() 

69 if('ib' in locals()): 

70 ib.close()