1515from odc .geo .geom import BoundingBox
1616from odc .algo import xr_quantile
1717from datacube .utils .aws import configure_s3_access
18- from dea_tools . coastal import pixel_tides
18+ from eo_tides . eo import pixel_tides
1919from dea_tools .dask import create_local_dask_cluster
2020
2121from intertidal .io import (
2929from intertidal .utils import (
3030 configure_logging ,
3131 round_date_strings ,
32+ spearman_correlation ,
3233)
3334from intertidal .extents import extents , load_connectivity_mask
3435from intertidal .exposure import exposure
@@ -43,6 +44,7 @@ def ds_to_flat(
4344 max_freq = 0.99 ,
4445 min_correlation = 0.15 ,
4546 corr_method = "pearson" ,
47+ apply_threshold = True ,
4648 correct_seasonality = False ,
4749 valid_mask = None ,
4850):
@@ -77,6 +79,11 @@ def ds_to_flat(
7779 corr_method : str, optional
7880 Correlation method to use. Defaults to "pearson", also supports
7981 "spearman".
82+ apply_threshold : bool, optional
83+ Whether to threshold the water index timeseries before calculating
84+ correlations, to ensure small changes in index values beneath the
85+ water surface are not included when calcualting correlations.
86+ Defaults to True.
8087 correct_seasonality : bool, optional
8188 If True, remove any seasonal signal from the tide height data
8289 by subtracting monthly mean tide height from each value. This
@@ -132,12 +139,17 @@ def ds_to_flat(
132139 clear = clear .stack (z = ("y" , "x" ))
133140
134141 # Calculate correlations between NDWI water observations and tide
135- # height. Because we are only interested in pixels with inundation
136- # patterns (e.g.transitions from dry to wet) are driven by tide, we
137- # first convert NDWI into a boolean dry/wet layer before running the
138- # correlation. This prevents small changes in NDWI beneath the water
139- # surface from producing correlations with tide height.
140- wet_dry = flat_ds [index ] > ndwi_thresh
142+ # height. By default, because we are only interested in pixels with
143+ # inundation patterns (e.g.transitions from dry to wet) that are driven
144+ # by the tide, we first convert NDWI into a boolean dry/wet layer before
145+ # running the correlation. This prevents small changes in NDWI beneath
146+ # the water surface from producing correlations with tide height.
147+ # This can be turned off by passing `apply_threshold=False`.
148+ if apply_threshold :
149+ wet_dry = flat_ds [index ] > ndwi_thresh
150+ else :
151+ print ("Using raw water index values for correlation" )
152+ wet_dry = flat_ds [index ]
141153
142154 # Use either tides directly or correct to remove seasonal signal
143155 if correct_seasonality :
@@ -149,19 +161,13 @@ def ds_to_flat(
149161
150162 # Calculate correlation
151163 if corr_method == "pearson" :
152- corr = xr .corr (wet_dry , tide_array , dim = "time" ). rename ( "qa_ndwi_corr" )
164+ corr = xr .corr (wet_dry , tide_array , dim = "time" )
153165 elif corr_method == "spearman" :
154- import xskillscore
155-
156- corr = xskillscore .spearman_r (
157- flat_ds [index ], tide_array , dim = "time" , skipna = True , keep_attrs = True
158- ).rename ("qa_ndwi_corr" )
159-
160- # TODO: investigate alternative function from DEA Tools
161- # (doesn't currently handle multiple tide models)
162- # corr = lag_linregress_3D(x=flat_ds.tide_m, y=wet_dry).cor.rename("qa_ndwi_corr")
166+ print ("Applying Spearman correlation" )
167+ corr = spearman_correlation (x = wet_dry , y = tide_array , dim = "time" )
163168
164169 # Keep only pixels with correlations that meet min threshold
170+ corr = corr .rename ("qa_ndwi_corr" )
165171 corr_mask = corr >= min_correlation
166172 flat_ds = flat_ds .where (corr_mask , drop = True )
167173
@@ -785,14 +791,14 @@ def elevation(
785791 window_prop_tide = 0.15 ,
786792 correct_seasonality = False ,
787793 max_workers = None ,
788- tide_model = "FES2014 " ,
794+ tide_model = "EOT20 " ,
789795 tide_model_dir = "/var/share/tide_models" ,
790796 run_id = None ,
791797 log = None ,
792798):
793799 """
794- Calculates DEA Intertidal Elevation using satellite imagery and
795- tidal modeling.
800+ Generates DEA Intertidal Elevation outputs using satellite imagery
801+ and tidal modeling.
796802
797803 Parameters
798804 ----------
@@ -835,18 +841,19 @@ def elevation(
835841 determine workers.
836842 tide_model : str, optional
837843 The tide model or a list of models used to model tides, as
838- supported by the `pyTMD` Python package. Options include:
839- - "FES2014" (default; pre-configured on DEA Sandbox)
840- - "TPXO9-atlas-v5"
841- - "TPXO8-atlas"
842- - "EOT20"
843- - "HAMTIDE11"
844- - "GOT4.10"
844+ supported by the `eo-tides` Python package. Options include:
845+ - "EOT20" (default)
846+ - "TPXO10-atlas-v2-nc"
847+ - "FES2022"
848+ - "FES2022_extrapolated"
849+ - "FES2014"
850+ - "FES2014_extrapolated"
851+ - "GOT5.6"
845852 - "ensemble" (experimental: combine all above into single ensemble)
846853 tide_model_dir : str, optional
847854 The directory containing tide model data files. Defaults to
848855 "/var/share/tide_models"; for more information about the
849- directory structure, refer to `dea_tools.coastal.model_tides `.
856+ directory structure, refer to `eo-tides.utils.list_models `.
850857 run_id : string, optional
851858 An optional string giving the name of the analysis; used to
852859 prefix log entries.
@@ -881,8 +888,8 @@ def elevation(
881888 # dataset (x by y by time). If `model` is "ensemble" this will model
882889 # tides by combining the best local tide models.
883890 log .info (f"{ run_id } : Modelling tide heights for each pixel" )
884- tide_m , _ = pixel_tides (
885- ds = satellite_ds ,
891+ tide_m = pixel_tides (
892+ data = satellite_ds ,
886893 model = tide_model ,
887894 directory = tide_model_dir ,
888895 )
@@ -1097,18 +1104,18 @@ def elevation(
10971104 "--tide_model" ,
10981105 type = str ,
10991106 multiple = True ,
1100- default = ["FES2014 " ],
1107+ default = ["EOT20 " ],
11011108 help = "The model used for tide modelling, as supported by the "
1102- "`pyTMD ` Python package. Options include 'FES2014 ' (default), "
1103- "'TPXO9 -atlas-v5 ', 'TPXO8-atlas-v1 ', 'EOT20 ', 'HAMTIDE11 ', 'GOT4.10'. " ,
1109+ "`eo-tides ` Python package. Options include 'EOT20 ' (default), "
1110+ "'TPXO10 -atlas-v2-nc ', 'FES2022 ', 'FES2014 ', 'GOT5.6 ', 'ensemble'."
11041111)
11051112@click .option (
11061113 "--tide_model_dir" ,
11071114 type = str ,
11081115 default = "/var/share/tide_models" ,
11091116 help = "The directory containing tide model data files. Defaults to "
11101117 "'/var/share/tide_models'; for more information about the required "
1111- "directory structure, refer to `dea_tools.coastal.model_tides `." ,
1118+ "directory structure, refer to `eo-tides.utils.list_models `." ,
11121119)
11131120@click .option (
11141121 "--modelled_freq" ,
0 commit comments