15
15
from odc .geo .geom import BoundingBox
16
16
from odc .algo import xr_quantile
17
17
from datacube .utils .aws import configure_s3_access
18
- from dea_tools . coastal import pixel_tides
18
+ from eo_tides . eo import pixel_tides
19
19
from dea_tools .dask import create_local_dask_cluster
20
20
21
21
from intertidal .io import (
29
29
from intertidal .utils import (
30
30
configure_logging ,
31
31
round_date_strings ,
32
+ spearman_correlation ,
32
33
)
33
34
from intertidal .extents import extents , load_connectivity_mask
34
35
from intertidal .exposure import exposure
@@ -43,6 +44,7 @@ def ds_to_flat(
43
44
max_freq = 0.99 ,
44
45
min_correlation = 0.15 ,
45
46
corr_method = "pearson" ,
47
+ apply_threshold = True ,
46
48
correct_seasonality = False ,
47
49
valid_mask = None ,
48
50
):
@@ -77,6 +79,11 @@ def ds_to_flat(
77
79
corr_method : str, optional
78
80
Correlation method to use. Defaults to "pearson", also supports
79
81
"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.
80
87
correct_seasonality : bool, optional
81
88
If True, remove any seasonal signal from the tide height data
82
89
by subtracting monthly mean tide height from each value. This
@@ -132,12 +139,17 @@ def ds_to_flat(
132
139
clear = clear .stack (z = ("y" , "x" ))
133
140
134
141
# 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 ]
141
153
142
154
# Use either tides directly or correct to remove seasonal signal
143
155
if correct_seasonality :
@@ -149,19 +161,13 @@ def ds_to_flat(
149
161
150
162
# Calculate correlation
151
163
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" )
153
165
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" )
163
168
164
169
# Keep only pixels with correlations that meet min threshold
170
+ corr = corr .rename ("qa_ndwi_corr" )
165
171
corr_mask = corr >= min_correlation
166
172
flat_ds = flat_ds .where (corr_mask , drop = True )
167
173
@@ -785,14 +791,14 @@ def elevation(
785
791
window_prop_tide = 0.15 ,
786
792
correct_seasonality = False ,
787
793
max_workers = None ,
788
- tide_model = "FES2014 " ,
794
+ tide_model = "EOT20 " ,
789
795
tide_model_dir = "/var/share/tide_models" ,
790
796
run_id = None ,
791
797
log = None ,
792
798
):
793
799
"""
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.
796
802
797
803
Parameters
798
804
----------
@@ -835,18 +841,19 @@ def elevation(
835
841
determine workers.
836
842
tide_model : str, optional
837
843
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"
845
852
- "ensemble" (experimental: combine all above into single ensemble)
846
853
tide_model_dir : str, optional
847
854
The directory containing tide model data files. Defaults to
848
855
"/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 `.
850
857
run_id : string, optional
851
858
An optional string giving the name of the analysis; used to
852
859
prefix log entries.
@@ -881,8 +888,8 @@ def elevation(
881
888
# dataset (x by y by time). If `model` is "ensemble" this will model
882
889
# tides by combining the best local tide models.
883
890
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 ,
886
893
model = tide_model ,
887
894
directory = tide_model_dir ,
888
895
)
@@ -1097,18 +1104,18 @@ def elevation(
1097
1104
"--tide_model" ,
1098
1105
type = str ,
1099
1106
multiple = True ,
1100
- default = ["FES2014 " ],
1107
+ default = ["EOT20 " ],
1101
1108
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'."
1104
1111
)
1105
1112
@click .option (
1106
1113
"--tide_model_dir" ,
1107
1114
type = str ,
1108
1115
default = "/var/share/tide_models" ,
1109
1116
help = "The directory containing tide model data files. Defaults to "
1110
1117
"'/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 `." ,
1112
1119
)
1113
1120
@click .option (
1114
1121
"--modelled_freq" ,
0 commit comments