Skip to content

Commit 785fedb

Browse files
authored
Merge pull request #556 from USACE/dss-py
switch to dsspy from tiffdss
2 parents 839034c + 030ed14 commit 785fedb

File tree

6 files changed

+163
-261
lines changed

6 files changed

+163
-261
lines changed

async_packager/Dockerfile

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
# Packager
2-
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.7.0 AS base
2+
ARG GDAL_TAG=ubuntu-full-3.9.1
3+
4+
5+
FROM ghcr.io/osgeo/gdal:${GDAL_TAG} AS builder
36

47
# force stdout and stderr to be unbuffered setting to non-empty
58
ENV PYTHONUNBUFFERED=1
69

10+
#GDAL
711
ENV GDAL_DATA=/usr/share/gdal
812
ENV GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR
913

10-
ENV PACKAGE=async_packager
14+
# packager
15+
ENV USERNAME=packager
16+
ENV PACKAGER=/opt/packager
17+
ENV PACKAGER_VENV=${PACKAGER}/venv
18+
19+
ENV PATH=${PACKAGER_VENV}/bin:$PATH
1120

12-
ENV TIFFDSS_VERSION=v0.2.2
13-
ENV TIFFDSS=tiffdss_ubuntu-latest
21+
#ENV PACKAGE=async_packager
1422

1523
# solving possible issue of ATP behind a proxy
1624
RUN cat <<EOF > /etc/apt/apt.conf.d/99proxy
@@ -19,39 +27,30 @@ Acquire::http::No-Cache true;
1927
Acquire::BrokenProxy true;
2028
EOF
2129

