Example #1
0
    def test_sun_earth_distance(self):
        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)

        target = 0.9877038273760421
        result = HotspotDetector._compute_sun_earth_distance()
        self.assertAlmostEqual(target, result)
Example #2
0
    def test_compute_frp(self):
        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)
        HotspotDetector.run_detector(flares_or_sampling=True)

        path_to_target = "../../data/test_data/atx_frp.npy"
        target = np.load(path_to_target)
        result = HotspotDetector.frp
        self.assertEqual(True, (target == result).all())
Example #3
0
    def test_detect_hotspots_atx(self):
        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        path_to_target = "../../data/test_data/atx_detect_hotspots.npy"

        target = np.load(path_to_target)

        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)
        HotspotDetector.run_detector()

        self.assertEqual(True, (target == HotspotDetector.hotspots).all())
Example #4
0
    def test_radiance_from_BT(self):

        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)

        brightness_temp = 1500
        wavelength = 1.6
        result = HotspotDetector._rad_from_BT(wavelength, brightness_temp)
        target = 28200.577465487077
        self.assertAlmostEqual(target, result)
Example #5
0
    def test_radiance_from_reflectance(self):

        path_to_target = "../../data/test_data/atx_radiance_from_reflectance.npy"
        target = np.load(path_to_target)

        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)
        reflectance = product.get_band('reflec_nadir_1600').read_as_array()
        result = HotspotDetector._rad_from_ref(reflectance)

        self.assertEqual(True, (target == result).all())
Example #6
0
    def test_night_mask_atx(self):
        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        path_to_target = "../../data/test_data/atx_nightmask.npy"
        target = np.load(path_to_target)

        target_mean = np.mean(target)

        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)
        HotspotDetector.run_detector()

        self.assertAlmostEqual(target_mean,
                               np.mean(HotspotDetector.night_mask))
Example #7
0
    def test_get_arcmin_int(self):

        coords = np.array([
            -150.53434, -100.13425, -50.20493, 0.34982, 50.43562, 100.12343,
            150.56443
        ])
        target = np.array([-15032, -10008, -5012, 21, 5026, 10007, 15034])

        path_to_data = glob.glob("../../data/test_data/*.N1")[0]
        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)

        result = HotspotDetector._find_arcmin_gridcell(coords)
        self.assertEqual(True, (target == result).all())
Example #8
0
    def test_run_atx(self):
        target = pd.read_csv(glob.glob("../../data/test_data/ATS*.csv")[0])
        path_to_data = glob.glob("../../data/test_data/*.N1")[0]

        product = epr.Product(path_to_data)
        HotspotDetector = ATXDetector(product)
        HotspotDetector.run_detector()
        result = HotspotDetector.to_dataframe(keys=['latitude', 'longitude'])

        # TODO determine why floating point errors are causing issues in testing here
        target = target.astype(int)
        result = result.astype(int)
        are_equal = target.equals(result)

        self.assertEqual(True, are_equal)
Example #9
0
def main():
    file_to_process = sys.argv[1]
    sensor = sys.argv[2]

    if sensor != 'sls':
        product = epr.Product(file_to_process)
        HotspotDetector = ATXDetector(product)
        keys = ['latitude', 'longitude']
    else:
        product = utils.extract_zip(file_to_process, fp.slstr_extract_temp)
        HotspotDetector = SLSDetector(product)
        keys = ['latitude', 'longitude']

    HotspotDetector.run_detector()
    df = HotspotDetector.to_dataframe(keys=keys)
    df.to_csv(utils.build_outpath(sensor, file_to_process, 'hotspots'))
Example #10
0
def main():
    file_to_process = sys.argv[1]
    sensor = sys.argv[2]

    if sensor != 'sls':
        product = epr.Product(file_to_process)
        HotspotDetector = ATXDetector(product)

        flare_keys = [
            'latitude', 'longitude', 'local_cloudiness', 'swir_16', 'frp',
            'pixel_size', 'mwir', 'background_mwir'
        ]

        flare_aggregator = {
            'frp': np.sum,
            'swir_16': np.mean,
            'mwir': np.mean,
            'background_mwir': np.mean,
            'pixel_size': np.sum,
            'latitude': np.mean,
            'longitude': np.mean,
            'local_cloudiness': np.mean,
            'year': 'first',
            'month': 'first',
            'day': 'first',
            'hhmm': 'first'
        }

        sampling_keys = ['latitude', 'longitude', 'local_cloudiness']

        sampling_aggregator = {
            'local_cloudiness': np.mean,
            'year': 'first',
            'month': 'first',
            'day': 'first',
            'hhmm': 'first'
        }

        atx_persistent_fp = os.path.join(fp.output_l3, 'all_sensors',
                                         'all_flare_locations_ats.csv')
        persistent_df = pd.read_csv(atx_persistent_fp)

    else:
        product = utils.extract_zip(file_to_process, fp.slstr_extract_temp)
        HotspotDetector = SLSDetector(product)

        flare_keys = [
            'latitude', 'longitude', 'local_cloudiness', 'swir_16', 'swir_22',
            'frp', 'pixel_size'
        ]

        flare_aggregator = {
            'frp': np.sum,
            'swir_16': np.mean,
            'swir_22': np.mean,
            'pixel_size': np.sum,
            'latitude': np.mean,
            'longitude': np.mean,
            'local_cloudiness': np.mean,
            'year': 'first',
            'month': 'first',
            'day': 'first',
            'hhmm': 'first'
        }

        sampling_keys = [
            'latitude',
            'longitude',
            'local_cloudiness',
        ]

        sampling_aggregator = {
            'local_cloudiness': np.mean,
            'year': 'first',
            'month': 'first',
            'day': 'first',
            'hhmm': 'first'
        }

        # merge persistent dataframes for SLSTR
        atx_persistent_fp = os.path.join(fp.output_l3, 'all_sensors',
                                         'all_flare_locations_atx.csv')
        atx_persistent_df = pd.read_csv(atx_persistent_fp)

        sls_persistent_fp = os.path.join(fp.output_l3, 'all_sensors',
                                         'all_flare_locations_sls.csv')
        sls_persistent_df = pd.read_csv(sls_persistent_fp)

        persistent_df = merge_hotspot_dataframes(atx_persistent_df,
                                                 sls_persistent_df)
    # find persistent hotspots (i.e. flares)
    HotspotDetector.run_detector(flares_or_sampling=True)
    flare_df = HotspotDetector.to_dataframe(keys=flare_keys,
                                            joining_df=persistent_df)
    aggregated_flare_df = aggregate(flare_df, flare_aggregator)
    aggregated_flare_df.to_csv(
        utils.build_outpath(sensor, file_to_process, 'flares'))

    # get sampling associated with persistent hotspots
    sampling_df = HotspotDetector.to_dataframe(keys=sampling_keys,
                                               joining_df=persistent_df)
    aggregated_sampling_df = aggregate(sampling_df, sampling_aggregator)
    aggregated_sampling_df.to_csv(
        utils.build_outpath(sensor, file_to_process, 'samples'))