wavespectra 3.15.2__tar.gz → 3.17.0__tar.gz

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.
Files changed (61) hide show
  1. {wavespectra-3.15.2/wavespectra.egg-info → wavespectra-3.17.0}/PKG-INFO +1 -1
  2. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/__init__.py +1 -1
  3. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/select.py +34 -15
  4. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/dataset.py +14 -11
  5. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/era5.py +22 -5
  6. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/ncswan.py +3 -3
  7. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/ndbc.py +0 -1
  8. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/octopus.py +27 -12
  9. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/swan.py +21 -11
  10. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/specdataset.py +19 -4
  11. {wavespectra-3.15.2 → wavespectra-3.17.0/wavespectra.egg-info}/PKG-INFO +1 -1
  12. {wavespectra-3.15.2 → wavespectra-3.17.0}/AUTHORS.rst +0 -0
  13. {wavespectra-3.15.2 → wavespectra-3.17.0}/LICENSE.txt +0 -0
  14. {wavespectra-3.15.2 → wavespectra-3.17.0}/README.rst +0 -0
  15. {wavespectra-3.15.2 → wavespectra-3.17.0}/pyproject.toml +0 -0
  16. {wavespectra-3.15.2 → wavespectra-3.17.0}/setup.cfg +0 -0
  17. {wavespectra-3.15.2 → wavespectra-3.17.0}/setup.py +0 -0
  18. {wavespectra-3.15.2 → wavespectra-3.17.0}/tests/test_cookiecutter_template.py +0 -0
  19. {wavespectra-3.15.2 → wavespectra-3.17.0}/tests/test_specarray.py +0 -0
  20. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/cli.py +0 -0
  21. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/construct/__init__.py +0 -0
  22. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/construct/helpers.py +0 -0
  23. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/construct/jonswap.py +0 -0
  24. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/construct/ochihubble.py +0 -0
  25. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/__init__.py +0 -0
  26. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/attributes.py +0 -0
  27. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/attributes.yml +0 -0
  28. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/npstats.py +0 -0
  29. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/swan.py +0 -0
  30. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/utils.py +0 -0
  31. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/watershed.py +0 -0
  32. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/core/xrstats.py +0 -0
  33. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/__init__.py +0 -0
  34. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/funwave.py +0 -0
  35. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/json.py +0 -0
  36. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/ndbc_ascii.py +0 -0
  37. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/netcdf.py +0 -0
  38. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/octopus.py +0 -0
  39. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/spotter.py +0 -0
  40. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/swan.py +0 -0
  41. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/triaxys.py +0 -0
  42. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/wavespectra.py +0 -0
  43. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/ww3.py +0 -0
  44. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/ww3_station.py +0 -0
  45. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/input/wwm.py +0 -0
  46. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/__init__.py +0 -0
  47. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/funwave.py +0 -0
  48. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/json.py +0 -0
  49. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/netcdf.py +0 -0
  50. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/orcaflex.py +0 -0
  51. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/ww3.py +0 -0
  52. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/output/ww3.yml +0 -0
  53. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/plot.py +0 -0
  54. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/specarray.py +0 -0
  55. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/specpart/specpart.f90 +0 -0
  56. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra/specpart/specpart.pyf +0 -0
  57. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra.egg-info/SOURCES.txt +0 -0
  58. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra.egg-info/dependency_links.txt +0 -0
  59. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra.egg-info/entry_points.txt +0 -0
  60. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra.egg-info/requires.txt +0 -0
  61. {wavespectra-3.15.2 → wavespectra-3.17.0}/wavespectra.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wavespectra
3
- Version: 3.15.2
3
+ Version: 3.17.0
4
4
  Summary: Library for ocean wave spectra
5
5
  Author-email: Wavespectra Developers <r.guedes@oceanum.science>
6
6
  Maintainer-email: Rafael Guedes <r.guedes@oceanum.science>, Tom Durrant <t.durrant@oceanum.science>
