Skip to content

Commit

Permalink
improving error handling for case where a variable is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ericthewizard committed Sep 21, 2021
1 parent 5925494 commit 6c1b21d
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions pyspedas/mms/fgm/mms_curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,57 @@ def mms_curl(fields=None, positions=None, suffix=''):

m0 = 4.0*math.pi*1e-7

timesb1, datab1 = get_data(fields[0])
timesb2, datab2 = get_data(fields[1] + '_i')
timesb3, datab3 = get_data(fields[2] + '_i')
timesb4, datab4 = get_data(fields[3] + '_i')
mms1_bfield = get_data(fields[0])
mms2_bfield = get_data(fields[1] + '_i')
mms3_bfield = get_data(fields[2] + '_i')
mms4_bfield = get_data(fields[3] + '_i')

if mms1_bfield is None:
print('Error, B-field variable is missing: ' + fields[0])
return
elif mms2_bfield is None:
print('Error, B-field variable is missing: ' + fields[1] + '_i')
return
elif mms3_bfield is None:
print('Error, B-field variable is missing: ' + fields[2] + '_i')
return
elif mms4_bfield is None:
print('Error, B-field variable is missing: ' + fields[3] + '_i')
return

timesb1, datab1 = mms1_bfield
timesb2, datab2 = mms2_bfield
timesb3, datab3 = mms3_bfield
timesb4, datab4 = mms4_bfield

# extract the vector
b1 = datab1[:, 0:3]
b2 = datab2[:, 0:3]
b3 = datab3[:, 0:3]
b4 = datab4[:, 0:3]

timesp1, p1 = get_data(positions[0] + '_i')
timesp2, p2 = get_data(positions[1] + '_i')
timesp3, p3 = get_data(positions[2] + '_i')
timesp4, p4 = get_data(positions[3] + '_i')
mms1_pos = get_data(positions[0] + '_i')
mms2_pos = get_data(positions[1] + '_i')
mms3_pos = get_data(positions[2] + '_i')
mms4_pos = get_data(positions[3] + '_i')

if mms1_pos is None:
print('Error, S/C position variable is missing: ' + positions[0] + '_i')
return
elif mms2_pos is None:
print('Error, S/C position variable is missing: ' + positions[1] + '_i')
return
elif mms3_pos is None:
print('Error, S/C position variable is missing: ' + positions[2] + '_i')
return
elif mms4_pos is None:
print('Error, S/C position variable is missing: ' + positions[3] + '_i')
return

timesp1, p1 = mms1_pos
timesp2, p2 = mms2_pos
timesp3, p3 = mms3_pos
timesp4, p4 = mms4_pos

divb = np.zeros([len(timesb1), 5])
baryb = np.zeros([len(timesb1), 3])
Expand Down

0 comments on commit 6c1b21d

Please sign in to comment.