Skip to content

Commit

Permalink
refactor: change 'geotiff' to 'GTiff' and 'cog'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley committed Aug 22, 2024
1 parent 0fe1c4a commit e3122fe
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 31 deletions.
16 changes: 10 additions & 6 deletions DEM/MPI_interpolate_DEM.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
MPI_interpolate_DEM.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Determines which digital elevation model tiles for an input file
Reads 3x3 array of tiles for points within bounding box of central mosaic tile
Interpolates digital elevation model to coordinates
Expand Down Expand Up @@ -33,7 +33,8 @@
csv (default)
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in csv, HDF5 or netCDF4 file
for csv files: the order of the columns within the file
for HDF5 and netCDF4 files: time, y, x and data variable names
Expand Down Expand Up @@ -84,6 +85,7 @@
https://nsidc.org/data/nsidc-0645/versions/1
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
Updated 07/2023: using pathlib to define and operate on paths
use geoms attribute for shapely 2.0 compliance
Expand Down Expand Up @@ -168,7 +170,8 @@ def arguments():
help='Digital Elevation Model to run')
# input and output data format
parser.add_argument('--format','-F',
type=str, default='csv', choices=('csv','netCDF4','HDF5','geotiff'),
type=str, default='csv',
choices=('csv','netCDF4','HDF5','GTiff','cog'),
help='Input and output data format')
# variable names (for csv names of columns)
parser.add_argument('--variables','-v',
Expand Down Expand Up @@ -475,7 +478,7 @@ def main():
attrib[args.variables[2]] = dinput['attributes']['x']
attrib[args.variables[1]] = dinput['attributes']['y']
attrib[args.variables[0]] = dinput['attributes']['time']
elif (args.format == 'geotiff') and (comm.rank == 0):
elif (args.format in ('GTiff','cog')) and (comm.rank == 0):
dinput = pyTMD.spatial.from_geotiff(args.infile,
verbose=args.verbose)
# copy global geotiff attributes for projection and grid parameters
Expand Down Expand Up @@ -710,9 +713,10 @@ def main():
elif (args.format == 'HDF5'):
pyTMD.spatial.to_HDF5(output, attrib, args.outfile,
verbose=args.verbose)
elif (args.format == 'geotiff'):
elif args.format in ('GTiff','cog'):
pyTMD.spatial.to_geotiff(output, attrib, args.outfile,
varname='dem_h', verbose=args.verbose)
varname='dem_h', driver=args.format,
verbose=args.verbose)
# change the permissions level to MODE
args.outfile.chmod(mode=args.mode)

