Skip to content

Commit

Permalink
refactor: change 'geotiff' to 'GTiff' and 'cog' for #320 (#321)
Browse files Browse the repository at this point in the history
* refactor: change `'geotiff'` to `'GTiff'` and `'cog'` for #320

* Create pyproject.toml
  • Loading branch information
tsutterley authored Aug 22, 2024
1 parent 5548bb6 commit 6988bdc
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 52 deletions.
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_LPET_elevations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ compute_LPET_elevation.py

- Calculates long-period equilibrium tides for an input file
- Uses the summation of fifteen tidal spectral lines from [Cartwright1971]_ [Cartwright1973]_
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -20,6 +20,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_LPT_displacements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compute_LPT_displacements.py
- Calculates radial pole load tide displacements for an input file following IERS Convention (2010) guidelines

* `https://iers-conventions.obspm.fr/chapter7.php <https://iers-conventions.obspm.fr/chapter7.php>`_
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -21,6 +21,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_OPT_displacements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ compute_OPT_displacements.py

* `https://iers-conventions.obspm.fr/chapter7.php <https://iers-conventions.obspm.fr/chapter7.php>`_
* `ftp://tai.bipm.org/iers/conv2010/chapter7/opoleloadcoefcmcor.txt.gz <ftp://tai.bipm.org/iers/conv2010/chapter7/opoleloadcoefcmcor.txt.gz>`_
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -22,6 +22,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_SET_displacements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compute_SET_displacements.py
- Calculates radial solid Earth tide displacements for an input file following IERS Convention (2010) guidelines

* `https://iers-conventions.obspm.fr/chapter7.php <https://iers-conventions.obspm.fr/chapter7.php>`_
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -21,6 +21,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_tidal_currents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compute_tidal_currents.py
- Calculates tidal currents for an input file following [Egbert2002]_
- Can use OTIS format tidal solutions provided by Oregon State University and ESR
- Can use Finite Element Solution (FES) models provided by AVISO
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -21,6 +21,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
10 changes: 9 additions & 1 deletion doc/source/api_reference/compute_tidal_elevations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ compute_tidal_elevations.py
- Can use OTIS format tidal solutions provided by Oregon State University and ESR
- Can use Global Tide Model (GOT) solutions provided by Richard Ray at GSFC
- Can use Finite Element Solution (FES) models provided by AVISO
- Can read and write ascii, netCDF4, HDF5, parquet and geotiff formats
- Can read and write ascii, netCDF4, HDF5, (cloud optimized) geotiff and (geo)parquet formats

`Source code`__

Expand All @@ -22,6 +22,14 @@ Calling Sequence
:nodescription:
:nodefault:

--format -F : @after
* ``'csv'``: ascii with comma-separated values
* ``'netCDF4'``: Network Common Data Format version 4
* ``'HDF5'``: Hierarchical Data Format version 5
* ``'GTiff'``: GeoTiff georeferenced raster imagery
* ``'cog'``: Cloud Optimized GeoTIFF
* ``'parquet'``: Apache (geo)parquet

--variables : @after
* for csv files: the order of the columns within the file
* for HDF5, netCDF4 and parquet files: time, y, x and data variable names
Expand Down
2 changes: 2 additions & 0 deletions doc/source/api_reference/spatial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ spatial

Utilities for reading, writing and operating on spatial data

- Can read netCDF4, HDF5, (cloud optimized) geotiff or (geo)parquet files

Calling Sequence
----------------