22-
# update and install other dependencies
23-
RUN apt-get -y update && \
24-
apt-get -y upgrade && \
25-
apt-get install -y python3-pip curl && \
26-
rm -rf /var/lib/apt/lists/* && \
27-
pip install --no-cache-dir --upgrade pip && \
28-
pip install --no-cache-dir --upgrade setuptools && \
29-
pip install --no-cache-dir --upgrade wheel && \
30-
pip install --no-cache-dir --upgrade pillow
31-
# pip install --no-cache-dir --upgrade numpy
32-
3330

34-
RUN mkdir -p /app/${PACKAGE}
31+
# update and install other dependencies
32+
RUN apt-get -y update \
33+
# && apt-get -y upgrade \
34+
&& apt-get install -y python3.12-venv \
35+
&& apt-get remove python3-pil -y \
36+
&& apt clean
3537

36-
WORKDIR /app/${PACKAGE}
38+
# install package in venv
39+
COPY . ${PACKAGER}/pkg
3740

38-
COPY . .
41+
RUN python3 -m venv --system-site-packages ${PACKAGER_VENV} \
42+
&& . activate \
43+
&& pip install ${PACKAGER}/pkg/ \
44+
&& pip install hecdss
3945

40-
# pip install the package and upgrade outdated packages
41-
RUN pip3 install /app/${PACKAGE}/
46+
RUN groupadd -r ${USERNAME} && \
47+
useradd -g ${USERNAME} -ms /bin/bash ${USERNAME}
4248

43-
# get libtiffdss.so
44-
RUN curl -L https://github.com/HydrologicEngineeringCenter/tiffdss/releases/download/${TIFFDSS_VERSION}/${TIFFDSS}_${TIFFDSS_VERSION}.tar.gz \
45-
--output ${TIFFDSS}_${TIFFDSS_VERSION}.tar.gz && \
46-
tar -zxvf ${TIFFDSS}_${TIFFDSS_VERSION}.tar.gz && \
47-
mv libtiffdss.so /usr/lib/ && \
48-
mv tiffdss /usr/local/bin/ && \
49-
rm -f ${TIFFDSS}_${TIFFDSS_VERSION}.tar.gz tiffdss *.o
49+
WORKDIR ${PACKAGER}
5050

51-
RUN useradd appuser && \
52-
mkdir -p -m 775 docs && \
53-
chown appuser:appuser docs
51+
# packager and run it
52+
COPY ./packager.py ./
5453

55-
USER appuser
54+
USER ${USERNAME}:${USERNAME}
5655

57-
CMD ["./packager.py"]
56+
ENTRYPOINT ["python3", "packager.py"]

async_packager/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ install_requires =
3030
gdal-utils
3131
psycopg2-binary
3232
codetiming
33+
hecdss
3334
include_package_data = True
3435

3536
[options.packages.find]

async_packager/src/cumulus_packager/heclib/__init__.py renamed to async_packager/src/cumulus_packager/dssutil/__init__.py

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
"""Module 'heclib'
1+
"""Module 'dssutil' for handling DSS grids
22
33
Enumerations, constants and functions
44
55
"""
66

7-
from ctypes import (
8-
CDLL,
9-
POINTER,
10-
LibraryLoader,
11-
Structure,
12-
c_char_p,
13-
c_float,
14-
c_int,
15-
c_void_p,
16-
pointer,
17-
)
187
from enum import Enum, auto
198

20-
import numpy
21-
22-
# libtiffdss.so is compiled and put in /usr/lib during image creation
23-
tiffdss = LibraryLoader(CDLL).LoadLibrary("libtiffdss.so")
24-
"""ctypes.CDLL: tiff to dss shared object"""
25-
269
FLOAT_MAX = 3.40282347e38
2710
UNDEFINED = -FLOAT_MAX
2811

@@ -159,88 +142,4 @@ class TimeZone(Enum):
159142
HST = auto()
160143

161144

162-
time_zone = {i.name: i.value for i in TimeZone}
163-
164-
165-
class zStructSpatialGrid(Structure):
166-
_fields_ = [
167-
("structType", c_int),
168-
("pathname", c_char_p),
169-
("_structVersion", c_int),
170-
("_type", c_int),
171-
("_version", c_int),
172-
("_dataUnits", c_char_p),
173-
("_dataType", c_int),
174-
("_dataSource", c_char_p),
175-
("_lowerLeftCellX", c_int),
176-
("_lowerLeftCellY", c_int),
177-
("_numberOfCellsX", c_int),
178-
("_numberOfCellsY", c_int),
179-
("_cellSize", c_float),
180-
("_compressionMethod", c_int),
181-
("_sizeofCompressedElements", c_int),
182-
("_compressionParameters", c_void_p),
183-
("_srsName", c_char_p),
184-
("_srsDefinitionType", c_int),
185-
("_srsDefinition", c_char_p),
186-
("_xCoordOfGridCellZero", c_float),
187-
("_yCoordOfGridCellZero", c_float),
188-
("_nullValue", c_float),
189-
("_timeZoneID", c_char_p),
190-
("_timeZoneRawOffset", c_int),
191-
("_isInterval", c_int),
192-
("_isTimeStamped", c_int),
193-
("_numberOfRanges", c_int),
194-
("_storageDataType", c_int),
195-
("_maxDataValue", c_void_p),
196-
("_minDataValue", c_void_p),
197-
("_meanDataValue", c_void_p),
198-
("_rangeLimitTable", c_void_p),
199-
("_numberEqualOrExceedingRangeLimit", c_int),
200-
("_data", c_void_p),
201-
]
202-
203-
def __init__(self, *args, **kw):
204-
self._nullValue = UNDEFINED
205-
super().__init__(*args, **kw)
206-
207-
208-
def zwrite_record(
209-
dssfilename: str,
210-
gridStructStore: zStructSpatialGrid,
211-
data_flat: numpy,
212-
):
213-
"""Write the data array to DSS record using the 'writeRecord' C function
214-
215-
Parameters
216-
----------
217-
dssfilename : str
218-
DSS file name and path
219-
gridStructStore : zStructSpatialGrid
220-
ctypes structure
221-
data_flat : numpy
222-
1D numpy array
223-
gridStats : GridStats
224-
ctypes structure
225-
226-
Returns
227-
-------
228-
int
229-
Response from the C function
230-
"""
231-
ND_POINTER_1 = numpy.ctypeslib.ndpointer(dtype=numpy.float32, ndim=1, flags="C")
232-
233-
tiffdss.writeRecord_External.argtypes = (
234-
c_char_p,
235-
POINTER(zStructSpatialGrid),
236-
ND_POINTER_1,
237-
)
238-
tiffdss.writeRecord_External.restype = c_int
239-
240-
res = tiffdss.writeRecord_External(
241-
c_char_p(dssfilename.encode()),
242-
pointer(gridStructStore),
243-
data_flat,
244-
)
245-
246-
return res
145+
time_zone = {i.name: i.value for i in TimeZone}

0 commit comments

Comments
 (0)