Alaea 2.4.2__tar.gz → 2.4.3__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.
- {alaea-2.4.2 → alaea-2.4.3}/.DS_Store +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Standard/__init__.py +2 -0
- alaea-2.4.3/Alaea/Standard/vars_name.py +52 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Standard/xr_attrs.py +188 -116
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/baysalt/erosion_coastline.py +1 -0
- {alaea-2.4.2 → alaea-2.4.3/Alaea.egg-info}/PKG-INFO +1 -1
- {alaea-2.4.2 → alaea-2.4.3}/Alaea.egg-info/SOURCES.txt +1 -0
- {alaea-2.4.2/Alaea.egg-info → alaea-2.4.3}/PKG-INFO +1 -1
- {alaea-2.4.2 → alaea-2.4.3}/setup.py +1 -1
- {alaea-2.4.2 → alaea-2.4.3}/.gitattributes +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/.gitignore +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Blogging.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Pyshell/RS_File.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Pyshell/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/S_DateTime.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/SameAsMATLAB/CoorTrans.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/SameAsMATLAB/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/SameAsMATLAB/calculatefuns.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Standard/xr_ice.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/Standard/xr_wave.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/baysalt/Forage/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/baysalt/Forage/erosion_data/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/baysalt/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/commonCode.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/cprintfs.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/exutils/Interp/Interp_g2s.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/exutils/Interp/Interp_s2g.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/exutils/Interp/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/exutils/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/fvcom_class.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/fvcom_image.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/fvcom_load.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/fvcom_tools.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/pFVCOM/writeFile.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/processBar.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/read_conf.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/server_info.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/P_params.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/Read.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/download_check.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/geo_distance.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/tools/kml2shp.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea/warningTools/__init__.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea.egg-info/dependency_links.txt +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea.egg-info/requires.txt +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/Alaea.egg-info/top_level.txt +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/MANIFEST.in +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/README.md +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/run_twine.py +0 -0
- {alaea-2.4.2 → alaea-2.4.3}/setup.cfg +0 -0
|
Binary file
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# 日期 : 2026/4/24 10:48
|
|
4
|
+
# 作者 : Christmas
|
|
5
|
+
# 邮箱 : 273519355@qq.com
|
|
6
|
+
# 项目 : Alaea
|
|
7
|
+
# 版本 : python 3
|
|
8
|
+
# 摘要 :
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
NAME_lon = ['lon', 'longitude']
|
|
15
|
+
NAME_lat = ['lat', 'latitude']
|
|
16
|
+
|
|
17
|
+
NAME_time = ['time']
|
|
18
|
+
NAME_TIME = ['TIME']
|
|
19
|
+
|
|
20
|
+
NAME_u10 = ['wind_U10', 'U10', 'u10']
|
|
21
|
+
NAME_v10 = ['wind_V10', 'V10', 'v10']
|
|
22
|
+
NAME_wpsd10max = ['WSPD10MAX']
|
|
23
|
+
|
|
24
|
+
NAME_t2 = ['temperature', 'T2', 't2']
|
|
25
|
+
|
|
26
|
+
NAME_visi = ['visibility', 'AFWA_VIS', 'VISIBILITY']
|
|
27
|
+
|
|
28
|
+
NAME_swr = ['SWR', 'Shortwave', 'SWDOWN']
|
|
29
|
+
NAME_lwr = ['LWR', 'Longwave', 'GLW']
|
|
30
|
+
NAME_swrn = ['SWRN', 'SWDOWN_NORM', 'SWNORM']
|
|
31
|
+
|
|
32
|
+
NAME_tcc = ['tcc', 'TCC', 'cloud_cover']
|
|
33
|
+
|
|
34
|
+
NAME_prec = ['precipitation', 'tp', 'TP', 'Precipitation']
|
|
35
|
+
|
|
36
|
+
NAME_slp = ['slp', 'SLP']
|
|
37
|
+
|
|
38
|
+
NAME_swh = ['swh', 'SWH', 'Significant_wave_height']
|
|
39
|
+
NAME_mwp = ['mwp', 'MWP', 'Mean_wave_period']
|
|
40
|
+
NAME_mwd = ['mwd', 'MWD', 'Mean_wave_direction']
|
|
41
|
+
NAME_mwl = ['mwl', 'MWL', 'Mean_wave_length']
|
|
42
|
+
NAME_shww = ['shww', 'SHWW', 'Significant_wave_height_of_swell']
|
|
43
|
+
NAME_shts = ['shts', 'SHTS', 'Significant_wave_height_of_sea']
|
|
44
|
+
NAME_mdww = ['mdww', 'MDWW', 'Mean_wave_direction_of_swell']
|
|
45
|
+
NAME_mdts = ['mdts', 'MDTS', 'Mean_wave_direction_of_sea']
|
|
46
|
+
NAME_mpww = ['mpww', 'MPWW', 'Mean_wave_period_of_swell']
|
|
47
|
+
NAME_mpts = ['mpts', 'MPTS', 'Mean_wave_period_of_sea']
|
|
48
|
+
NAME_pp1d = ['pp1d', 'PP1D', 'Peak_period_of_1st_wave_component']
|
|
49
|
+
NAME_hmax = ['hmax', 'HMAX', 'Max_wave_height']
|
|
50
|
+
|
|
51
|
+
NAME_aice = ['aice', 'AICE', 'sea_ice_concentration']
|
|
52
|
+
NAME_tice = ['tice', 'TICE', 'sea_ice_thickness']
|
|
@@ -14,13 +14,15 @@ from typing import Optional, Union
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
import xarray as xr
|
|
16
16
|
|
|
17
|
+
from .vars_name import *
|
|
18
|
+
|
|
17
19
|
# from .. import new_filename
|
|
18
20
|
|
|
19
21
|
__all__ = ['add_coors_attrs',
|
|
20
22
|
'add_lon_attrs', 'add_lat_attrs', 'add_time_attrs', 'add_TIME_attrs',
|
|
21
23
|
'add_wind_attrs', 'add_temperature_attrs', 'add_precipitation_attrs', 'add_slp_attrs',
|
|
22
|
-
'add_wave_attrs', '
|
|
23
|
-
'
|
|
24
|
+
'add_wave_attrs', 'add_visibility_attrs', 'add_radiation_attrs', 'add_cloudCover_attrs',
|
|
25
|
+
'add_ice_attrs', 'transpose_dims',
|
|
24
26
|
'fixed_encoding', 'calc_scale_offset', 'compress_scale_offset',
|
|
25
27
|
'calc_dtype', 'calc_fillvalue',
|
|
26
28
|
]
|
|
@@ -42,10 +44,10 @@ def add_coors_attrs(
|
|
|
42
44
|
:param TIME_name: TIME维度名,默认为自动识别
|
|
43
45
|
:return: xarray.Dataset
|
|
44
46
|
"""
|
|
45
|
-
lon_name = next((x for x in
|
|
46
|
-
lat_name = next((x for x in
|
|
47
|
-
time_name = next((x for x in
|
|
48
|
-
TIME_name = next((x for x in
|
|
47
|
+
lon_name = next((x for x in NAME_lon if x in _ds.dims), None) if lon_name is None else lon_name
|
|
48
|
+
lat_name = next((x for x in NAME_lat if x in _ds.dims), None) if lat_name is None else lat_name
|
|
49
|
+
time_name = next((x for x in NAME_time if x in _ds.dims), None) if time_name is None else time_name
|
|
50
|
+
TIME_name = next((x for x in NAME_TIME if x in _ds.variables), None) if TIME_name is None else TIME_name
|
|
49
51
|
|
|
50
52
|
add_lon_attrs(_ds, lon_name)
|
|
51
53
|
add_lat_attrs(_ds, lat_name)
|
|
@@ -133,12 +135,12 @@ def add_TIME_attrs(
|
|
|
133
135
|
:return: xarray.Dataset
|
|
134
136
|
"""
|
|
135
137
|
_ds[TIME_name].attrs = {
|
|
136
|
-
'reference_time': ''.join(_ds[TIME_name].
|
|
138
|
+
'reference_time': ''.join(_ds[TIME_name].values[0].astype(str))[:10],
|
|
137
139
|
'long_name': 'UTC time',
|
|
138
140
|
'standard_name': 'UTC_time',
|
|
139
141
|
'calendar': 'gregorian',
|
|
140
|
-
'start_time': ''.join(_ds[TIME_name].
|
|
141
|
-
'end_time': ''.join(_ds[TIME_name].
|
|
142
|
+
'start_time': ''.join(_ds[TIME_name].values[0].astype(str)),
|
|
143
|
+
'end_time': ''.join(_ds[TIME_name].values[-1].astype(str))
|
|
142
144
|
}
|
|
143
145
|
_ds[TIME_name].encoding['char_dim_name'] = dim_name
|
|
144
146
|
# _ds[TIME_name].encoding['zlib'] = True
|
|
@@ -147,32 +149,37 @@ def add_TIME_attrs(
|
|
|
147
149
|
|
|
148
150
|
def add_wind_attrs(
|
|
149
151
|
_ds: xr.Dataset,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
u10_name: Optional[str] = None,
|
|
153
|
+
v10_name: Optional[str] = None,
|
|
154
|
+
wpsd10max_name: Optional[str] = None,
|
|
155
|
+
_exclude_other_vars: bool = False,
|
|
152
156
|
) -> xr.Dataset:
|
|
153
157
|
"""
|
|
154
158
|
给xarray.Dataset的风添加属性
|
|
155
159
|
:param _ds: xarray.Dataset
|
|
156
|
-
:param
|
|
157
|
-
:param
|
|
160
|
+
:param u10_name: u10变量名,默认为自动识别
|
|
161
|
+
:param v10_name: v10变量名,默认为自动识别
|
|
162
|
+
:param wpsd10max_name: wpsd10max变量名,默认为自动识别
|
|
163
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
158
164
|
:return: xarray.Dataset
|
|
159
165
|
"""
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
_ds
|
|
166
|
+
u10_name = next((x for x in NAME_u10 if x in _ds.data_vars), None) if u10_name is None else u10_name
|
|
167
|
+
v10_name = next((x for x in NAME_v10 if x in _ds.data_vars), None) if v10_name is None else v10_name
|
|
168
|
+
wpsd10max_name = next((x for x in NAME_wpsd10max if x in _ds.data_vars), None) if wpsd10max_name is None else wpsd10max_name
|
|
169
|
+
_ds[u10_name].attrs = {
|
|
163
170
|
'units': 'm s-1',
|
|
164
171
|
'long_name': '10 meter U wind component',
|
|
165
172
|
'standard_name': 'eastward_wind',
|
|
166
173
|
}
|
|
167
|
-
_ds[
|
|
174
|
+
_ds[v10_name].attrs = {
|
|
168
175
|
'units': 'm s-1',
|
|
169
176
|
'long_name': '10 meter V wind component',
|
|
170
177
|
'standard_name': 'northward_wind',
|
|
171
178
|
}
|
|
172
|
-
dtype = calc_dtype(_ds[
|
|
173
|
-
_ds[
|
|
174
|
-
dtype = calc_dtype(_ds[
|
|
175
|
-
_ds[
|
|
179
|
+
dtype = calc_dtype(_ds[u10_name].data)
|
|
180
|
+
_ds[u10_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
181
|
+
dtype = calc_dtype(_ds[v10_name].data)
|
|
182
|
+
_ds[v10_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
176
183
|
|
|
177
184
|
if 'AGL_heights' in _ds.variables:
|
|
178
185
|
_ds['AGL_heights'].attrs = {
|
|
@@ -180,7 +187,8 @@ def add_wind_attrs(
|
|
|
180
187
|
'long_name': 'Above Ground Level Height',
|
|
181
188
|
'standard_name': 'height',
|
|
182
189
|
}
|
|
183
|
-
|
|
190
|
+
dtype = calc_dtype(_ds['AGL_heights'].data)
|
|
191
|
+
_ds['AGL_heights'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
184
192
|
|
|
185
193
|
if 'U_AGL' in _ds.variables and 'V_AGL' in _ds.variables:
|
|
186
194
|
_ds['U_AGL'].attrs = {
|
|
@@ -195,6 +203,7 @@ def add_wind_attrs(
|
|
|
195
203
|
}
|
|
196
204
|
dtype = calc_dtype(_ds['U_AGL'].data)
|
|
197
205
|
_ds['U_AGL'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
206
|
+
dtype = calc_dtype(_ds['V_AGL'].data)
|
|
198
207
|
_ds['V_AGL'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
199
208
|
|
|
200
209
|
if 'MSL_heights' in _ds.variables:
|
|
@@ -203,7 +212,8 @@ def add_wind_attrs(
|
|
|
203
212
|
'long_name': 'Mean Sea Level Height',
|
|
204
213
|
'standard_name': 'height',
|
|
205
214
|
}
|
|
206
|
-
|
|
215
|
+
dtype = calc_dtype(_ds['MSL_heights'].data)
|
|
216
|
+
_ds['MSL_heights'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
207
217
|
|
|
208
218
|
if 'U_MSL' in _ds.variables and 'V_MSL' in _ds.variables:
|
|
209
219
|
_ds['U_MSL'].attrs = {
|
|
@@ -218,203 +228,233 @@ def add_wind_attrs(
|
|
|
218
228
|
}
|
|
219
229
|
dtype = calc_dtype(_ds['U_MSL'].data)
|
|
220
230
|
_ds['U_MSL'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
231
|
+
dtype = calc_dtype(_ds['V_MSL'].data)
|
|
221
232
|
_ds['V_MSL'].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
222
233
|
|
|
223
|
-
if
|
|
224
|
-
_ds[
|
|
234
|
+
if wpsd10max_name in _ds:
|
|
235
|
+
_ds[wpsd10max_name].attrs = {
|
|
225
236
|
'units': 'm s-1',
|
|
226
237
|
'long_name': 'Maximum 10m wind speed',
|
|
227
238
|
'standard_name': 'maximum_10m_wind_speed',
|
|
228
239
|
}
|
|
229
|
-
dtype = calc_dtype(_ds[
|
|
230
|
-
_ds[
|
|
240
|
+
dtype = calc_dtype(_ds[wpsd10max_name].data)
|
|
241
|
+
_ds[wpsd10max_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
242
|
+
|
|
243
|
+
_ds = transpose_dims(_ds)
|
|
231
244
|
|
|
232
245
|
new_order = ['longitude', 'latitude', 'time', 'TIME',
|
|
233
|
-
|
|
246
|
+
u10_name, v10_name,
|
|
234
247
|
'U_AGL', 'V_AGL',
|
|
235
248
|
'U_MSL', 'V_MSL',
|
|
236
|
-
|
|
249
|
+
wpsd10max_name,
|
|
237
250
|
]
|
|
238
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
239
|
-
|
|
251
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
252
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
253
|
+
_ds = _ds[existing_vars]
|
|
240
254
|
|
|
241
255
|
return _ds
|
|
242
256
|
|
|
243
257
|
|
|
244
258
|
def add_temperature_attrs(
|
|
245
259
|
_ds: xr.Dataset,
|
|
246
|
-
|
|
260
|
+
t2_name: Optional[str] = None,
|
|
261
|
+
_exclude_other_vars: bool = False,
|
|
247
262
|
) -> xr.Dataset:
|
|
248
263
|
"""
|
|
249
264
|
给xarray.Dataset的温度添加属性
|
|
250
265
|
:param _ds: xarray.Dataset
|
|
251
|
-
:param
|
|
266
|
+
:param t2_name: T2变量名,默认为自动识别
|
|
267
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
252
268
|
:return: xarray.Dataset
|
|
253
269
|
"""
|
|
254
|
-
|
|
270
|
+
t2_name = next((x for x in NAME_t2 if x in _ds.data_vars), None) if t2_name is None else t2_name
|
|
255
271
|
|
|
256
|
-
_ds[
|
|
272
|
+
_ds[t2_name].attrs = {
|
|
257
273
|
'units': 'K',
|
|
258
274
|
'long_name': 'temperature at 2m',
|
|
259
275
|
'standard_name': 'temperature_at_2m'
|
|
260
276
|
}
|
|
261
|
-
dtype = calc_dtype(_ds[
|
|
262
|
-
_ds[
|
|
277
|
+
dtype = calc_dtype(_ds[t2_name].data)
|
|
278
|
+
_ds[t2_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
279
|
+
|
|
280
|
+
_ds = transpose_dims(_ds)
|
|
263
281
|
|
|
264
|
-
new_order = ['longitude', 'latitude', 'time', 'TIME',
|
|
265
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
266
|
-
|
|
282
|
+
new_order = ['longitude', 'latitude', 'time', 'TIME', t2_name]
|
|
283
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
284
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
285
|
+
_ds = _ds[existing_vars]
|
|
267
286
|
|
|
268
287
|
return _ds
|
|
269
288
|
|
|
270
289
|
|
|
271
290
|
def add_visibility_attrs(
|
|
272
291
|
_ds: xr.Dataset,
|
|
273
|
-
|
|
292
|
+
visi_name: Optional[str] = None,
|
|
293
|
+
_exclude_other_vars: bool = False,
|
|
274
294
|
) -> xr.Dataset:
|
|
275
295
|
"""
|
|
276
296
|
给xarray.Dataset的能见度添加属性
|
|
277
297
|
:param _ds: xarray.Dataset
|
|
278
|
-
:param
|
|
298
|
+
:param visi_name: 能见度变量名,默认为自动识别
|
|
299
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
279
300
|
:return: xarray.Dataset
|
|
280
301
|
"""
|
|
281
|
-
|
|
302
|
+
visi_name = next((x for x in NAME_visi if x in _ds.data_vars), None) if visi_name is None else visi_name
|
|
282
303
|
|
|
283
|
-
_ds[
|
|
304
|
+
_ds[visi_name].attrs = {
|
|
284
305
|
'units': 'm',
|
|
285
306
|
'long_name': 'visibility',
|
|
286
307
|
'standard_name': 'visibility'
|
|
287
308
|
}
|
|
288
|
-
dtype = calc_dtype(_ds[
|
|
289
|
-
_ds[
|
|
309
|
+
dtype = calc_dtype(_ds[visi_name].data)
|
|
310
|
+
_ds[visi_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
290
311
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
312
|
+
_ds = transpose_dims(_ds)
|
|
313
|
+
|
|
314
|
+
new_order = ['longitude', 'latitude', 'time', 'TIME', visi_name]
|
|
315
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
316
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
317
|
+
_ds = _ds[existing_vars]
|
|
294
318
|
|
|
295
319
|
return _ds
|
|
296
320
|
|
|
297
321
|
|
|
298
322
|
def add_radiation_attrs(
|
|
299
323
|
_ds: xr.Dataset,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
324
|
+
swr_name: Optional[str] = None,
|
|
325
|
+
lwr_name: Optional[str] = None,
|
|
326
|
+
swrn_name: Optional[str] = None,
|
|
327
|
+
_exclude_other_vars: bool = False,
|
|
303
328
|
) -> xr.Dataset:
|
|
304
329
|
"""
|
|
305
330
|
给xarray.Dataset的辐射添加属性
|
|
306
331
|
:param _ds: xarray.Dataset
|
|
307
|
-
:param
|
|
308
|
-
:param
|
|
309
|
-
:param
|
|
332
|
+
:param swr_name: 短波辐射变量名,默认为自动识别
|
|
333
|
+
:param lwr_name: 长波辐射变量名,默认为自动识别
|
|
334
|
+
:param swrn_name: 短波辐射法向量变量名,默认为自动识别
|
|
335
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
310
336
|
:return: xarray.Dataset
|
|
311
337
|
"""
|
|
312
|
-
|
|
313
|
-
|
|
338
|
+
swr_name = next((x for x in NAME_swr if x in _ds.data_vars), None) if swr_name is None else swr_name
|
|
339
|
+
lwr_name = next((x for x in NAME_lwr if x in _ds.data_vars), None) if lwr_name is None else lwr_name
|
|
340
|
+
swrn_name = next((x for x in NAME_swrn if x in _ds.data_vars), None) if swrn_name is None else swrn_name
|
|
314
341
|
|
|
315
|
-
_ds[
|
|
342
|
+
_ds[swr_name].attrs = {
|
|
316
343
|
'units': 'W/m^2',
|
|
317
344
|
'long_name': 'Short wave radiation',
|
|
318
345
|
'standard_name': 'Short_wave_radiation',
|
|
319
346
|
'description': 'Short wave radiation, positive for ocean gaining energy',
|
|
320
347
|
}
|
|
321
|
-
dtype = calc_dtype(_ds[
|
|
322
|
-
_ds[
|
|
348
|
+
dtype = calc_dtype(_ds[swr_name].data)
|
|
349
|
+
_ds[swr_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
323
350
|
|
|
324
|
-
_ds[
|
|
351
|
+
_ds[lwr_name].attrs = {
|
|
325
352
|
'units': 'W/m^2',
|
|
326
353
|
'long_name': 'Long wave radiation',
|
|
327
354
|
'standard_name': 'Long_wave_radiation',
|
|
328
355
|
'description': 'Long wave radiation, positive for ocean gaining energy',
|
|
329
356
|
}
|
|
330
|
-
dtype = calc_dtype(_ds[
|
|
331
|
-
_ds[
|
|
357
|
+
dtype = calc_dtype(_ds[lwr_name].data)
|
|
358
|
+
_ds[lwr_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
332
359
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
_ds[swnorm_name].attrs = {
|
|
360
|
+
if swrn_name in _ds:
|
|
361
|
+
_ds[swrn_name].attrs = {
|
|
336
362
|
'units': 'W/m^2',
|
|
337
363
|
'long_name': 'Short wave radiation normal',
|
|
338
364
|
'standard_name': 'Short_wave_radiation_normal',
|
|
339
365
|
'description': 'normal short wave flux at ground surface (slope-dependent)',
|
|
340
366
|
}
|
|
341
|
-
dtype = calc_dtype(_ds[
|
|
342
|
-
_ds[
|
|
367
|
+
dtype = calc_dtype(_ds[swrn_name].data)
|
|
368
|
+
_ds[swrn_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
343
369
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
370
|
+
_ds = transpose_dims(_ds)
|
|
371
|
+
|
|
372
|
+
new_order = ['longitude', 'latitude', 'time', 'TIME', swr_name, lwr_name, swrn_name]
|
|
373
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
374
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
375
|
+
_ds = _ds[existing_vars]
|
|
348
376
|
|
|
349
377
|
return _ds
|
|
350
378
|
|
|
351
379
|
|
|
352
380
|
def add_cloudCover_attrs(
|
|
353
381
|
_ds: xr.Dataset,
|
|
354
|
-
|
|
382
|
+
tcc_name: Optional[str] = None,
|
|
383
|
+
_exclude_other_vars: bool = False,
|
|
355
384
|
) -> xr.Dataset:
|
|
356
385
|
"""
|
|
357
386
|
给xarray.Dataset的云量添加属性
|
|
358
387
|
:param _ds: xarray.Dataset
|
|
359
|
-
:param
|
|
388
|
+
:param tcc_name: 云量变量名,默认为自动识别
|
|
389
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
360
390
|
:return: xarray.Dataset
|
|
361
391
|
"""
|
|
362
|
-
|
|
392
|
+
tcc_name = next((x for x in NAME_tcc if x in _ds.data_vars), None) if tcc_name is None else tcc_name
|
|
363
393
|
|
|
364
|
-
_ds[
|
|
394
|
+
_ds[tcc_name].attrs = {
|
|
365
395
|
'units': '1',
|
|
366
396
|
'long_name': 'total cloud cover',
|
|
367
397
|
'standard_name': 'total_cloud_cover',
|
|
368
398
|
'description': 'Total cloud cover, percentage of the sky covered by clouds'
|
|
369
399
|
}
|
|
370
|
-
dtype = calc_dtype(_ds[
|
|
371
|
-
_ds[
|
|
400
|
+
dtype = calc_dtype(_ds[tcc_name].data)
|
|
401
|
+
_ds[tcc_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
372
402
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
403
|
+
_ds = transpose_dims(_ds)
|
|
404
|
+
|
|
405
|
+
new_order = ['longitude', 'latitude', 'time', 'TIME', tcc_name]
|
|
406
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
407
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
408
|
+
_ds = _ds[existing_vars]
|
|
376
409
|
|
|
377
410
|
return _ds
|
|
378
411
|
|
|
379
412
|
|
|
380
413
|
def add_precipitation_attrs(
|
|
381
414
|
_ds: xr.Dataset,
|
|
382
|
-
|
|
415
|
+
prec_name: Optional[str] = None,
|
|
416
|
+
_exclude_other_vars: bool = False,
|
|
383
417
|
) -> xr.Dataset:
|
|
384
418
|
"""
|
|
385
419
|
给xarray.Dataset的降水添加属性
|
|
386
420
|
:param _ds: xarray.Dataset
|
|
387
|
-
:param
|
|
421
|
+
:param prec_name: 降水变量名,默认为自动识别
|
|
422
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
388
423
|
:return: xarray.Dataset
|
|
389
424
|
"""
|
|
390
|
-
|
|
425
|
+
prec_name = next((x for x in NAME_prec if x in _ds.data_vars), None) if prec_name is None else prec_name
|
|
391
426
|
|
|
392
|
-
_ds[
|
|
427
|
+
_ds[prec_name].attrs = {
|
|
393
428
|
'units': 'mm',
|
|
394
429
|
'long_name': 'precipitation, positive for ocean gaining water',
|
|
395
430
|
'standard_name': 'precipitation_positive_ocean_gaining_water'
|
|
396
431
|
}
|
|
397
|
-
dtype = calc_dtype(_ds[
|
|
398
|
-
_ds[
|
|
432
|
+
dtype = calc_dtype(_ds[prec_name].data)
|
|
433
|
+
_ds[prec_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
434
|
+
|
|
435
|
+
_ds = transpose_dims(_ds)
|
|
399
436
|
|
|
400
|
-
new_order = ['longitude', 'latitude', 'time', 'TIME',
|
|
401
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
402
|
-
|
|
437
|
+
new_order = ['longitude', 'latitude', 'time', 'TIME', prec_name]
|
|
438
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
439
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
440
|
+
_ds = _ds[existing_vars]
|
|
403
441
|
|
|
404
442
|
return _ds
|
|
405
443
|
|
|
406
444
|
|
|
407
445
|
def add_slp_attrs(
|
|
408
446
|
_ds: xr.Dataset,
|
|
409
|
-
slp_name: Optional[str] = None
|
|
447
|
+
slp_name: Optional[str] = None,
|
|
448
|
+
_exclude_other_vars: bool = False,
|
|
410
449
|
) -> xr.Dataset:
|
|
411
450
|
"""
|
|
412
451
|
给xarray.Dataset的海平面气压添加属性
|
|
413
452
|
:param _ds: xarray.Dataset
|
|
414
453
|
:param slp_name: 海平面气压变量名,默认为自动识别
|
|
454
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
415
455
|
:return: xarray.Dataset
|
|
416
456
|
"""
|
|
417
|
-
slp_name = next((x for x in
|
|
457
|
+
slp_name = next((x for x in NAME_slp if x in _ds.data_vars), None) if slp_name is None else slp_name
|
|
418
458
|
|
|
419
459
|
_ds[slp_name].attrs = {
|
|
420
460
|
'units': 'Pa',
|
|
@@ -424,9 +464,12 @@ def add_slp_attrs(
|
|
|
424
464
|
dtype = calc_dtype(_ds[slp_name].data)
|
|
425
465
|
_ds[slp_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
426
466
|
|
|
467
|
+
_ds = transpose_dims(_ds)
|
|
468
|
+
|
|
427
469
|
new_order = ['longitude', 'latitude', 'time', 'TIME', slp_name]
|
|
428
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
429
|
-
|
|
470
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
471
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
472
|
+
_ds = _ds[existing_vars]
|
|
430
473
|
|
|
431
474
|
return _ds
|
|
432
475
|
|
|
@@ -444,7 +487,8 @@ def add_wave_attrs(
|
|
|
444
487
|
mpww_name: Optional[str] = None,
|
|
445
488
|
mpts_name: Optional[str] = None,
|
|
446
489
|
pp1d_name: Optional[str] = None,
|
|
447
|
-
hmax_name: Optional[str] = None
|
|
490
|
+
hmax_name: Optional[str] = None,
|
|
491
|
+
_exclude_other_vars: bool = False,
|
|
448
492
|
) -> xr.Dataset:
|
|
449
493
|
"""
|
|
450
494
|
给xarray.Dataset的海浪添加属性
|
|
@@ -461,22 +505,23 @@ def add_wave_attrs(
|
|
|
461
505
|
:param mpts_name: 涌浪平均波周期变量名,默认为自动识别
|
|
462
506
|
:param pp1d_name: 谱峰周期变量名,默认为自动识别
|
|
463
507
|
:param hmax_name: 最大波高变量名,默认为自动识别
|
|
508
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
464
509
|
:return: xarray.Dataset
|
|
465
510
|
"""
|
|
466
|
-
swh_name = next((x for x in
|
|
467
|
-
mwp_name = next((x for x in
|
|
468
|
-
mwd_name = next((x for x in
|
|
469
|
-
mwl_name = next((x for x in
|
|
470
|
-
|
|
471
|
-
shww_name = next((x for x in
|
|
472
|
-
shts_name = next((x for x in
|
|
473
|
-
mdww_name = next((x for x in
|
|
474
|
-
mdts_name = next((x for x in
|
|
475
|
-
mpww_name = next((x for x in
|
|
476
|
-
mpts_name = next((x for x in
|
|
477
|
-
|
|
478
|
-
pp1d_name = next((x for x in
|
|
479
|
-
hmax_name = next((x for x in
|
|
511
|
+
swh_name = next((x for x in NAME_swh if x in _ds.data_vars), None) if swh_name is None else swh_name
|
|
512
|
+
mwp_name = next((x for x in NAME_mwp if x in _ds.data_vars), None) if mwp_name is None else mwp_name
|
|
513
|
+
mwd_name = next((x for x in NAME_mwd if x in _ds.data_vars), None) if mwd_name is None else mwd_name
|
|
514
|
+
mwl_name = next((x for x in NAME_mwl if x in _ds.data_vars), None) if mwl_name is None else mwl_name
|
|
515
|
+
|
|
516
|
+
shww_name = next((x for x in NAME_shww if x in _ds.data_vars), None) if shww_name is None else shww_name # 风浪有效波高
|
|
517
|
+
shts_name = next((x for x in NAME_shts if x in _ds.data_vars), None) if shts_name is None else shts_name # 涌浪有效波高
|
|
518
|
+
mdww_name = next((x for x in NAME_mdww if x in _ds.data_vars), None) if mdww_name is None else mdww_name # 风浪平均波向
|
|
519
|
+
mdts_name = next((x for x in NAME_mdts if x in _ds.data_vars), None) if mdts_name is None else mdts_name # 涌浪平均波向
|
|
520
|
+
mpww_name = next((x for x in NAME_mpww if x in _ds.data_vars), None) if mpww_name is None else mpww_name # 风浪平均波周期
|
|
521
|
+
mpts_name = next((x for x in NAME_mpts if x in _ds.data_vars), None) if mpts_name is None else mpts_name # 涌浪平均波周期
|
|
522
|
+
|
|
523
|
+
pp1d_name = next((x for x in NAME_pp1d if x in _ds.data_vars), None) if pp1d_name is None else pp1d_name # 谱峰周期
|
|
524
|
+
hmax_name = next((x for x in NAME_hmax if x in _ds.data_vars), None) if hmax_name is None else hmax_name # 最大波高
|
|
480
525
|
|
|
481
526
|
if swh_name in _ds:
|
|
482
527
|
_ds[swh_name].attrs = {
|
|
@@ -593,6 +638,8 @@ def add_wave_attrs(
|
|
|
593
638
|
dtype = calc_dtype(_ds[hmax_name].data)
|
|
594
639
|
_ds[hmax_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
595
640
|
|
|
641
|
+
_ds = transpose_dims(_ds)
|
|
642
|
+
|
|
596
643
|
new_order = ['longitude', 'latitude', 'time', 'TIME',
|
|
597
644
|
swh_name, mwp_name, mwd_name,
|
|
598
645
|
mwl_name, pp1d_name, hmax_name,
|
|
@@ -600,8 +647,9 @@ def add_wave_attrs(
|
|
|
600
647
|
mdww_name, mdts_name,
|
|
601
648
|
mpww_name, mpts_name,
|
|
602
649
|
]
|
|
603
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
604
|
-
|
|
650
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
651
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
652
|
+
_ds = _ds[existing_vars]
|
|
605
653
|
|
|
606
654
|
return _ds
|
|
607
655
|
|
|
@@ -609,17 +657,19 @@ def add_wave_attrs(
|
|
|
609
657
|
def add_ice_attrs(
|
|
610
658
|
_ds: xr.Dataset,
|
|
611
659
|
aice_name: Optional[str] = None,
|
|
612
|
-
tice_name: Optional[str] = None
|
|
660
|
+
tice_name: Optional[str] = None,
|
|
661
|
+
_exclude_other_vars: bool = False,
|
|
613
662
|
) -> xr.Dataset:
|
|
614
663
|
"""
|
|
615
664
|
给xarray.Dataset的海冰添加属性
|
|
616
665
|
:param _ds: xarray.Dataset
|
|
617
666
|
:param aice_name: 海冰浓度变量名,默认为自动识别
|
|
618
667
|
:param tice_name: 海冰厚度变量名,默认为自动识别
|
|
668
|
+
:param _exclude_other_vars: 是否排除其他变量,默认为False
|
|
619
669
|
:return: xarray.Dataset
|
|
620
670
|
"""
|
|
621
|
-
aice_name = next((x for x in
|
|
622
|
-
tice_name = next((x for x in
|
|
671
|
+
aice_name = next((x for x in NAME_aice if x in _ds.data_vars), None) if aice_name is None else aice_name
|
|
672
|
+
tice_name = next((x for x in NAME_tice if x in _ds.data_vars), None) if tice_name is None else tice_name
|
|
623
673
|
|
|
624
674
|
if aice_name in _ds:
|
|
625
675
|
_ds[aice_name].attrs = {
|
|
@@ -639,13 +689,34 @@ def add_ice_attrs(
|
|
|
639
689
|
dtype = calc_dtype(_ds[tice_name].data)
|
|
640
690
|
_ds[tice_name].encoding = dict(_FillValue=calc_fillvalue(dtype), dtype=dtype, zlib=True)
|
|
641
691
|
|
|
692
|
+
_ds = transpose_dims(_ds)
|
|
693
|
+
|
|
642
694
|
new_order = ['longitude', 'latitude', 'time', 'TIME', aice_name, tice_name]
|
|
643
|
-
existing_vars = [var for var in new_order if var in _ds.
|
|
644
|
-
|
|
695
|
+
existing_vars = [var for var in new_order if var is not None and var in _ds.variables]
|
|
696
|
+
existing_vars += [var for var in _ds.data_vars if var not in existing_vars] if not _exclude_other_vars else existing_vars
|
|
697
|
+
_ds = _ds[existing_vars]
|
|
645
698
|
|
|
646
699
|
return _ds
|
|
647
700
|
|
|
648
701
|
|
|
702
|
+
def transpose_dims(_ds: xr.Dataset) -> xr.Dataset:
|
|
703
|
+
"""
|
|
704
|
+
转置xarray.Dataset的维度顺序为(time, latitude, longitude)
|
|
705
|
+
"""
|
|
706
|
+
if 'DateStr' in _ds.dims:
|
|
707
|
+
transpose_order = ['DateStr', 'time', 'latitude', 'longitude']
|
|
708
|
+
elif 'TIME' in _ds.dims:
|
|
709
|
+
transpose_order = ['TIME', 'time', 'latitude', 'longitude']
|
|
710
|
+
else:
|
|
711
|
+
transpose_order = ['time', 'latitude', 'longitude']
|
|
712
|
+
|
|
713
|
+
# 有其他维度的话放在前面
|
|
714
|
+
for _dim in _ds.dims:
|
|
715
|
+
transpose_order.insert(0, _dim) if _dim not in transpose_order else None
|
|
716
|
+
|
|
717
|
+
return _ds.transpose(*transpose_order)
|
|
718
|
+
|
|
719
|
+
|
|
649
720
|
def fixed_encoding(_ds, **kwargs):
|
|
650
721
|
"""
|
|
651
722
|
修正xarray.Dataset的encoding
|
|
@@ -794,6 +865,7 @@ def calc_dtype(_values) -> type:
|
|
|
794
865
|
# 其他情况兜底
|
|
795
866
|
return np.float32
|
|
796
867
|
|
|
868
|
+
|
|
797
869
|
def calc_fillvalue(_dtype):
|
|
798
870
|
"""
|
|
799
871
|
根据数据类型计算合适的_FillValue
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|