def test_filename_calname(): with pytest.raises(ValueError): ta.load(datfn, calfn=cal1fn) data = ta.load(datfn, calfn=cal2fn) assert "az" in data and "el" in data assert data["az"].shape == data["imgs"].shape[1:]
def test_good_time(): dat = ta.load(datfn, treq="2011-01-06T17:00:12") assert dat["imgs"].shape[0] == 1 time = dat.time.values.astype("datetime64[us]").astype(datetime) assert abs(time - datetime(2011, 1, 6, 17, 0, 12)) < timedelta(seconds=0.02) dat = ta.load(datfn, treq=("2011-01-06T17:00:00", "2011-01-06T17:00:12")) assert dat["imgs"].shape[0] == 4 time = dat.time.values.astype("datetime64[us]").astype(datetime)
def test_load_site_timerange(site, treq): """ load by sitename + timerange """ dat = ta.load(R, site, treq=treq) assert dat["imgs"].shape[0] == 4 times = dat.time.values.astype("datetime64[us]").astype(datetime) assert (times >= datetime(2011, 1, 6, 17)).all() assert (times <= datetime(2011, 1, 6, 17, 0, 12)).all()
def test_load_filename(): """load by filename""" dat = ta.load(datfn) times = dat.time.values.astype("datetime64[us]").astype(datetime) assert (times >= datetime(2011, 1, 6, 17)).all() assert (times <= datetime(2011, 1, 6, 18)).all()
def main(): p = ArgumentParser( description=" reads THEMIS GBO ASI CDF files and plays high speed video" ) p.add_argument("path", help="ASI data path") p.add_argument("site", help="site 4 character code e.g. gako") p.add_argument("treq", help="time (or time start,stop) requested", nargs="+") g = p.add_mutually_exclusive_group() p.add_argument("-az", help="azimuth(s) to plot (degrees)", type=float, nargs="+") g.add_argument("-el", help="elevation(s) to plot (degrees)", type=float, nargs="+") g.add_argument("-lla", help="latitude, longitude, altitude [km] projection", type=float, nargs=3) p.add_argument("-o", "--odir", help="write video to this directory") p.add_argument("-v", "--verbose", action="store_true") P = p.parse_args() imgs = ta.load(P.path, site=P.site, treq=P.treq) if P.verbose: tap.plotazel(imgs) # %% select nearest neighbor ind = taf.getimgind(imgs, P.lla, P.az, P.el) az, el, plat, plon, palt_m = taf.projected_coord(imgs, ind, P.lla) print(f"Using az, el {az}, {el}") print(f"Using projected lat,lon, alt [km] {plat} {plon} {palt_m}") dat = np.empty((imgs.time.size, ind.shape[0]), dtype=imgs["imgs"].dtype) for i, j in enumerate(ind): dat[:, i] = imgs["imgs"][:, j[0], j[1]] # %% plot ttxt = f"{imgs.filename}" tap.plottimeseries(dat, imgs.time, ttxt) show()
def main(): p = ArgumentParser( description=" reads THEMIS GBO ASI CDF files and plays high speed video" ) p.add_argument("path", help="directory THEMIS ASI video files are in") p.add_argument("site", help="THEMIS ASI site code e.g. fykn") p.add_argument("treq", help="time or start,stop time range requested", nargs="+") p.add_argument("-o", "--odir", help="write video to this directory") P = p.parse_args() imgs = ta.load(P.path, site=P.site, treq=P.treq) # %% plot tap.plotazel(imgs) tap.plotasi(imgs, P.odir)
def test_bad_time(path, val, err): with pytest.raises(err): ta.load(path, "gako", treq=val)
def test_load_site_time(site, time): """ load by sitename + time""" dat = ta.load(R, site, time) assert dat["imgs"].shape[0] == 1 t = dat.time.values.astype("datetime64[us]").astype(datetime) assert abs(t - datetime(2011, 1, 6, 17, 0, 0)) < timedelta(seconds=0.5)
def test_filename(): data = ta.load(datfn) assert data["imgs"].site == "gako" assert data["imgs"].shape == (23, 256, 256) and data["imgs"].dtype == "uint16"
def test_missing_file(tmp_path): badfn = tmp_path / "notafile.cdf" with pytest.raises(FileNotFoundError): ta.load(badfn)
def test_autoload_cal(): dat = ta.load(R, "gako", "2011-01-06T17:00:00") assert "el" in dat and "az" in dat
#!/usr/bin/env python """ example of image projection to an altitude. This assumes all the brightness comes from a thin layer at that altitude, which is a common first-order approximation made in multi-instrument studies, for example using auroral video with GNSS TEC measurements. """ from pathlib import Path import themisasi as ta import themisasi.projections as tap datadir = Path("~/data/2016-11-29").expanduser() time_query = "2016-11-29T12" ta.download(time_query, "mcgr", datadir) dat = ta.load(datadir, site="mcgr", treq=time_query) tap.asi_projection(dat, 110e3)
import seaborn as sns sns.set_context("talk") except ImportError: pass # %% user parameters datadir = Path("~/data/themis").expanduser() site = "gako" asifn = ("thg_l1_asf_gako_2008032607_v01.cdf", "thg_l1_asf_gako_2008032608_v01.cdf") treq = [ ("2008-03-26T07:34", "2008-03-26T07:38"), # Slide 9 ("2008-03-26T07:46", "2008-03-26T07:50"), # Slide 15 ("2008-03-26T08:16", "2008-03-26T08:20"), # Slide 30 ] odir = None asical = datadir / "themis_skymap_gako_20070401.sav" # %% load data, with calibration az/el data0 = ta.load(datadir / asifn[0], treq=treq[0], calfn=asical) data1 = ta.load(datadir / asifn[0], treq=treq[1], calfn=asical) data2 = ta.load(datadir / asifn[1], treq=treq[2], calfn=asical) # %% plot tap.plotasi(data0) tap.plotasi(data1) tap.plotasi(data2) tap.plotazel(data0) show()