Skip to content

Commit 75cd2e2

Browse files
authored
refactor: single implicit import of altimetry tools (#68)
* docs: place some imports behind try/except statements
1 parent 839ddf6 commit 75cd2e2

43 files changed

Lines changed: 987 additions & 609 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/environment.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,22 @@ dependencies:
88
- freetype
99
- future
1010
- graphviz
11-
- h5py>=2.9=mpi*
1211
- lxml
1312
- matplotlib
14-
- mpi4py
15-
- netCDF4
1613
- notebook
1714
- numpy
1815
- numpydoc
19-
- pandas
2016
- paramiko
2117
- pip
2218
- pyproj
2319
- python>=3.6
2420
- python-dateutil
2521
- pyyaml
2622
- scipy
27-
- scikit-learn
2823
- scp
2924
- sphinx
3025
- sphinx_rtd_theme
31-
- texlive-core
32-
- zarr
3326
- pip:
3427
- sphinx-argparse>=0.4
35-
- git+https://github.com/tsutterley/yapc.git
3628
- ..
3729

doc/source/api_reference/utilities.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ General Methods
2121

2222
.. autofunction:: icesat2_toolkit.utilities.get_hash
2323

24+
.. autofunction:: icesat2_toolkit.utilities.get_git_revision_hash
25+
26+
.. autofunction:: icesat2_toolkit.utilities.get_git_status
27+
2428
.. autofunction:: icesat2_toolkit.utilities.url_split
2529

2630
.. autofunction:: icesat2_toolkit.utilities.s3_client

icesat2_toolkit/convert.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
convert.py
3-
Written by Tyler Sutterley (06/2022)
3+
Written by Tyler Sutterley (12/2022)
44
Utilities for converting ICESat-2 HDF5 files into different formats
55
66
PYTHON DEPENDENCIES:
@@ -21,6 +21,7 @@
2121
time.py: Utilities for calculating time operations
2222
2323
UPDATE HISTORY:
24+
Updated 12/2022: place some imports behind try/except statements
2425
Updated 06/2022: place zarr and pandas imports behind try/except statements
2526
Updated 04/2022: updated docstrings to numpy documentation format
2627
Updated 01/2022: added ascii and dataframe outputs for ATL07
@@ -33,26 +34,33 @@
3334
"""
3435
import os
3536
import re
36-
import h5py
3737
import warnings
3838
import itertools
3939
import posixpath
4040
import numpy as np
4141
from icesat2_toolkit.convert_delta_time import convert_delta_time
4242

43+
# attempt imports
44+
try:
45+
import h5py
46+
except ModuleNotFoundError:
47+
warnings.filterwarnings("always")
48+
warnings.warn("h5py not available")
49+
warnings.warn("Some functions will throw an exception if called")
4350
try:
4451
import pandas
4552
except ModuleNotFoundError:
4653
warnings.filterwarnings("always")
4754
warnings.warn("pandas not available")
4855
warnings.warn("Some functions will throw an exception if called")
49-
5056
try:
5157
import zarr
5258
except ModuleNotFoundError:
5359
warnings.filterwarnings("always")
5460
warnings.warn("zarr not available")
5561
warnings.warn("Some functions will throw an exception if called")
62+
# ignore warnings
63+
warnings.filterwarnings("ignore")
5664

5765
class convert():
5866
np.seterr(invalid='ignore')

icesat2_toolkit/fit.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
fit.py
4-
Written by Tyler Sutterley (05/2021)
4+
Written by Tyler Sutterley (12/2021)
55
Utilities for calculating average fits from ATL03 Geolocated Photon Data
66
77
PYTHON DEPENDENCIES:
@@ -15,16 +15,26 @@
1515
https://github.com/scikit-learn/scikit-learn
1616
1717
UPDATE HISTORY:
18+
Updated 12/2022: place some imports behind try/except statements
1819
Updated 04/2022: updated docstrings to numpy documentation format
1920
Written 05/2021
2021
"""
2122
import operator
23+
import warnings
2224
import itertools
2325
import numpy as np
2426
import scipy.stats
2527
import scipy.signal
2628
import scipy.optimize
27-
import sklearn.neighbors
29+
30+
# attempt imports
31+
try:
32+
import sklearn.neighbors
33+
except (ImportError, ModuleNotFoundError) as e:
34+
warnings.filterwarnings("always")
35+
warnings.warn("scikit-learn not available")
36+
# ignore warnings
37+
warnings.filterwarnings("ignore")
2838

2939
# PURPOSE: compress complete list of valid indices into a set of ranges
3040
def compress_list(i,n):

icesat2_toolkit/read_ICESat2_ATL03.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL03.py (04/2022)
3+
read_ICESat2_ATL03.py (12/2022)
44
Read ICESat-2 ATL03 and ATL09 data files to calculate average segment surfaces
55
ATL03 datasets: Global Geolocated Photons
66
ATL09 datasets: Atmospheric Characteristics
@@ -15,6 +15,7 @@
1515
https://www.h5py.org/
1616
1717
UPDATE HISTORY:
18+
Updated 12/2022: place some imports behind try/except statements
1819
Updated 04/2022: updated docstrings to numpy documentation format
1920
Updated 10/2021: using python logging for handling verbose output
2021
Updated 02/2021: add check if input streaming from bytes
@@ -33,11 +34,21 @@
3334
import os
3435
import io
3536
import re
36-
import h5py
3737
import logging
38+
import warnings
3839
import numpy as np
3940
import scipy.interpolate
4041

42+
# attempt imports
43+
try:
44+
import h5py
45+
except ModuleNotFoundError:
46+
warnings.filterwarnings("always")
47+
warnings.warn("h5py not available")
48+
warnings.warn("Some functions will throw an exception if called")
49+
# ignore warnings
50+
warnings.filterwarnings("ignore")
51+
4152
# PURPOSE: read ICESat-2 ATL03 HDF5 data files
4253
def read_HDF5_ATL03(FILENAME, ATTRIBUTES=False, **kwargs):
4354
"""

icesat2_toolkit/read_ICESat2_ATL06.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL06.py (04/2022)
3+
read_ICESat2_ATL06.py (12/2022)
44
Read ICESat-2 ATL06 (Land Ice Along-Track Height Product) data files
55
66
OPTIONS:
@@ -16,6 +16,7 @@
1616
https://www.h5py.org/
1717
1818
UPDATE HISTORY:
19+
Updated 12/2022: place some imports behind try/except statements
1920
Updated 04/2022: updated docstrings to numpy documentation format
2021
Updated 10/2021: using python logging for handling verbose output
2122
Updated 02/2021: add check if input streaming from bytes
@@ -31,10 +32,20 @@
3132
import os
3233
import io
3334
import re
34-
import h5py
3535
import logging
36+
import warnings
3637
import numpy as np
3738

39+
# attempt imports
40+
try:
41+
import h5py
42+
except ModuleNotFoundError:
43+
warnings.filterwarnings("always")
44+
warnings.warn("h5py not available")
45+
warnings.warn("Some functions will throw an exception if called")
46+
# ignore warnings
47+
warnings.filterwarnings("ignore")
48+
3849
# PURPOSE: read ICESat-2 ATL06 HDF5 data files
3950
def read_HDF5_ATL06(FILENAME, ATTRIBUTES=False, HISTOGRAM=False,
4051
QUALITY=False, **kwargs):

icesat2_toolkit/read_ICESat2_ATL07.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL07.py (04/2022)
3+
read_ICESat2_ATL07.py (12/2022)
44
Read ICESat-2 ATL07 (Sea Ice Height) data files
55
66
PYTHON DEPENDENCIES:
@@ -11,6 +11,7 @@
1111
https://www.h5py.org/
1212
1313
UPDATE HISTORY:
14+
Updated 12/2022: place some imports behind try/except statements
1415
Updated 04/2022: updated docstrings to numpy documentation format
1516
Updated 10/2021: using python logging for handling verbose output
1617
Updated 02/2021: add check if input streaming from bytes
@@ -24,10 +25,20 @@
2425
import os
2526
import io
2627
import re
27-
import h5py
2828
import logging
29+
import warnings
2930
import numpy as np
3031

32+
# attempt imports
33+
try:
34+
import h5py
35+
except ModuleNotFoundError:
36+
warnings.filterwarnings("always")
37+
warnings.warn("h5py not available")
38+
warnings.warn("Some functions will throw an exception if called")
39+
# ignore warnings
40+
warnings.filterwarnings("ignore")
41+
3142
# PURPOSE: read ICESat-2 ATL07 HDF5 data files
3243
def read_HDF5_ATL07(FILENAME, ATTRIBUTES=False, **kwargs):
3344
"""

icesat2_toolkit/read_ICESat2_ATL10.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL10.py (04/2022)
3+
read_ICESat2_ATL10.py (12/2022)
44
Read ICESat-2 ATL10 (Sea Ice Freeboard) data files
55
66
PYTHON DEPENDENCIES:
@@ -11,6 +11,7 @@
1111
https://www.h5py.org/
1212
1313
UPDATE HISTORY:
14+
Updated 12/2022: place some imports behind try/except statements
1415
Updated 04/2022: updated docstrings to numpy documentation format
1516
Written 12/2021
1617
"""
@@ -19,10 +20,20 @@
1920
import os
2021
import io
2122
import re
22-
import h5py
2323
import logging
24+
import warnings
2425
import numpy as np
2526

27+
# attempt imports
28+
try:
29+
import h5py
30+
except ModuleNotFoundError:
31+
warnings.filterwarnings("always")
32+
warnings.warn("h5py not available")
33+
warnings.warn("Some functions will throw an exception if called")
34+
# ignore warnings
35+
warnings.filterwarnings("ignore")
36+
2637
# PURPOSE: read ICESat-2 ATL10 HDF5 data files
2738
def read_HDF5_ATL10(FILENAME, ATTRIBUTES=False, **kwargs):
2839
"""

icesat2_toolkit/read_ICESat2_ATL11.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL11.py (04/2022)
3+
read_ICESat2_ATL11.py (12/2022)
44
Read ICESat-2 ATL11 (Annual Land Ice Height) data files
55
66
OPTIONS:
@@ -18,6 +18,7 @@
1818
https://www.h5py.org/
1919
2020
UPDATE HISTORY:
21+
Updated 12/2022: place some imports behind try/except statements
2122
Updated 04/2022: updated docstrings to numpy documentation format
2223
Updated 10/2021: using python logging for handling verbose output
2324
Updated 03/2021: added function for reading only pair level variables
@@ -32,10 +33,20 @@
3233
import os
3334
import io
3435
import re
35-
import h5py
3636
import logging
37+
import warnings
3738
import numpy as np
3839

40+
# attempt imports
41+
try:
42+
import h5py
43+
except ModuleNotFoundError:
44+
warnings.filterwarnings("always")
45+
warnings.warn("h5py not available")
46+
warnings.warn("Some functions will throw an exception if called")
47+
# ignore warnings
48+
warnings.filterwarnings("ignore")
49+
3950
# PURPOSE: read ICESat-2 ATL11 HDF5 data files
4051
def read_HDF5_ATL11(FILENAME, GROUPS=['cycle_stats'], ATTRIBUTES=False,
4152
REFERENCE=False, CROSSOVERS=False, SUBSETTING=False, **kwargs):

icesat2_toolkit/read_ICESat2_ATL12.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
u"""
3-
read_ICESat2_ATL12.py (04/2022)
3+
read_ICESat2_ATL12.py (12/2022)
44
Read ICESat-2 ATL12 (Ocean Surface Height) data files
55
66
PYTHON DEPENDENCIES:
@@ -11,6 +11,7 @@
1111
https://www.h5py.org/
1212
1313
UPDATE HISTORY:
14+
Updated 12/2022: place some imports behind try/except statements
1415
Updated 04/2022: updated docstrings to numpy documentation format
1516
Updated 10/2021: using python logging for handling verbose output
1617
Updated 02/2021: add check if input streaming from bytes
@@ -23,10 +24,20 @@
2324
import os
2425
import io
2526
import re
26-
import h5py
2727
import logging
28+
import warnings
2829
import numpy as np
2930

31+
# attempt imports
32+
try:
33+
import h5py
34+
except ModuleNotFoundError:
35+
warnings.filterwarnings("always")
36+
warnings.warn("h5py not available")
37+
warnings.warn("Some functions will throw an exception if called")
38+
# ignore warnings
39+
warnings.filterwarnings("ignore")
40+
3041
# PURPOSE: read ICESat-2 ATL12 HDF5 data files
3142
def read_HDF5_ATL12(FILENAME, ATTRIBUTES=False, **kwargs):
3243
"""

0 commit comments

Comments
 (0)