@@ -13,7 +13,7 @@ except ImportError:
13
13
  warnings.warn("Cannot import accessors at the main module level")
14
14
 
15
15
 
16
- __version__ = "3.15.2"
16
+ __version__ = "3.17.0"
17
17
 
18
18
 
19
19
  def _import_read_functions(pkgname="input"):
@@ -1,11 +1,11 @@
1
1
  """Interpolate stations."""
2
+ import logging
3
+
2
4
  import numpy as np
3
5
  import xarray as xr
4
- import logging
5
6
 
6
7
  from wavespectra.core.attributes import attrs, set_spec_attributes
7
8
 
8
-
9
9
  logger = logging.getLogger(__name__)
10
10
 
11
11
 
@@ -119,12 +119,12 @@ class Coordinates:
119
119
  def nearest(self, lon, lat):
120
120
  """Nearest station in (dset_lons, dset_lats) to site (lon, lat).
121
121
 
122
- Args:
123
- lon (float): Longitude to locate from lons.
124
- lat (float): Latitude to locate from lats.
122
+ Args:
123
+ lon (float): Longitude to locate from lons.
124
+ lat (float): Latitude to locate from lats.
125
125
 
126
- Returns:
127
- Index and distance of closest station.
126
+ Returns:
127
+ Index and distance of closest station.
128
128
 
129
129
  """
130
130
  dist = self.distance(lon, lat)
@@ -142,6 +142,7 @@ def sel_nearest(
142
142
  exact=False,
143
143
  dset_lons=None,
144
144
  dset_lats=None,
145
+ missing="raise",
145
146
  ):
146
147
  """Select sites from nearest distance.
147
148
 
@@ -154,6 +155,9 @@ def sel_nearest(
154
155
  exact (bool): Require exact matches.
155
156
  dset_lons (array): Longitude of stations in dset.
156
157
  dset_lats (array): Latitude of stations in dset.
158
+ missing (str): Action to take if no site is found within tolerance:
159
+ - 'raise': raise an error
160
+ - 'ignore': skip site
157
161
 
158
162
  Returns:
159
163
  Selected SpecDataset at locations defined by (lons, lats).
@@ -170,19 +174,34 @@ def sel_nearest(
170
174
  for lon, lat in zip(coords.lons, coords.lats):
171
175
  closest_id, closest_dist = coords.nearest(lon, lat)
172
176
  if closest_dist > tolerance:
173
- raise AssertionError(
174
- f"Nearest site from (lat={lat}, lon={lon}) is {closest_dist:g} "
175
- f"deg away but tolerance is {tolerance:g} deg."
176
- )
177
+ if missing == "raise":
178
+ raise AssertionError(
179
+ f"Nearest site in dataset from ({lon, lat}) is {closest_dist:g} "
180
+ f"deg away but tolerance is {tolerance:g} deg"
181
+ )
182
+ elif missing == "ignore":
183
+ logger.debug(
184
+ f"No site in dataset within tolerance={tolerance} deg "
185
+ f"from requested location ({lon, lat}), skipping"
186
+ )
187
+ continue
177
188
  if exact and closest_dist > 0:
178
189
  raise AssertionError(
179
- f"Exact match required but no site at (lat={lat}, lon={lon}), "
190
+ f"Exact match required but no site in dataset at ({lon, lat}), "
180
191
  f"nearest site is {closest_dist} deg away."
181
192
  )
193
+ if unique and closest_id in station_ids:
194
+ logger.debug(
195
+ f"Nearest site at ({lon, lat}) is repeated, skipping "
196
+ f"because unique=True"
197
+ )
198
+ continue
182
199
  station_ids.append(closest_id)
183
- if unique:
184
- station_ids = list(set(station_ids))
185
-
200
+ if not station_ids:
201
+ raise ValueError(
202
+ f"No site in dataset found within tolerance={tolerance} deg of any site "
203
+ f"{list(zip(coords.lons, coords.lats))}"
204
+ )
186
205
  dsout = dset.isel(**{attrs.SITENAME: station_ids})
187
206
 
188
207
  # Return longitudes in the convention provided
@@ -4,6 +4,8 @@ import logging
4
4
  from wavespectra.input.ww3 import from_ww3
5
5
  from wavespectra.input.wwm import from_wwm
6
6
  from wavespectra.input.ncswan import from_ncswan
7
+ from wavespectra.input.era5 import from_era5
8
+ from wavespectra.input.ndbc import from_ndbc
7
9
  from wavespectra.specdataset import SpecDataset
8
10
 
9
11
  logger = logging.getLogger(__name__)
@@ -20,17 +22,12 @@ def read_dataset(dset):
20
22
  consistent any supported file format (currently WW3, SWAN and WWM).
21
23
 
22
24
  """
