Commits

Takeshi Nakazato authored and Ville Suoranta committed b51086e06c4 Merge
Pull request #913: CAS-14401 set image brightness unit according to the unit of MS data column

Merge in CASA/casa6 from CAS-14401 to master * commit '26fe7533fa5c48d4f094f7af9596d1626b74432b': add one more test case: check if task parameter overrides brightness unit Add type hint and docstring to test helper function Add description on unit search order fixed wrong test name Add supplementary comment CAS-14401 refactoring, type hints, docstrings, and one more test case CAS-14401 make sure CORRECTED_DATA column takes priority CAS-14401 add unit test to verify brightnessunit CAS-14401 add another keyword name to search for brightness unit

casatasks/src/private/task_tsdimaging.py

Modified
870 870 collapsed.close()
871 871 except RuntimeError as e:
872 872 if 'All selected pixels are masked' in str(e):
873 873 valid_pixels_after = 0
874 874 else:
875 875 raise
876 876
877 877 masked_fraction = 100. * (1. - valid_pixels_after / float(valid_pixels[0]))
878 878
879 879 logger.post(f"This amounts to {masked_fraction:5.1f} % "
880 - "of the area with nonzero weight.",
880 + "of the area with nonzero weight.",
881 881 priority="INFO")
882 882 logger.post(
883 883 f"The weight image '{weightimage}' is returned by this task, "
884 884 "if the user wishes to assess the results in detail.",
885 885 priority="INFO")
886 886
887 887
888 888 def get_ms_column_unit(tb, colname):
889 889 col_unit = ''
890 890 if colname in tb.colnames():
891 891 cdkw = tb.getcoldesc(colname)['keywords']
892 - if 'QuantumUnits' in cdkw:
893 - u = cdkw['QuantumUnits']
894 - if isinstance(u, str):
895 - col_unit = u.strip()
896 - elif isinstance(u, list):
897 - col_unit = u[0].strip()
892 + for key in ['UNIT', 'QuantumUnits']:
893 + if key in cdkw:
894 + u = cdkw[key]
895 + if isinstance(u, str):
896 + col_unit = u.strip()
897 + elif isinstance(u, (list, numpy.ndarray)) and len(u) > 0:
898 + col_unit = u[0].strip()
899 + if col_unit:
900 + break
898 901 return col_unit
899 902
900 903
901 904 def get_brightness_unit_from_ms(msname):
902 905 image_unit = ''
903 906 with sdutil.table_manager(msname) as tb:
904 - image_unit = get_ms_column_unit(tb, 'DATA')
905 - if image_unit == '':
906 - image_unit = get_ms_column_unit(tb, 'FLOAT_DATA')
907 + for column in ['CORRECTED_DATA', 'FLOAT_DATA', 'DATA']:
908 + image_unit = get_ms_column_unit(tb, column)
909 + if image_unit:
910 + break
911 +
907 912 if image_unit.upper() == 'K':
908 913 image_unit = 'K'
909 914 else:
910 915 image_unit = 'Jy/beam'
911 916
912 917 return image_unit
913 918
914 919
915 920 @sdutil.sdtask_decorator
916 921 def tsdimaging(

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut