def test_check_user_scanlines(self): """Check the scanlines.""" # All scanlines start, end = utils.check_user_scanlines(0, 0, 100, 200) self.assertEqual(start, 0) self.assertEqual(end, 100) start, end = utils.check_user_scanlines(0, 0, None, None, 100) self.assertEqual(start, 0) self.assertEqual(end, 99) # Valid scanlines start, end = utils.check_user_scanlines(10, 20, 100, 200) self.assertEqual(start, 10) self.assertEqual(end, 20) start, end = utils.check_user_scanlines(10, 20, None, None, 100) self.assertEqual(start, 10) self.assertEqual(end, 20) # Invalid scanlines start, end = utils.check_user_scanlines(10, 110, 100, 200) self.assertEqual(start, 10) self.assertEqual(end, 100) start, end = utils.check_user_scanlines(10, 110, None, None, 100) self.assertEqual(start, 10) self.assertEqual(end, 99) self.assertRaises(ValueError, gac_io.check_user_scanlines, 110, 120, 100, 200) self.assertRaises(ValueError, gac_io.check_user_scanlines, 110, 120, None, None, 100)
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)