23
- vars_wavespectra = {"freq", "dir", "site", "efth", "lon", "lat"}
24
- vars_ww3 = {"frequency", "direction", "station", "efth", "longitude", "latitude"}
25
- vars_wwm = {"nfreq", "ndir", "nbstation", "AC", "lon", "lat"}
26
- vars_ncswan = {
27
- "frequency",
28
- "direction",
29
- "points",
30
- "density",
31
- "longitude",
32
- "latitude",
33
- }
25
+ vars_wavespectra = {"freq", "dir", "site", "efth"}
26
+ vars_ww3 = {"frequency", "direction", "station", "efth"}
27
+ vars_wwm = {"nfreq", "ndir", "nbstation", "AC"}
28
+ vars_era5 = {"frequency", "direction", "d2fd"}
29
+ vars_ndbc = {"frequency", "direction", "spectral_wave_density"}
30
+ vars_ncswan = {"frequency", "direction", "points", "density"}
34
31
 
35
32
  vars_dset = set(dset.variables.keys()).union(dset.dims)
36
33
  if not vars_wavespectra - vars_dset:
@@ -45,6 +42,12 @@ def read_dataset(dset):
45
42
  elif not vars_wwm - vars_dset:
46
43
  logger.debug("Dataset identified as wwm")
47
44
  func = from_wwm
45
+ elif not vars_era5 - vars_dset:
46
+ logger.debug("Dataset identified as era5")
47
+ func = from_era5
48
+ elif not vars_ndbc - vars_dset:
49
+ logger.debug("Dataset identified as ndbc")
50
+ func = from_ndbc
48
51
  else:
