tfv-get-tools 0.2.0__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.
- tfv_get_tools/__init__.py +4 -0
- tfv_get_tools/_standard_attrs.py +107 -0
- tfv_get_tools/atmos.py +167 -0
- tfv_get_tools/cli/_cli_base.py +173 -0
- tfv_get_tools/cli/atmos_cli.py +192 -0
- tfv_get_tools/cli/ocean_cli.py +204 -0
- tfv_get_tools/cli/tide_cli.py +118 -0
- tfv_get_tools/cli/wave_cli.py +183 -0
- tfv_get_tools/fvc/__init__.py +3 -0
- tfv_get_tools/fvc/_atmos.py +230 -0
- tfv_get_tools/fvc/_fvc.py +218 -0
- tfv_get_tools/fvc/_ocean.py +171 -0
- tfv_get_tools/fvc/_tide.py +195 -0
- tfv_get_tools/ocean.py +170 -0
- tfv_get_tools/providers/__init__.py +0 -0
- tfv_get_tools/providers/_custom_conversions.py +34 -0
- tfv_get_tools/providers/_downloader.py +566 -0
- tfv_get_tools/providers/_merger.py +520 -0
- tfv_get_tools/providers/_utilities.py +255 -0
- tfv_get_tools/providers/atmos/barra2.py +209 -0
- tfv_get_tools/providers/atmos/cfgs/barra2_c2.yaml +52 -0
- tfv_get_tools/providers/atmos/cfgs/barra2_r2.yaml +85 -0
- tfv_get_tools/providers/atmos/cfgs/barra2_re2.yaml +70 -0
- tfv_get_tools/providers/atmos/cfgs/cfsr.yaml +68 -0
- tfv_get_tools/providers/atmos/cfgs/era5.yaml +77 -0
- tfv_get_tools/providers/atmos/cfgs/era5_gcp.yaml +77 -0
- tfv_get_tools/providers/atmos/cfsr.py +207 -0
- tfv_get_tools/providers/atmos/era5.py +20 -0
- tfv_get_tools/providers/atmos/era5_gcp.py +20 -0
- tfv_get_tools/providers/ocean/cfgs/copernicus_blk.yaml +64 -0
- tfv_get_tools/providers/ocean/cfgs/copernicus_glo.yaml +67 -0
- tfv_get_tools/providers/ocean/cfgs/copernicus_nws.yaml +62 -0
- tfv_get_tools/providers/ocean/cfgs/hycom.yaml +73 -0
- tfv_get_tools/providers/ocean/copernicus_ocean.py +457 -0
- tfv_get_tools/providers/ocean/hycom.py +611 -0
- tfv_get_tools/providers/wave/cawcr.py +166 -0
- tfv_get_tools/providers/wave/cfgs/cawcr_aus_10m.yaml +39 -0
- tfv_get_tools/providers/wave/cfgs/cawcr_aus_4m.yaml +39 -0
- tfv_get_tools/providers/wave/cfgs/cawcr_glob_24m.yaml +39 -0
- tfv_get_tools/providers/wave/cfgs/cawcr_pac_10m.yaml +39 -0
- tfv_get_tools/providers/wave/cfgs/cawcr_pac_4m.yaml +39 -0
- tfv_get_tools/providers/wave/cfgs/copernicus_glo.yaml +56 -0
- tfv_get_tools/providers/wave/cfgs/copernicus_nws.yaml +51 -0
- tfv_get_tools/providers/wave/cfgs/era5.yaml +48 -0
- tfv_get_tools/providers/wave/cfgs/era5_gcp.yaml +48 -0
- tfv_get_tools/providers/wave/copernicus_wave.py +38 -0
- tfv_get_tools/providers/wave/era5.py +232 -0
- tfv_get_tools/providers/wave/era5_gcp.py +169 -0
- tfv_get_tools/tide/__init__.py +2 -0
- tfv_get_tools/tide/_nodestring.py +214 -0
- tfv_get_tools/tide/_tidal_base.py +568 -0
- tfv_get_tools/utilities/_tfv_bc.py +78 -0
- tfv_get_tools/utilities/horizontal_padding.py +89 -0
- tfv_get_tools/utilities/land_masking.py +93 -0
- tfv_get_tools/utilities/parsers.py +44 -0
- tfv_get_tools/utilities/warnings.py +38 -0
- tfv_get_tools/wave.py +179 -0
- tfv_get_tools-0.2.0.dist-info/METADATA +286 -0
- tfv_get_tools-0.2.0.dist-info/RECORD +62 -0
- tfv_get_tools-0.2.0.dist-info/WHEEL +5 -0
- tfv_get_tools-0.2.0.dist-info/entry_points.txt +5 -0
- tfv_get_tools-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""Ocean CLI tool
|
|
2
|
+
|
|
3
|
+
This tool provides two sub-programs:
|
|
4
|
+
- Downloading raw ocean physics data
|
|
5
|
+
- Merging raw ocean physics data and assisting with TUFLOW FV fvc template setup
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from argparse import ArgumentParser
|
|
10
|
+
import sys
|
|
11
|
+
import textwrap
|
|
12
|
+
|
|
13
|
+
from tfv_get_tools.cli._cli_base import CLIBase, check_bbox
|
|
14
|
+
from tfv_get_tools import DownloadOcean, MergeOcean
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def print_ocean_info():
|
|
18
|
+
"""Returns detailed help text for GetOcean"""
|
|
19
|
+
return textwrap.dedent("""
|
|
20
|
+
GetOcean
|
|
21
|
+
=======================================
|
|
22
|
+
|
|
23
|
+
This tool is designed to support users with downloading ocean physics datasets
|
|
24
|
+
from common online publicly available sources, as well as subsequent
|
|
25
|
+
pre-processing and collation for TUFLOW FV modelling.
|
|
26
|
+
The ideology of the tool is to provide the datasets in a true to original
|
|
27
|
+
raw format (program "A"), and then a processed "simplified"
|
|
28
|
+
merged format ready for TUFLOW FV modelling (program "B").
|
|
29
|
+
|
|
30
|
+
GetOcean works with ocean physics data including sea surface height, water
|
|
31
|
+
temperature, salinity, and ocean current velocity components (u, v).
|
|
32
|
+
|
|
33
|
+
There are several data sources and sub-models available currently. These are listed
|
|
34
|
+
below. Some of these may require registration.
|
|
35
|
+
|
|
36
|
+
Available data sources and sub-models:
|
|
37
|
+
-------------
|
|
38
|
+
1. (Default) "HYCOM" - Global Ocean Forecasting System
|
|
39
|
+
- "default" - Global ocean analysis and forecast system
|
|
40
|
+
|
|
41
|
+
2. Other sources available - see documentation
|
|
42
|
+
|
|
43
|
+
Example Usage:
|
|
44
|
+
---------
|
|
45
|
+
Download HYCOM Ocean Data - all defaults, daily timestep
|
|
46
|
+
`GetOcean A 2011-01-01 2012-01-01 145 150 -30 -25`
|
|
47
|
+
|
|
48
|
+
Download HYCOM with 3-hourly timestep and depth limits
|
|
49
|
+
`GetOcean A 2011-01-01 2012-01-01 145 150 -30 -25 -ts 3 -z 0 100`
|
|
50
|
+
|
|
51
|
+
Merge Ocean Data - all defaults, merge all data in the raw folder
|
|
52
|
+
`GetOcean B`
|
|
53
|
+
|
|
54
|
+
Merge Ocean Data with reprojection and local time
|
|
55
|
+
`GetOcean B -tz 10 -ltz AEST -rp 7856`
|
|
56
|
+
|
|
57
|
+
For more specific help, please use:
|
|
58
|
+
`GetOcean A -h` or `GetOcean B -h`
|
|
59
|
+
""")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def entry():
|
|
63
|
+
"""This is the entrypoint to the CLI, linked in the pyproject.toml"""
|
|
64
|
+
cli = GetOcean()
|
|
65
|
+
sys.argv = check_bbox(sys.argv)
|
|
66
|
+
cli.run_cli()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class GetOcean(CLIBase):
|
|
70
|
+
def __init__(self, download_func=None, merge_func=None):
|
|
71
|
+
super().__init__("GetOcean", "Tool for downloading and merging Ocean data")
|
|
72
|
+
|
|
73
|
+
# Allow injection of functions for testing
|
|
74
|
+
self.download_func = download_func or DownloadOcean
|
|
75
|
+
self.merge_func = merge_func or MergeOcean
|
|
76
|
+
|
|
77
|
+
dparser = self.add_download_parser(
|
|
78
|
+
"A",
|
|
79
|
+
"Download raw Ocean files for a set time period and bounding box extents",
|
|
80
|
+
)
|
|
81
|
+
self.add_merge_parser(
|
|
82
|
+
"B",
|
|
83
|
+
"Merge raw Ocean files into a single netcdf, and optionally write a TUFLOW FV FVC file",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Add ocean-specific download arguments
|
|
87
|
+
dparser.add_argument(
|
|
88
|
+
"-ts",
|
|
89
|
+
"--timestep",
|
|
90
|
+
default=24,
|
|
91
|
+
type=int,
|
|
92
|
+
help="Download timestep interval in hours, only relevant for HYCOM. Must be a multiple of 3 (highest resolution available). Default is 24 (daily). All sources other than HYCOM are downloaded in the best available time resolution.",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
dparser.add_argument(
|
|
96
|
+
"-z",
|
|
97
|
+
"--zlim",
|
|
98
|
+
nargs=2,
|
|
99
|
+
type=float,
|
|
100
|
+
default=None,
|
|
101
|
+
help='Minimum and maximum depth "zmin zmax". Defaults to the maximum for source.',
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.add_info_parser()
|
|
105
|
+
|
|
106
|
+
def run_cli(self):
|
|
107
|
+
"""Parse arguments and execute the appropriate function."""
|
|
108
|
+
args = self.parser.parse_args()
|
|
109
|
+
if args.command is not None:
|
|
110
|
+
args.func(args)
|
|
111
|
+
else:
|
|
112
|
+
self.parser.print_help()
|
|
113
|
+
|
|
114
|
+
def add_info_parser(self):
|
|
115
|
+
parser = self.subparsers.add_parser('info', help="Print detailed information about this program and the options")
|
|
116
|
+
parser.set_defaults(func=self.print_detailed_info)
|
|
117
|
+
|
|
118
|
+
def print_detailed_info(self, args):
|
|
119
|
+
text = print_ocean_info()
|
|
120
|
+
print(text)
|
|
121
|
+
|
|
122
|
+
def add_source_arguments(self, parser: ArgumentParser):
|
|
123
|
+
"""Add source arguments
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
parser: The parser to add arguments to.
|
|
127
|
+
"""
|
|
128
|
+
super().add_source_arguments(parser)
|
|
129
|
+
|
|
130
|
+
parser.add_argument(
|
|
131
|
+
'--info',
|
|
132
|
+
action="store_true",
|
|
133
|
+
help="Display the full program help"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
parser.add_argument(
|
|
137
|
+
"-s",
|
|
138
|
+
"--source",
|
|
139
|
+
type=str,
|
|
140
|
+
default="HYCOM",
|
|
141
|
+
help='Ocean data source. Default = "HYCOM". Optionally others see wiki.',
|
|
142
|
+
)
|
|
143
|
+
parser.add_argument(
|
|
144
|
+
"-m",
|
|
145
|
+
"--model",
|
|
146
|
+
type=str,
|
|
147
|
+
default="default",
|
|
148
|
+
help='Model from source. Default is "default". Optionally others see wiki.',
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def run_download(self, args):
|
|
152
|
+
"""Call the DownloadOcean function
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
args: CLI argument parser
|
|
156
|
+
"""
|
|
157
|
+
xlims = tuple([float(x) for x in args.bbox[:2]])
|
|
158
|
+
ylims = tuple([float(x) for x in args.bbox[2:]])
|
|
159
|
+
|
|
160
|
+
# Handle zlim - can be None
|
|
161
|
+
zlims = tuple(args.zlim) if args.zlim is not None else None
|
|
162
|
+
|
|
163
|
+
self.download_func(
|
|
164
|
+
args.time_start,
|
|
165
|
+
args.time_end,
|
|
166
|
+
xlims,
|
|
167
|
+
ylims,
|
|
168
|
+
zlims=zlims,
|
|
169
|
+
time_interval=args.timestep,
|
|
170
|
+
source=args.source,
|
|
171
|
+
out_path=args.path,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
def run_merge(self, args):
|
|
175
|
+
"""Call the MergeOcean function
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
args: CLI argument parser
|
|
179
|
+
"""
|
|
180
|
+
# Sort out the timezone arguments
|
|
181
|
+
if (args.timezone_offset is not None) and (args.timezone_label is not None):
|
|
182
|
+
tz = (args.timezone_offset, args.timezone_label)
|
|
183
|
+
elif args.timezone_offset is not None:
|
|
184
|
+
sign = "+" if args.timezone_offset > 0 else "-"
|
|
185
|
+
tz = (args.timezone_offset, f"UTC{sign}{abs(args.timezone_offset):0.1f}")
|
|
186
|
+
elif (args.timezone_offset is None) and (args.timezone_label is not None):
|
|
187
|
+
raise ValueError("Need to supply a timezone_offset!")
|
|
188
|
+
else:
|
|
189
|
+
tz = None
|
|
190
|
+
|
|
191
|
+
self.merge_func(
|
|
192
|
+
in_path=args.in_path,
|
|
193
|
+
out_path=args.out_path,
|
|
194
|
+
fname=args.file_name,
|
|
195
|
+
source=args.source,
|
|
196
|
+
model=args.model,
|
|
197
|
+
time_start=args.time_start,
|
|
198
|
+
time_end=args.time_end,
|
|
199
|
+
write_fvc=args.write_fvc,
|
|
200
|
+
reproject=args.reproject,
|
|
201
|
+
local_tz=tz,
|
|
202
|
+
wrapto360=args.wrapto360,
|
|
203
|
+
pad_dry=args.pad_dry,
|
|
204
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from tfv_get_tools import ExtractTide
|
|
6
|
+
from tfv_get_tools.tide._tidal_base import _detect_tide_model_source
|
|
7
|
+
|
|
8
|
+
def entry():
|
|
9
|
+
parser = argparse.ArgumentParser(
|
|
10
|
+
description="""
|
|
11
|
+
Tool for extracting tidal water-levels from FES2014 or FES2022 global tidal models
|
|
12
|
+
|
|
13
|
+
This data is provided by AVISO+.
|
|
14
|
+
|
|
15
|
+
Requires the user to supply a filepath to pre-downloaded constituent .nc files.
|
|
16
|
+
These can be downloaded (after registration) from AVISO+:
|
|
17
|
+
https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html
|
|
18
|
+
"""
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"out",
|
|
23
|
+
type=str,
|
|
24
|
+
help="Output netcdf path and name (e.g., './outputs/my_tide_file.nc')",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"time_start", type=str, help="Start date of tide timeseries (yyyy-mm-dd)"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"time_end", type=str, help="End date of tide timeseries (yyyy-mm-dd)"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"nodestring",
|
|
37
|
+
type=Path,
|
|
38
|
+
help="Path to nodestring Shapefile (e.g., ./inputs/2d_ns_xx_L.shp)",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
parser.add_argument(
|
|
42
|
+
"model_dir",
|
|
43
|
+
type=Path,
|
|
44
|
+
help="Path to folder containing the tidal model files (e.g., fes2014 or fes2022b folders)",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--spacing",
|
|
49
|
+
default=2500,
|
|
50
|
+
type=float,
|
|
51
|
+
help="Approx resolution (meters) for WL verticies along nodestring (default == 2500m)",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
"--freq",
|
|
56
|
+
type=str,
|
|
57
|
+
default="15min",
|
|
58
|
+
help="Frequency of tidal data (default is '15min')",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"-tz", "--timezone_offset", default=None, type=float, help='Fixed offset hours for local timezone, e.g. "-tz 10"',
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"-ltz", "--timezone_label",
|
|
67
|
+
type=str,
|
|
68
|
+
default=None,
|
|
69
|
+
help='Custom timezone label, e.g. "-ltz AEST"',
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
parser.add_argument(
|
|
73
|
+
"--source",
|
|
74
|
+
type=str,
|
|
75
|
+
default=None,
|
|
76
|
+
help="Tidal model source name. This will attempt to be automatically detected from model_dir, but it can be overriden if there are issues."
|
|
77
|
+
)
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"-fvc",
|
|
80
|
+
"--write_fvc",
|
|
81
|
+
action="store_true",
|
|
82
|
+
help="Write a TUFLOW FV '.fvc' file to accompany extracted tide dataset",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Try to parse args - if blank, print the description
|
|
86
|
+
if len(sys.argv) == 1:
|
|
87
|
+
parser.print_help()
|
|
88
|
+
sys.exit(0)
|
|
89
|
+
args = parser.parse_args()
|
|
90
|
+
|
|
91
|
+
# Check if tz_offset or tz_label is supplied. If not, pass None.
|
|
92
|
+
if args.timezone_offset is None:
|
|
93
|
+
local_tz = None
|
|
94
|
+
else:
|
|
95
|
+
local_tz = (args.timezone_offset, args.timezone_label)
|
|
96
|
+
|
|
97
|
+
# Pull out source name if unspecified
|
|
98
|
+
model_dir = Path(args.model_dir)
|
|
99
|
+
|
|
100
|
+
if args.source is None:
|
|
101
|
+
source, model_dir = _detect_tide_model_source(model_dir)
|
|
102
|
+
else:
|
|
103
|
+
source = args.source
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
ExtractTide(
|
|
107
|
+
args.out,
|
|
108
|
+
args.tstart,
|
|
109
|
+
args.tend,
|
|
110
|
+
model_dir,
|
|
111
|
+
shapefile=args.nodestring,
|
|
112
|
+
freq=args.freq,
|
|
113
|
+
spacing=args.spacing,
|
|
114
|
+
local_tz=local_tz,
|
|
115
|
+
source=source,
|
|
116
|
+
write_fvc=args.write_fvc,
|
|
117
|
+
)
|
|
118
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Wave CLI tool
|
|
2
|
+
|
|
3
|
+
This tool provides two sub-programs:
|
|
4
|
+
- Downloading raw wave hindcast data
|
|
5
|
+
- Merging raw wave hindcast data
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from argparse import ArgumentParser
|
|
10
|
+
import sys
|
|
11
|
+
import textwrap
|
|
12
|
+
|
|
13
|
+
from tfv_get_tools.cli._cli_base import CLIBase, check_bbox
|
|
14
|
+
from tfv_get_tools import DownloadWave, MergeWave
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def print_wave_info():
|
|
18
|
+
"""Returns detailed help text for GetWave"""
|
|
19
|
+
return textwrap.dedent("""
|
|
20
|
+
GetWave
|
|
21
|
+
=======================================
|
|
22
|
+
|
|
23
|
+
This tool is designed to support users with downloading wave hindcast datasets
|
|
24
|
+
from common online publicly available sources, as well as subsequent
|
|
25
|
+
pre-processing and collation for TUFLOW FV and Other Wave modelling.
|
|
26
|
+
The ideology of the tool is to provide the datasets in a true to original
|
|
27
|
+
raw format (program "A"), and then in a processed "simplified"
|
|
28
|
+
merged format ready for model applications (program "B").
|
|
29
|
+
|
|
30
|
+
GetWave works with wave hindcast data including significant wave height,
|
|
31
|
+
wave direction, wave period, and other wave parameters from numerical
|
|
32
|
+
wave models.
|
|
33
|
+
|
|
34
|
+
There are several data sources and sub-models available currently. These are listed
|
|
35
|
+
below. Some of these may require registration.
|
|
36
|
+
|
|
37
|
+
Available data sources and sub-models:
|
|
38
|
+
-------------
|
|
39
|
+
1. (Default) "CAWCR" - CSIRO WaveWatch III Hindcast
|
|
40
|
+
- "glob_24m" - Global model with 24-minute resolution (default)
|
|
41
|
+
- Other resolutions available - see documentation
|
|
42
|
+
|
|
43
|
+
2. Other wave model sources available - see documentation
|
|
44
|
+
|
|
45
|
+
Example Usage:
|
|
46
|
+
---------
|
|
47
|
+
Download CAWCR Wave Data - all defaults
|
|
48
|
+
`GetWave A 2011-01-01 2012-01-01 145 150 -30 -25`
|
|
49
|
+
|
|
50
|
+
Download with different source/model
|
|
51
|
+
`GetWave A 2011-01-01 2012-01-01 145 150 -30 -25 -s CAWCR -m glob_24m`
|
|
52
|
+
|
|
53
|
+
Merge Wave Data - all defaults, merge all data in the raw folder
|
|
54
|
+
`GetWave B`
|
|
55
|
+
|
|
56
|
+
Merge Wave Data with reprojection and local time
|
|
57
|
+
`GetWave B -tz 10 -ltz AEST -rp 7856`
|
|
58
|
+
|
|
59
|
+
For more specific help, please use:
|
|
60
|
+
`GetWave A -h` or `GetWave B -h`
|
|
61
|
+
""")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def entry():
|
|
65
|
+
"""This is the entrypoint to the CLI, linked in the pyproject.toml"""
|
|
66
|
+
cli = GetWave()
|
|
67
|
+
sys.argv = check_bbox(sys.argv)
|
|
68
|
+
cli.run_cli()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class GetWave(CLIBase):
|
|
72
|
+
def __init__(self, download_func=None, merge_func=None):
|
|
73
|
+
super().__init__("GetWave", "Tool for downloading and merging Wave data")
|
|
74
|
+
|
|
75
|
+
# Allow injection of functions for testing
|
|
76
|
+
self.download_func = download_func or DownloadWave
|
|
77
|
+
self.merge_func = merge_func or MergeWave
|
|
78
|
+
|
|
79
|
+
self.add_download_parser(
|
|
80
|
+
"A",
|
|
81
|
+
"Download raw wave files for a set time period and bounding box extents"
|
|
82
|
+
)
|
|
83
|
+
self.add_merge_parser(
|
|
84
|
+
"B",
|
|
85
|
+
"Merge raw Wave files into a single netcdf, and optionally write a TUFLOW FV FVC file"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
self.add_info_parser()
|
|
89
|
+
|
|
90
|
+
def run_cli(self):
|
|
91
|
+
"""Parse arguments and execute the appropriate function."""
|
|
92
|
+
args = self.parser.parse_args()
|
|
93
|
+
if args.command is not None:
|
|
94
|
+
args.func(args)
|
|
95
|
+
else:
|
|
96
|
+
self.parser.print_help()
|
|
97
|
+
|
|
98
|
+
def add_info_parser(self):
|
|
99
|
+
parser = self.subparsers.add_parser('info', help="Print detailed information about this program and the options")
|
|
100
|
+
parser.set_defaults(func=self.print_detailed_info)
|
|
101
|
+
|
|
102
|
+
def print_detailed_info(self, args):
|
|
103
|
+
text = print_wave_info()
|
|
104
|
+
print(text)
|
|
105
|
+
|
|
106
|
+
def add_source_arguments(self, parser: ArgumentParser):
|
|
107
|
+
"""Add source arguments
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
parser: The parser to add arguments to.
|
|
111
|
+
"""
|
|
112
|
+
super().add_source_arguments(parser)
|
|
113
|
+
|
|
114
|
+
parser.add_argument(
|
|
115
|
+
'--info',
|
|
116
|
+
action="store_true",
|
|
117
|
+
help="Display the full program help"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
parser.add_argument(
|
|
121
|
+
"-s",
|
|
122
|
+
"--source",
|
|
123
|
+
type=str,
|
|
124
|
+
default="CAWCR",
|
|
125
|
+
help='Wave data source. Default = "CAWCR" (CSIRO WaveWatch III Hindcast). Optionally others see wiki.',
|
|
126
|
+
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"-m",
|
|
129
|
+
"--model",
|
|
130
|
+
type=str,
|
|
131
|
+
default="glob_24m",
|
|
132
|
+
help='Model from source. Default = "glob_24m" (global model from source "CAWCR"). Optionally others see wiki.',
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def run_download(self, args):
|
|
136
|
+
"""Call the DownloadWave function
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
args: CLI argument parser
|
|
140
|
+
"""
|
|
141
|
+
xlims = tuple([float(x) for x in args.bbox[:2]])
|
|
142
|
+
ylims = tuple([float(x) for x in args.bbox[2:]])
|
|
143
|
+
|
|
144
|
+
self.download_func(
|
|
145
|
+
args.time_start,
|
|
146
|
+
args.time_end,
|
|
147
|
+
xlims,
|
|
148
|
+
ylims,
|
|
149
|
+
source=args.source,
|
|
150
|
+
out_path=args.path,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
def run_merge(self, args):
|
|
154
|
+
"""Call the MergeWave function
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
args: CLI argument parser
|
|
158
|
+
"""
|
|
159
|
+
# Sort out the timezone arguments
|
|
160
|
+
if (args.timezone_offset is not None) and (args.timezone_label is not None):
|
|
161
|
+
tz = (args.timezone_offset, args.timezone_label)
|
|
162
|
+
elif args.timezone_offset is not None:
|
|
163
|
+
sign = "+" if args.timezone_offset > 0 else "-"
|
|
164
|
+
tz = (args.timezone_offset, f"UTC{sign}{abs(args.timezone_offset):0.1f}")
|
|
165
|
+
elif (args.timezone_offset is None) and (args.timezone_label is not None):
|
|
166
|
+
raise ValueError("Need to supply a timezone_offset!")
|
|
167
|
+
else:
|
|
168
|
+
tz = None
|
|
169
|
+
|
|
170
|
+
self.merge_func(
|
|
171
|
+
in_path=args.in_path,
|
|
172
|
+
out_path=args.out_path,
|
|
173
|
+
fname=args.file_name,
|
|
174
|
+
source=args.source,
|
|
175
|
+
model=args.model,
|
|
176
|
+
time_start=args.time_start,
|
|
177
|
+
time_end=args.time_end,
|
|
178
|
+
write_fvc=args.write_fvc,
|
|
179
|
+
reproject=args.reproject,
|
|
180
|
+
local_tz=tz,
|
|
181
|
+
wrapto360=args.wrapto360,
|
|
182
|
+
pad_dry=args.pad_dry,
|
|
183
|
+
)
|