Expand Down
2 changes: 1 addition & 1 deletion GZ/calculate_grounding_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def arguments():
help='Digital Elevation Model to run')
# input and output data format
parser.add_argument('--format','-F',
type=str, default='csv', choices=('csv','netCDF4','HDF5','geotiff'),
type=str, default='csv', choices=('csv','netCDF4','HDF5'),
help='Input and output data format')
# variable names (for csv names of columns)
parser.add_argument('--variables','-v',
Expand Down
2 changes: 1 addition & 1 deletion doc/source/api_reference/DEM/MPI_interpolate_DEM.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MPI_interpolate_DEM.py
======================

- Determines which digital elevation model tiles for an input file (ascii, netCDF4, HDF5, geotiff)
- Determines which digital elevation model tiles for an input file (ascii, netCDF4, HDF5, GTiff, cog)
- Reads 3\ |times|\ 3 array of tiles for points within bounding box of central mosaic tile
- Interpolates digital elevation model to coordinates

Expand Down
9 changes: 6 additions & 3 deletions subset/reduce_ICESat2_ATL06_raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
reduce_ICESat2_ATL06_raster.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Create masks for reducing ICESat-2 ATL06 data using raster imagery
Expand All @@ -10,7 +10,8 @@
-F X, --format X: Input raster file format
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in HDF5 or netCDF4 file
x, y and data variable names
-P X, --projection X: spatial projection as EPSG code or PROJ4 string
Expand Down Expand Up @@ -43,6 +44,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
moved from icesat2_toolkit to Grounding-Zones package
Updated 04/2024: use timescale for temporal operations
Expand Down Expand Up @@ -578,7 +580,8 @@ def arguments():
type=pathlib.Path,
help='Input raster file')
parser.add_argument('--format','-F',
type=str, default='geotiff', choices=('netCDF4','HDF5','geotiff'),
type=str, default='GTiff',
choices=('netCDF4','HDF5','GTiff','cog'),
help='Input raster file format')
# variable names of data in HDF5 or netCDF4 file
parser.add_argument('--variables','-v',
Expand Down
9 changes: 6 additions & 3 deletions subset/reduce_ICESat2_ATL07_raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
reduce_ICESat2_ATL07_raster.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Create masks for reducing ICESat-2 ATL07 data using raster imagery
Expand All @@ -10,7 +10,8 @@
-F X, --format X: Input raster file format
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in HDF5 or netCDF4 file
x, y and data variable names
-P X, --projection X: spatial projection as EPSG code or PROJ4 string
Expand Down Expand Up @@ -43,6 +44,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
moved from icesat2_toolkit to Grounding-Zones package
Updated 04/2024: use timescale for temporal operations
Expand Down Expand Up @@ -614,7 +616,8 @@ def arguments():
type=pathlib.Path,
help='Input raster file')
parser.add_argument('--format','-F',
type=str, default='geotiff', choices=('netCDF4','HDF5','geotiff'),
type=str, default='GTiff',
choices=('netCDF4','HDF5','GTiff','cog'),
help='Input raster file format')
# variable names of data in HDF5 or netCDF4 file
parser.add_argument('--variables','-v',
Expand Down
9 changes: 6 additions & 3 deletions subset/reduce_ICESat2_ATL10_raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
reduce_ICESat2_ATL10_raster.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Create masks for reducing ICESat-2 ATL10 data using raster imagery
Expand All @@ -10,7 +10,8 @@
-F X, --format X: Input raster file format
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in HDF5 or netCDF4 file
x, y and data variable names
-P X, --projection X: spatial projection as EPSG code or PROJ4 string
Expand Down Expand Up @@ -43,6 +44,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
moved from icesat2_toolkit to Grounding-Zones package
Updated 04/2024: use timescale for temporal operations
Expand Down Expand Up @@ -573,7 +575,8 @@ def arguments():
type=pathlib.Path,
help='Input raster file')
parser.add_argument('--format','-F',
type=str, default='geotiff', choices=('netCDF4','HDF5','geotiff'),
type=str, default='GTiff',
choices=('netCDF4','HDF5','GTiff','cog'),
help='Input raster file format')
# variable names of data in HDF5 or netCDF4 file
parser.add_argument('--variables','-v',
Expand Down
9 changes: 6 additions & 3 deletions subset/reduce_ICESat2_ATL11_raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
reduce_ICESat2_ATL11_raster.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Create masks for reducing ICESat-2 ATL11 data using raster imagery
Expand All @@ -10,7 +10,8 @@
-F X, --format X: Input raster file format
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in HDF5 or netCDF4 file
x, y and data variable names
-P X, --projection X: spatial projection as EPSG code or PROJ4 string
Expand Down Expand Up @@ -43,6 +44,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
moved from icesat2_toolkit to Grounding-Zones package
Updated 04/2024: use timescale for temporal operations
Expand Down Expand Up @@ -583,7 +585,8 @@ def arguments():
type=pathlib.Path,
help='Input raster file')
parser.add_argument('--format','-F',
type=str, default='geotiff', choices=('netCDF4','HDF5','geotiff'),
type=str, default='GTiff',
choices=('netCDF4','HDF5','GTiff','cog'),
help='Input raster file format')
# variable names of data in HDF5 or netCDF4 file
parser.add_argument('--variables','-v',
Expand Down
9 changes: 6 additions & 3 deletions subset/reduce_ICESat_GLA12_raster.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
reduce_ICESat_GLA12_raster.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Create masks for reducing ICESat/GLAS L2 GLA12 Antarctic and Greenland
Ice Sheet elevation data data using raster imagery
Expand All @@ -11,7 +11,8 @@
-F X, --format X: Input raster file format
netCDF4
HDF5
geotiff
GTiff
cog
-v X, --variables X: variable names of data in HDF5 or netCDF4 file
x, y and data variable names
-P X, --projection X: spatial projection as EPSG code or PROJ4 string
Expand Down Expand Up @@ -44,6 +45,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
Updated 04/2024: use timescale for temporal operations
Updated 03/2024: use pathlib to define and operate on paths
Expand Down Expand Up @@ -520,7 +522,8 @@ def arguments():
type=pathlib.Path,
help='Input raster file')
parser.add_argument('--format','-F',
type=str, default='geotiff', choices=('netCDF4','HDF5','geotiff'),
type=str, default='GTiff',
choices=('netCDF4','HDF5','GTiff','cog'),
help='Input raster file format')
# variable names of data in HDF5 or netCDF4 file
parser.add_argument('--variables','-v',
Expand Down
5 changes: 3 additions & 2 deletions tides/mosaic_tide_adjustment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
mosaic_tide_adjustment.py
Written by Tyler Sutterley (05/2024)
Written by Tyler Sutterley (08/2024)
Creates a mosaic of interpolated tidal adjustment scale factors
Expand All @@ -18,6 +18,7 @@
-M X, --mode X: Local permissions mode of the output mosaic
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 05/2024: use wrapper to importlib for optional dependencies
Updated 12/2023: don't have a default tide model in arguments
Updated 11/2023: mask individual tiles before building mosaic
Expand Down Expand Up @@ -101,7 +102,7 @@ def mosaic_tide_adjustment(base_dir, output_file,
# read mask from geotiff file
# flip to be monotonically increasing in y dimension
MASK = pathlib.Path(MASK).expanduser().absolute()
raster = gz.io.raster().from_file(MASK, format='geotiff').flip()
raster = gz.io.raster().from_file(MASK, format='GTiff').flip()

# pyproj transformer for converting to polar stereographic
EPSG = dict(N=3413, S=3031)[HEM]
Expand Down
12 changes: 6 additions & 6 deletions tides/tidal_histogram_ICESat2_ATL11.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ def tidal_histogram(tile_file,
SUB,PRD,TRK,GRAN,SCYC,ECYC,RL,VERS,AUX = R2.findall(ATL11).pop()
# read tide model corrections
if TIDE_MODEL:
# ATL11 tide correction HDF5 file
# read ATL11 tide correction HDF5 file
a3 = (PRD,TIDE_MODEL,'_TIDES',TRK,GRAN,SCYC,ECYC,RL,VERS,AUX)
FILE3 = d1.joinpath(file_format.format(*a3))
f3 = gz.io.multiprocess_h5py(FILE3, mode='r')
# read inverse barometer correction
if REANALYSIS:
# read inverse barometer HDF5 file
# read ATL11 inverse barometer HDF5 file
a4 = (PRD,REANALYSIS,'IB',TRK,GRAN,SCYC,ECYC,RL,VERS,AUX)
FILE4 = d1.joinpath(file_format.format(*a4))
f4 = gz.io.multiprocess_h5py(FILE4, mode='r')
Expand All @@ -273,15 +273,15 @@ def tidal_histogram(tile_file,
)
# read tide model corrections
if TIDE_MODEL:
# read data and reduce to indices
# read tide data and reduce to indices
temp = f3[ptx]['cycle_stats']['tide_ocean'][:].copy()
tide_ocean = temp[indices,:]
else:
tide_ocean = np.zeros((file_length,ncycles))
# read inverse barometer correction
if REANALYSIS:
# read data and reduce to indices
temp = f3[ptx]['cycle_stats']['ib'][:].copy()
# read IB data and reduce to indices
temp = f4[ptx]['cycle_stats']['ib'][:].copy()
IB = temp[indices,:]
else:
# reduce DAC to indices
Expand All @@ -303,7 +303,7 @@ def tidal_histogram(tile_file,
# reference heights to geoid
h1 -= mds[ptx]['ref_surf']['geoid_h'][indices]
h2 -= mds[ptx]['ref_surf']['geoid_h'][indices]
# correct heights for DAC
# correct heights for DAC/IB
h1 -= IB[:,k]
h2 -= IB[:,k+1]
# correct heights for ocean tides
Expand Down

0 comments on commit e3122fe

Please sign in to comment.