mirror of
https://github.com/JHUAPL/kaiju.git
synced 2026-01-09 10:47:54 -05:00
Add parallel processing capability for satellite comparisons
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import numpy as np
|
||||
import datetime
|
||||
import os
|
||||
import glob
|
||||
from astropy.time import Time
|
||||
from xml.dom import minidom
|
||||
|
||||
@@ -11,8 +13,10 @@ def MJD2UT(mjd):
|
||||
|
||||
return utall
|
||||
|
||||
def genSCXML(scid="sctrack_A",ebfile="msphere",h5traj="sctrack_A.h5"):
|
||||
def genSCXML(fdir,ftag,
|
||||
scid="sctrack_A",h5traj="sctrack_A.h5"):
|
||||
|
||||
(fname,isMPI,Ri,Rj,Rk) = getRunInfo(fdir,ftag)
|
||||
root = minidom.Document()
|
||||
xml = root.createElement('Chimp')
|
||||
root.appendChild(xml)
|
||||
@@ -22,8 +26,16 @@ def genSCXML(scid="sctrack_A",ebfile="msphere",h5traj="sctrack_A.h5"):
|
||||
fieldsChild = root.createElement("fields")
|
||||
fieldsChild.setAttribute("doMHD","T")
|
||||
fieldsChild.setAttribute("grType","LFM")
|
||||
fieldsChild.setAttribute("ebfile",ebfile)
|
||||
fieldsChild.setAttribute("ebfile",ftag)
|
||||
if isMPI:
|
||||
fieldsChild.setAttribute("isMPI","T")
|
||||
xml.appendChild(fieldsChild)
|
||||
if isMPI:
|
||||
parallelChild = root.createElement("parallel")
|
||||
parallelChild.setAttribute("Ri","%d"%Ri)
|
||||
parallelChild.setAttribute("Rj","%d"%Rj)
|
||||
parallelChild.setAttribute("Rk","%d"%Rk)
|
||||
xml.appendChild(parallelChild)
|
||||
unitsChild = root.createElement("units")
|
||||
unitsChild.setAttribute("uid","EARTH")
|
||||
xml.appendChild(unitsChild)
|
||||
@@ -34,4 +46,236 @@ def genSCXML(scid="sctrack_A",ebfile="msphere",h5traj="sctrack_A.h5"):
|
||||
|
||||
return root
|
||||
|
||||
def getRunInfo(fdir,ftag):
|
||||
idStr = "_0000_0000_0000.gam.h5"
|
||||
isMPI = False
|
||||
Ri = 0
|
||||
Rj = 0
|
||||
Rk = 0
|
||||
fOld = os.path.join(fdir,ftag+'.h5')
|
||||
fNew = os.path.join(fdir,ftag+'.gam.h5')
|
||||
try:
|
||||
if (os.path.exists(fOld)):
|
||||
return fOld,isMPI,Ri,Rj,Rk
|
||||
if (os.path.exists(fNew)):
|
||||
return fNew,isMPI,Ri,Rj,Rk
|
||||
fIns = glob.glob(os.path.join(fdir,ftag)+'_*'+idStr)
|
||||
if (len(fIns) > 1):
|
||||
raise ValueError('Should not find more that one parallel file')
|
||||
if (len(fIns) == 0):
|
||||
raise ValueError('No MPI database found')
|
||||
else:
|
||||
isMPI = True
|
||||
fName = fIns[0]
|
||||
Ns = [int(s) for s in fName.split('_') if s.isdigit()]
|
||||
Ri = Ns[-5]
|
||||
Rj = Ns[-4]
|
||||
Rk = Ns[-3]
|
||||
return fName,isMPI,Ri,Rj,Rk
|
||||
except ValueError as ve:
|
||||
print(ve)
|
||||
sys.exit()
|
||||
|
||||
def getScIds():
|
||||
scDic = {}
|
||||
scDic['GOES11'] = {'ephemId':'GOES11_K0_MAG',
|
||||
'ephemData':'SC_pos_sm',
|
||||
'ephemCoordSys':'SM',
|
||||
'denId':None,
|
||||
'denData':None,
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'GOES11_K0_MAG',
|
||||
'magData': 'B_GSM_c',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['GOES12'] = {'ephemId':'GOES12_K0_MAG',
|
||||
'ephemData':'SC_pos_sm',
|
||||
'ephemCoordSys':'SM',
|
||||
'denId':None,
|
||||
'denData':None,
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'GOES12_K0_MAG',
|
||||
'magData': 'B_GSM_c',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['GEOTAIL'] = {'ephemId':'GE_K0_MGF',
|
||||
'ephemData':'POS',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'GE_H0_CPI',
|
||||
'denData':'SW_P_Den',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'GE_H0_CPI',
|
||||
'velData':'SW_Vc',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'GE_K0_MGF',
|
||||
'magData': 'IB_vector',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['RBSPA'] = {'ephemId':'RBSP-A_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'ephemData':'coordinates',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'RBSPA_REL04_ECT-HOPE-MOM-L3',
|
||||
'denData':'Dens_p_30',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'RBSP-A_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'magData': 'B_vec_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['RBSPB'] = {'ephemId':'RBSP-B_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'ephemData':'coordinates',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'RBSPB_REL04_ECT-HOPE-MOM-L3',
|
||||
'denData':'Dens_p_30',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'RBSP-B_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'magData': 'B_vec_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['CLUSTER1'] = {'ephemId':'C1_CP_FGM_SPIN',
|
||||
'ephemData':'sc_pos_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'C1_PP_CIS',
|
||||
'denData':'N_p__C1_PP_CIS',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'C1_PP_CIS',
|
||||
'velData':'V_p_xyz_gse__C1_PP_CIS',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'C1_CP_FGM_SPIN',
|
||||
'magData': 'B_vec_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['CLUSTER2'] = {'ephemId':'C2_CP_FGM_SPIN',
|
||||
'ephemData':'sc_pos_xyz_gse__C2_CP_FGM_SPIN',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'C2_PP_CIS',
|
||||
'denData':'N_p__C2_PP_CIS',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'C2_PP_CIS',
|
||||
'velData':'V_p_xyz_gse__C2_PP_CIS',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'C2_CP_FGM_SPIN',
|
||||
'magData': 'B_vec_xyz_gse__C2_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['CLUSTER3'] = {'ephemId':'C3_CP_FGM_SPIN',
|
||||
'ephemData':'sc_pos_xyz_gse__C3_CP_FGM_SPIN',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'C3_PP_CIS',
|
||||
'denData':'N_p__C3_PP_CIS',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'C3_PP_CIS',
|
||||
'velData':'V_p_xyz_gse__C3_PP_CIS',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'C3_CP_FGM_SPIN',
|
||||
'magData': 'B_vec_xyz_gse__C3_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['CLUSTER4'] = {'ephemId':'C4_CP_FGM_SPIN',
|
||||
'ephemData':'sc_pos_xyz_gse__C4_CP_FGM_SPIN',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'C4_PP_CIS',
|
||||
'denData':'N_p__C4_PP_CIS',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'C4_PP_CIS',
|
||||
'velData':'V_p_xyz_gse__C4_PP_CIS',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'C4_CP_FGM_SPIN',
|
||||
'magData': 'B_vec_xyz_gse__C4_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['THEMISA'] = {'ephemId':'THA_L1_STATE',
|
||||
'ephemData':'tha_pos_gsmV',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'THA_L2_MOM',
|
||||
'denData':'tha_peim_density',
|
||||
'presId': 'THA_L2_MOM',
|
||||
'presData': 'tha_peim_ptot',
|
||||
'velId': 'THA_L2_MOM',
|
||||
'velData':'tha_peim_velocity_gsm',
|
||||
'velCoordSys':'GSM',
|
||||
'magId': 'THA_L2_MOM',
|
||||
'magData': 'tha_peim_mag',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS1'] = {'ephemId':'MMS1_FGM_SRVY_L2',
|
||||
'ephemData':'mms1_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms1_dis_numberdensity_fast',
|
||||
'presId': 'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms1_dis_pres_bg_fast',
|
||||
'velId': 'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms1_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS1_FGM_SRVY_L2',
|
||||
'magData': 'mms1_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS2'] = {'ephemId':'MMS2_FGM_SRVY_L2',
|
||||
'ephemData':'mms2_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms2_dis_numberdensity_fast',
|
||||
'presId': 'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms2_dis_pres_bg_fast',
|
||||
'velId': 'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms2_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS2_FGM_SRVY_L2',
|
||||
'magData': 'mms2_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS3'] = {'ephemId':'MMS3_FGM_SRVY_L2',
|
||||
'ephemData':'mms3_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms3_dis_numberdensity_fast',
|
||||
'presId': 'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms3_dis_pres_bg_fast',
|
||||
'velId': 'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms3_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS3_FGM_SRVY_L2',
|
||||
'magData': 'mms3_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS4'] = {'ephemId':'MMS4_FGM_SRVY_L2',
|
||||
'ephemData':'mms4_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms4_dis_numberdensity_fast',
|
||||
'presId': 'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms1_dis_pres_bg_fast',
|
||||
'velId': 'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms4_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS1_FGM_SRVY_L2',
|
||||
'magData': 'mms4_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
|
||||
return scDic
|
||||
|
||||
|
||||
|
||||
|
||||
20
places/cheyenne/satExample.pbs
Normal file
20
places/cheyenne/satExample.pbs
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/tcsh
|
||||
#PBS -A P28100045
|
||||
#PBS -N PSATCOMP
|
||||
#PBS -j oe
|
||||
#PBS -q casper
|
||||
#PBS -l walltime=4:00:00
|
||||
#PBS -l select=1:ncpus=18
|
||||
|
||||
source ~/.tcshrc
|
||||
echo $DIR
|
||||
cd $DIR
|
||||
module purge
|
||||
module restore kaiju
|
||||
ncar_pylib casper_kaiju_pylib
|
||||
|
||||
date
|
||||
echo "Running parallel analysis"
|
||||
msphParallelSatComp.py
|
||||
date
|
||||
|
||||
89
scripts/msphParallelSatComp.py
Executable file
89
scripts/msphParallelSatComp.py
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#standard python
|
||||
import sys
|
||||
import os
|
||||
import datetime
|
||||
import subprocess
|
||||
from xml.dom import minidom
|
||||
import argparse
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
|
||||
#import spacepy and cdasws
|
||||
import spacepy
|
||||
from spacepy.coordinates import Coords
|
||||
from spacepy.time import Ticktock
|
||||
import spacepy.datamodel as dm
|
||||
from cdasws import CdasWs
|
||||
|
||||
|
||||
#import numpy and matplotlib
|
||||
import numpy as np
|
||||
import matplotlib as mpl
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.gridspec as gridspec
|
||||
|
||||
|
||||
#Kaipy and related
|
||||
from astropy.time import Time
|
||||
import h5py
|
||||
import kaipy.kaiH5 as kaiH5
|
||||
import kaipy.kaiViz as kv
|
||||
import kaipy.kaiTools as kaiTools
|
||||
|
||||
if __name__ == '__main__':
|
||||
MainS = """Extracts information from satellite trajectory for various
|
||||
spacecraft. Space craft data is pulled from CDAWeb. Output CDF files
|
||||
contain data pulled from CDAWeb along with data extracted from GAMERA.
|
||||
Image files of satellite comparisons are also produced.
|
||||
"""
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description=MainS,
|
||||
formatter_class=RawTextHelpFormatter)
|
||||
parser.add_argument('-id',type=str,metavar='runid',default='msphere',
|
||||
help='RunID of data (default: %(default)s)')
|
||||
parser.add_argument('-path',type=str,metavar='path',default='.',
|
||||
help='Path to directory containing REMIX files (default: %(default)s)')
|
||||
parser.add_argument('-cmd',type=str,metavar='command',default=None,
|
||||
help='Full path to sctrack.x command')
|
||||
parser.add_argument('--keep',action='store_true',
|
||||
help='Keep intermediate files')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
fdir = args.path
|
||||
ftag = args.id
|
||||
cmd = args.cmd
|
||||
keep = args.keep
|
||||
|
||||
if fdir == '.':
|
||||
fdir = os.getcwd()
|
||||
|
||||
if None == cmd:
|
||||
my_env = os.environ.copy()
|
||||
cmd = os.path.join(os.getenv('KAIJUDIR'),'build','bin','sctrack.x')
|
||||
if not (os.path.isfile(cmd) and os.access(cmd, os.X_OK)):
|
||||
print(cmd,'either not found or not executable')
|
||||
sys.exit()
|
||||
|
||||
satCmd = os.path.join(os.getenv('KAIJUDIR'),'scripts',
|
||||
'msphSatComp.py')
|
||||
if not (os.path.isfile(satCmd) and os.access(satCmd, os.X_OK)):
|
||||
print(satCmd,'either not found or not executable')
|
||||
sys.exit()
|
||||
scIds = kaiTools.getScIds()
|
||||
|
||||
process = []
|
||||
|
||||
for scId in scIds:
|
||||
cmdList = [satCmd,'-id',ftag,'-path',fdir,'-cmd',cmd,'-satId',scId]
|
||||
if keep:
|
||||
cmdList.append('--keep')
|
||||
print(cmdList)
|
||||
process.append(subprocess.Popen(cmdList,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE))
|
||||
for proc in process:
|
||||
proc.communicate()
|
||||
print('All done!')
|
||||
@@ -33,137 +33,6 @@ import kaipy.kaiViz as kv
|
||||
import kaipy.kaiTools as kaiTools
|
||||
|
||||
|
||||
def getScIds():
|
||||
scDic = {}
|
||||
scDic['GOES11'] = {'ephemId':'GOES11_K0_MAG',
|
||||
'ephemData':'SC_pos_sm',
|
||||
'ephemCoordSys':'SM',
|
||||
'denId':None,
|
||||
'denData':None,
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'GOES11_K0_MAG',
|
||||
'magData': 'B_GSM_c',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['GOES12'] = {'ephemId':'GOES12_K0_MAG',
|
||||
'ephemData':'SC_pos_sm',
|
||||
'ephemCoordSys':'SM',
|
||||
'denId':None,
|
||||
'denData':None,
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'GOES12_K0_MAG',
|
||||
'magData': 'B_GSM_c',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['GEOTAIL'] = {'ephemId':'GE_K0_MGF',
|
||||
'ephemData':'POS',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'GE_H0_CPI',
|
||||
'denData':'SW_P_Den',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'GE_H0_CPI',
|
||||
'velData':'SW_Vc',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'GE_K0_MGF',
|
||||
'magData': 'IB_vector',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['RBSPA'] = {'ephemId':'RBSP-A_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'ephemData':'coordinates',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'RBSPA_REL04_ECT-HOPE-MOM-L3',
|
||||
'denData':'Dens_p_30',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': None,
|
||||
'velData':None,
|
||||
'velCoordSys':None,
|
||||
'magId': 'RBSP-A_MAGNETOMETER_1SEC-GSM_EMFISIS-L3',
|
||||
'magData': 'B_vec_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['CLUSTER1'] = {'ephemId':'C1_CP_FGM_SPIN',
|
||||
'ephemData':'sc_pos_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'ephemCoordSys':'GSE',
|
||||
'denId':'C1_PP_CIS',
|
||||
'denData':'N_p__C1_PP_CIS',
|
||||
'presId': None,
|
||||
'presData': None,
|
||||
'velId': 'C1_PP_CIS',
|
||||
'velData':'V_p_xyz_gse__C1_PP_CIS',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'C1_CP_FGM_SPIN',
|
||||
'magData': 'B_vec_xyz_gse__C1_CP_FGM_SPIN',
|
||||
'magCoordSys': 'GSE'
|
||||
}
|
||||
scDic['MMS1'] = {'ephemId':'MMS1_FGM_SRVY_L2',
|
||||
'ephemData':'mms1_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms1_dis_numberdensity_fast',
|
||||
'presId': 'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms1_dis_pres_bg_fast',
|
||||
'velId': 'MMS1_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms1_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS1_FGM_SRVY_L2',
|
||||
'magData': 'mms1_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS2'] = {'ephemId':'MMS2_FGM_SRVY_L2',
|
||||
'ephemData':'mms2_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms2_dis_numberdensity_fast',
|
||||
'presId': 'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms2_dis_pres_bg_fast',
|
||||
'velId': 'MMS2_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms2_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS2_FGM_SRVY_L2',
|
||||
'magData': 'mms2_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS3'] = {'ephemId':'MMS3_FGM_SRVY_L2',
|
||||
'ephemData':'mms3_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms3_dis_numberdensity_fast',
|
||||
'presId': 'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms3_dis_pres_bg_fast',
|
||||
'velId': 'MMS3_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms3_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS3_FGM_SRVY_L2',
|
||||
'magData': 'mms3_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
scDic['MMS4'] = {'ephemId':'MMS4_FGM_SRVY_L2',
|
||||
'ephemData':'mms4_fgm_r_gsm_srvy_l2',
|
||||
'ephemCoordSys':'GSM',
|
||||
'denId':'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'denData':'mms4_dis_numberdensity_fast',
|
||||
'presId': 'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'presData': 'mms1_dis_pres_bg_fast',
|
||||
'velId': 'MMS4_FPI_FAST_L2_DIS-MOMS',
|
||||
'velData':'mms4_dis_bulkv_gse_fast',
|
||||
'velCoordSys':'GSE',
|
||||
'magId': 'MMS1_FGM_SRVY_L2',
|
||||
'magData': 'mms4_fgm_b_gsm_srvy_l2',
|
||||
'magCoordSys': 'GSM'
|
||||
}
|
||||
|
||||
return scDic
|
||||
|
||||
def pullVar(cdaObsId,cdaDataId,t0,t1,deltaT):
|
||||
cdas = CdasWs()
|
||||
status,data = cdas.get_data(cdaObsId,cdaDataId,t0,t1,
|
||||
@@ -211,6 +80,11 @@ def getSatData(scDic,t0,t1,deltaT):
|
||||
status1 = addVar(mydata,scDic,'Velocity','velId','velData')
|
||||
status1 = addVar(mydata,scDic,'Density','denId','denData')
|
||||
status1 = addVar(mydata,scDic,'Pressure','presId','presData')
|
||||
#Add any metavar since they might be needed for unit/label determination
|
||||
search_key = 'metavar'
|
||||
res = [key for key,val in data.items() if search_key in key]
|
||||
for name in res:
|
||||
mydata[name] = dm.dmarray(data[name],attrs=data[name].attrs)
|
||||
|
||||
return status,mydata
|
||||
|
||||
@@ -318,90 +192,98 @@ def convertGameraVec(x,y,z,ut,fromSys,fromType,toSys,toType):
|
||||
outvec = invec.convert(toSys,toType)
|
||||
return outvec
|
||||
|
||||
def extractGAMERA(data,scDic,mjd0,fdir,cmd):
|
||||
def extractGAMERA(data,scDic,mjd0,sec0,fdir,ftag,cmd,keep):
|
||||
Re = 6380.0
|
||||
toRe = 1.0
|
||||
if "km" in data['Ephemeris'].attrs['UNITS']:
|
||||
toRe = 1.0/Re
|
||||
if 'SM' == scDic['ephemCoordSys']:
|
||||
smpos = Coords(data['Ephemeris']*toRe,'SM','car')
|
||||
smpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
elif 'GSM' == scDic['ephemCoordSys'] :
|
||||
scpos = Coords(data['Ephemeris']*toRe,'GSM','car')
|
||||
scpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
smpos = scpos.convert('SM','car')
|
||||
elif 'GSE'== scDic['ephemCoordSys']:
|
||||
scpos = Coords(data['Ephemeris']*toRe,'GSE','car')
|
||||
scpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
smpos = scpos.convert('SM','car')
|
||||
else:
|
||||
print('Coordinate system transformation failed')
|
||||
return
|
||||
elapsedSecs = (smpos.ticks.getMJD()-mjd0)*86400.0
|
||||
scId = scDic['ephemId']
|
||||
fOut = os.path.join(fdir,scId+"sctrack.h5")
|
||||
with h5py.File(fOut,'w') as hf:
|
||||
hf.create_dataset("T" ,data=elapsedSecs)
|
||||
hf.create_dataset("X" ,data=smpos.x)
|
||||
hf.create_dataset("Y" ,data=smpos.y)
|
||||
hf.create_dataset("Z" ,data=smpos.z)
|
||||
chimpxml = kaiTools.genSCXML(scid=scId,h5traj=os.path.basename(fOut))
|
||||
xmlfile = os.path.join(fdir,scId+'.xml')
|
||||
with open(xmlfile,"w") as f:
|
||||
f.write(chimpxml.toprettyxml())
|
||||
if 'UNITS' in data['Ephemeris'].attrs:
|
||||
if "km" in data['Ephemeris'].attrs['UNITS']:
|
||||
toRe = 1.0/Re
|
||||
elif 'UNIT_PTR' in data['Ephemeris'].attrs:
|
||||
if data[data['Ephemeris'].attrs['UNIT_PTR']][0]:
|
||||
toRe = 1.0/Re
|
||||
if 'SM' == scDic['ephemCoordSys']:
|
||||
smpos = Coords(data['Ephemeris'][:,0:3]*toRe,'SM','car')
|
||||
smpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
elif 'GSM' == scDic['ephemCoordSys'] :
|
||||
scpos = Coords(data['Ephemeris'][:,0:3]*toRe,'GSM','car')
|
||||
scpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
smpos = scpos.convert('SM','car')
|
||||
elif 'GSE'== scDic['ephemCoordSys']:
|
||||
scpos = Coords(data['Ephemeris'][:,0:3]*toRe,'GSE','car')
|
||||
scpos.ticks = Ticktock(data['Epoch_bin'])
|
||||
smpos = scpos.convert('SM','car')
|
||||
else:
|
||||
print('Coordinate system transformation failed')
|
||||
return
|
||||
elapsedSecs = (smpos.ticks.getMJD()-mjd0)*86400.0+sec0
|
||||
scId = scDic['ephemId']
|
||||
fOut = os.path.join(fdir,scId+"sctrack.h5")
|
||||
with h5py.File(fOut,'w') as hf:
|
||||
hf.create_dataset("T" ,data=elapsedSecs)
|
||||
hf.create_dataset("X" ,data=smpos.x)
|
||||
hf.create_dataset("Y" ,data=smpos.y)
|
||||
hf.create_dataset("Z" ,data=smpos.z)
|
||||
chimpxml = kaiTools.genSCXML(fdir,ftag,
|
||||
scid=scId,h5traj=os.path.basename(fOut))
|
||||
xmlfile = os.path.join(fdir,scId+'.xml')
|
||||
with open(xmlfile,"w") as f:
|
||||
f.write(chimpxml.toprettyxml())
|
||||
|
||||
sctrack = subprocess.run([cmd, xmlfile], cwd=fdir,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
text=True)
|
||||
sctrack = subprocess.run([cmd, xmlfile], cwd=fdir,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
text=True)
|
||||
|
||||
h5name = os.path.join(fdir, scId + '.sc.h5')
|
||||
h5file = h5py.File(h5name, 'r')
|
||||
ut = kaiTools.MJD2UT(h5file['MJDs'][:])
|
||||
h5name = os.path.join(fdir, scId + '.sc.h5')
|
||||
h5file = h5py.File(h5name, 'r')
|
||||
ut = kaiTools.MJD2UT(h5file['MJDs'][:])
|
||||
|
||||
bx = h5file['Bx']
|
||||
by = h5file['By']
|
||||
bz = h5file['Bz']
|
||||
if scDic['magCoordSys'] is None:
|
||||
toCoordSys = 'GSM'
|
||||
else:
|
||||
toCoordSys = scDic['magCoordSys']
|
||||
lfmb_out = convertGameraVec(bx[:],by[:],bz[:],ut,
|
||||
'SM','car',toCoordSys,'car')
|
||||
data['GAMERA_MagneticField'] = dm.dmarray(lfmb_out.data,
|
||||
attrs={'UNITS':bx.attrs['Units'],
|
||||
'CATDESC':'Magnetic Field, cartesian'+toCoordSys,
|
||||
'FIELDNAM':"Magnetic field",'AXISLABEL':'B'})
|
||||
vx = h5file['Vx']
|
||||
vy = h5file['Vy']
|
||||
vz = h5file['Vz']
|
||||
if scDic['velCoordSys'] is None:
|
||||
toCoordSys = 'GSM'
|
||||
else:
|
||||
toCoordSys = scDic['velCoordSys']
|
||||
lfmv_out = convertGameraVec(vx[:],vy[:],vz[:],ut,
|
||||
'SM','car',scDic['magCoordSys'],'car')
|
||||
data['GAMERA_Velocity'] = dm.dmarray(lfmv_out.data,
|
||||
attrs={'UNITS':vx.attrs['Units'],
|
||||
'CATDESC':'Velocity, cartesian'+toCoordSys,
|
||||
'FIELDNAM':"Velocity",'AXISLABEL':'V'})
|
||||
den = h5file['D']
|
||||
data['GAMERA_Density'] = dm.dmarray(den[:],
|
||||
attrs={'UNITS':den.attrs['Units'],
|
||||
'CATDESC':'Density','FIELDNAM':"Density",'AXISLABEL':'n'})
|
||||
pres = h5file['P']
|
||||
data['GAMERA_Pressure'] = dm.dmarray(pres[:],
|
||||
attrs={'UNITS':pres.attrs['Units'],
|
||||
'CATDESC':'Pressure','FIELDNAM':"Pressure",'AXISLABEL':'P'})
|
||||
temp = h5file['T']
|
||||
data['GAMERA_Temperature'] = dm.dmarray(temp[:],
|
||||
attrs={'UNITS':pres.attrs['Units'],
|
||||
'CATDESC':'Temperature','FIELDNAM':"Temperature",
|
||||
'AXISLABEL':'T'})
|
||||
bx = h5file['Bx']
|
||||
by = h5file['By']
|
||||
bz = h5file['Bz']
|
||||
if scDic['magCoordSys'] is None:
|
||||
toCoordSys = 'GSM'
|
||||
else:
|
||||
toCoordSys = scDic['magCoordSys']
|
||||
lfmb_out = convertGameraVec(bx[:],by[:],bz[:],ut,
|
||||
'SM','car',toCoordSys,'car')
|
||||
data['GAMERA_MagneticField'] = dm.dmarray(lfmb_out.data,
|
||||
attrs={'UNITS':bx.attrs['Units'],
|
||||
'CATDESC':'Magnetic Field, cartesian'+toCoordSys,
|
||||
'FIELDNAM':"Magnetic field",'AXISLABEL':'B'})
|
||||
vx = h5file['Vx']
|
||||
vy = h5file['Vy']
|
||||
vz = h5file['Vz']
|
||||
if scDic['velCoordSys'] is None:
|
||||
toCoordSys = 'GSM'
|
||||
else:
|
||||
toCoordSys = scDic['velCoordSys']
|
||||
lfmv_out = convertGameraVec(vx[:],vy[:],vz[:],ut,
|
||||
'SM','car',scDic['magCoordSys'],'car')
|
||||
data['GAMERA_Velocity'] = dm.dmarray(lfmv_out.data,
|
||||
attrs={'UNITS':vx.attrs['Units'],
|
||||
'CATDESC':'Velocity, cartesian'+toCoordSys,
|
||||
'FIELDNAM':"Velocity",'AXISLABEL':'V'})
|
||||
den = h5file['D']
|
||||
data['GAMERA_Density'] = dm.dmarray(den[:],
|
||||
attrs={'UNITS':den.attrs['Units'],
|
||||
'CATDESC':'Density','FIELDNAM':"Density",'AXISLABEL':'n'})
|
||||
pres = h5file['P']
|
||||
data['GAMERA_Pressure'] = dm.dmarray(pres[:],
|
||||
attrs={'UNITS':pres.attrs['Units'],
|
||||
'CATDESC':'Pressure','FIELDNAM':"Pressure",'AXISLABEL':'P'})
|
||||
temp = h5file['T']
|
||||
data['GAMERA_Temperature'] = dm.dmarray(temp[:],
|
||||
attrs={'UNITS':pres.attrs['Units'],
|
||||
'CATDESC':'Temperature','FIELDNAM':"Temperature",
|
||||
'AXISLABEL':'T'})
|
||||
|
||||
if not keep:
|
||||
subprocess.run(['rm',h5name])
|
||||
subprocess.run(['rm',xmlfile])
|
||||
subprocess.run(['rm',fOut])
|
||||
return
|
||||
return
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
MainS = """Extracts information from satellite trajectory for various
|
||||
@@ -419,12 +301,18 @@ if __name__ == '__main__':
|
||||
help='Path to directory containing REMIX files (default: %(default)s)')
|
||||
parser.add_argument('-cmd',type=str,metavar='command',default=None,
|
||||
help='Full path to sctrack.x command')
|
||||
parser.add_argument('-satId',type=str,metavar='Satellite Id',
|
||||
default=None,help='Name of Satellite to compare')
|
||||
parser.add_argument('--keep',action='store_true',
|
||||
help='Keep intermediate files')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
fdir = args.path
|
||||
ftag = args.id
|
||||
cmd = args.cmd
|
||||
scRequested = args.satId
|
||||
keep = args.keep
|
||||
|
||||
if fdir == '.':
|
||||
fdir = os.getcwd()
|
||||
@@ -436,13 +324,13 @@ if __name__ == '__main__':
|
||||
print(cmd,'either not found or not executable')
|
||||
sys.exit()
|
||||
|
||||
scIds = getScIds()
|
||||
scIds = kaiTools.getScIds()
|
||||
|
||||
#print(cmddir)
|
||||
#print('Extracting GAMERA data along',scId, 'trajectory')
|
||||
#cmd = "/Users/wiltbemj/src/kaiju/build/bin/sctrack.x"
|
||||
#Pull the timestep information from the magnetosphere files
|
||||
fname = os.path.join(fdir,ftag+'.mix.h5')
|
||||
(fname,isMPI,Ri,Rj,Rk) = kaiTools.getRunInfo(fdir,ftag)
|
||||
nsteps,sIds=kaiH5.cntSteps(fname)
|
||||
gamMJD=kaiH5.getTs(fname,sIds,aID='MJD')
|
||||
gamT=kaiH5.getTs(fname,sIds,aID='time')
|
||||
@@ -454,9 +342,15 @@ if __name__ == '__main__':
|
||||
t1 = gamUT[-1]
|
||||
deltaT = np.round(gamT[loc+1]-gamT[loc])
|
||||
mjd0 = gamMJD[loc]
|
||||
sec0 = gamT[loc]
|
||||
|
||||
#scToDo =['CLUSTER1']
|
||||
scToDo = scIds
|
||||
if None == scRequested:
|
||||
scToDo = scIds
|
||||
else:
|
||||
scToDo = []
|
||||
scToDo.append(scRequested)
|
||||
|
||||
for scId in scToDo:
|
||||
print('Getting spacecraft data for', scId)
|
||||
status,data = getSatData(scIds[scId],
|
||||
@@ -467,7 +361,7 @@ if __name__ == '__main__':
|
||||
print('No data available for', scId)
|
||||
else:
|
||||
print('Extracting GAMERA data')
|
||||
extractGAMERA(data,scIds[scId],mjd0,fdir,cmd)
|
||||
extractGAMERA(data,scIds[scId],mjd0,sec0,fdir,ftag,cmd,keep)
|
||||
cdfname = os.path.join(fdir, scId + '.comp.cdf')
|
||||
if os.path.exists(cdfname):
|
||||
print('Deleting %s' % cdfname)
|
||||
|
||||
Reference in New Issue
Block a user