widetrax 0.0.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.
- widetrax/DataPreprocessing.py +638 -0
- widetrax/Spectram.py +232 -0
- widetrax/__init__.py +5 -0
- widetrax/version.py +1 -0
- widetrax-0.0.1.dist-info/LICENSE +201 -0
- widetrax-0.0.1.dist-info/METADATA +31 -0
- widetrax-0.0.1.dist-info/RECORD +9 -0
- widetrax-0.0.1.dist-info/WHEEL +5 -0
- widetrax-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
from collections import defaultdict
|
|
2
|
+
from datetime import datetime, timedelta
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import cartopy.crs as ccrs
|
|
8
|
+
import cartopy.feature as cfeature
|
|
9
|
+
import matplotlib.pyplot as plt
|
|
10
|
+
import numpy as np
|
|
11
|
+
import pyinterp
|
|
12
|
+
import pyinterp.fill as fill
|
|
13
|
+
import xarray as xr
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# =============================================================================
|
|
17
|
+
# extract_xarray_in_region
|
|
18
|
+
# =============================================================================
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def extract_xarray_in_region(directory, area):
|
|
22
|
+
"""
|
|
23
|
+
Extracts xarray datasets from SWOT NetCDF data for a specific region
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
------------
|
|
28
|
+
directory : str
|
|
29
|
+
Path to the directory containing the NetCDF files
|
|
30
|
+
area : list
|
|
31
|
+
List with the boundaries of the region of interest [longitude_min, latitude_min, longitude_max, latitude_max]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
---------
|
|
36
|
+
datasets : Dict
|
|
37
|
+
Dictionary containing the xarray.Datasets for the region
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
lon_min, lat_min, lon_max, lat_max = area
|
|
42
|
+
datasets = {}
|
|
43
|
+
i = 0
|
|
44
|
+
|
|
45
|
+
variables_to_load = ["ssha", "mdt", "latitude", "longitude"]
|
|
46
|
+
files_in_dir = os.listdir(directory)
|
|
47
|
+
|
|
48
|
+
for filename in files_in_dir:
|
|
49
|
+
file_path = os.path.join(directory, filename)
|
|
50
|
+
|
|
51
|
+
ds_tmp = xr.open_dataset(file_path, chunks={})
|
|
52
|
+
variables_to_drop = [var for var in ds_tmp.variables if var not in variables_to_load]
|
|
53
|
+
ds_tmp.close()
|
|
54
|
+
del ds_tmp
|
|
55
|
+
|
|
56
|
+
# Open the file (lazy loading) excluding unnecessary variables
|
|
57
|
+
ds = xr.open_dataset(file_path, chunks={}, drop_variables=variables_to_drop)
|
|
58
|
+
|
|
59
|
+
if ds:
|
|
60
|
+
if lon_min < lon_max:
|
|
61
|
+
selection = (
|
|
62
|
+
|
|
63
|
+
(ds['latitude'] >= lat_min) &
|
|
64
|
+
(ds['latitude'] <= lat_max) &
|
|
65
|
+
(ds['longitude'] >= lon_min) &
|
|
66
|
+
(ds['longitude'] <= lon_max)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
else:
|
|
70
|
+
selection = (
|
|
71
|
+
|
|
72
|
+
(ds['latitude'] >= lat_min) &
|
|
73
|
+
(ds['latitude'] <= lat_max) &
|
|
74
|
+
(((ds['longitude'] >= lon_min) & (ds['longitude'] <= 360)) | (ds['longitude'] <= lon_max))
|
|
75
|
+
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
selection = selection.compute()
|
|
79
|
+
|
|
80
|
+
ds_area = ds.where(selection, drop=True)
|
|
81
|
+
ds.close()
|
|
82
|
+
|
|
83
|
+
if ds_area['latitude'].size > 0:
|
|
84
|
+
datasets[i] = ds_area
|
|
85
|
+
i += 1
|
|
86
|
+
|
|
87
|
+
ds_area.close()
|
|
88
|
+
|
|
89
|
+
return datasets
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# =============================================================================
|
|
93
|
+
# count_observations
|
|
94
|
+
# =============================================================================
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def count_observations(datasets, area, resolution):
|
|
98
|
+
"""
|
|
99
|
+
Calculates the number of available observations per bin in the region of interest.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Parameters
|
|
103
|
+
------------
|
|
104
|
+
datasets : Dict
|
|
105
|
+
Dictionary containing xarray.Datasets
|
|
106
|
+
area : list
|
|
107
|
+
List with the boundaries of the region of interest [longitude_min, latitude_min, longitude_max, latitude_max]
|
|
108
|
+
resolution : float
|
|
109
|
+
Grid resolution
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
---------
|
|
113
|
+
obs_count : np.ndarray
|
|
114
|
+
Array containing the number of observations per pixel
|
|
115
|
+
|
|
116
|
+
"""
|
|
117
|
+
lon_min, lat_min, lon_max, lat_max = area
|
|
118
|
+
|
|
119
|
+
# Define the grid
|
|
120
|
+
if lon_min > lon_max: # if for example lon_min est 2W=358 et lon max 5E=5
|
|
121
|
+
lon_grid = np.concatenate([np.arange(lon_min, 360, resolution),
|
|
122
|
+
np.arange(0, lon_max, resolution)])
|
|
123
|
+
else:
|
|
124
|
+
lon_grid = np.arange(lon_min, lon_max, resolution)
|
|
125
|
+
|
|
126
|
+
# for latitudes
|
|
127
|
+
lat_grid = np.arange(lat_min, lat_max, resolution)
|
|
128
|
+
|
|
129
|
+
# Create an array filled with zeros
|
|
130
|
+
obs_count = np.full((len(lat_grid), len(lon_grid)), 0)
|
|
131
|
+
|
|
132
|
+
# Iterating on xarrays in datasets dictionnary
|
|
133
|
+
for key in range(len(datasets)):
|
|
134
|
+
# print(f"{key}/{len(datasets)}")
|
|
135
|
+
|
|
136
|
+
one_dtset = datasets[key].compute()
|
|
137
|
+
|
|
138
|
+
# Iterating on rows/columns
|
|
139
|
+
for j in range(one_dtset.ssha.shape[0]):
|
|
140
|
+
for k in range(one_dtset.ssha.shape[1]):
|
|
141
|
+
valeur = one_dtset.ssha[j, k]
|
|
142
|
+
if not np.isnan(valeur):
|
|
143
|
+
lt = float(one_dtset.latitude[j, k])
|
|
144
|
+
ln = float(one_dtset.longitude[j, k])
|
|
145
|
+
|
|
146
|
+
# Find the corresponding indexes in the grid
|
|
147
|
+
lon_index = int((ln - lon_min) / resolution)
|
|
148
|
+
lat_index = int((lt - lat_min) / resolution)
|
|
149
|
+
|
|
150
|
+
if lon_index < 0:
|
|
151
|
+
lon_index = int((ln - (lon_min - 360)) / resolution)
|
|
152
|
+
|
|
153
|
+
# Increment the corresponding element in obs_count
|
|
154
|
+
obs_count[lat_index, lon_index] += 1
|
|
155
|
+
|
|
156
|
+
one_dtset.close()
|
|
157
|
+
del (one_dtset)
|
|
158
|
+
|
|
159
|
+
return obs_count
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# =============================================================================
|
|
163
|
+
# fill_nan
|
|
164
|
+
# =============================================================================
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def fill_nan(datasets, varname: str = "ssha"):
|
|
168
|
+
"""
|
|
169
|
+
Fills in missing values (NaN) in each xarray.Dataset using Gauss-Seidel method.
|
|
170
|
+
|
|
171
|
+
Parameters
|
|
172
|
+
------------
|
|
173
|
+
datasets: Dict
|
|
174
|
+
Dictionary containing xarray.Datasets
|
|
175
|
+
varname: str, optional
|
|
176
|
+
Variable name to fill in missing values.
|
|
177
|
+
Defaults to "ssha"
|
|
178
|
+
|
|
179
|
+
Returns
|
|
180
|
+
---------
|
|
181
|
+
has_converged: bool
|
|
182
|
+
Indicates whether the method has converged, returns True if the method has converged, otherwise returns False
|
|
183
|
+
filled_dataset: Dict
|
|
184
|
+
Dictionary containing xarray.Datasets (with missing values filled in)
|
|
185
|
+
"""
|
|
186
|
+
has_converged = True
|
|
187
|
+
filled_datasets = {}
|
|
188
|
+
new_key = 0
|
|
189
|
+
for key in range(len(datasets)):
|
|
190
|
+
|
|
191
|
+
# Selects only the variable of interest
|
|
192
|
+
data = datasets[key][[varname]]
|
|
193
|
+
|
|
194
|
+
latitudes = data["latitude"].values
|
|
195
|
+
longitudes = data["longitude"].values
|
|
196
|
+
values = data[varname].values
|
|
197
|
+
|
|
198
|
+
if longitudes.size > 0 and latitudes.size > 0:
|
|
199
|
+
|
|
200
|
+
# Replace all values in columns 33 and 34 with NaN (the two middle columns)
|
|
201
|
+
if values.shape[1] >= 34:
|
|
202
|
+
values[:, 33:35] = np.nan
|
|
203
|
+
|
|
204
|
+
# Identify columns entirely NaN
|
|
205
|
+
nan_columns = np.all(np.isnan(values), axis=0)
|
|
206
|
+
|
|
207
|
+
# fill NaN data
|
|
208
|
+
x_axis = pyinterp.core.Axis(longitudes[0, :], is_circle=True)
|
|
209
|
+
y_axis = pyinterp.core.Axis(latitudes[:, 0], is_circle=False)
|
|
210
|
+
grid = pyinterp.Grid2D(y_axis, x_axis, values)
|
|
211
|
+
_has_converged, filled_values = fill.gauss_seidel(grid, num_threads=16)
|
|
212
|
+
has_converged &= _has_converged
|
|
213
|
+
|
|
214
|
+
# Restore columns entirely NaN
|
|
215
|
+
filled_values[:, nan_columns] = np.nan
|
|
216
|
+
|
|
217
|
+
# Add filled values to the output dictionary
|
|
218
|
+
datasets[key][varname] = (("num_lines", "num_pixels"), filled_values)
|
|
219
|
+
filled_datasets[new_key] = datasets[key]
|
|
220
|
+
new_key = new_key + 1
|
|
221
|
+
else:
|
|
222
|
+
print(f"Size of longitudes/latitudes is zero for dict number {key}")
|
|
223
|
+
|
|
224
|
+
return has_converged, filled_datasets
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
# =============================================================================
|
|
228
|
+
# check_directory
|
|
229
|
+
# =============================================================================
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def check_directory(database_path, start_date_str, end_date_str):
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
Scans the folders in the `database_path` directory, identifies the folders
|
|
236
|
+
containing NetCDF files whose dates are between `start_date_str` and `end_date_str`,
|
|
237
|
+
and returns a list of these folder names.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
Parameters
|
|
241
|
+
------------
|
|
242
|
+
database_path : str
|
|
243
|
+
Path to the `database` directory
|
|
244
|
+
start_date_str : str
|
|
245
|
+
Start date in 'YYYYMMDD' format
|
|
246
|
+
end_date_str : str
|
|
247
|
+
End date in 'YYYYMMDD' format
|
|
248
|
+
|
|
249
|
+
Returns
|
|
250
|
+
---------
|
|
251
|
+
|
|
252
|
+
matching_folders : list
|
|
253
|
+
List of folder names containing NetCDF files within the specified date range
|
|
254
|
+
If an error occurs, an error message is printed and an empty list is returned.
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
# Regex pattern to match folder names like cycle_001, cycle_002, etc.
|
|
259
|
+
folder_pattern = re.compile(r'cycle_\d{3}')
|
|
260
|
+
# Regex pattern to match the date in the file name SWOT........_YYYYMMDD...
|
|
261
|
+
file_pattern = re.compile(r'SWOT.*_(\d{8})T.*\.nc')
|
|
262
|
+
|
|
263
|
+
# Convert date strings to datetime objects
|
|
264
|
+
start_date = datetime.strptime(start_date_str, '%Y%m%d')
|
|
265
|
+
end_date = datetime.strptime(end_date_str, '%Y%m%d')
|
|
266
|
+
|
|
267
|
+
# List to store the names of folders that meet the criteria
|
|
268
|
+
matching_folders = []
|
|
269
|
+
|
|
270
|
+
try:
|
|
271
|
+
# List all items in the database directory
|
|
272
|
+
items = os.listdir(database_path)
|
|
273
|
+
|
|
274
|
+
for item in items:
|
|
275
|
+
folder_path = os.path.join(database_path, item)
|
|
276
|
+
|
|
277
|
+
# Check if the item is a directory and matches the pattern
|
|
278
|
+
if os.path.isdir(folder_path) and folder_pattern.match(item):
|
|
279
|
+
netcdf_files = [f for f in os.listdir(folder_path) if f.endswith('.nc')]
|
|
280
|
+
for nc_file in netcdf_files:
|
|
281
|
+
match = file_pattern.search(nc_file)
|
|
282
|
+
if match:
|
|
283
|
+
file_date_str = match.group(1)
|
|
284
|
+
file_date = datetime.strptime(file_date_str, '%Y%m%d')
|
|
285
|
+
|
|
286
|
+
if start_date <= file_date <= end_date:
|
|
287
|
+
matching_folders.append(item)
|
|
288
|
+
break # Stop checking files in this folder once a match is found
|
|
289
|
+
|
|
290
|
+
return matching_folders
|
|
291
|
+
|
|
292
|
+
except Exception as e:
|
|
293
|
+
print(f"An error occurred: {e}")
|
|
294
|
+
return []
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
# =============================================================================
|
|
298
|
+
# extract_xarrays_by_time
|
|
299
|
+
# =============================================================================
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def extract_xarrays_by_time(database_path, start_date_str, end_date_str, area):
|
|
303
|
+
"""
|
|
304
|
+
Processes folders in the `database_path` directory, applies the `extract_xarray_in_region`
|
|
305
|
+
function to each folder that contains NetCDF files within the date range specified
|
|
306
|
+
by `start_date_str` and `end_date_str`, and combines the results into a single dictionary.
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
Parameters
|
|
310
|
+
------------
|
|
311
|
+
database_path : str
|
|
312
|
+
Path to the `database` directory
|
|
313
|
+
start_date_str : str
|
|
314
|
+
Start date in 'YYYYMMDD' format
|
|
315
|
+
end_date_str : str
|
|
316
|
+
End date in 'YYYYMMDD' format
|
|
317
|
+
area : list
|
|
318
|
+
List with the boundaries of the region of interest [longitude_min, latitude_min, longitude_max, latitude_max]
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
Returns
|
|
322
|
+
---------
|
|
323
|
+
|
|
324
|
+
combined_datasets_dict : Dict
|
|
325
|
+
A dictionary of xarray.Datasets combining the results from `extract_xarray_in_region` function for each folder.
|
|
326
|
+
|
|
327
|
+
"""
|
|
328
|
+
|
|
329
|
+
matching_folders = check_directory(database_path, start_date_str, end_date_str)
|
|
330
|
+
combined_datasets_dict = defaultdict(list)
|
|
331
|
+
current_key = 0
|
|
332
|
+
|
|
333
|
+
for folder in matching_folders:
|
|
334
|
+
folder_path = os.path.join(database_path, folder)
|
|
335
|
+
result_dict = extract_xarray_in_region(folder_path, area)
|
|
336
|
+
|
|
337
|
+
# Add entries to the combined_dict with sequential keys
|
|
338
|
+
for value in result_dict.values():
|
|
339
|
+
combined_datasets_dict[current_key] = value
|
|
340
|
+
current_key += 1
|
|
341
|
+
|
|
342
|
+
# Convert defaultdict back to dict
|
|
343
|
+
combined_datasets_dict = dict(combined_datasets_dict)
|
|
344
|
+
|
|
345
|
+
return combined_datasets_dict
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
# =============================================================================
|
|
349
|
+
# plot_obs_count
|
|
350
|
+
# =============================================================================
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def plot_obs_count(obs_count, area, obs_count2=None, title=None, title2=None, save_fig=None):
|
|
354
|
+
"""
|
|
355
|
+
Plots the number of observations on a geographical map
|
|
356
|
+
|
|
357
|
+
Parameters
|
|
358
|
+
------------
|
|
359
|
+
obs_count : numpy.ndarray
|
|
360
|
+
A 2D array containing the count of observations in each geographical bin.
|
|
361
|
+
obs_count2 : numpy.ndarray, optional
|
|
362
|
+
A second 2D array containing the count of observations in each geographical bin.
|
|
363
|
+
area : list
|
|
364
|
+
List with the boundaries of the region of interest [longitude_min, latitude_min, longitude_max, latitude_max]
|
|
365
|
+
title : str, optional
|
|
366
|
+
The title of the plot. Defaults to None.
|
|
367
|
+
title2 : str, optional
|
|
368
|
+
The title of the 2nd plot. Defaults to None.
|
|
369
|
+
save_fig: Optional[str], default None
|
|
370
|
+
Name of the file to save the plot to.
|
|
371
|
+
Does not save if None.
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
Returns
|
|
375
|
+
---------
|
|
376
|
+
None
|
|
377
|
+
|
|
378
|
+
"""
|
|
379
|
+
lon_min, lat_min, lon_max, lat_max = area
|
|
380
|
+
|
|
381
|
+
if lon_min > 180:
|
|
382
|
+
lon_min = lon_min - 360
|
|
383
|
+
|
|
384
|
+
if lon_max > 180:
|
|
385
|
+
lon_max = lon_max - 360
|
|
386
|
+
|
|
387
|
+
# Créer des sous-graphes côte à côte
|
|
388
|
+
if obs_count2 is not None:
|
|
389
|
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 12), subplot_kw={'projection': ccrs.PlateCarree()})
|
|
390
|
+
maxobs = max(obs_count.max(), obs_count2.max())
|
|
391
|
+
else:
|
|
392
|
+
fig, ax1 = plt.subplots(1, 1, figsize=(8, 7), subplot_kw={'projection': ccrs.PlateCarree()})
|
|
393
|
+
maxobs = obs_count.max()
|
|
394
|
+
|
|
395
|
+
ax1.add_feature(cfeature.LAND, facecolor='gray')
|
|
396
|
+
ax1.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
|
|
397
|
+
# Create a mask for zero values to present the continent in its color
|
|
398
|
+
obs_count_masked = np.ma.masked_where(obs_count == 0, obs_count)
|
|
399
|
+
|
|
400
|
+
im1 = ax1.imshow(obs_count_masked, extent=[lon_min, lon_max, lat_min, lat_max],
|
|
401
|
+
origin='lower', cmap="jet", transform=ccrs.PlateCarree(),
|
|
402
|
+
vmin=0, vmax=maxobs)
|
|
403
|
+
|
|
404
|
+
ax1.coastlines()
|
|
405
|
+
gl1 = ax1.gridlines(draw_labels=True)
|
|
406
|
+
gl1.right_labels = False
|
|
407
|
+
gl1.top_labels = False
|
|
408
|
+
|
|
409
|
+
plt.colorbar(im1, ax=ax1, label='Number of observations per bin', shrink=0.5)
|
|
410
|
+
|
|
411
|
+
if title:
|
|
412
|
+
if len(title) >= 40:
|
|
413
|
+
ax1.set_title(title, fontsize=11, fontweight='bold', color='black')
|
|
414
|
+
else:
|
|
415
|
+
ax1.set_title(title, fontsize=15, fontweight='bold', color='black')
|
|
416
|
+
|
|
417
|
+
if obs_count2 is not None:
|
|
418
|
+
ax2.add_feature(cfeature.LAND, facecolor='gray')
|
|
419
|
+
ax2.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())
|
|
420
|
+
# Create a mask for zero values to present the continent in its color
|
|
421
|
+
obs_count_masked2 = np.ma.masked_where(obs_count2 == 0, obs_count2)
|
|
422
|
+
|
|
423
|
+
im2 = ax2.imshow(obs_count_masked2, extent=[lon_min, lon_max, lat_min, lat_max],
|
|
424
|
+
origin='lower', cmap="jet", transform=ccrs.PlateCarree(),
|
|
425
|
+
vmin=0, vmax=maxobs)
|
|
426
|
+
|
|
427
|
+
ax2.coastlines()
|
|
428
|
+
gl2 = ax2.gridlines(draw_labels=True)
|
|
429
|
+
gl2.right_labels = False
|
|
430
|
+
gl2.top_labels = False
|
|
431
|
+
plt.colorbar(im2, ax=ax2, label='Number of observations per bin', shrink=0.5)
|
|
432
|
+
if title2:
|
|
433
|
+
ax2.set_title(title2, fontsize=15, fontweight='bold', color='black')
|
|
434
|
+
|
|
435
|
+
# Optionally save the figure
|
|
436
|
+
if save_fig is not None:
|
|
437
|
+
plt.savefig(save_fig)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
# =============================================================================
|
|
441
|
+
# read_zarr_to_xarray_dict
|
|
442
|
+
# =============================================================================
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
# Fonction pour lire les fichiers Zarr pour une plage de dates spécifique
|
|
446
|
+
def read_zarr_to_xarray_dict(base_directory, area, start_date_str, end_date_str, variables_to_keep):
|
|
447
|
+
"""
|
|
448
|
+
|
|
449
|
+
Reads Zarr files from a directory structure organized by month and day, converts them into a dictionnary of xarray.Dataset objects, retains only specified variables, and extracts a specific geographical region based on latitude and longitude limits.
|
|
450
|
+
|
|
451
|
+
Parameters
|
|
452
|
+
------------
|
|
453
|
+
base_directory : str
|
|
454
|
+
The path to the base directory containing Zarr data organized by month and day.
|
|
455
|
+
area : list
|
|
456
|
+
List with the boundaries of the region of interest [longitude_min, latitude_min, longitude_max, latitude_max]
|
|
457
|
+
start_date_str : str
|
|
458
|
+
The desired start date in the format 'YYYYMMDD'.
|
|
459
|
+
|
|
460
|
+
end_date_str : str
|
|
461
|
+
The desired end date in the format 'YYYYMMDD'.
|
|
462
|
+
|
|
463
|
+
variables_to_keep : list of str
|
|
464
|
+
A list of variable names to retain in each xarray.Dataset.
|
|
465
|
+
|
|
466
|
+
Returns
|
|
467
|
+
---------
|
|
468
|
+
datasets_dict : Dict
|
|
469
|
+
A dictionary containing the resulting xarray.Dataset objects, indexed by unique integers.
|
|
470
|
+
|
|
471
|
+
"""
|
|
472
|
+
|
|
473
|
+
lon_min = area[0]
|
|
474
|
+
lon_max = area[2]
|
|
475
|
+
lat_min = area[1]
|
|
476
|
+
lat_max = area[3]
|
|
477
|
+
|
|
478
|
+
# le nombre de fichiers
|
|
479
|
+
nfiles = 0
|
|
480
|
+
datasets_dict = {}
|
|
481
|
+
index = 0
|
|
482
|
+
|
|
483
|
+
# Convertir les chaînes de date en objets datetime
|
|
484
|
+
start_date = datetime.strptime(start_date_str, '%Y%m%d')
|
|
485
|
+
end_date = datetime.strptime(end_date_str, '%Y%m%d')
|
|
486
|
+
|
|
487
|
+
# Parcourir chaque jour entre les dates de début et de fin
|
|
488
|
+
current_date = start_date
|
|
489
|
+
while current_date <= end_date:
|
|
490
|
+
month = current_date.strftime('%m')
|
|
491
|
+
day = current_date.strftime('%d')
|
|
492
|
+
|
|
493
|
+
month_directory = os.path.join(base_directory, f'month={month}')
|
|
494
|
+
if os.path.exists(month_directory):
|
|
495
|
+
day_directory = os.path.join(month_directory, f'day={day}')
|
|
496
|
+
if os.path.exists(day_directory):
|
|
497
|
+
|
|
498
|
+
zarr_ds = xr.open_zarr(day_directory)
|
|
499
|
+
|
|
500
|
+
# Garder uniquement les variables spécifiées
|
|
501
|
+
zarr_ds = zarr_ds[variables_to_keep]
|
|
502
|
+
|
|
503
|
+
coord_vars = ['latitude', 'longitude']
|
|
504
|
+
zarr_ds = zarr_ds.set_coords(coord_vars)
|
|
505
|
+
|
|
506
|
+
if lon_min > lon_max:
|
|
507
|
+
|
|
508
|
+
selection = (
|
|
509
|
+
|
|
510
|
+
(zarr_ds['latitude'] >= lat_min) &
|
|
511
|
+
(zarr_ds['latitude'] <= lat_max) &
|
|
512
|
+
(((zarr_ds['longitude'] >= lon_min) & (zarr_ds['longitude'] <= 360)) | (
|
|
513
|
+
zarr_ds['longitude'] <= lon_max))
|
|
514
|
+
)
|
|
515
|
+
else:
|
|
516
|
+
selection = (
|
|
517
|
+
|
|
518
|
+
(zarr_ds['latitude'] >= lat_min) &
|
|
519
|
+
(zarr_ds['latitude'] <= lat_max) &
|
|
520
|
+
(zarr_ds['longitude'] >= lon_min) &
|
|
521
|
+
(zarr_ds['longitude'] <= lon_max)
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
selection = selection.compute()
|
|
525
|
+
|
|
526
|
+
zarr_ds = zarr_ds.where(selection, drop=True)
|
|
527
|
+
|
|
528
|
+
# créer la variable ssha
|
|
529
|
+
zarr_ds['ssha'] = zarr_ds.duacs_ssha_karin_2_calibrated.where(zarr_ds.duacs_editing_flag == 0)
|
|
530
|
+
zarr_ds = zarr_ds.drop_vars('duacs_ssha_karin_2_calibrated')
|
|
531
|
+
zarr_ds = zarr_ds.drop_vars('duacs_editing_flag')
|
|
532
|
+
|
|
533
|
+
# créer la variable mdt
|
|
534
|
+
zarr_ds['mdt'] = zarr_ds.cvl_mean_dynamic_topography_cnes_cls_22
|
|
535
|
+
zarr_ds = zarr_ds.drop_vars('cvl_mean_dynamic_topography_cnes_cls_22')
|
|
536
|
+
|
|
537
|
+
datasets_dict[index] = zarr_ds
|
|
538
|
+
|
|
539
|
+
index += 1
|
|
540
|
+
nfiles += 1
|
|
541
|
+
|
|
542
|
+
else:
|
|
543
|
+
print(f'The directory for day{day} does not exist in month {month}')
|
|
544
|
+
else:
|
|
545
|
+
print(f'The directory for month{month} does not exist')
|
|
546
|
+
|
|
547
|
+
# Passer au jour suivant
|
|
548
|
+
current_date += timedelta(days=1)
|
|
549
|
+
|
|
550
|
+
return datasets_dict
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
# =============================================================================
|
|
554
|
+
# split_dsets_based_cnum
|
|
555
|
+
# =============================================================================
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def split_dsets_based_cnum(datasets_dict):
|
|
559
|
+
"""
|
|
560
|
+
Splits xarray.dataset objects based on unique cycle and pass numbers.
|
|
561
|
+
|
|
562
|
+
The function takes a dictionary of xarray.dataset objects and splits each dataset into smaller datasets based on unique values of 'cycle_number' and 'pass_number'.
|
|
563
|
+
The resulting datasets are stored in a new dictionary with sequential keys.
|
|
564
|
+
|
|
565
|
+
Conditions:
|
|
566
|
+
A dataset is split if it contains at least 2 different 'cycle_number' values.
|
|
567
|
+
For each unique 'cycle_number', the dataset is further split if it contains at least 2 different 'pass_number' values.
|
|
568
|
+
If an xarray.dataset in the input dictionary meets the splitting conditions (having at least 2 different 'cycle_number' and 'pass_number'), it is split into smaller xarray datasets. Otherwise, the original dataset is included as is.
|
|
569
|
+
|
|
570
|
+
Parameters
|
|
571
|
+
-----------
|
|
572
|
+
datasets_dict : Dict
|
|
573
|
+
A dictionary where each key corresponds to an xarray Dataset.
|
|
574
|
+
Each xarray Dataset is expected to have 'cycle_number' and 'pass_number' attributes.
|
|
575
|
+
|
|
576
|
+
Returns
|
|
577
|
+
--------
|
|
578
|
+
splited_dict : Dict
|
|
579
|
+
A new dictionary containing the split xarray.dataset objects.
|
|
580
|
+
"""
|
|
581
|
+
|
|
582
|
+
splited_dict = {}
|
|
583
|
+
index = 0
|
|
584
|
+
|
|
585
|
+
for key in range(len(datasets_dict)):
|
|
586
|
+
# Check if the condition is met(The datasets contain 2 cycle numbers.)
|
|
587
|
+
if len(np.unique(datasets_dict[key].cycle_number.compute())) >= 2:
|
|
588
|
+
# Retrieve the cycle number.
|
|
589
|
+
long_cycle = len(np.unique(datasets_dict[key].cycle_number.compute()))
|
|
590
|
+
|
|
591
|
+
for i in np.arange(long_cycle - 1):
|
|
592
|
+
cycle = np.unique(datasets_dict[key].cycle_number.compute())[i]
|
|
593
|
+
ds_cycle = datasets_dict[key].where(datasets_dict[key]['cycle_number'].compute() == cycle.astype(float),
|
|
594
|
+
drop=True)
|
|
595
|
+
|
|
596
|
+
# Condition separation based on the pass numbers.
|
|
597
|
+
if len(np.unique(ds_cycle.pass_number.compute())) >= 2:
|
|
598
|
+
|
|
599
|
+
long_pass = len(np.unique(ds_cycle.pass_number.compute()))
|
|
600
|
+
|
|
601
|
+
for i in np.arange(long_pass - 1):
|
|
602
|
+
passs = np.unique(ds_cycle.pass_number.compute())[i]
|
|
603
|
+
ds_cyclepass = ds_cycle.where(ds_cycle.pass_number.compute() == passs.astype(float), drop=True)
|
|
604
|
+
|
|
605
|
+
# Add the new datasets to the output dictionary with sequential keys
|
|
606
|
+
splited_dict[index] = ds_cyclepass
|
|
607
|
+
index += 1
|
|
608
|
+
else:
|
|
609
|
+
# If the dataset doesn't meet the condition, add it to the output dictionary as is
|
|
610
|
+
splited_dict[index] = datasets_dict[key]
|
|
611
|
+
index += 1
|
|
612
|
+
|
|
613
|
+
return splited_dict
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
# =============================================================================
|
|
617
|
+
# remove_duplicates_from_sys_path
|
|
618
|
+
# =============================================================================
|
|
619
|
+
|
|
620
|
+
def remove_duplicates_from_sys_path():
|
|
621
|
+
"""
|
|
622
|
+
Removes duplicates from the sys.path list while preserving the order of elements.
|
|
623
|
+
|
|
624
|
+
Iterates through the sys.path list and constructs a new list without duplicates.
|
|
625
|
+
Updates sys.path with this new list.
|
|
626
|
+
|
|
627
|
+
Returns
|
|
628
|
+
--------
|
|
629
|
+
None
|
|
630
|
+
|
|
631
|
+
"""
|
|
632
|
+
seen = set()
|
|
633
|
+
new_sys_path = []
|
|
634
|
+
for path in sys.path:
|
|
635
|
+
if path not in seen:
|
|
636
|
+
new_sys_path.append(path)
|
|
637
|
+
seen.add(path)
|
|
638
|
+
sys.path = new_sys_path
|
widetrax/Spectram.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
from concurrent.futures import ProcessPoolExecutor, as_completed
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import scipy.signal as signal
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# =============================================================================
|
|
8
|
+
# retrieve_segments
|
|
9
|
+
# =============================================================================
|
|
10
|
+
|
|
11
|
+
def retrieve_segments(datasets,FileType):
|
|
12
|
+
"""
|
|
13
|
+
Extracts segments from xarray.datasets
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
datasets : Dict
|
|
18
|
+
Dictionary containing xarray.Datasets
|
|
19
|
+
FileType : str
|
|
20
|
+
The file type used to calculate datasets, "NetCDF" or "Zarr"
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
segments_dict : Dict
|
|
25
|
+
Dictionary containing segments (numpy.arrays).
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
segments_dict = {}
|
|
30
|
+
counter = 0
|
|
31
|
+
|
|
32
|
+
#Calculation of Sea Surface Height (SSH) : SSH = SSHA + MDT
|
|
33
|
+
for ky in range(len(datasets)):
|
|
34
|
+
datasets[ky]['ssh'] = datasets[ky]['ssha'] + datasets[ky]['mdt']
|
|
35
|
+
|
|
36
|
+
for key, dataset in datasets.items():
|
|
37
|
+
#print(f"starting processing dict number {key} among {len(datasets)}")
|
|
38
|
+
for col in range(dataset.dims['num_pixels']):
|
|
39
|
+
# Extract data for one column
|
|
40
|
+
col_data = dataset.isel(num_pixels=col)
|
|
41
|
+
|
|
42
|
+
# Delete coords to avoid duplicates and variables we don't need
|
|
43
|
+
if FileType == "NetCDF":
|
|
44
|
+
col_dataset = col_data.drop_vars(['latitude', 'longitude','ssha', 'mdt'])
|
|
45
|
+
|
|
46
|
+
elif FileType == "Zarr":
|
|
47
|
+
col_dataset = col_data.drop_vars(['latitude', 'longitude','ssha', 'mdt',
|
|
48
|
+
'cycle_number','duacs_land_sea_mask','pass_number'])
|
|
49
|
+
else:
|
|
50
|
+
print("The specified format is not supported")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Check whether the column is entirely NaN
|
|
54
|
+
if not np.all(np.isnan(col_dataset['ssh'])):
|
|
55
|
+
|
|
56
|
+
segment_data = col_dataset.to_array().values.squeeze()
|
|
57
|
+
|
|
58
|
+
# Remove NaN values at the beginning
|
|
59
|
+
while len(segment_data) > 0 and np.isnan(segment_data[0]):
|
|
60
|
+
segment_data = segment_data[1:]
|
|
61
|
+
|
|
62
|
+
# Remove NaN values at the end
|
|
63
|
+
while len(segment_data) > 0 and np.isnan(segment_data[-1]):
|
|
64
|
+
segment_data = segment_data[:-1]
|
|
65
|
+
|
|
66
|
+
# Verify if any NaN values remain for islands or continents after interpolation
|
|
67
|
+
if not np.isnan(segment_data).any():
|
|
68
|
+
segments_dict[counter] = segment_data
|
|
69
|
+
counter += 1
|
|
70
|
+
|
|
71
|
+
return segments_dict
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# =============================================================================
|
|
75
|
+
# calculate_psd
|
|
76
|
+
# =============================================================================
|
|
77
|
+
|
|
78
|
+
def calculate_segment_psd(segment_data, fs):
|
|
79
|
+
if len(segment_data) > 199: # Check segment length
|
|
80
|
+
return signal.welch(segment_data, fs=fs, nperseg=len(segment_data), noverlap=0)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def calculate_psd(segments_dict):
|
|
84
|
+
"""
|
|
85
|
+
Computes the power spectral density (PSD)
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
------------
|
|
89
|
+
segments_dict: Dict
|
|
90
|
+
Dictionary containing segments (numpy.arrays)
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
---------
|
|
94
|
+
psd_dict: Dict
|
|
95
|
+
Dictionary containing PSDs for each segment
|
|
96
|
+
freqs_dict: Dict
|
|
97
|
+
Dictionary containing the associated frequencies
|
|
98
|
+
"""
|
|
99
|
+
fs = 0.5 # maybe it could be an argument?
|
|
100
|
+
|
|
101
|
+
psd_dict = {}
|
|
102
|
+
freqs_dict = {}
|
|
103
|
+
counter = 0
|
|
104
|
+
|
|
105
|
+
with ProcessPoolExecutor() as executor:
|
|
106
|
+
futures = [executor.submit(calculate_segment_psd, segment_data, fs) for segment_data in segments_dict.values()]
|
|
107
|
+
|
|
108
|
+
for future in as_completed(futures):
|
|
109
|
+
result = future.result()
|
|
110
|
+
if result is not None:
|
|
111
|
+
freqs, psd = result
|
|
112
|
+
psd_dict[counter] = psd
|
|
113
|
+
freqs_dict[counter] = freqs
|
|
114
|
+
counter += 1
|
|
115
|
+
|
|
116
|
+
return psd_dict, freqs_dict
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# =============================================================================
|
|
120
|
+
# psd_mean_and_freq
|
|
121
|
+
# =============================================================================
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def psd_mean_and_freq(psd_dict, freqs_dict):
|
|
125
|
+
"""
|
|
126
|
+
Calculate the mean of the Power Spectral Densities (PSD) for each frequency point using the values from a PSD
|
|
127
|
+
dictionary.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
------------
|
|
131
|
+
psd_dict: Dict
|
|
132
|
+
A dictionary of numpy arrays containing the Power Spectral Densities (PSD) for segments.
|
|
133
|
+
The arrays can be of different lengths.
|
|
134
|
+
freqs_dict: Dict
|
|
135
|
+
A dictionary containing the corresponding frequencies for each segment (numpy array)
|
|
136
|
+
|
|
137
|
+
Returns
|
|
138
|
+
---------
|
|
139
|
+
psd_mean: np.ndarray
|
|
140
|
+
A numpy array containing the mean of the Power Spectral Densities (PSD) for each frequency point.
|
|
141
|
+
The length of this array is equal to the maximum length of the arrays in psd_dict.
|
|
142
|
+
freqs_mean: np.ndarray
|
|
143
|
+
A numpy array containing frequency values of the longest column in freqs_dict
|
|
144
|
+
"""
|
|
145
|
+
max_length = 0
|
|
146
|
+
freqs_mean = None
|
|
147
|
+
for k, array in psd_dict.items():
|
|
148
|
+
if array.size > max_length:
|
|
149
|
+
max_length = array.size
|
|
150
|
+
freqs_mean = freqs_dict[k]
|
|
151
|
+
|
|
152
|
+
psd_sum = np.zeros(max_length)
|
|
153
|
+
psd_counts = np.zeros(max_length)
|
|
154
|
+
for array in psd_dict.values():
|
|
155
|
+
psd_sum[:array.size] += array
|
|
156
|
+
psd_counts[:array.size] += 1
|
|
157
|
+
psd_mean = psd_sum / psd_counts
|
|
158
|
+
|
|
159
|
+
return psd_mean, freqs_mean
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# =============================================================================
|
|
163
|
+
# plot_psd
|
|
164
|
+
# =============================================================================
|
|
165
|
+
|
|
166
|
+
def plot_psd(ax, freqs, psds, unit, psd_labels, title=None):
|
|
167
|
+
"""
|
|
168
|
+
Plots the Power Spectral Density (PSD) on a logarithmic scale.
|
|
169
|
+
|
|
170
|
+
The function plots the PSD on the given axes, `ax`. The plot is on a logarithmic scale
|
|
171
|
+
for both x and y axes. The function can handle one or two PSD arrays. If provided,
|
|
172
|
+
it adds labels and a title to the plot. It also includes reference lines for $k^{-2}$
|
|
173
|
+
and $k^{-5}$ slopes.
|
|
174
|
+
|
|
175
|
+
The function adds grid lines, legends, and adjusts axis labels and ticks for better readability.
|
|
176
|
+
|
|
177
|
+
If `freqs` or `psd1` are empty, the function prints an error message and returns
|
|
178
|
+
without plotting.
|
|
179
|
+
|
|
180
|
+
Parameters
|
|
181
|
+
------------
|
|
182
|
+
ax: matplotlib.axes.Axes
|
|
183
|
+
The axes on which to plot the PSD.
|
|
184
|
+
freqs: np.ndarray
|
|
185
|
+
A numpy array containing frequency values.
|
|
186
|
+
psds: [np.ndarray, ...] | np.ndarray
|
|
187
|
+
A list of numpy array or a single numpy array of PSD values corresponding to `freqs`.
|
|
188
|
+
unit: str
|
|
189
|
+
Unit of the physical quantity for which the PSD was computed.
|
|
190
|
+
psd_labels: [str, ...] | str, optional
|
|
191
|
+
A list of labels or a single label for the PDS array(s).
|
|
192
|
+
title: str, optional
|
|
193
|
+
Title of the plot.
|
|
194
|
+
"""
|
|
195
|
+
if isinstance(psds, np.ndarray):
|
|
196
|
+
psds = [psds]
|
|
197
|
+
psd_labels = [psd_labels]
|
|
198
|
+
if psd_labels is None:
|
|
199
|
+
psd_labels = [None] * len(psds)
|
|
200
|
+
|
|
201
|
+
for psd, label in zip(psds, psd_labels):
|
|
202
|
+
ax.loglog(freqs, psd, label=label)
|
|
203
|
+
|
|
204
|
+
ax.set_ylim(1e-7, 1e2)
|
|
205
|
+
ax.set_ylabel(f"PSD [${unit}/(cy/km)$]", fontsize=8, fontweight="bold", color="black")
|
|
206
|
+
|
|
207
|
+
ax.xaxis.set_label_position("top")
|
|
208
|
+
ax.xaxis.tick_top()
|
|
209
|
+
ax.set_xlabel("Wavenumber [$cy/km$]", fontsize=8, fontweight="bold", color="black")
|
|
210
|
+
|
|
211
|
+
# filters out zero frequencies
|
|
212
|
+
non_zero_freqs = freqs[freqs != 0]
|
|
213
|
+
|
|
214
|
+
# k^-2 & k^-5
|
|
215
|
+
k_2 = non_zero_freqs ** -2 * (psds[0][0] / (non_zero_freqs[0] ** -2)) # Scale according to the first PSD value
|
|
216
|
+
k_5 = non_zero_freqs ** -5 * (psds[0][0] / (non_zero_freqs[0] ** -5))
|
|
217
|
+
|
|
218
|
+
ax.loglog(non_zero_freqs, k_2*30, "k--", label="$k^{-2}$") # 30 to fix the line
|
|
219
|
+
ax.loglog(non_zero_freqs, k_5*1e6, "b--", label="$k^{-5}$") # 1e6 to fix the line
|
|
220
|
+
|
|
221
|
+
ax2 = ax.secondary_xaxis("bottom", functions=(lambda x: 1 / x, lambda x: 1 / x))
|
|
222
|
+
ax2.set_xlabel("Wave-length [$km$]", fontsize=8, fontweight="bold", color="black")
|
|
223
|
+
|
|
224
|
+
wavelength_ticks = np.array([5, 10, 25, 50, 100, 200, 500, 1000])
|
|
225
|
+
ax2.set_xticks(wavelength_ticks)
|
|
226
|
+
ax2.set_xticklabels(wavelength_ticks)
|
|
227
|
+
ax.grid(True, which="both")
|
|
228
|
+
ax.legend()
|
|
229
|
+
|
|
230
|
+
# Set the title if provided
|
|
231
|
+
if title:
|
|
232
|
+
ax.set_title(title, fontsize=15, fontweight="bold", color="black")
|
widetrax/__init__.py
ADDED
widetrax/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: widetrax
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Computes the Power Spectrum density (PSD) from SWOT data
|
|
5
|
+
Author-email: Amine Ouhechou <amine.ouhechou@univ-grenoble-alpes.fr>, Julien Le Sommer <julien.lesommer@univ-grenoble-alpes.fr>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: PSD,SWOT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: cartopy
|
|
15
|
+
Requires-Dist: matplotlib
|
|
16
|
+
Requires-Dist: netCDF4
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Requires-Dist: scipy
|
|
19
|
+
Requires-Dist: xarray
|
|
20
|
+
Requires-Dist: datetime
|
|
21
|
+
|
|
22
|
+
[](https://widetrax.readthedocs.io/en/latest/?badge=latest)
|
|
23
|
+
# WideTrax
|
|
24
|
+
## Description
|
|
25
|
+
|
|
26
|
+
**widetrax** is a package for manipulating wide-swath altimetry ocean data.
|
|
27
|
+
It computes the power spectrum density (PSD) of Sea surface Height (SSH) for both phases/orbits of the SWOT mission.
|
|
28
|
+
**widetrax** provides easy-to-use functions that allow users to read SWOT data in both NetCDF and Zarr collections formats, clean and handle NaN values, perform interpolation, and compute the wave spectrum.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
See the full [documentation](https://widetrax.readthedocs.io/en/latest/)!
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
widetrax/DataPreprocessing.py,sha256=dXm6Ut-KkhMO5D-FodjBO1blla8PgrPtonzZNeHRXoI,22662
|
|
2
|
+
widetrax/Spectram.py,sha256=uLVLm8ezI7dRHeidT_Ae7z917CAGUwBb3opxIGNHH7o,8319
|
|
3
|
+
widetrax/__init__.py,sha256=VV7vKXzNdI6D5sSI2LfWG5d3XhagJitYM0yPuJl3PXI,141
|
|
4
|
+
widetrax/version.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
|
5
|
+
widetrax-0.0.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
widetrax-0.0.1.dist-info/METADATA,sha256=yMOqIxm_ukA2Oh8IzDOC3dI-2BksoaPEdL48dwrXuCU,1340
|
|
7
|
+
widetrax-0.0.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
8
|
+
widetrax-0.0.1.dist-info/top_level.txt,sha256=TfgruUy7R7K5TKgXWBfUqQPtUlBPl6dsrZRLD1xmhHc,9
|
|
9
|
+
widetrax-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
widetrax
|