Skip to content

Commit c24d764

Browse files
committed
docs: slimmer build to prevent overutilization (#24)
1 parent 472a8c1 commit c24d764

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

geoid_toolkit/spatial.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
u"""
33
spatial.py
4-
Written by Tyler Sutterley (10/2022)
4+
Written by Tyler Sutterley (12/2022)
55
66
Utilities for reading, writing and operating on spatial data
77
@@ -20,6 +20,7 @@
2020
2121
UPDATE HISTORY:
2222
Updated 12/2022: add software information to output HDF5 and netCDF4
23+
place netCDF4 import within try/except statements
2324
Updated 10/2022: added datetime parser for ascii time columns
2425
Updated 06/2022: added field_mapping options to netCDF4 and HDF5 reads
2526
added from_file wrapper function to read from particular formats
@@ -53,25 +54,30 @@
5354
import uuid
5455
import yaml
5556
import logging
56-
import netCDF4
5757
import datetime
5858
import warnings
5959
import numpy as np
6060
import dateutil.parser
6161
import geoid_toolkit.version
6262
from geoid_toolkit.utilities import get_git_revision_hash
6363
# attempt imports
64+
try:
65+
import h5py
66+
except (ImportError, ModuleNotFoundError) as e:
67+
warnings.filterwarnings("always")
68+
warnings.warn("h5py not available")
69+
warnings.warn("Some functions will throw an exception if called")
6470
try:
6571
import osgeo.gdal, osgeo.osr, osgeo.gdalconst
6672
except (ImportError, ModuleNotFoundError) as e:
6773
warnings.filterwarnings("always")
6874
warnings.warn("GDAL not available")
6975
warnings.warn("Some functions will throw an exception if called")
7076
try:
71-
import h5py
77+
import netCDF4
7278
except (ImportError, ModuleNotFoundError) as e:
7379
warnings.filterwarnings("always")
74-
warnings.warn("h5py not available")
80+
warnings.warn("netCDF4 not available")
7581
warnings.warn("Some functions will throw an exception if called")
7682
# ignore warnings
7783
warnings.filterwarnings("ignore")

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
gdal
2-
h5py
31
lxml
42
matplotlib
5-
netCDF4
63
numpy
74
pyproj
85
python-dateutil

scripts/read_EGM2008_geoid_grids.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,29 @@
2525
2626
UPDATE HISTORY:
2727
Updated 12/2022: single implicit import of geoid toolkit
28+
place netCDF4 import within try/except statements
2829
Written 06/2022
2930
"""
3031
from __future__ import print_function
3132

3233
import os
3334
import logging
34-
import netCDF4
3535
import argparse
3636
import datetime
37+
import warnings
3738
import numpy as np
3839
import geoid_toolkit as geoidtk
3940

41+
# attempt imports
42+
try:
43+
import netCDF4
44+
except (ImportError, ModuleNotFoundError) as e:
45+
warnings.filterwarnings("always")
46+
warnings.warn("netCDF4 not available")
47+
warnings.warn("Some functions will throw an exception if called")
48+
# ignore warnings
49+
warnings.filterwarnings("ignore")
50+
4051
def read_EGM2008_geoid_grids(FILE, FILENAME=None, LOVE=0.3,
4152
VERBOSE=False, MODE=0o775):
4253

scripts/read_ICGEM_geoid_grids.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
UPDATE HISTORY:
2626
Updated 12/2022: single implicit import of geoid toolkit
27+
place netCDF4 import within try/except statements
2728
Updated 05/2022: use argparse descriptions within sphinx documentation
2829
Updated 04/2022: include utf-8 encoding in reads to be windows compliant
2930
check if gravity field data file is present in file-system
@@ -43,12 +44,22 @@
4344
import os
4445
import re
4546
import logging
46-
import netCDF4
4747
import argparse
4848
import datetime
49+
import warnings
4950
import numpy as np
5051
import geoid_toolkit as geoidtk
5152

53+
# attempt imports
54+
try:
55+
import netCDF4
56+
except (ImportError, ModuleNotFoundError) as e:
57+
warnings.filterwarnings("always")
58+
warnings.warn("netCDF4 not available")
59+
warnings.warn("Some functions will throw an exception if called")
60+
# ignore warnings
61+
warnings.filterwarnings("ignore")
62+
5263
# PURPOSE: Reads .gdf grids from the GFZ calculation service
5364
def read_ICGEM_geoid_grids(FILE, FILENAME=None, MARKER='', SPACING=None,
5465
VERBOSE=False, MODE=0o775):

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def check_output(cmd):
4343
except Exception as e:
4444
log.warning('Failed to get options via gdal-config')
4545
else:
46-
log.info(f"GDAL version from via gdal-config: {0}gdal_output[3]")
46+
log.info(f"GDAL version from via gdal-config: {gdal_output[3]}")
4747
# if setting GDAL version from via gdal-config
48-
if gdal_output[3]:
48+
if gdal_output[3] and ('gdal' in install_requires):
4949
# add version information to gdal in install_requires
5050
gdal_index = install_requires.index('gdal')
5151
install_requires[gdal_index] = f'gdal=={gdal_output[3]}'
52-
elif any(install_requires):
52+
elif any(install_requires) and ('gdal' in install_requires):
5353
# gdal version not found
5454
gdal_index = install_requires.index('gdal')
5555
install_requires.pop(gdal_index)
@@ -66,7 +66,7 @@ def check_output(cmd):
6666
else:
6767
log.info(f"HDF5 version from via h5dump: {hdf5_version}")
6868
# if the HDF5 version not found
69-
if not any(hdf5_output) and any(install_requires):
69+
if not any(hdf5_output) and ('h5py' in install_requires):
7070
hdf5_index = install_requires.index('h5py')
7171
install_requires.pop(hdf5_index)
7272

0 commit comments

Comments
 (0)