def test9(): base = datetime(2000, 1, 1, 12) start = 1391363511.1 - calendar.timegm(base.timetuple()); end = 1391542311.1 - calendar.timegm(base.timetuple()) print('Getting data...') nc_all = get_data(start, end, 'MAG-L1b-GEOF') print('Flattening data...') time = nc_all.variables['IB_time'] mag_EPN = nc_all.variables['amb_mag_EPN'] time = time[:].flatten() mag_EPN_x = mag_EPN[:, :, 0].flatten() print('Averaging...') (new_time, new_values) = chunk_average(time, mag_EPN_x, 60, start, end, -9999, 10, .5)
def average_var(nc_obj, var_name): print('Averaging ' + var_name) var_x = nc_obj.variables[var_name][:, 0].flatten() var_y = nc_obj.variables[var_name][:, 1].flatten() var_z = nc_obj.variables[var_name][:, 2].flatten() dqf = nc_obj.variables[flag_name][:] time = nc_obj.variables[in_time_name][:] var_x = check_flags(var_x, dqf, fill_value) var_y = check_flags(var_y, dqf, fill_value) var_z = check_flags(var_z, dqf, fill_value) (time_60savg, var_x_60savg) = chunk_average(time, var_x.filled(), delta_time, start_time, end_time, fill_value, data_rate, min_percent) (time_60savg, var_y_60savg) = chunk_average(time, var_y.filled(), delta_time, start_time, end_time, fill_value, data_rate, min_percent) (time_60savg, var_z_60savg) = chunk_average(time, var_z.filled(), delta_time, start_time, end_time, fill_value, data_rate, min_percent) var_60savg = rot90(vstack((var_z_60savg, var_y_60savg, var_x_60savg)),3) return (time_60savg, var_60savg)
def test8(): print('-----------') print('Test 8') theValues = array([-9999, 1, -9999, 2, 3, 3, 4, 4, 5, 5, 6, -9999]) theTimes = arange(12) + 1 deltaTime = 2 (newTime, newValues) = chunk_average(theTimes, theValues, deltaTime, 1, 13, -9999, 1, .6) if not (newTime == array([1, 3, 5, 7, 9, 11])).all(): warning('Test 8 Failed!! Time values incorrect') print(newTime) # return if not (newValues == array([-9.999e+03, -9.999e+03, 3., 4., 5., -9.999e+03])).all(): warning('Test 8 Failed!! Data values incorrect') print(newValues) # return print('Passed')
def test1(): print('-----------') print('Test 1') theValues = array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) theTimes = arange(12) + 1 deltaTime = 2 (newTime, newValues) = chunk_average(theTimes, theValues, deltaTime, 1, 13, -9999, 1, .5) if not (newTime == array([1, 3, 5, 7, 9, 11])).all(): warning('Test 1 Failed!! Time values incorrect') print(newTime) return if not (newValues == array([1., 2., 3., 4., 5., 6.])).all(): warning('Test 1 Failed!! Data values incorrect') print(newValues) return print('Pass') print('------------')
def test10(): print('-----------') print('Test 10') theValues = array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) theTimes = array([1, 2, 3, 4, 5, 11, 11, 12, 13, 14, 15, 16]) deltaTime = 2 (newTime, newValues) = chunk_average(theTimes + 0.2, theValues, deltaTime, 1, 11, -9999, 1, .5) if not (newTime == array([1, 3, 5, 7, 9])).all(): warning('Test 1 Failed!! Time values incorrect') print(newTime) # return if not (newValues == array([1., 2., 3., -9.999e+03, -9.999e+03])).all(): warning('Test 1 Failed!! Data values incorrect') print(newValues) # return print('Pass') print('-----------')
def test7(): print('-----------') print('Test 7') theValues = array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) theTimes = array([1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16]) deltaTime = 2 (newTime, newValues) = chunk_average(theTimes + 0.2, theValues, deltaTime, 6, 16, -9999, 1, .5) if not (newTime == array([6, 8, 10, 12, 14])).all(): warning('Test 1 Failed!! Time values incorrect') print(newTime) return if not (newValues == array([-9.999e+03, -9.999e+03, 3.5, 4.5, 5.5])).all(): warning('Test 1 Failed!! Data values incorrect') print(newValues) return print('Pass') print('-----------')
def test2(): print('-----------') print('Test 2') base = datetime(2000, 1, 1, 13) start = 1391363512.1 - calendar.timegm(base.timetuple()); end = 1391363572.1 - calendar.timegm(base.timetuple()) # nc_all = get_data('2014-02-04T14:13:12.0Z','2014-02-04T14:16:12.1Z','MAG-L1b-GEOF','GOES-16','IT') nc_all = get_data(start, end, 'MAG-L1b-GEOF') time = nc_all.variables['IB_time'] mag_EPN = nc_all.variables['amb_mag_EPN'] time = time[:].flatten() mag_EPN_x = mag_EPN[:, :, 0].flatten() (newTime, newValues) = chunk_average(time, mag_EPN_x, 10, start, end, -9999, 10, .5) if len(newTime) != len(newValues): print('Test Failed!! Time and data are not the same size') return print('Pass') print('------------')
def test3(): print('-----------') print('Test 3') base = datetime(2000, 1, 1, 12) start = 1391363511.1 - calendar.timegm(base.timetuple()); end = 1391369511.1 - calendar.timegm(base.timetuple()) print('Getting data...') nc_all = get_data(start, end, 'MAG-L1b-GEOF') print('Flattening data...') time = nc_all.variables['IB_time'] mag_EPN = nc_all.variables['amb_mag_EPN'] time = time[:].flatten() mag_EPN_x = mag_EPN[:, :, 0].flatten() print('Averaging...') (newTime, newValues) = chunk_average(time, mag_EPN_x, 60, start, end, -9999, 10, .5) if len(newTime) != len(newValues): print('Test Failed!! Time and data are not the same size') return print('Pass') print('------------')
# Initialize values for get_data() and chunk_average() start_str = "2014-02-04T14:14:00.1Z" end_str = "2014-02-04T15:14:00.1Z" delta_time = 60 fill_value = -9999 data_rate = 10 min_percent = 0.9 print("Getting data") nc_all = get_data(start_str, end_str, "MAG-L1b-GEOF", "GOES-16", "IT") print("Preparing data") time = nc_all.variables["IB_time"] # Get time values out of nc object mag_EPN = nc_all.variables["amb_mag_EPN"] # Get mag field values out of nc object time_data = time[:].flatten() # Flatten 2-D time mag_EPN_x = mag_EPN[:, :, 0].flatten() # Flatten 2-D x component of mag field print("Computing averages") (time_60savg, mag_EPN_x_60savg) = chunk_average( time_data, mag_EPN_x, delta_time, start_str, end_str, fill_value, data_rate, min_percent ) print("Plotting") fig = plt.figure() plt.plot(time_data, mag_EPN_x, "r-", time_60savg, mag_EPN_x_60savg, "b-") fig.suptitle("Ambient Magnetic Field from " + start_str + " to " + end_str, fontsize=20) plt.xlabel("Time (" + time.units + ")", fontsize=18) plt.ylabel("EPN Ambient Magnetic Field (" + mag_EPN.units + ")", fontsize=18) plt.show()