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.

expname.py 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/env python3
  2. """Change the name of an project in a measurement set (MS).
  3. Usage: expname.py <msdata> <new_expname>
  4. Options:
  5. msdata : str MS data set to be changed.
  6. new_expname : str New name for the project ( experiment) that is quoted in the MS.
  7. It will replace the existing one and it will be converted into
  8. capital letters.
  9. Version: 1.0
  10. Date: April 2017
  11. Written by Benito Marcote (marcote@jive.eu)
  12. """
  13. from pyrap import tables as pt
  14. import sys
  15. help_msdata = ''
  16. help_newexpname = ''
  17. try:
  18. usage = "%(prog)s [-h] <msdata> <new_expname>"
  19. description="""Change the name of a project in a measurement set (MS).
  20. """
  21. import argparse
  22. parser = argparse.ArgumentParser(description=description, prog='expname.py', usage=usage)
  23. parser.add_argument('msdata', type=str, help=help_msdata)
  24. parser.add_argument('new_expname', type=str, help=help_newexpname)
  25. parser.add_argument('--version', action='version', version='%(prog)s 1.0')
  26. arguments = parser.parse_args()
  27. msdata = arguments.msdata[:-1] if arguments.msdata[-1]=='/' else arguments.msdata
  28. new_expname = arguments.new_expname
  29. except ImportError:
  30. usage = "%(prog)s [-h] <msdata> <new_expname>"
  31. description="""Change the name of a project in a measurement set (MS) to new_expname (in upper case).
  32. """
  33. # Compatibility with Python 2.7
  34. import optparse
  35. parser = optparse.OptionParser(usage=usage, description=description, prog='expname.py', version='%prog 1.0')
  36. theparser = parser.parse_args()
  37. arguments = theparser[1]
  38. #arguments = parser.parse_args()[1]
  39. if len(arguments) != 2:
  40. print('Two arguments must be provided: expname.py [-h] [-v] <msdata> <new_expname>')
  41. print('Use -h to get help.')
  42. sys.exit(1)
  43. msdata = arguments[0][:-1] if arguments[0][-1]=='/' else arguments[0]
  44. new_expname = arguments[1]
  45. # The actual work
  46. with pt.table(msdata+'/OBSERVATION', readonly=False, ack=False) as ms:
  47. old_project = ms.getcol('PROJECT')[0] # Should always be one-element list
  48. ms.putcol('PROJECT', [new_expname.upper()])
  49. # Sometimes it can happen that the OBSERVER is also the PROJECT, although not always
  50. if ms.getcol('OBSERVER')[0] == old_project:
  51. ms.putcol('OBSERVER', [new_expname()])
  52. ms.close()
  53. print('Experiment name changed to {}.'.format(new_expname.upper()))