Expand Down
9 changes: 5 additions & 4 deletions pyTMD/spatial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
spatial.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (08/2024)
Utilities for reading, writing and operating on spatial data
Expand Down Expand Up @@ -30,6 +30,7 @@
crs.py: Coordinate Reference System (CRS) routines
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 07/2024: added functions to convert to and from DMS
Updated 06/2024: added function to write parquet files with metadata
Updated 05/2024: added function to read from parquet files
Expand Down Expand Up @@ -195,7 +196,7 @@ def from_file(filename: str, format: str, **kwargs):
dinput = from_netCDF4(filename, **kwargs)
elif (format == 'HDF5'):
dinput = from_HDF5(filename, **kwargs)
elif (format == 'geotiff'):
elif format in ('GTiff','cog'):
dinput = from_geotiff(filename, **kwargs)
elif (format == 'parquet'):
dinput = from_parquet(filename, **kwargs)
Expand Down Expand Up @@ -750,7 +751,7 @@ def to_file(
to_netCDF4(output, attributes, filename, **kwargs)
elif (format == 'HDF5'):
to_HDF5(output, attributes, filename, **kwargs)
elif (format == 'geotiff'):
elif format in ('GTiff','cog'):
to_geotiff(output, attributes, filename, **kwargs)
elif (format == 'parquet'):
to_parquet(output, attributes, filename, **kwargs)
Expand Down Expand Up @@ -1083,7 +1084,7 @@ def to_geotiff(
**kwargs
):
"""
Write data to a geotiff file
Write data to a (cloud optimized) geotiff file
Parameters
----------
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "setuptools_scm"]
build-backend = "setuptools.build_meta"
17 changes: 10 additions & 7 deletions scripts/compute_LPET_elevations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
compute_LPET_elevations.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (08/2024)
Calculates long-period equilibrium tidal elevations for an input file
INPUTS:
Expand All @@ -17,7 +17,8 @@
netCDF4
HDF5
parquet
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, netCDF4 and parquet files: time, y, x and data variable names
Expand Down Expand Up @@ -69,6 +70,7 @@
predict.py: calculates long-period equilibrium ocean tides
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 07/2024: assert that data type is a known value
Updated 06/2024: include attributes in output parquet files
Updated 05/2024: use function to reading parquet files to allow
Expand Down Expand Up @@ -171,7 +173,7 @@ def compute_LPET_elevations(input_file, output_file,
dinput = pyTMD.spatial.from_HDF5(input_file,
field_mapping=field_mapping)
attributes = dinput['attributes']
elif (FORMAT == 'geotiff'):
elif FORMAT in ('GTiff', 'cog'):
dinput = pyTMD.spatial.from_geotiff(input_file)
attributes = dinput['attributes']
elif (FORMAT == 'parquet'):
Expand Down Expand Up @@ -277,19 +279,20 @@ def compute_LPET_elevations(input_file, output_file,
elif (FORMAT == 'HDF5'):
# write to HDF5
pyTMD.spatial.to_HDF5(output, attrib, output_file)
elif (FORMAT == 'geotiff'):
elif FORMAT in ('GTiff', 'cog'):
# write raster data to geotiff
# copy global geotiff attributes for projection and grid parameters
for att_name in ['projection','wkt','spacing','extent']:
attrib[att_name] = attributes[att_name]
pyTMD.spatial.to_geotiff(output, attrib, output_file,
varname='tide_lpe')
varname='tide_lpe', driver=FORMAT)
elif (FORMAT == 'parquet'):
# write to (geo)parquet
geoparquet = attributes.get('geoparquet', False)
geometry_encoding = attributes.get('geometry_encoding', None)
pyTMD.spatial.to_parquet(output, attrib, output_file,
geoparquet=geoparquet, geometry_encoding=geometry_encoding, crs=4326)
geoparquet=geoparquet, geometry_encoding=geometry_encoding,
crs=4326)
# change the permissions level to MODE
output_file.chmod(mode=MODE)

Expand All @@ -313,7 +316,7 @@ def arguments():
# input and output data format
parser.add_argument('--format','-F',
type=str, default='csv',
choices=('csv','netCDF4','HDF5','geotiff','parquet'),
choices=('csv','netCDF4','HDF5','GTiff','cog','parquet'),
help='Input and output data format')
# variable names (for csv names of columns)
parser.add_argument('--variables','-v',
Expand Down
17 changes: 10 additions & 7 deletions scripts/compute_LPT_displacements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
compute_LPT_displacements.py
Written by Tyler Sutterley (07/2024)
Written by Tyler Sutterley (08/2024)
Calculates radial load pole tide displacements for an input file
following IERS Convention (2010) guidelines
https://iers-conventions.obspm.fr/chapter7.php
Expand All @@ -19,7 +19,8 @@
netCDF4
HDF5
parquet
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, netCDF4 and parquet files: time, y, x and data variable names
Expand Down Expand Up @@ -78,6 +79,7 @@
utilities.py: download and management utilities for syncing files
UPDATE HISTORY:
Updated 08/2024: changed from 'geotiff' to 'GTiff' and 'cog' formats
Updated 07/2024: assert that data type is a known value
Updated 06/2024: include attributes in output parquet files
Updated 05/2024: use function to reading parquet files to allow
Expand Down Expand Up @@ -192,7 +194,7 @@ def compute_LPT_displacements(input_file, output_file,
dinput = pyTMD.spatial.from_HDF5(input_file,
field_mapping=field_mapping)
attributes = dinput['attributes']
elif (FORMAT == 'geotiff'):
elif FORMAT in ('GTiff', 'cog'):
dinput = pyTMD.spatial.from_geotiff(input_file)
attributes = dinput['attributes']
elif (FORMAT == 'parquet'):
Expand Down Expand Up @@ -350,19 +352,20 @@ def compute_LPT_displacements(input_file, output_file,
elif (FORMAT == 'HDF5'):
# write to HDF5
pyTMD.spatial.to_HDF5(output, attrib, output_file)
elif (FORMAT == 'geotiff'):
elif FORMAT in ('GTiff', 'cog'):
# write raster data to geotiff
# copy global geotiff attributes for projection and grid parameters
for att_name in ['projection','wkt','spacing','extent']:
attrib[att_name] = attributes[att_name]
pyTMD.spatial.to_geotiff(output, attrib, output_file,
varname='tide_pole')
varname='tide_pole', driver=FORMAT)
elif (FORMAT == 'parquet'):
# write to (geo)parquet
geoparquet = attributes.get('geoparquet', False)
geometry_encoding = attributes.get('geometry_encoding', None)
pyTMD.spatial.to_parquet(output, attrib, output_file,
geoparquet=geoparquet, geometry_encoding=geometry_encoding, crs=4326)
geoparquet=geoparquet, geometry_encoding=geometry_encoding,
crs=4326)
# change the permissions level to MODE
output_file.chmod(mode=MODE)

Expand All @@ -386,7 +389,7 @@ def arguments():
# input and output data format
parser.add_argument('--format','-F',
type=str, default='csv',
choices=('csv','netCDF4','HDF5','geotiff','parquet'),
choices=('csv','netCDF4','HDF5','GTiff','cog','parquet'),
help='Input and output data format')
# variable names (for csv names of columns)
parser.add_argument('--variables','-v',
Expand Down
Loading

0 comments on commit 6988bdc

Please sign in to comment.