oafuncs 0.0.98.42__tar.gz → 0.0.98.43__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {oafuncs-0.0.98.42/oafuncs.egg-info → oafuncs-0.0.98.43}/PKG-INFO +1 -1
  2. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/netcdf_write.py +8 -24
  3. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/plot_dataset.py +8 -3
  4. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_nc.py +6 -3
  5. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43/oafuncs.egg-info}/PKG-INFO +1 -1
  6. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/setup.py +1 -1
  7. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/LICENSE.txt +0 -0
  8. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/MANIFEST.in +0 -0
  9. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/README.md +0 -0
  10. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/__init__.py +0 -0
  11. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_data/hycom.png +0 -0
  12. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_data/oafuncs.png +0 -0
  13. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/cprogressbar.py +0 -0
  14. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/data_interp.py +0 -0
  15. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/email.py +0 -0
  16. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/netcdf_merge.py +0 -0
  17. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/netcdf_modify.py +0 -0
  18. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/parallel.py +0 -0
  19. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/parallel_bak.py +0 -0
  20. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/_script/replace_file_content.py +0 -0
  21. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_cmap.py +0 -0
  22. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_data.py +0 -0
  23. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_date.py +0 -0
  24. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/User_Agent-list.txt +0 -0
  25. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/__init__.py +0 -0
  26. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/hycom_3hourly.py +0 -0
  27. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/idm.py +0 -0
  28. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/literature.py +0 -0
  29. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/read_proxy.py +0 -0
  30. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/test_ua.py +0 -0
  31. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_down/user_agent.py +0 -0
  32. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_draw.py +0 -0
  33. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_file.py +0 -0
  34. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_help.py +0 -0
  35. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_model/__init__.py +0 -0
  36. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_model/roms/__init__.py +0 -0
  37. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_model/roms/test.py +0 -0
  38. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_model/wrf/__init__.py +0 -0
  39. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_model/wrf/little_r.py +0 -0
  40. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_python.py +0 -0
  41. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_sign/__init__.py +0 -0
  42. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_sign/meteorological.py +0 -0
  43. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_sign/ocean.py +0 -0
  44. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_sign/scientific.py +0 -0
  45. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs/oa_tool.py +0 -0
  46. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs.egg-info/SOURCES.txt +0 -0
  47. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs.egg-info/dependency_links.txt +0 -0
  48. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs.egg-info/requires.txt +0 -0
  49. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/oafuncs.egg-info/top_level.txt +0 -0
  50. {oafuncs-0.0.98.42 → oafuncs-0.0.98.43}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oafuncs
3
- Version: 0.0.98.42
3
+ Version: 0.0.98.43
4
4
  Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -81,13 +81,9 @@ def _calculate_scale_and_offset(data, dtype="int32"):
81
81
  if dtype == "int32":
82
82
  n = 32
83
83
  fill_value = np.iinfo(np.int32).min # -2147483648
84
- max_packed_value = np.iinfo(np.int32).max # 2147483647
85
- min_packed_value = np.iinfo(np.int32).min + 1 # -2147483647 (保留最小值作为填充值)
86
84
  elif dtype == "int16":
87
85
  n = 16
88
86
  fill_value = np.iinfo(np.int16).min # -32768
89
- max_packed_value = np.iinfo(np.int16).max # 32767
90
- min_packed_value = np.iinfo(np.int16).min + 1 # -32767 (保留最小值作为填充值)
91
87
  else:
92
88
  raise ValueError("Unsupported dtype. Supported types are 'int16' and 'int32'.")
93
89
 
@@ -97,15 +93,8 @@ def _calculate_scale_and_offset(data, dtype="int32"):
97
93
  valid_mask &= ~data.mask
98
94
 
99
95
  if np.any(valid_mask):
100
- data_min = np.min(data[valid_mask])
101
- data_max = np.max(data[valid_mask])
102
-
103
- # 添加一个小的缓冲以确保所有值都在范围内,但不要过大
104
- data_range = data_max - data_min
105
- if data_range > 0:
106
- buffer = data_range * 1e-6 # 使用相对缓冲而不是绝对值1
107
- data_min -= buffer
108
- data_max += buffer
96
+ data_min = np.min(data[valid_mask])-1
97
+ data_max = np.max(data[valid_mask])+1
109
98
  else:
110
99
  data_min, data_max = 0, 1
111
100
 
@@ -114,9 +103,7 @@ def _calculate_scale_and_offset(data, dtype="int32"):
114
103
  scale_factor = 1.0
115
104
  add_offset = data_min
116
105
  else:
117
- # 使用可用的打包值范围计算scale_factor
118
- packed_range = max_packed_value - min_packed_value
119
- scale_factor = (data_max - data_min) / packed_range
106
+ scale_factor = (data_max - data_min) / (2**n - 2)
120
107
  add_offset = (data_max + data_min) / 2.0
121
108
  return scale_factor, add_offset
122
109
 
@@ -154,18 +141,14 @@ def _data_to_scale_offset(data, scale, offset, dtype='int32'):
154
141
  # 只有掩码标记的区域视为无效
155
142
  valid_mask &= ~data.mask
156
143
 
157
- # 初始化结果数组为填充值
158
- result = np.full_like(data, fill_value, dtype=np_dtype)
159
-
144
+ result = data.copy()
160
145
  if np.any(valid_mask):
161
- # 标准的scale/offset转换公式:packed_value = (unpacked_value - add_offset) / scale_factor
146
+ # 反向映射时能还原原始值
162
147
  scaled = (data[valid_mask] - offset) / scale
163
- # 四舍五入到最近的整数
164
148
  scaled = np.round(scaled).astype(np_dtype)
