Browse Source

Working script (tested in eee)

master
Benito Marcote 1 year ago
parent
commit
0c1b30dd07
  1. 136
      nme_standardplots.py

136
nme_standplots.py → nme_standardplots.py

@ -2,11 +2,11 @@
import os
import sys
import configparser
import tempfile
import argparse
import subprocess
import datetime
import jplotter
import command
__version__ = 1
__prog__ = 'nme_standardplots.py'
@ -26,7 +26,7 @@ def scp(originpath, destpath):
then it raises ValueError.
"""
process = subprocess.call(["scp", originpath, destpath], shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1)
if process != 0:
raise ValueError(f"\nError code {process} when running scp {originpath} {destpath}.")
@ -34,9 +34,19 @@ def scp(originpath, destpath):
def get_vixfile(expname: str):
"""Copies the .vix file from ccs to the current directory for the given expname.
"""
scp(f"jops@ccs:/ccs/expr/{expname}/{expname.lower()}.vix", '.')
os.symlink(f"{expname.lower()}.vix", f"{expname.upper()}.vix")
print('Vix file copied to the current directory.')
if not os.path.isfile(f"{expname.lower()}.vix"):
scp(f"jops@ccs:/ccs/expr/{expname.upper()}/{expname.lower()}.vix", '.')
print('Vix file copied to the current directory.')
if not os.path.isfile(f"{expname.upper()}.vix"):
os.symlink(f"{expname.lower()}.vix", f"{expname.upper()}.vix")
print('Symbolic link created to vix file.')
# Because j2ms2 will search for a vix file named as the current directory
pwd = os.getcwd().split('/')[-1]
if not os.path.isfile(f"{pwd}.vix"):
os.symlink(f"{expname.lower()}.vix", f"{pwd}.vix")
def copy_cor_file(expname: str, scanno: str, date: str):
@ -48,6 +58,7 @@ def copy_cor_file(expname: str, scanno: str, date: str):
date : date for the given experiment in the form YYYY_month, where month is the full name of the month.
"""
scp(f"jops@tail.sfxc:/home/jops/sfxc/ftp/{date}/{expname.lower()}/output/scan{scanno}.cor", ".")
print(f"Correlation file 'scan{scanno}.cor' copied from tail.sfxc.")
def j2ms2(expname: str, scanno: str):
@ -57,11 +68,19 @@ def j2ms2(expname: str, scanno: str):
"""
msfile = f"{expname.lower()}-scan{scanno}.ms"
if os.path.isdir(msfile):
process = subprocess.call(["rm", "-rf", f"{msfile}"], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
print("Removing existing MS file.")
process = subprocess.call(["rm", "-rf", msfile], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, bufsize=1)
print("Running j2ms2...")
process = subprocess.Popen(f"j2ms2 -o {msfile} scan{scanno}.cor", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while process.poll() is None:
out = process.stdout.readline().decode('utf-8')
sys.stdout.write(out)
sys.stdout.flush()
subprocess.call(["j2ms2", "-o", msfile, f"scan{scanno}.cor"], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1)
print(f"MS file '{msfile}' created.")
def standardplots(expname: str, scanno: str, refant: str):
@ -70,42 +89,61 @@ def standardplots(expname: str, scanno: str, refant: str):
{expname.lower()}-scan{scanno}.ms
"""
def open_ms(expname, scanno):
yield f"ms {expname.lower()}-scan{scanno}.ms"
yield "indexr"
def auto_plots():
yield "bl auto"
yield "fq */p"
yield "pt ampchan"
yield "ch none"
yield "avc none"
yield "avt vector"
yield "ckey p['RR']=2 p['LL']=3 p['RL']=4 p['LR']=5 p[none]=1"
yield "sort bl sb"
yield "new sb false"
yield "multi true"
yield "nxy 1 4"
yield "y 0 1.8"
yield "pl"
def cross_plots():
yield f"bl {refant}* -auto"
yield "fq *"
yield "pt ampchan"
yield "ch none"
yield "avc none"
yield "avt vector"
yield "ckey p['RR']=2 p['LL']=3 p['RL']=4 p['LR']=5 p[none]=1"
yield "sort bl sb"
yield "new sb false"
yield "multi true"
yield "nxy 1 4"
yield "y local"
yield "pl"
todo = [open_ms(expname, scanno), auto_plots(), cross_plots()]
jplotter.run_plotter(command.scripted(*todo))
tmp = tempfile.NamedTemporaryFile()
return f"ms {expname.lower()}-scan{scanno}.ms;refile {tmp.name};indexr"
def auto_plots(expname, scanno):
todo = ["bl auto"]
todo += ["fq */p"]
todo += ["pt ampchan"]
todo += ["ch none"]
todo += ["avc none"]
todo += ["avt vector"]
todo += ["ckey p[RR]=2 p[LL]=3 p[RL]=4 p[LR]=5 p[none]=1"]
todo += ["sort bl sb"]
todo += ["new sb false"]
todo += ["multi true"]
todo += ["nxy 1 4"]
todo += ["y 0 1.8"]
todo += [f"refile {expname.lower()}-scan{scanno}-auto.ps/cps"]
todo += ["pl"]
return ';'.join(todo)
def cross_plots(expname, scanno, refant):
todo = [f"bl {refant}* -auto"]
todo += ["fq *"]
todo += ["pt ampchan"]
todo += ["ch none"]
todo += ["avc none"]
todo += ["avt vector"]
todo += ["ckey p[RR]=2 p[LL]=3 p[RL]=4 p[LR]=5 p[none]=1"]
todo += ["sort bl sb"]
todo += ["new sb false"]
todo += ["multi true"]
todo += ["nxy 1 4"]
todo += ["y local"]
todo += [f"refile {expname.lower()}-scan{scanno}-cross.ps/cps"]
todo += ["pl"]
return ';'.join(todo)
for afile in (f"{expname.lower()}-scan{scanno}-auto.ps", f"{expname.lower()}-scan{scanno}-cross.ps"):
if os.path.isfile(afile):
print("Removing existing plot files...")
# process = subprocess.Popen(["rm", "-f", f"{afile}"], shell=True, stdout=subprocess.PIPE,
process = subprocess.Popen(f"rm -f {afile}", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, bufsize=1)
todo = [open_ms(expname, scanno), auto_plots(expname, scanno), cross_plots(expname, scanno, refant)]
print("Running jplotter...")
print(f"\n\njplotter -c {';'.join(todo)}\n\n")
process = subprocess.Popen(f"jplotter -c '{';'.join(todo)}'", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, bufsize=1)
while process.poll() is None:
out = process.stdout.readline().decode('utf-8')
sys.stdout.write(out)
sys.stdout.flush()
print("Plots produced and saved.")
if __name__ == '__main__':
@ -123,9 +161,9 @@ if __name__ == '__main__':
version='%(prog)s {}'.format(__version__))
args = parser.parse_args()
if args.date is None:
nme_date = args.date
else:
nme_date = datetime.datetime.today().strftime('%Y_%B').lower()
else:
nme_date = args.date
get_vixfile(args.expname)
copy_cor_file(args.expname, args.scan_number, nme_date)
Loading…
Cancel
Save