Skip to content

Commit

Permalink
minimize imports
Browse files Browse the repository at this point in the history
separate tests
  • Loading branch information
scivision committed Oct 10, 2018
1 parent df5ae49 commit 5d14d8d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
3 changes: 2 additions & 1 deletion PlotDASC.py
Expand Up @@ -10,6 +10,7 @@
from matplotlib.pyplot import show
from argparse import ArgumentParser
import dascutils as du
import dascutils.projection as dp
import dascutils.plots as dup


Expand All @@ -34,7 +35,7 @@ def main():
imgs = du.load(p.indir, p.azelfn, p.tlim, p.wavelength, ofn=p.odir)

if p.mappingAlt:
imgs = du.project_altitude(imgs, p.mappingAlt)
imgs = dp.project_altitude(imgs, p.mappingAlt)

plotdasc(imgs, p.odir, p.cadence)

Expand Down
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -78,9 +78,12 @@ Typically that altitude is on the order of 100 km.
The `dascutils.project_altitude()` function adds coordinates `mapping_lat` `mapping_lon` to the xarray.Dataset by:
```python
import dascutils as du
import dascutils.projection as dp

data = du.load('myfile.FITS', azelfn='cal/PKR_DASC_20110112')

data = du.project_altitude(data, 100.) # for 100 km
data = dp.project_altitude(data, 100.) # for 100 km
```

The `dascutils.projection` is a separate import because it calls extra Python modules that aren't needed for basic data loading.

1 change: 0 additions & 1 deletion dascutils/__init__.py
@@ -1,3 +1,2 @@
from .web import download # noqa: F401
from .io import load, loadcal # noqa: F401
from .projection import project_altitude # noqa: F401
16 changes: 1 addition & 15 deletions tests/test_mod.py
Expand Up @@ -3,7 +3,6 @@
import xarray
import tempfile
import pytest
from pytest import approx
from datetime import datetime
#
import dascutils as du
Expand Down Expand Up @@ -55,21 +54,8 @@ def test_full_load():
assert data['0428'].shape == (1, 512, 512)


def test_projection():
pytest.importorskip('pymap3d')
pytest.importorskip('scipy')

data = du.load(R, azelstem)

data = du.project_altitude(data, 100.)

assert data.mapping_alt_km == approx(100.)
assert data.mapping_lat[266, 247] == approx(65.12351)
assert data.mapping_lon[266, 247] == approx(-147.48196)


def test_write_hdf5():
pytest.importorskip('netcdf4')
pytest.importorskip('netCDF4')

with tempfile.TemporaryDirectory() as D:

Expand Down
24 changes: 24 additions & 0 deletions tests/test_projection.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python
from pathlib import Path
import dascutils as du
import pytest
from pytest import approx

R = Path(__file__).parent
azelstem = R.parent/'cal/PKR_DASC_20110112'


def test_projection():
dp = pytest.importorskip('dascutils.projection')

data = du.load(R, azelstem)

data = dp.project_altitude(data, 100.)

assert data.mapping_alt_km == approx(100.)
assert data.mapping_lat[266, 247] == approx(65.12351)
assert data.mapping_lon[266, 247] == approx(-147.48196)


if __name__ == '__main__':
pytest.main(['-x', __file__])

0 comments on commit 5d14d8d

Please sign in to comment.