def test_slice_channel(self): """Test selection of user defined scanlines. Scanline Nr: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Missing: X X X X Inv. lat/lon: X X X X Before stripping of invalid lats -------------------------------- idx: 0 1 2 3 4 5 6 7 8 9 data: 1 2 3 4 5 6 7 8 9 10 After stripping of invalid lats ------------------------------- idx: 0 1 2 3 4 5 data: 3 4 5 6 7 8 => All missing lines: [1, 2, 3, 4, 11, 12, 13, 14] """ # Define test data ch = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]).transpose() miss_lines = np.array([1, 4, 11, 12]) # never recorded qualflags = np.array([[2, 3, 5, 6, 7, 8, 9, 10, 13, 14]]).transpose() # scanline number midn_line = 3 first_valid_lat = 2 last_valid_lat = 7 start_line = 1 end_line = 4 # Without lat stripping sliced_ref = np.array([[2, 3, 4, 5]]).transpose() sliced, miss_lines_new, midn_line_new = utils.slice_channel( ch, start_line=start_line, end_line=end_line, miss_lines=miss_lines, midnight_scanline=midn_line, qual_flags=qualflags) numpy.testing.assert_array_equal(sliced, sliced_ref) numpy.testing.assert_array_equal(miss_lines_new, miss_lines) self.assertEqual(midn_line_new, 2) # With lat stripping sliced_ref = np.array([[4, 5, 6, 7]]).transpose() miss_lines_ref = np.array([1, 2, 3, 4, 11, 12, 13, 14]) sliced, miss_lines_new, midn_line_new = utils.slice_channel( ch, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat, miss_lines=miss_lines, midnight_scanline=midn_line, qual_flags=qualflags) numpy.testing.assert_array_equal(sliced, sliced_ref) numpy.testing.assert_array_equal(miss_lines_new, miss_lines_ref) self.assertEqual(midn_line_new, 0)
def save_gac(satellite_name, xutcs, lats, lons, ref1, ref2, ref3, bt3, bt4, bt5, sun_zen, sat_zen, sun_azi, sat_azi, rel_azi, qual_flags, start_line, end_line, gac_file, meta_data): midnight_scanline = meta_data['midnight_scanline'] miss_lines = meta_data['missing_scanlines'] corr = meta_data['sun_earth_distance_correction_factor'] last_scan_line_number = qual_flags[-1, 0] # Strip invalid coordinates first_valid_lat, last_valid_lat = strip_invalid_lat(lats) if first_valid_lat > start_line: LOG.info('New start_line chosen (due to invalid lat/lon ' 'info) = ' + str(first_valid_lat)) if end_line > last_valid_lat: LOG.info('New end_line chosen (due to invalid lat/lon ' 'info) = ' + str(last_valid_lat)) # Check user-defined scanlines start_line, end_line = check_user_scanlines( start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) # Slice data using new start/end lines _, miss_lines, midnight_scanline = slice_channel( np.zeros(lats.shape), start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat, qual_flags=qual_flags, miss_lines=miss_lines, midnight_scanline=midnight_scanline) ref1, _, _ = slice_channel(ref1, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) ref2, _, _ = slice_channel(ref2, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) ref3, _, _ = slice_channel(ref3, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) bt3, _, _ = slice_channel(bt3, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) bt4, _, _ = slice_channel(bt4, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) bt5, _, _ = slice_channel(bt5, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) sun_zen, _, _ = slice_channel(sun_zen, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) sun_azi, _, _ = slice_channel(sun_azi, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) sat_zen, _, _ = slice_channel(sat_zen, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) sat_azi, _, _ = slice_channel(sat_azi, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) rel_azi, _, _ = slice_channel(rel_azi, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) lons, _, _ = slice_channel(lons, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) lats, _, _ = slice_channel(lats, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) qual_flags, _, _ = slice_channel(qual_flags, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) xutcs, _, _ = slice_channel(xutcs, start_line=start_line, end_line=end_line, first_valid_lat=first_valid_lat, last_valid_lat=last_valid_lat) total_number_of_scan_lines = lats.shape[0] # Reading time from the body of the gac file start = xutcs[0].astype(datetime.datetime) end = xutcs[-1].astype(datetime.datetime) startdate = start.strftime("%Y%m%d") starttime = start.strftime("%H%M%S%f")[:-5] enddate = end.strftime("%Y%m%d") endtime = end.strftime("%H%M%S%f")[:-5] # Apply scaling & offset bt3 -= 273.15 bt4 -= 273.15 bt5 -= 273.15 for array in [ bt3, bt4, bt5, ref1, ref2, ref3, sun_zen, sat_zen, sun_azi, sat_azi, rel_azi ]: array *= 100.0 for array in [lats, lons]: array *= 1000.0 # Replace NaN with fill values for array in [ ref1, ref2, ref3, bt3, bt4, bt5, sun_zen, sat_zen, sun_azi, sat_azi, rel_azi ]: array[np.isnan(array)] = MISSING_DATA for array in [lats, lons]: array[np.isnan(array)] = MISSING_DATA_LATLON avhrrGAC_io(satellite_name, xutcs, startdate, enddate, starttime, endtime, lats, lons, ref1, ref2, ref3, bt3, bt4, bt5, sun_zen, sat_zen, sun_azi, sat_azi, rel_azi, qual_flags, start_line, end_line, total_number_of_scan_lines, last_scan_line_number, corr, gac_file, midnight_scanline, miss_lines)