Skip to content

Commit cbdc270

Browse files
authored
Merge pull request #66 from GeoscienceAustralia/update_mask_funcs
Update ancillary data loading functions
2 parents 71dcd3e + 19fd698 commit cbdc270

File tree

8 files changed

+1458
-609
lines changed

8 files changed

+1458
-609
lines changed

.github/workflows/dea-intertidal-image.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ on:
3232
- 'codecov.yaml'
3333

3434
release:
35-
types: [created, edited, published]
35+
types: [edited, published]
3636

3737
permissions:
3838
id-token: write # Required for requesting Json web token
@@ -107,13 +107,10 @@ jobs:
107107
cp ./artifacts/validation.csv ./tests/validation.csv
108108
cp ./artifacts/README.md ./tests/README.md
109109
110-
# - name: Setup upterm session
111-
# uses: lhotari/action-upterm@v1
112-
113110
# Commit validation results produced by integration tests back into repo
114111
- name: Commit validation results into repository
115112
uses: stefanzweifel/git-auto-commit-action@v4
116-
if: github.event_name != 'release'
113+
if: github.event_name == 'pull_request'
117114
with:
118115
commit_message: Automatically update integration test validation results
119116
file_pattern: 'tests/validation.jpg tests/validation.csv tests/README.md'

intertidal/elevation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
from intertidal.io import (
2222
load_data,
23-
load_aclum,
24-
load_topobathy,
23+
load_topobathy_mask,
24+
load_aclum_mask,
2525
prepare_for_export,
2626
tidal_metadata,
2727
export_dataset_metadata,
@@ -1103,14 +1103,11 @@ def intertidal_cli(
11031103
)
11041104
satellite_ds.load()
11051105

1106-
# Load data from GA's AusBathyTopo 250m 2023 Grid
1107-
topobathy_ds = load_topobathy(
1108-
dc, satellite_ds, product="ga_ausbathytopo250m_2023", resampling="bilinear"
1109-
)
1110-
valid_mask = topobathy_ds.height_depth > -15
1106+
# Load topobathy mask from GA's AusBathyTopo 250m 2023 Grid
1107+
topobathy_mask = load_topobathy_mask(dc, satellite_ds.odc.geobox.compat)
11111108

1112-
# Load and reclassify for intensive urban land use class only the ABARES ACLUM ds
1113-
reclassified_aclum = load_aclum(dc, satellite_ds)
1109+
# Load urban land use class mask from ABARES CLUM
1110+
reclassified_aclum = load_aclum_mask(dc, satellite_ds.odc.geobox.compat)
11141111

11151112
# Also load ancillary dataset IDs to use in metadata
11161113
# (both layers are continental continental products with only
@@ -1123,7 +1120,7 @@ def intertidal_cli(
11231120
log.info(f"{run_id}: Calculating Intertidal Elevation")
11241121
ds, tide_m = elevation(
11251122
satellite_ds,
1126-
valid_mask=valid_mask,
1123+
valid_mask=topobathy_mask,
11271124
ndwi_thresh=ndwi_thresh,
11281125
min_freq=min_freq,
11291126
max_freq=max_freq,
@@ -1187,7 +1184,7 @@ def intertidal_cli(
11871184
# Prepare data for export
11881185
ds["qa_ndwi_freq"] *= 100 # Convert frequency to %
11891186
ds_prepared = prepare_for_export(ds) # sets correct dtypes and nodata
1190-
1187+
11911188
# Calculate additional tile-level tidal metadata attributes
11921189
metadata_dict = tidal_metadata(ds)
11931190

intertidal/io.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,15 @@ def load_data(
460460
return satellite_ds, dss_s2, dss_ls
461461

462462

463-
def load_topobathy(
463+
def load_topobathy_mask(
464464
dc,
465-
satellite_ds,
465+
geobox,
466466
product="ga_ausbathytopo250m_2023",
467+
elevation_band="height_depth",
467468
resampling="bilinear",
468469
mask_invalid=True,
470+
min_threshold=-15,
471+
mask_filters=[("dilation", 25)],
469472
):
470473
"""
471474
Loads a topo-bathymetric DEM for the extents of the loaded satellite
@@ -476,38 +479,58 @@ def load_topobathy(
476479
----------
477480
dc : Datacube
478481
A Datacube instance for loading data.
479-
satellite_ds : ndarray
480-
The loaded satellite data, used to obtain the spatial extents
481-
of the data.
482+
geobox : ndarray
483+
The GeoBox of the loaded satellite data, used to ensure the data
484+
is loaded into the same pixel grid (e.g. resolution, extents, CRS).
482485
product : str, optional
483486
The name of the topo-bathymetric DEM product to load from the
484487
datacube. Defaults to "ga_ausbathytopo250m_2023".
488+
elevation_band : str, optional
489+
The name of the band containing elevation data. Defaults to
490+
"height_depth".
485491
resampling : str, optional
486492
The resampling method to use, by default "bilinear".
487493
mask_invalid : bool, optional
488494
Whether to mask invalid/nodata values in the array by setting
489495
them to NaN, by default True.
496+
min_threshold : int or float, optional
497+
The elevation value used to create the mask; all pixels with
498+
elevations above this value will be given a value of True.
499+
mask_filters : list of tuples, optional
500+
An optional list of morphological processing steps to pass to
501+
the `mask_cleanup` function. The default is `[("dilation", 25)]`,
502+
which will dilate True pixels by a radius of 25 pixels (~250 m).
490503
491504
Returns
492505
-------
493-
topobathy_ds : xarray.Dataset
494-
The loaded topo-bathymetric DEM.
506+
topobathy_ds : xarray.DataArray
507+
An output boolean mask, where True represent pixels to use in the
508+
following analysis.
495509
"""
496-
topobathy_ds = dc.load(
497-
product=product, like=satellite_ds.odc.geobox.compat, resampling=resampling
498-
).squeeze("time")
510+
# Load from datacube, reprojecting to GeoBox of input satellite data
511+
topobathy_ds = dc.load(product=product, like=geobox, resampling=resampling).squeeze(
512+
"time"
513+
)
499514

500515
# Mask invalid data
501516
if mask_invalid:
502517
topobathy_ds = mask_invalid_data(topobathy_ds)
503518

504-
return topobathy_ds
519+
# Threshold to minumum elevation
520+
topobathy_mask = topobathy_ds[elevation_band] > min_threshold
521+
522+
# If requested, apply cleanup
523+
if mask_filters is not None:
524+
topobathy_mask = mask_cleanup(topobathy_mask, mask_filters=mask_filters)
525+
526+
return topobathy_mask
505527

506528

507-
def load_aclum(
529+
def load_aclum_mask(
508530
dc,
509-
satellite_ds,
531+
geobox,
510532
product="abares_clum_2020",
533+
class_band="alum_class",
511534
resampling="nearest",
512535
mask_invalid=True,
513536
):
@@ -521,12 +544,15 @@ def load_aclum(
521544
----------
522545
dc : Datacube
523546
A Datacube instance for loading data.
524-
satellite_ds : ndarray
525-
The loaded satellite data, used to obtain the spatial extents
526-
of the data.
547+
geobox : ndarray
548+
The GeoBox of the loaded satellite data, used to ensure the data
549+
is loaded into the same pixel grid (e.g. resolution, extents, CRS).
527550
product : str, optional
528551
The name of the ABARES land use dataset product to load from the
529552
datacube. Defaults to "abares_clum_2020".
553+
class_band : str, optional
554+
The name of the band containing land use class data. Defaults to
555+
"alum_class".
530556
resampling : str, optional
531557
The resampling method to use, by default "nearest".
532558
mask_invalid : bool, optional
@@ -535,22 +561,23 @@ def load_aclum(
535561
536562
Returns
537563
-------
538-
reclassified_aclum : xarray.Dataset
539-
The ABARES land use mask, summarised to include only two land
540-
use classes: 'intensive urban' and 'other'.
564+
reclassified_aclum : xarray.DataArray
565+
An output boolean mask, where True equals intensive urban and
566+
False equals all other classes.
541567
"""
568+
# Load from datacube, reprojecting to GeoBox of input satellite data
542569
aclum_ds = dc.load(
543-
product=product, like=satellite_ds.odc.geobox.compat, resampling=resampling
570+
product=product, like=geobox, resampling=resampling
544571
).squeeze("time")
545572

546573
# Mask invalid data
547574
if mask_invalid:
548575
aclum_ds = mask_invalid_data(aclum_ds)
549576

550577
# Manually isolate the 'intensive urban' land use summary class, set
551-
# all other pixels to false. For class definitions, refer to
578+
# all other pixels to False. For class definitions, refer to
552579
# gdata1/data/land_use/ABARES_CLUM/geotiff_clum_50m1220m/Land use, 18-class summary.qml)
553-
reclassified_aclum = aclum_ds.alum_class.isin(
580+
reclassified_aclum = aclum_ds[class_band].isin(
554581
[
555582
500,
556583
530,
@@ -926,7 +953,7 @@ def export_dataset_metadata(
926953
Dataset maturity to use for the output dataset. Default is
927954
"final", can also be "interim".
928955
additional_metadata : dict, optional
929-
An option dictionary containing additional metadata fields to
956+
An option dictionary containing additional metadata fields to
930957
add to the dataset metadata properties.
931958
debug : bool, optional
932959
When true, this will write S3 outputs locally so they can be

0 commit comments

Comments
 (0)