def test_script_multiple_config(): start_date = datetime(2015, 3, 17, 5, 0, 0) end_date = datetime(2015, 3, 17, 15, 0, 0) offset = timedelta(hours=5) with TemporaryDirectory() as tempdir: with config.temp_config(base_dir=tempdir): scripts.full_run(start_date, end_date) with config.temp_config(base_dir=tempdir, time_res_n=30, time_res_unit='m'): scripts.full_run(start_date + offset, end_date + offset) with config.temp_config(base_dir=tempdir): n_files = len([p for p in Path(config.processed_labels_dir).glob('labels*.nc')]) n_times = 1 + ((end_date - start_date) / timedelta(hours=1)) assert n_files == (end_date.year - start_date.year + 1) * 2 data = get_data(start_date, end_date, 'north') data.load() assert data.time.shape[0] == n_times data.close() with config.temp_config(base_dir=tempdir, time_res_n=30, time_res_unit='m'): n_files = len([p for p in Path(config.processed_labels_dir).glob('labels*.nc')]) n_times = 1 + ((end_date - start_date) / timedelta(minutes=30)) assert n_files == (end_date.year - start_date.year + 1) * 2 data = get_data(start_date + offset, end_date + offset, 'north') data.load() assert data.time.shape[0] == n_times data.close()
def test_scripts(test_dates): start, end = test_dates with TemporaryDirectory() as base_dir: with config.temp_config(base_dir=base_dir) as cfg: scripts.download_tec(start, end) tec_files = list(Path(cfg.download_tec_dir).glob('*')) assert len(tec_files) > 0 data = _get_downloaded_tec_data(start, end, cfg.download_tec_dir) assert data.time.values[0] < np.datetime64(test_dates[0], 's') assert data.time.values[-1] > np.datetime64(test_dates[-1], 's') scripts.process_tec(start, end) for hemisphere in ['north', 'south']: data = get_tec_data(start, end, hemisphere, cfg.processed_tec_dir) data.load() dt = np.timedelta64(1, 'h') mlt_vals = config.mlt_vals mlat_vals = config.mlat_vals correct_times = np.arange(np.datetime64(test_dates[0]), np.datetime64(test_dates[-1]) + dt, dt) h = 1 if hemisphere == 'north' else -1 assert data.shape == (correct_times.shape[0], mlat_vals.shape[0], mlt_vals.shape[0]) assert (data.mlt == mlt_vals).all().item() assert (data.mlat == h * mlat_vals).all().item() assert (data.time == correct_times).all().item()
def test_get_tec_troughs(): """Verify that get_tec_troughs can detect an actual trough, verify that high troughs are rejected using auroral boundary data """ n_hours = 12 start_date = datetime(2015, 10, 7, 6, 0, 0) end_date = start_date + timedelta(hours=n_hours) params = TroughIdParams(bg_est_shape=(1, 19, 19), model_weight_max=5, l2_weight=.1, tv_weight=.05, tv_hw=2) with config.temp_config(trough_id_params=params): scripts.download_all(start_date, end_date) scripts.process_all(start_date, end_date) data_north = _trough.label_trough_interval( start_date, end_date, config.trough_id_params, 'north', config.processed_tec_dir, config.processed_arb_dir, config.processed_omni_file ) data_south = _trough.label_trough_interval( start_date, end_date, config.trough_id_params, 'south', config.processed_tec_dir, config.processed_arb_dir, config.processed_omni_file ) labels_north = data_north['labels'].values labels_south = data_south['labels'].values assert labels_north.shape == (n_hours + 1, 60, 180) assert labels_north[1, 20:30, 60:120].mean() > .5 assert labels_south.shape == (n_hours + 1, 60, 180) assert labels_south[3, 20:30, 60:80].mean() > .5 for i in range(12): assert labels_north[i][(data_north.mlat > data_north['arb'][i] + 3).values].sum() == 0 assert labels_south[i][(data_south.mlat < data_south['arb'][i] - 3).values].sum() == 0
def test_script(dates): start_date, end_date = dates n_times = 1 + ((end_date - start_date) / timedelta(hours=1)) with TemporaryDirectory() as tempdir: with config.temp_config(base_dir=tempdir): scripts.full_run(*dates) n_files = len([p for p in Path(config.processed_labels_dir).glob('labels*.nc')]) assert n_files == (end_date.year - start_date.year + 1) * 2 data = get_data(start_date, end_date, 'north') data.load() assert data.time.shape[0] == n_times data.close()
def test_scripts(test_dates): start, end = test_dates with TemporaryDirectory() as base_dir: with config.temp_config(base_dir=base_dir) as cfg: scripts.download_arb(start, end) arb_files = list(Path(cfg.download_arb_dir).glob('*')) assert len(arb_files) > 0 data, times = _get_downloaded_arb_data(start, end, cfg.download_arb_dir) assert min(times) < start assert max(times) > end scripts.process_arb(start, end) data = get_arb_data(start, end, 'north', cfg.processed_arb_dir) data.load() dt = np.timedelta64(1, 'h') mlt = config.mlt_vals correct_times = np.arange(np.datetime64(test_dates[0]), np.datetime64(test_dates[-1]) + dt, dt) assert data.shape == (correct_times.shape[0], mlt.shape[0]) assert (data.mlt == mlt).all().item() assert (data.time == correct_times).all().item()