oafuncs 0.0.98.38__py3-none-any.whl → 0.0.98.40__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.
- oafuncs/oa_cmap.py +1 -0
- oafuncs/oa_draw.py +84 -91
- {oafuncs-0.0.98.38.dist-info → oafuncs-0.0.98.40.dist-info}/METADATA +1 -1
- {oafuncs-0.0.98.38.dist-info → oafuncs-0.0.98.40.dist-info}/RECORD +7 -7
- {oafuncs-0.0.98.38.dist-info → oafuncs-0.0.98.40.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.98.38.dist-info → oafuncs-0.0.98.40.dist-info}/licenses/LICENSE.txt +0 -0
- {oafuncs-0.0.98.38.dist-info → oafuncs-0.0.98.40.dist-info}/top_level.txt +0 -0
oafuncs/oa_cmap.py
CHANGED
oafuncs/oa_draw.py
CHANGED
@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
|
|
6
6
|
import numpy as np
|
7
7
|
from rich import print
|
8
8
|
|
9
|
-
__all__ = ["fig_minus", "gif", "movie", "setup_map", "
|
9
|
+
__all__ = ["fig_minus", "gif", "movie", "setup_map", "ticks_symmetric"]
|
10
10
|
|
11
11
|
warnings.filterwarnings("ignore")
|
12
12
|
|
@@ -247,44 +247,41 @@ def setup_map(
|
|
247
247
|
from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
|
248
248
|
lon_formatter = LongitudeFormatter(zero_direction_label=False, number_format=f".{tick_decimals}f")
|
249
249
|
lat_formatter = LatitudeFormatter(number_format=f".{tick_decimals}f")
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
gl.xlocator = mticker.FixedLocator(np.array(longitude_ticks))
|
269
|
-
if latitude_ticks is not None:
|
270
|
-
gl.ylocator = mticker.FixedLocator(np.array(latitude_ticks))
|
271
|
-
|
272
|
-
elif show_labels:
|
250
|
+
|
251
|
+
# 只要传入经纬度数据就自动设置范围
|
252
|
+
# 范围必须在cartopy添加地图特征之后设置,因为添加特征可能会改变axes的范围
|
253
|
+
if longitude_data is not None and latitude_data is not None:
|
254
|
+
# 过滤掉NaN,避免极端值影响
|
255
|
+
lon_data = np.asarray(longitude_data)
|
256
|
+
lat_data = np.asarray(latitude_data)
|
257
|
+
lon_valid = lon_data[~np.isnan(lon_data)]
|
258
|
+
lat_valid = lat_data[~np.isnan(lat_data)]
|
259
|
+
if lon_valid.size > 0 and lat_valid.size > 0:
|
260
|
+
lon_min, lon_max = np.min(lon_valid), np.max(lon_valid)
|
261
|
+
lat_min, lat_max = np.min(lat_valid), np.max(lat_valid)
|
262
|
+
axes.set_extent([lon_min, lon_max, lat_min, lat_max], crs=map_projection)
|
263
|
+
else:
|
264
|
+
# 若全是NaN则不设置范围
|
265
|
+
pass
|
266
|
+
|
267
|
+
if show_labels:
|
273
268
|
# Add tick labels without gridlines
|
274
269
|
# Generate default tick positions based on current extent if not provided
|
275
270
|
if longitude_ticks is None:
|
276
271
|
current_extent = axes.get_extent(crs=map_projection)
|
277
272
|
lon_range = current_extent[1] - current_extent[0]
|
278
273
|
# Generate reasonable tick spacing
|
279
|
-
tick_spacing = 1 if lon_range <= 10 else (5 if lon_range <= 30 else (
|
280
|
-
longitude_ticks = np.arange(np.ceil(current_extent[0] / tick_spacing) * tick_spacing, current_extent[1] +
|
274
|
+
tick_spacing = 1 if lon_range <= 10 else (5 if lon_range <= 30 else (15 if lon_range <= 90 else (30 if lon_range <= 180 else 60)))
|
275
|
+
longitude_ticks = np.arange(np.ceil(current_extent[0] / tick_spacing) * tick_spacing, current_extent[1] + 0.1, tick_spacing)
|
276
|
+
# print(f"[green]Longitude ticks set to:[/green] {longitude_ticks}")
|
281
277
|
|
282
278
|
if latitude_ticks is None:
|
283
279
|
current_extent = axes.get_extent(crs=map_projection)
|
284
280
|
lat_range = current_extent[3] - current_extent[2]
|
285
281
|
# Generate reasonable tick spacing
|
286
|
-
tick_spacing = 1 if lat_range <= 10 else (5 if lat_range <= 30 else (
|
287
|
-
latitude_ticks = np.arange(np.ceil(current_extent[2] / tick_spacing) * tick_spacing, current_extent[3] +
|
282
|
+
tick_spacing = 1 if lat_range <= 10 else (5 if lat_range <= 30 else (15 if lat_range <= 90 else 30))
|
283
|
+
latitude_ticks = np.arange(np.ceil(current_extent[2] / tick_spacing) * tick_spacing, current_extent[3] + 0.1, tick_spacing)
|
284
|
+
# print(f"[green]Latitude ticks set to:[/green] {latitude_ticks}")
|
288
285
|
|
289
286
|
# Set tick positions and formatters
|
290
287
|
axes.set_xticks(longitude_ticks, crs=map_projection)
|
@@ -296,75 +293,71 @@ def setup_map(
|
|
296
293
|
axes.tick_params(axis="x", labelbottom=bottom_labels, labeltop=top_labels)
|
297
294
|
axes.tick_params(axis="y", labelleft=left_labels, labelright=right_labels)
|
298
295
|
|
299
|
-
#
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
lon_data = np.asarray(longitude_data)
|
304
|
-
lat_data = np.asarray(latitude_data)
|
305
|
-
lon_valid = lon_data[~np.isnan(lon_data)]
|
306
|
-
lat_valid = lat_data[~np.isnan(lat_data)]
|
307
|
-
if lon_valid.size > 0 and lat_valid.size > 0:
|
308
|
-
lon_min, lon_max = np.min(lon_valid), np.max(lon_valid)
|
309
|
-
lat_min, lat_max = np.min(lat_valid), np.max(lat_valid)
|
310
|
-
axes.set_extent([lon_min, lon_max, lat_min, lat_max], crs=map_projection)
|
311
|
-
else:
|
312
|
-
# 若全是NaN则不设置范围
|
313
|
-
pass
|
314
|
-
return axes
|
315
|
-
|
316
|
-
|
317
|
-
class MidpointNormalize(mpl.colors.Normalize):
|
318
|
-
"""Custom normalization class to center a specific value.
|
319
|
-
|
320
|
-
Args:
|
321
|
-
vmin (float, optional): Minimum data value. Defaults to None.
|
322
|
-
vmax (float, optional): Maximum data value. Defaults to None.
|
323
|
-
vcenter (float, optional): Center value for normalization. Defaults to 0.
|
324
|
-
clip (bool, optional): Whether to clip data outside the range. Defaults to False.
|
325
|
-
|
326
|
-
Example:
|
327
|
-
>>> norm = MidpointNormalize(vmin=-2, vmax=1, vcenter=0)
|
328
|
-
"""
|
296
|
+
# Handle gridlines and ticks
|
297
|
+
if show_gridlines:
|
298
|
+
# Add gridlines with labels
|
299
|
+
gl = axes.gridlines(crs=map_projection, draw_labels=show_labels, linewidth=grid_width, color=grid_color, alpha=grid_alpha, linestyle=grid_style)
|
329
300
|
|
330
|
-
|
331
|
-
|
332
|
-
|
301
|
+
# Configure label positions
|
302
|
+
gl.left_labels = left_labels
|
303
|
+
gl.bottom_labels = bottom_labels
|
304
|
+
gl.right_labels = right_labels
|
305
|
+
gl.top_labels = top_labels
|
333
306
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
clip = self.clip
|
307
|
+
# Set formatters
|
308
|
+
gl.xformatter = lon_formatter
|
309
|
+
gl.yformatter = lat_formatter
|
338
310
|
|
339
|
-
|
340
|
-
|
311
|
+
# Set custom tick positions if provided
|
312
|
+
if longitude_ticks is not None:
|
313
|
+
gl.xlocator = mticker.FixedLocator(np.array(longitude_ticks))
|
314
|
+
if latitude_ticks is not None:
|
315
|
+
gl.ylocator = mticker.FixedLocator(np.array(latitude_ticks))
|
316
|
+
|
317
|
+
return axes
|
341
318
|
|
342
|
-
# Apply clipping if requested
|
343
|
-
if clip:
|
344
|
-
result = np.clip(result, 0, 1)
|
345
319
|
|
346
|
-
|
320
|
+
def ticks_symmetric(vmin: float, vcenter: float, vmax: float, num: int = 7) -> np.ndarray:
|
321
|
+
"""
|
322
|
+
生成以指定中心点对称分布的刻度值
|
347
323
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
324
|
+
参数:
|
325
|
+
vmin (float): 最小值
|
326
|
+
vcenter (float): 中心值
|
327
|
+
vmax (float): 最大值
|
328
|
+
num (int, optional): 期望的刻度数量(必须是奇数)。默认为7
|
329
|
+
|
330
|
+
返回:
|
331
|
+
np.ndarray: 对称分布的刻度值数组
|
332
|
+
|
333
|
+
异常:
|
334
|
+
ValueError: 如果输入值无效
|
335
|
+
|
336
|
+
示例:
|
337
|
+
>>> ticks_symmetric(vmin=-10, vcenter=0, vmax=10, num=5)
|
338
|
+
array([-10., -5., 0., 5., 10.])
|
339
|
+
"""
|
340
|
+
# 验证输入参数
|
341
|
+
if vmin >= vcenter:
|
342
|
+
raise ValueError(f"vmin ({vmin}) must be less than vcenter ({vcenter})")
|
343
|
+
if vcenter >= vmax:
|
344
|
+
raise ValueError(f"vcenter ({vcenter}) must be less than vmax ({vmax})")
|
345
|
+
|
346
|
+
# 确保刻度数量是奇数
|
347
|
+
if num % 2 == 0:
|
348
|
+
num += 1
|
349
|
+
|
350
|
+
# 计算每侧的点数(包括中心点)
|
351
|
+
side_points = (num - 1) // 2 + 1
|
352
|
+
|
353
|
+
# 生成左侧刻度(从最小值到中心值)
|
354
|
+
left_ticks = np.linspace(vmin, vcenter, side_points)[:-1]
|
355
|
+
|
356
|
+
# 生成右侧刻度(从中心值到最大值)
|
357
|
+
right_ticks = np.linspace(vcenter, vmax, side_points)[1:]
|
358
|
+
|
359
|
+
# 组合所有刻度
|
360
|
+
return np.concatenate([left_ticks, [vcenter], right_ticks])
|
368
361
|
|
369
362
|
|
370
363
|
if __name__ == "__main__":
|
@@ -1,8 +1,8 @@
|
|
1
1
|
oafuncs/__init__.py,sha256=T_-VtnWWllV3Q91twT5Yt2sUapeA051QbPNnBxmg9nw,1456
|
2
|
-
oafuncs/oa_cmap.py,sha256=
|
2
|
+
oafuncs/oa_cmap.py,sha256=JwZMJ36uNwiCnzXqEtH2_PpeLtEaRaXP9YeGSl0PJSU,13886
|
3
3
|
oafuncs/oa_data.py,sha256=u4H1ZazQf2jmGx3IAiaGxLjQHY9cQEMizRIaTQW4UiE,8075
|
4
4
|
oafuncs/oa_date.py,sha256=aU2wVIWXyWoRiSQ9dg8sHvShFTxw86RrgbV3Q6tDjD4,6841
|
5
|
-
oafuncs/oa_draw.py,sha256=
|
5
|
+
oafuncs/oa_draw.py,sha256=zal0Y3RPpN0TCGN4Gw9qLtjQdT6V0ZqpSUBFVOPL0x4,13952
|
6
6
|
oafuncs/oa_file.py,sha256=fLb0gRhq2AiPl-5ASDHMrx6Z267FmhqNcTV7CdCxTdI,16934
|
7
7
|
oafuncs/oa_help.py,sha256=0J5VaZX-cB0c090KxgmktQJBc0o00FsY-4wB8l5y00k,4178
|
8
8
|
oafuncs/oa_nc.py,sha256=mKNxQ9jPxfRH7xINyrX7tBhitG5gmOKm6Dn7stk5mdw,15279
|
@@ -37,8 +37,8 @@ oafuncs/oa_sign/__init__.py,sha256=JSx1fcWpmNhQBvX_Bmq3xysfSkkFMrjbJASxV_V6aqE,1
|
|
37
37
|
oafuncs/oa_sign/meteorological.py,sha256=3MSjy7HTcvz2zsITkjUMr_0Y027Gas1LFE9pk99990k,6110
|
38
38
|
oafuncs/oa_sign/ocean.py,sha256=3uYEzaq-27yVy23IQoqy-clhWu1I_fhPFBAQyT-OF4M,5562
|
39
39
|
oafuncs/oa_sign/scientific.py,sha256=moIl2MEY4uitbXoD596JmXookXGQtQsS-8_1NBBTx84,4689
|
40
|
-
oafuncs-0.0.98.
|
41
|
-
oafuncs-0.0.98.
|
42
|
-
oafuncs-0.0.98.
|
43
|
-
oafuncs-0.0.98.
|
44
|
-
oafuncs-0.0.98.
|
40
|
+
oafuncs-0.0.98.40.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
41
|
+
oafuncs-0.0.98.40.dist-info/METADATA,sha256=oD8heaDgtaCRU2T3HJZK1UXU7hnasx6dVk9WtC9TwQ4,4326
|
42
|
+
oafuncs-0.0.98.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
43
|
+
oafuncs-0.0.98.40.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
44
|
+
oafuncs-0.0.98.40.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|