165
- # clip到整数范围,保留最大范围供转换
166
- scaled = np.clip(scaled, clip_min, clip_max) # 不使用最小值,保留做 _FillValue
149
+ # clip到int32范围,保留最大范围供转换
150
+ scaled = np.clip(scaled, clip_min, clip_max) # 不使用 -2147483648,保留做 _FillValue
167
151
  result[valid_mask] = scaled
168
-
169
152
  return result
170
153
 
171
154
 
@@ -391,6 +374,7 @@ def save_to_nc(file, data, varname=None, coords=None, mode="w", convert_dtype='i
391
374
  raise RuntimeError(f"netCDF4 保存失败: {str(e)}") from e
392
375
 
393
376
 
377
+
394
378
  # 测试用例
395
379
  if __name__ == "__main__":
396
380
  # 示例文件路径,需根据实际情况修改
@@ -197,12 +197,12 @@ def select_colormap_and_levels(data_range: Tuple[float, float], plot_type: str)
197
197
  num_levels = 128
198
198
 
199
199
  if data_range[0] * data_range[1] < 0:
200
- cmap = oafuncs.oa_cmap.get("diverging_1")
200
+ cmap = oafuncs.oa_cmap.get(diverging_cmap)
201
201
  bdy = max(abs(data_range[0]), abs(data_range[1]))
202
202
  norm = mpl.colors.TwoSlopeNorm(vmin=-bdy, vcenter=0, vmax=bdy)
203
203
  levels = np.linspace(-bdy, bdy, num_levels)
204
204
  else:
205
- cmap = oafuncs.oa_cmap.get("cool_1") if data_range[0] < 0 else oafuncs.oa_cmap.get("warm_1")
205
+ cmap = oafuncs.oa_cmap.get(negative_cmap) if data_range[0] < 0 else oafuncs.oa_cmap.get(positive_cmap)
206
206
  norm = mpl.colors.Normalize(vmin=data_range[0], vmax=data_range[1])
207
207
  levels = np.linspace(data_range[0], data_range[1], num_levels)
208
208
 
@@ -320,9 +320,14 @@ def get_xyzt_names(ds_in, xyzt_dims):
320
320
  return x_dim, y_dim, z_dim, t_dim
321
321
 
322
322
 
323
- def func_plot_dataset(ds_in: Union[xr.Dataset, xr.DataArray], output_dir: str, xyzt_dims: Tuple[str, str, str, str] = None, plot_type: str = "contourf", fixed_colorscale: bool = False) -> None:
323
+ def func_plot_dataset(ds_in: Union[xr.Dataset, xr.DataArray], output_dir: str, cmap='diverging_3', pcmap='warm_3', ncmap='cool_3', xyzt_dims: Tuple[str, str, str, str] = None, plot_type: str = "contourf", fixed_colorscale: bool = False) -> None:
324
324
  """Plot variables from a NetCDF file and save the plots to the specified directory."""
325
325
  os.makedirs(output_dir, exist_ok=True)
326
+
327
+ global diverging_cmap, positive_cmap, negative_cmap
328
+ diverging_cmap = cmap
329
+ positive_cmap = pcmap
330
+ negative_cmap = ncmap
326
331
 
327
332
  # Main processing function
328
333
  try:
@@ -270,6 +270,9 @@ def draw(
270
270
  output_directory: Optional[str] = None,
271
271
  dataset: Optional[xr.Dataset] = None,
272
272
  file_path: Optional[str] = None,
273
+ cmap='diverging_3',
274
+ pcmap='warm_3',
275
+ ncmap='cool_3',
273
276
  dims_xyzt: Union[List[str], Tuple[str, str, str, str]] = None,
274
277
  plot_style: str = "contourf",
275
278
  use_fixed_colorscale: bool = False,
@@ -296,18 +299,18 @@ def draw(
296
299
  raise ValueError("dimensions must be a list or tuple")
297
300
 
298
301
  if dataset is not None:
299
- func_plot_dataset(dataset, output_directory, dims_xyzt, plot_style, use_fixed_colorscale)
302
+ func_plot_dataset(dataset, output_directory, cmap, pcmap, ncmap, dims_xyzt, plot_style, use_fixed_colorscale)
300
303
  elif file_path is not None:
301
304
  if check(file_path):
302
305
  ds = xr.open_dataset(file_path)
303
- func_plot_dataset(ds, output_directory, dims_xyzt, plot_style, use_fixed_colorscale)
306
+ func_plot_dataset(ds, output_directory, cmap, pcmap, ncmap, dims_xyzt, plot_style, use_fixed_colorscale)
304
307
  else:
305
308
  print(f"[red]Invalid file: {file_path}[/red]")
306
309
  else:
307
310
  print("[red]No dataset or file provided.[/red]")
308
311
 
309
312
 
310
- def compress(src_path, dst_path=None,convert_dtype='int16'):
313
+ def compress(src_path, dst_path=None,convert_dtype='int32'):
311
314
  """
312
315
  压缩 NetCDF 文件,使用 scale_factor/add_offset 压缩数据。
313
316
  若 dst_path 省略,则自动生成新文件名,写出后删除原文件并将新文件改回原名。
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oafuncs
3
- Version: 0.0.98.42
3
+ Version: 0.0.98.43
4
4
  Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -18,7 +18,7 @@ URL = "https://github.com/Industry-Pays/OAFuncs"
18
18
  EMAIL = "liukun0312@stu.ouc.edu.cn"
19
19
  AUTHOR = "Kun Liu"
20
20
  REQUIRES_PYTHON = ">=3.10.0" # 2025/03/13
21
- VERSION = "0.0.98.42"
21
+ VERSION = "0.0.98.43"
22
22
 
23
23
  # What packages are required for this module to be executed?
24
24
  REQUIRED = [
File without changes
File without changes
File without changes
File without changes