Skip to content

Commit

Permalink
refactored extents algorithm (#89)
Browse files Browse the repository at this point in the history
* refactored extents algorithm for PR

* Pin AWS CLI

* Automatically update integration test validation results

* resync 'label date' func in CLI calls

* Automatically update integration test validation results

* CLI updates

* Automatically update integration test validation results

---------

Co-authored-by: Robbi Bishop-Taylor <[email protected]>
Co-authored-by: robbibt <[email protected]>
Co-authored-by: erialC-P <[email protected]>
  • Loading branch information
4 people authored Aug 23, 2024
1 parent d794b9f commit 4d8b199
Show file tree
Hide file tree
Showing 8 changed files with 867 additions and 857 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN mkdir -p /conf
# RUN pip-compile --extra-index-url=https://packages.dea.ga.gov.au/ --output-file=/conf/requirements.txt /conf/requirements.in
COPY requirements.txt /conf/
RUN pip install -r /conf/requirements.txt \
&& pip install --no-cache-dir awscli
&& pip install --no-cache-dir awscli==1.33.37

# Copy source code and install it
RUN mkdir -p /code
Expand Down
56 changes: 43 additions & 13 deletions intertidal/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,45 @@
round_date_strings,
)
from intertidal.tide_modelling import pixel_tides_ensemble
from intertidal.extents import extents, ocean_connection
from intertidal.extents import extents#, ocean_connection
from intertidal.exposure import exposure
from intertidal.tidal_bias_offset import bias_offset

def ocean_connection(water, ocean_da, connectivity=2):
"""
Identifies areas of water pixels that are adjacent to or directly
connected to intertidal pixels.
Parameters:
-----------
water : xarray.DataArray
An array containing True for water pixels.
ocean_da : xarray.DataArray
An array containing True for ocean pixels.
connectivity : integer, optional
An integer passed to the 'connectivity' parameter of the
`skimage.measure.label` function.
Returns:
--------
ocean_connection : xarray.DataArray
An array containing the a mask consisting of identified
ocean-connected pixels as True.
"""

# First, break `water` array into unique, discrete
# regions/blobs.
blobs = xr.apply_ufunc(label, water, 0, False, connectivity)

# For each unique region/blob, use region properties to determine
# whether it overlaps with a feature from `intertidal`. If
# it does, then it is considered to be adjacent or directly connected
# to intertidal pixels
ocean_connection = blobs.isin(
[i.label for i in regionprops(blobs.values, ocean_da.values) if i.max_intensity]
)

return ocean_connection

def ds_to_flat(
satellite_ds,
Expand Down Expand Up @@ -1235,7 +1270,7 @@ def intertidal_cli(
ds, tide_m = elevation(
satellite_ds,
valid_mask=topobathy_mask,
ocean_mask=ocean_mask,
# ocean_mask=ocean_mask,
ndwi_thresh=ndwi_thresh,
min_freq=min_freq,
max_freq=max_freq,
Expand All @@ -1249,17 +1284,12 @@ def intertidal_cli(
log=log,
)

# # Calculate extents (to be included in next version)
# log.info(f"{run_id}: Calculating Intertidal Extents")
# ds["extents"] = extents(
# dem=ds.elevation,
# freq=ds.qa_ndwi_freq,
# corr=ds.qa_ndwi_corr,
# reclassified_aclum=reclassified_aclum,
# min_freq=min_freq,
# max_freq=max_freq,
# min_correlation=min_correlation,
# )
# Calculate extents (to be included in next version)
log.info(f"{run_id}: Calculating Intertidal Extents")
ds["extents"] = extents(
dc=dc,
ds=ds
)

if exposure_offsets:
log.info(f"{run_id}: Calculating Intertidal Exposure")
Expand Down
Loading

0 comments on commit 4d8b199

Please sign in to comment.