Collection of scripts and small programs used by the EVN Support Scientists at JIVE during the regular data processing of EVN observations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 lines
4.2 KiB

  1. #!/usr/bin/env python3
  2. """
  3. Change the MOUNT field in the ANTENNA table for Ys to 'ALT-AZ-NASMYTH-RH'.
  4. It allows tConvert to put MNTSTA=4 into the FITS AN table, to handle the
  5. parallactic angle correction for Ys's Nasmyth focus correctly.
  6. Also, changes Hobart X_YEW to X-YEW expected by tConvert (MNTSTA=3).
  7. Usage: ysfocus.py <measurement set>
  8. Options:
  9. msdata : str MS data set containing the data to be flagged.
  10. Version: 2.0
  11. Date: Jun 2018
  12. Written by Benito Marcote (marcote@jive.eu)
  13. version 2.0 changes
  14. - STATION name is now case insensitive.
  15. - Warns when the STATION already contains the right mount.
  16. - New direct access of the db (put/getcol) to keep the MS locked while running.
  17. This now also works with referenced MS files.
  18. version 1.2 changes
  19. - Now the script works when the STATION name is also YS or HO (not only
  20. YEBES40m or HOBART).
  21. """
  22. from pyrap import tables as pt
  23. import numpy as np
  24. import sys
  25. help_argument = 'Measurement Set containing the data to be corrected.'
  26. try:
  27. usage = "%(prog)s [-h] <measurement set>"
  28. description="""Change the MOUNT field in the ANTENNA table for Yebes to 'ALT-AZ-NASMYTH-RH'.
  29. It allows tConvert to put MNTSTA=4 into the FITS AN table to handle the
  30. parallactic angle correction for Ys's Nasmyth focus correctly.
  31. Also, changes Hobart X_YEW to X-YEW expected by tConvert (MNTSTA=3).
  32. """
  33. import argparse
  34. parser = argparse.ArgumentParser(description=description, prog='ysfocus.py', usage=usage)
  35. parser.add_argument('msdata', type=str, help=help_argument)
  36. parser.add_argument('--version', action='version', version='%(prog)s 2.0')
  37. arguments = parser.parse_args()
  38. # No necessary but it would look better in the output
  39. msdata = arguments.msdata[:-1] if arguments.msdata[-1]=='/' else arguments.msdata
  40. except ImportError:
  41. usage = "%prog [-h] <measurement set>"
  42. description="""Change the MOUNT field in the ANTENNA table for Ys to 'ALT-AZ-NASMYTH-RH'.
  43. It allows tConvert to put MNTSTA=4 into the FITS AN table, to handle the
  44. parallactic angle correction for Ys's Nasmyth focus correctly.
  45. Also, changes Hobart X_YEW to X-YEW expected by tConvert (MNTSTA=3).
  46. """
  47. # Compatibility with Python 2.7 in eee
  48. import optparse
  49. parser = optparse.OptionParser(usage=usage, description=description, prog='ysfocus.py', version='%prog 2.0')
  50. #parser.add_option('measurement_set', type='string', dest='msdata', help=help_doc)
  51. arguments = parser.parse_args()[1]
  52. if len(arguments) != 1:
  53. print('Only one argument is accepted: ysfocus.py <measurement set>')
  54. sys.exit(1)
  55. # No necessary but it would look better in the output
  56. msdata = arguments[0][:-1] if arguments[0][-1]=='/' else arguments[0]
  57. # The STATION name can be either the full name or the abreviation
  58. fixed_mounts = {'YEBES40M': 'ALT-AZ-NASMYTH-RH', 'YS': 'ALT-AZ-NASMYTH-RH',
  59. 'HOBART': 'X-YEW', 'HO': 'X-YEW', 'HOB_DBBC': 'X-YEW'}
  60. with pt.table(msdata, readonly=False, ack=False) as ms:
  61. with pt.table(ms.getkeyword('ANTENNA'), readonly=False, ack=False) as ant_table:
  62. stations = [i.upper() for i in ant_table.getcol('STATION')]
  63. mounts = ant_table.getcol('MOUNT')
  64. stations_to_change = set(stations).intersection(fixed_mounts.keys())
  65. # Function to get directly the position of a station in the array to get its mount
  66. getmount = lambda station: mounts[stations.index(station)]
  67. for a_station in stations_to_change:
  68. if getmount(a_station) == fixed_mounts[a_station]:
  69. print('{0} has already the right mount ({1})'.format(a_station, fixed_mounts[a_station]))
  70. else:
  71. print('Changing {} mount from {} to {}'.format(a_station, getmount(a_station),
  72. fixed_mounts[a_station]))
  73. mounts[stations.index(a_station)] = fixed_mounts[a_station]
  74. # In case no station has been found in the MS
  75. if len(stations_to_change) == 0:
  76. print("Neither Ys nor Ho found in the MS, no ysfocus.py required.")
  77. else:
  78. ant_table.putcol('MOUNT', mounts)
  79. ant_table.flush()
  80. print('\nDone.')