49
52
  raise ValueError(
50
53
  f"Cannot identify appropriate reader from dataset variables: {vars_dset}"
@@ -5,6 +5,10 @@ from wavespectra.core.attributes import attrs, set_spec_attributes
5
5
  from wavespectra.input.netcdf import read_netcdf
6
6
 
7
7
 
8
+ DEFAULT_FREQS = np.full(30, 0.03453) * (1.1 ** np.arange(0, 30))
9
+ DEFAULT_DIRS = (np.arange(7.5, 352.5 + 15, 15) + 180) % 360
10
+
11
+
8
12
  def read_era5(filename_or_fileglob, chunks={}, freqs=None, dirs=None):
9
13
  """Read Spectra from ECMWF ERA5 netCDF format.
10
14
 
@@ -21,12 +25,12 @@ def read_era5(filename_or_fileglob, chunks={}, freqs=None, dirs=None):
21
25
  - dset (SpecDataset): spectra dataset object read from netcdf file.
22
26
 
23
27
  Note:
28
+ - Frequency and diirection coordinates seem to have only integer positions
29
+ which is why they are allowed to be specified as a parameter.
24
30
  - If file is large to fit in memory, consider specifying chunks for
25
31
  'time' and/or 'station' dims.
26
32
 
27
33
  """
28
- default_freqs = np.full(30, 0.03453) * (1.1 ** np.arange(0, 30))
29
- default_dirs = direction = (np.arange(7.5, 352.5 + 15, 15) + 180) % 360
30
34
 
31
35
  dset = read_netcdf(
32
36
  filename_or_fileglob,
@@ -38,15 +42,28 @@ def read_era5(filename_or_fileglob, chunks={}, freqs=None, dirs=None):
38
42
  timename="time",
39
43
  chunks=chunks,
40
44
  )
45
+ return from_era5(dset, freqs=freqs, dirs=dirs)
46
+
47
+
48
+ def from_era5(dset, freqs=None, dirs=None):
49
+ """Format ERA5 netcdf dataset to receive wavespectra accessor.
50
+
51
+ Args:
52
+ - dset (xr.Dataset): Dataset created from a SWAN netcdf file.
53
+
54
+ Returns:
55
+ - Formated dataset with the SpecDataset accessor in the `spec` namespace.
56
+
57
+ """
41
58
 
42
59
  # Convert ERA5 format to wavespectra format
43
60
  dset = 10**dset * np.pi / 180
44
61
  dset = dset.fillna(0)
45
62
 
46
- dset[attrs.FREQNAME] = freqs if freqs else default_freqs
47
- dset[attrs.DIRNAME] = dirs if dirs else default_dirs
63
+ dset[attrs.FREQNAME] = freqs if freqs else DEFAULT_FREQS
64
+ dset[attrs.DIRNAME] = dirs if dirs else DEFAULT_DIRS
48
65
 
49
66
  # Setting standard attributes
50
67
  set_spec_attributes(dset)
51
68
 
52
- return dset
69
+ return dset
@@ -53,11 +53,11 @@ def read_ncswan(filename_or_fileglob, file_format="netcdf", mapping=MAPPING, chu
53
53
  def from_ncswan(dset):
54
54
  """Format SWAN netcdf dataset to receive wavespectra accessor.
55
55
 
56
- Args:o
57
- dset (xr.Dataset): Dataset created from a SWAN netcdf file.
56
+ Args:
57
+ - dset (xr.Dataset): Dataset created from a SWAN netcdf file.
58
58
 
59
59
  Returns:
60
- Formated dataset with the SpecDataset accessor in the `spec` namespace.
60
+ - Formated dataset with the SpecDataset accessor in the `spec` namespace.
61
61
 
62
62
  """
63
63
  dset = dset.rename(MAPPING)
@@ -3,7 +3,6 @@
3
3
  https://dods.ndbc.noaa.gov/
4
4
 
5
5
  """
6
- import warnings
7
6
  import xarray as xr
8
7
  import numpy as np
9
8
 
@@ -6,7 +6,14 @@ from wavespectra.core.attributes import attrs
6
6
 
7
7
 
8
8
  def to_octopus(
9
- self, filename, site_id="spec", fcut=0.125, missing_val=-99999, ntime=None
9
+ self,
10
+ filename,
11
+ site_id="spec",
12
+ fcut=0.125,
13
+ missing_val=-99999,
14
+ ntime=None,
15
+ lons=None,
16
+ lats=None,
10
17
  ):
11
18
  """Save spectra in Octopus format.
12
19
 
@@ -17,11 +24,15 @@ def to_octopus(
17
24
  - missing_value (int): missing value in output file.
18
25
  - ntime (int, None): number of times to load into memory before dumping output
19
26
  file if full dataset does not fit into memory, choose None to load all times.
27
+ - lons: (np.array, None): longitudes to use for each site if not in dataset.
28
+ - lats: (np.array, None): latitudes to use for each site if not in dataset.
20
29
 
21
30
  Note:
22
- - dataset needs to have lon/lat/time coordinates.
23
- - dataset with multiple locations dumped at same file with one location
24
- header per site.
31
+ - lons/lats parameters may be prescribed to set site locations if lon/lat are
32
+ not variables in the dataset (their sizes must match the number of sites).
33
+ - If lons/lats are not specified and the dataset does not have lon/lat coords,
34
+ all coordinates default to zero.
35
+ - multiple locations dumped at same file with one location header per site.
25
36
  - 1D spectra not supported.
26
37
  - ntime=None optimises speed as the dataset is loaded into memory however the
27
38
  dataset may not fit into memory in which case a smaller number of times may
@@ -34,6 +45,15 @@ def to_octopus(
34
45
  dset_stacked = self._check_and_stack_dims()
35
46
  ntime = min(ntime or dset_stacked.time.size, dset_stacked.time.size)
36
47
 
48
+ # Handle datasets with missing lon/lat
49
+ for arr, name in zip((lons, lats), (attrs.LONNAME, attrs.LATNAME)):
50
+ if name not in dset_stacked.data_vars:
51
+ if arr is None:
52
+ arr = np.zeros(dset_stacked.site.size)
53
+ elif len(arr) != dset_stacked.site.size:
54
+ raise ValueError(f"{name} must have same size as site dimension")
55
+ dset_stacked[name] = (("site",), arr)
56
+
37
57
  # Writing format definitions
38
58
  fmt = ",".join(len(self.freq) * ["{:8.7f}"]) + ","
39
59
  fmt2 = "{:0.0f}," + fmt + "{:8.7f}"
@@ -106,7 +126,7 @@ def to_octopus(
106
126
 
107
127
  # Put everything in dict because it is a lot faster to slice
108
128
  dset_dict = {v: dset[v].values for v in dset.data_vars}
109
- data_vars = list(dset_dict.keys() - ("lon", "lat"))
129
+ data_vars = list(dset_dict.keys() - (attrs.LONNAME, attrs.LATNAME))
110
130
 
111
131
  # Extend energy array with directions values and sums along frequencies
112
132
  right = dset["energy"].sum(dim="freq").expand_dims({"freq": [10]})
@@ -115,13 +135,8 @@ def to_octopus(
115
135
  (left.assign_coords({"freq": [-10]}), dset["energy"], right), dim="freq"
116
136
  ).transpose(attrs.TIMENAME, attrs.SITENAME, attrs.DIRNAME, attrs.FREQNAME).values
117
137
 
118
- try:
119
- lons = dset_dict["lon"]
120
- lats = dset_dict["lat"]
121
- except KeyError as err:
122
- raise NotImplementedError(
123
- "lon-lat variables are required to write Octopus spectra file"
124
- ) from err
138
+ lons = np.atleast_1d(dset_dict[attrs.LONNAME])
139
+ lats = np.atleast_1d(dset_dict[attrs.LATNAME])
125
140
 
126
141
  # Open output file
127
142
  with open(filename, mode) as f:
@@ -1,4 +1,5 @@
1
1
  """SWAN ASCII output plugin."""
2
+ import numpy as np
2
3
  from wavespectra.core.attributes import attrs
3
4
  from wavespectra.core.swan import SwanSpecFile
4
5
 
@@ -8,7 +9,9 @@ def to_swan(
8
9
  filename,
9
10
  append=False,
10
11
  id="Created by wavespectra",
11
- ntime=None
12
+ ntime=None,
13
+ lons=None,
14
+ lats=None,
12
15
  ):
13
16
  """Write spectra in SWAN ASCII format.
14
17
 
@@ -18,9 +21,14 @@ def to_swan(
18
21
  - id (str): used for header in output file.
19
22
  - ntime (int, None): number of times to load into memory before dumping output
20
23
  file if full dataset does not fit into memory, choose None to load all times.
24
+ - lons: (np.array, None): longitudes to use for each site, if None use.
25
+ - lats: (np.array, None): latitudes to use for each site, if None use.
21
26
 
22
27
  Note:
23
- - Only datasets with lat/lon coordinates are currently supported.
28
+ - lons/lats parameters may be prescribed to set site locations if lon/lat are
29
+ not variables in the dataset (their sizes must match the number of sites).
30
+ - If lons/lats are not specified and the dataset does not have lon/lat coords,
31
+ all coordinates default to zero.
24
32
  - Extra dimensions other than time, site, lon, lat, freq, dim not yet
25
33
  supported.
26
34
  - Only 2D spectra E(f,d) are currently supported.
@@ -33,6 +41,15 @@ def to_swan(
33
41
  dset = self._check_and_stack_dims()
34
42
  ntime = min(ntime or dset.time.size, dset.time.size)
35
43
 
44
+ # Handle datasets with missing lon/lat
45
+ for arr, name in zip((lons, lats), (attrs.LONNAME, attrs.LATNAME)):
46
+ if name not in dset.data_vars:
47
+ if arr is None:
48
+ arr = np.zeros(dset.site.size)
49
+ elif len(arr) != dset.site.size:
50
+ raise ValueError(f"{name} must have same size as site dimension")
51
+ dset[name] = (("site",), arr)
52
+
36
53
  # Ensure time dimension exists
37
54
  is_time = attrs.TIMENAME in dset[attrs.SPECNAME].dims
38
55
  if not is_time:
@@ -50,20 +67,13 @@ def to_swan(
50
67
  dset = dset.transpose(attrs.TIMENAME, attrs.SITENAME, attrs.FREQNAME, attrs.DIRNAME)
51
68
 
52
69
  # Instantiate swan object
53
- try:
54
- x = dset.lon.values
55
- y = dset.lat.values
56
- except AttributeError as err:
57
- raise NotImplementedError(
58
- "lon-lat variables are required to write SWAN spectra file"
59
- ) from err
60
70
  sfile = SwanSpecFile(
61
71
  filename,
62
72
  freqs=dset.freq,
63
73
  dirs=dset.dir,
64
74
  time=is_time,
65
- x=x,
66
- y=y,
75
+ x=dset[attrs.LONNAME].values,
76
+ y=dset[attrs.LATNAME].values,
67
77
  append=append,
68
78
  id=id,
69
79
  )
@@ -96,10 +96,25 @@ class SpecDataset(metaclass=Plugin):
96
96
  )
97
97
 
98
98
  # If grid reshape into site, if neither define fake site dimension
99
- if set(("lon", "lat")).issubset(dset.dims):
100
- dset = dset.stack(site=("lat", "lon"))
101
- elif "site" not in dset.dims:
102
- dset = dset.expand_dims("site")
99
+ if set((attrs.LONNAME, attrs.LATNAME)).issubset(dset.dims):
100
+ dset = dset.stack(site=(attrs.LATNAME, attrs.LONNAME), create_index=False)
101
+ elif attrs.SITENAME not in dset.dims:
102
+ dset = dset.expand_dims(attrs.SITENAME)
103
+
104
+ # Ensure lon/lat are not coordinates
105
+ if attrs.LONNAME in dset.coords:
106
+ dset = dset.reset_coords(attrs.LONNAME)
107
+ if attrs.LATNAME in dset.coords:
108
+ dset = dset.reset_coords(attrs.LATNAME)
109
+
110
+ # Ensure site dim in lon/lat
111
+ for coord in [attrs.LONNAME, attrs.LATNAME]:
112
+ if coord in dset.data_vars and attrs.SITENAME not in dset[coord].dims:
113
+ dset[coord] = dset[coord].expand_dims(attrs.SITENAME)
114
+
115
+ # Ensure times comes first
116
+ if attrs.TIMENAME in dset.dims:
117
+ dset = dset.transpose(attrs.TIMENAME, attrs.SITENAME, ...)
103
118
 
104
119
  return dset
105
120
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wavespectra
3
- Version: 3.15.2
3
+ Version: 3.17.0
4
4
  Summary: Library for ocean wave spectra
5
5
  Author-email: Wavespectra Developers <r.guedes@oceanum.science>
6
6
  Maintainer-email: Rafael Guedes <r.guedes@oceanum.science>, Tom Durrant <t.durrant@oceanum.science>
File without changes
File without changes
File without changes
File without changes
File without changes