eo-tides 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
eo_tides/model.py CHANGED
@@ -21,7 +21,7 @@ import pyproj
21
21
  import pyTMD
22
22
  from tqdm import tqdm
23
23
 
24
- from .utils import DatetimeLike, _set_directory, _standardise_time, idw, list_models
24
+ from .utils import DatetimeLike, _set_directory, _standardise_models, _standardise_time, idw, list_models
25
25
 
26
26
 
27
27
  def _ensemble_model(
@@ -276,6 +276,7 @@ def _model_tides(
276
276
  )
277
277
 
278
278
  # TODO: Return constituents
279
+ # print(model, amp.shape)
279
280
  # print(amp.shape, ph.shape, c)
280
281
  # print(pd.DataFrame({"amplitude": amp}))
281
282
 
@@ -511,7 +512,6 @@ def model_tides(
511
512
 
512
513
  """
513
514
  # Turn inputs into arrays for consistent handling
514
- models_requested = list(np.atleast_1d(model))
515
515
  x = np.atleast_1d(x)
516
516
  y = np.atleast_1d(y)
517
517
  time = _standardise_time(time)
@@ -540,58 +540,12 @@ def model_tides(
540
540
  # provided, try global environment variable.
541
541
  directory = _set_directory(directory)
542
542
 
543
- # Get full list of supported models from pyTMD database;
544
- # add ensemble option to list of models
545
- available_models, valid_models = list_models(
546
- directory, show_available=False, show_supported=False, raise_error=True
543
+ # Standardise model list, handling "all" and "ensemble" functionality
544
+ models_to_process, models_requested, ensemble_models = _standardise_models(
545
+ model=model,
546
+ directory=directory,
547
+ ensemble_models=ensemble_models,
547
548
  )
548
- # TODO: This is hacky, find a better way. Perhaps a kwarg that
549
- # turns ensemble functionality on, and checks that supplied
550
- # models match models expected for ensemble?
551
- available_models = available_models + ["ensemble"]
552
- valid_models = valid_models + ["ensemble"]
553
-
554
- # Error if any models are not supported
555
- if not all(m in valid_models for m in models_requested):
556
- error_text = (
557
- f"One or more of the requested models are not valid:\n"
558
- f"{models_requested}\n\n"
559
- "The following models are supported:\n"
560
- f"{valid_models}"
561
- )
562
- raise ValueError(error_text)
563
-
564
- # Error if any models are not available in `directory`
565
- if not all(m in available_models for m in models_requested):
566
- error_text = (
567
- f"One or more of the requested models are valid, but not available in `{directory}`:\n"
568
- f"{models_requested}\n\n"
569
- f"The following models are available in `{directory}`:\n"
570
- f"{available_models}"
571
- )
572
- raise ValueError(error_text)
573
-
574
- # If ensemble modelling is requested, use a custom list of models
575
- # for subsequent processing
576
- if "ensemble" in models_requested:
577
- print("Running ensemble tide modelling")
578
- models_to_process = (
579
- ensemble_models
580
- if ensemble_models is not None
581
- else [
582
- "FES2014",
583
- "TPXO9-atlas-v5",
584
- "EOT20",
585
- "HAMTIDE11",
586
- "GOT4.10",
587
- "FES2012",
588
- "TPXO8-atlas-v1",
589
- ]
590
- )
591
-
592
- # Otherwise, models to process are the same as those requested
593
- else:
594
- models_to_process = models_requested
595
549
 
596
550
  # Update tide modelling func to add default keyword arguments that
597
551
  # are used for every iteration during parallel processing
@@ -685,7 +639,7 @@ def model_tides(
685
639
 
686
640
  # Optionally compute ensemble model and add to dataframe
687
641
  if "ensemble" in models_requested:
688
- ensemble_df = _ensemble_model(tide_df, crs, models_to_process, **ensemble_kwargs)
642
+ ensemble_df = _ensemble_model(tide_df, crs, ensemble_models, **ensemble_kwargs)
689
643
 
690
644
  # Update requested models with any custom ensemble models, then
691
645
  # filter the dataframe to keep only models originally requested
eo_tides/utils.py CHANGED
@@ -68,6 +68,92 @@ def _standardise_time(
68
68
  return np.atleast_1d(time)
69
69
 
70
70
 
71
+ def _standardise_models(
72
+ model: str | list[str],
73
+ directory: str | os.PathLike,
74
+ ensemble_models: list[str] | None = None,
75
+ ) -> tuple[list[str], list[str], list[str] | None]:
76
+ """
77
+ Take an input model name or list of names, and return a list
78
+ of models to process, requested models, and ensemble models,
79
+ as required by the `model_tides` function.
80
+
81
+ Handles two special values passed to `model`: "all", which
82
+ will model tides for all models available in `directory`, and
83
+ "ensemble", which will model tides for all models in a list
84
+ of custom ensemble models.
85
+ """
86
+
87
+ # Turn inputs into arrays for consistent handling
88
+ models_requested = list(np.atleast_1d(model))
89
+
90
+ # Get full list of supported models from pyTMD database
91
+ available_models, valid_models = list_models(
92
+ directory, show_available=False, show_supported=False, raise_error=True
93
+ )
94
+ custom_options = ["ensemble", "all"]
95
+
96
+ # Error if any models are not supported
97
+ if not all(m in valid_models + custom_options for m in models_requested):
98
+ error_text = (
99
+ f"One or more of the requested models are not valid:\n"
100
+ f"{models_requested}\n\n"
101
+ "The following models are supported:\n"
102
+ f"{valid_models}"
103
+ )
104
+ raise ValueError(error_text)
105
+
106
+ # Error if any models are not available in `directory`
107
+ if not all(m in available_models + custom_options for m in models_requested):
108
+ error_text = (
109
+ f"One or more of the requested models are valid, but not available in `{directory}`:\n"
110
+ f"{models_requested}\n\n"
111
+ f"The following models are available in `{directory}`:\n"
112
+ f"{available_models}"
113
+ )
114
+ raise ValueError(error_text)
115
+
116
+ # If "all" models are requested, update requested list to include available models
117
+ if "all" in models_requested:
118
+ models_requested = available_models + [m for m in models_requested if m != "all"]
119
+
120
+ # If "ensemble" modeling is requested, use custom list of ensemble models
121
+ if "ensemble" in models_requested:
122
+ print("Running ensemble tide modelling")
123
+ ensemble_models = (
124
+ ensemble_models
125
+ if ensemble_models is not None
126
+ else [
127
+ "FES2014",
128
+ "TPXO9-atlas-v5",
129
+ "EOT20",
130
+ "HAMTIDE11",
131
+ "GOT4.10",
132
+ "FES2012",
133
+ "TPXO8-atlas-v1",
134
+ ]
135
+ )
136
+
137
+ # Error if any ensemble models are not available in `directory`
138
+ if not all(m in available_models for m in ensemble_models):
139
+ error_text = (
140
+ f"One or more of the requested ensemble models are not available in `{directory}`:\n"
141
+ f"{ensemble_models}\n\n"
142
+ f"The following models are available in `{directory}`:\n"
143
+ f"{available_models}"
144
+ )
145
+ raise ValueError(error_text)
146
+
147
+ # Return set of all ensemble plus any other requested models
148
+ models_to_process = sorted(list(set(ensemble_models + [m for m in models_requested if m != "ensemble"])))
149
+
150
+ # Otherwise, models to process are the same as those requested
151
+ else:
152
+ models_to_process = models_requested
153
+
154
+ return models_to_process, models_requested, ensemble_models
155
+
156
+
71
157
  def _clip_model_file(
72
158
  nc: xr.Dataset,
73
159
  bbox: BoundingBox,
@@ -393,7 +479,14 @@ def list_models(
393
479
  expected_paths = {}
394
480
  for m in supported_models:
395
481
  model_file = model_database[m]["model_file"]
396
- model_file = model_file[0] if isinstance(model_file, list) else model_file
482
+
483
+ # Handle GOT5.6 differently to ensure we test for presence of GOT5.6 constituents
484
+ if m in ("GOT5.6", "GOT5.6_extrapolated"):
485
+ model_file = [file for file in model_file if "GOT5.6" in file][0]
486
+ else:
487
+ model_file = model_file[0] if isinstance(model_file, list) else model_file
488
+
489
+ # Add path to dict
397
490
  expected_paths[m] = str(directory / pathlib.Path(model_file).expanduser().parent)
398
491
 
399
492
  # Define column widths
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eo-tides
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Tide modelling tools for large-scale satellite earth observation analysis
5
- Author: Stephen Sagar, Claire Phillips, Vanessa Newey
6
- Author-email: Robbi Bishop-Taylor <Robbi.BishopTaylor@ga.gov.au>
5
+ Author: Robbi Bishop-Taylor, Stephen Sagar, Claire Phillips, Vanessa Newey
6
+ Author-email: Robbi.BishopTaylor@ga.gov.au
7
7
  Project-URL: Homepage, https://GeoscienceAustralia.github.io/eo-tides/
8
8
  Project-URL: Repository, https://github.com/GeoscienceAustralia/eo-tides
9
9
  Project-URL: Documentation, https://GeoscienceAustralia.github.io/eo-tides/
@@ -0,0 +1,11 @@
1
+ eo_tides/__init__.py,sha256=rn6slQP0bAhqM9cL2W8omiEM8f0b7libt6WsQ5DvYTE,1655
2
+ eo_tides/eo.py,sha256=Vc_AHqT0_IDqdwbOpNcONjHhiCtbCe8Osk2gvzUeNmU,22377
3
+ eo_tides/model.py,sha256=abfwswxEgSCBveK0-kTN5L-jw-AceXz3-NXSCbYnalk,32747
4
+ eo_tides/stats.py,sha256=lchWWJ5gBDuZWvaD8TF-12Xlo2qCWiNI2IcgAaKWy2U,22668
5
+ eo_tides/utils.py,sha256=i7JoNAH41hWZ0-lIOa87i-zCPndzJl3ylXecMb1jHoQ,26056
6
+ eo_tides/validation.py,sha256=UREsc0yWRO4x0PJXvyoIx8gYiBZiRSim4z6TmAz_VDM,11857
7
+ eo_tides-0.3.1.dist-info/LICENSE,sha256=owxWsXViCL2J6Ks3XYhot7t4Y93nstmXAT95Zf030Cc,11350
8
+ eo_tides-0.3.1.dist-info/METADATA,sha256=06d3l-KrXyKSvqGD-ku2CKORtWA1AHgA841i-iDw7_Q,8039
9
+ eo_tides-0.3.1.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
10
+ eo_tides-0.3.1.dist-info/top_level.txt,sha256=lXZDUUM1DlLdKWHRn8zdmtW8Rx-eQOIWVvt0b8VGiyQ,9
11
+ eo_tides-0.3.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.5.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- eo_tides/__init__.py,sha256=rn6slQP0bAhqM9cL2W8omiEM8f0b7libt6WsQ5DvYTE,1655
2
- eo_tides/eo.py,sha256=Vc_AHqT0_IDqdwbOpNcONjHhiCtbCe8Osk2gvzUeNmU,22377
3
- eo_tides/model.py,sha256=T0IFvSiXjiTvlY-Vi7-jneHPfaCLt95pmcRd8CZxOjE,34478
4
- eo_tides/stats.py,sha256=lchWWJ5gBDuZWvaD8TF-12Xlo2qCWiNI2IcgAaKWy2U,22668
5
- eo_tides/utils.py,sha256=tqXAkLk_Dm8s3yuXPxBBkHW3PZ42ayV8VCQjNw3wDZw,22433
6
- eo_tides/validation.py,sha256=UREsc0yWRO4x0PJXvyoIx8gYiBZiRSim4z6TmAz_VDM,11857
7
- eo_tides-0.3.0.dist-info/LICENSE,sha256=owxWsXViCL2J6Ks3XYhot7t4Y93nstmXAT95Zf030Cc,11350
8
- eo_tides-0.3.0.dist-info/METADATA,sha256=lajVK9XoAA2fJqA9R3HHYJ7iUJFMtmxh3U07uGTs4_4,8040
9
- eo_tides-0.3.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
10
- eo_tides-0.3.0.dist-info/top_level.txt,sha256=lXZDUUM1DlLdKWHRn8zdmtW8Rx-eQOIWVvt0b8VGiyQ,9
11
- eo_tides-0.3.0.dist-info/RECORD,,