oafuncs 0.0.86__py2.py3-none-any.whl → 0.0.87__py2.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_help.py CHANGED
@@ -23,8 +23,10 @@ __all__ = ["query", "use", "log"]
23
23
 
24
24
  def query():
25
25
  """
26
- description: 查看oafuncs模块的函数列表
27
- example: query()
26
+ Description:
27
+ Show the number of functions and the list of functions in the module.
28
+ Example:
29
+ query()
28
30
  """
29
31
  funcs = [func for func in dir(oafuncs) if callable(getattr(oafuncs, func))]
30
32
  print("函数数量:")
@@ -62,9 +64,12 @@ def _use_single(func="get_var", module="oafuncs"):
62
64
 
63
65
  def use(func_name='log'):
64
66
  """
65
- description: 查看本库指定函数的所有模块全路径和函数提示
66
- param {func_name} : 函数名
67
- example: use('get_var')
67
+ Description:
68
+ Show the full path and help of the function.
69
+ Args:
70
+ func_name: The name of the function.
71
+ Example:
72
+ use('log')
68
73
  """
69
74
  found = False
70
75
  # 假设oafuncs是一个包
@@ -105,10 +110,19 @@ def use(func_name='log'):
105
110
 
106
111
  def log():
107
112
  """
108
- description: 查看更新日志
109
- example: log()
113
+ Description:
114
+ Show the update log.
115
+ Example:
116
+ log()
110
117
  """
111
118
  print("更新日志:")
119
+ print(
120
+ """
121
+ 2025-01-04
122
+ 1. 下调Python支持版本到3.7,但未经过测试
123
+ 2. 优化了部分函数说明
124
+ """
125
+ )
112
126
  print(
113
127
  """
114
128
  2025-01-01
oafuncs/oa_nc.py CHANGED
@@ -24,10 +24,15 @@ __all__ = ["get_var", "extract", "save", "merge", "modify", "rename", "check_fil
24
24
 
25
25
  def get_var(file, *vars):
26
26
  """
27
- description: 读取nc文件中的变量
28
- param {file: 文件路径, *vars: 变量名}
29
- example: datas = get_var(file_ecm, 'h', 't', 'u', 'v')
30
- return {datas: 变量数据}
27
+ Description:
28
+ Read variables from nc file
29
+ Parameters:
30
+ file: str, file path
31
+ *vars: str, variable name or variable names; should be in same size
32
+ Example:
33
+ datas = get_var(file_ecm, 'h', 't', 'u', 'v')
34
+ Return:
35
+ datas: list, variable data
31
36
  """
32
37
  ds = xr.open_dataset(file)
33
38
  datas = []
@@ -40,15 +45,15 @@ def get_var(file, *vars):
40
45
 
41
46
  def extract(file, varname, only_value=True):
42
47
  """
43
- 描述:
44
- 1、提取nc文件中的变量
45
- 2、将相应维度提取,建立字典
46
- return:返回变量及坐标字典
47
- 参数:
48
- file: 文件路径
49
- varname: 变量名
50
- only_value: 变量和维度是否只保留数值
51
- example: data, dimdict = extract(file_ecm, 'h')
48
+ Description:
49
+ Extract variables from nc file
50
+ Return the variable and coordinate dictionary
51
+ Parameters:
52
+ file: str, file path
53
+ varname: str, variable name
54
+ only_value: bool, whether to keep only the value of the variable and dimension
55
+ Example:
56
+ data, dimdict = extract('test.nc', 'h')
52
57
  """
53
58
  ds = xr.open_dataset(file)
54
59
  vardata = ds[varname]
@@ -103,18 +108,18 @@ def _calculate_scale_and_offset(data, n=16):
103
108
 
104
109
  def save(file, data, varname=None, coords=None, mode="w", scale_offset_switch=True, compile_switch=True):
105
110
  """
106
- description: 写入数据到nc文件
107
-
108
- 参数:
109
- file: 文件路径
110
- data: 数据
111
- varname: 变量名
112
- coords: 坐标,字典,键为维度名称,值为坐标数据
113
- mode: 写入模式,'w'为写入,'a'为追加
114
- scale_offset_switch: 是否使用scale_factoradd_offset,默认为True
115
- compile_switch: 是否使用压缩参数,默认为True
116
-
117
- example: save(r'test.nc', data, 'data', {'time': np.linspace(0, 120, 100), 'lev': np.linspace(0, 120, 50)}, 'a')
111
+ Description:
112
+ Write data to NetCDF file
113
+ Parameters:
114
+ file: str, file path
115
+ data: data
116
+ varname: str, variable name
117
+ coords: dict, coordinates, key is the dimension name, value is the coordinate data
118
+ mode: str, write mode, 'w' for write, 'a' for append
119
+ scale_offset_switch: bool, whether to use scale_factor and add_offset, default is True
120
+ compile_switch: bool, whether to use compression parameters, default is True
121
+ Example:
122
+ save(r'test.nc', data, 'u', {'time': np.linspace(0, 120, 100), 'lev': np.linspace(0, 120, 50)}, 'a')
118
123
  """
119
124
  # 设置压缩参数
120
125
  kwargs = {"zlib": True, "complevel": 4} if compile_switch else {}
@@ -177,20 +182,21 @@ def save(file, data, varname=None, coords=None, mode="w", scale_offset_switch=Tr
177
182
 
178
183
  def merge(file_list, var_name=None, dim_name=None, target_filename=None):
179
184
  """
180
- 批量提取 nc 文件中的变量,按照某一维度合并后写入新的 nc 文件。
181
- 如果 var_name 是字符串,则认为是单变量;如果是列表,且只有一个元素,也是单变量;
182
- 如果列表元素大于1,则是多变量;如果 var_name None,则合并所有变量。
183
-
184
- 参数:
185
- file_list:nc 文件路径列表
186
- var_name:要提取的变量名或变量名列表,默认为 None,表示提取所有变量
187
- dim_name:用于合并的维度名
188
- target_filename:合并后的目标文件名
189
-
190
- example:
191
- merge(file_list, var_name='data', dim_name='time', target_filename='merged.nc')
192
- merge(file_list, var_name=['data1', 'data2'], dim_name='time', target_filename='merged.nc')
193
- merge(file_list, var_name=None, dim_name='time', target_filename='merged.nc')
185
+ Description:
186
+ Merge variables from multiple NetCDF files along a specified dimension and write to a new file.
187
+ If var_name is a string, it is considered a single variable; if it is a list and has only one element, it is also a single variable;
188
+ If the list has more than one element, it is a multi-variable; if var_name is None, all variables are merged.
189
+
190
+ Parameters:
191
+ file_list: List of NetCDF file paths
192
+ var_name: Name of the variable to be extracted or a list of variable names, default is None, which means all variables are extracted
193
+ dim_name: Dimension name used for merging
194
+ target_filename: Target file name after merging
195
+
196
+ Example:
197
+ merge(file_list, var_name='u', dim_name='time', target_filename='merged.nc')
198
+ merge(file_list, var_name=['u', 'v'], dim_name='time', target_filename='merged.nc')
199
+ merge(file_list, var_name=None, dim_name='time', target_filename='merged.nc')
194
200
  """
195
201
  if isinstance(file_list, str):
196
202
  file_list = [file_list]
@@ -249,15 +255,17 @@ def merge(file_list, var_name=None, dim_name=None, target_filename=None):
249
255
 
250
256
 
251
257
  def _modify_var(nc_file_path, variable_name, new_value):
252
- """
253
- 使用 netCDF4 库修改 NetCDF 文件中特定变量的值
254
-
255
- 参数:
256
- nc_file_path (str): NetCDF 文件路径
257
- variable_name (str): 要修改的变量名
258
- new_value (numpy.ndarray): 新的变量值
259
-
260
- example: modify_var('test.nc', 'data', np.random.rand(100, 50))
258
+ """
259
+ Description:
260
+ Modify the value of a variable in a NetCDF file using the netCDF4 library.
261
+
262
+ Parameters:
263
+ nc_file_path (str): The path to the NetCDF file.
264
+ variable_name (str): The name of the variable to be modified.
265
+ new_value (numpy.ndarray): The new value of the variable.
266
+
267
+ Example:
268
+ modify_var('test.nc', 'u', np.random.rand(100, 50))
261
269
  """
262
270
  try:
263
271
  # Open the NetCDF file
@@ -273,15 +281,18 @@ def _modify_var(nc_file_path, variable_name, new_value):
273
281
 
274
282
 
275
283
  def _modify_attr(nc_file_path, variable_name, attribute_name, attribute_value):
276
- """
277
- 使用 netCDF4 库添加或修改 NetCDF 文件中特定变量的属性。
278
-
279
- 参数:
280
- nc_file_path (str): NetCDF 文件路径
281
- variable_name (str): 要操作的变量名
282
- attribute_name (str): 属性名
283
- attribute_value (任意类型): 属性值
284
- example: modify_attr('test.nc', 'temperature', 'long_name', 'Temperature in Celsius')
284
+ """
285
+ Description:
286
+ Add or modify an attribute of a variable in a NetCDF file using the netCDF4 library.
287
+
288
+ Parameters:
289
+ nc_file_path (str): The path to the NetCDF file.
290
+ variable_name (str): The name of the variable to be modified.
291
+ attribute_name (str): The name of the attribute to be added or modified.
292
+ attribute_value (any): The value of the attribute.
293
+
294
+ Example:
295
+ modify_attr('test.nc', 'temperature', 'long_name', 'Temperature in Celsius')
285
296
  """
286
297
  try:
287
298
  ds = nc.Dataset(nc_file_path, "r+")
@@ -303,15 +314,18 @@ def _modify_attr(nc_file_path, variable_name, attribute_name, attribute_value):
303
314
 
304
315
  def modify(nc_file,var_name,attr_name=None,new_value=None):
305
316
  """
306
- description: 修改nc文件中的变量值或属性值
307
- parameters:
308
- nc_file: str, nc文件路径
309
- var_name: str, 变量名
310
- attr_name: str, 属性名; None表示修改变量值
311
- new_value: 任意类型, 新的变量值或属性值
312
- example:
313
- modify(nc_file, 'h', 'long_name', 'Height')
314
- modify(nc_file, 'h', None, np.random.rand(100, 50))
317
+ Description:
318
+ Modify the value of a variable or the value of an attribute in a NetCDF file.
319
+
320
+ Parameters:
321
+ nc_file (str): The path to the NetCDF file.
322
+ var_name (str): The name of the variable to be modified.
323
+ attr_name (str): The name of the attribute to be modified. If None, the variable value will be modified.
324
+ new_value (any): The new value of the variable or attribute.
325
+
326
+ Example:
327
+ modify('test.nc', 'temperature', 'long_name', 'Temperature in Celsius')
328
+ modify('test.nc', 'temperature', None, np.random.rand(100, 50))
315
329
  """
316
330
  if attr_name is None:
317
331
  _modify_var(nc_file, var_name, new_value)
@@ -321,14 +335,16 @@ def modify(nc_file,var_name,attr_name=None,new_value=None):
321
335
 
322
336
  def rename(ncfile_path, old_name, new_name):
323
337
  """
324
- Rename a variable and/or dimension in a NetCDF file.
338
+ Description:
339
+ Rename a variable and/or dimension in a NetCDF file.
325
340
 
326
341
  Parameters:
327
- ncfile_path (str): The path to the NetCDF file.
328
- old_name (str): The name of the variable or dimension to be renamed.
329
- new_name (str): The new name for the variable or dimension.
342
+ ncfile_path (str): The path to the NetCDF file.
343
+ old_name (str): The current name of the variable or dimension.
344
+ new_name (str): The new name to assign to the variable or dimension.
330
345
 
331
- example: rename('test.nc', 'time', 'ocean_time')
346
+ example:
347
+ rename('test.nc', 'temperature', 'temp')
332
348
  """
333
349
  try:
334
350
  with nc.Dataset(ncfile_path, "r+") as dataset:
@@ -355,14 +371,15 @@ def rename(ncfile_path, old_name, new_name):
355
371
 
356
372
  def check_file(ncfile, if_delete=False):
357
373
  '''
358
- Description: 检查nc文件是否损坏
359
-
374
+ Description:
375
+ Check if the NetCDF file is corrupted.
376
+
360
377
  Parameters:
361
- ncfile: str, nc文件路径
362
- if_delete: bool, 是否删除损坏的文件,默认为False
363
-
364
- Example:
365
- check_file(ncfile, if_delete=True)
378
+ ncfile (str): The path to the NetCDF file.
379
+ if_delete (bool): Whether to delete the file if it is corrupted, default is False.
380
+
381
+ Returns:
382
+ bool: True if the file is not corrupted, False otherwise.
366
383
  '''
367
384
  if not os.path.exists(ncfile):
368
385
  return False
@@ -393,15 +410,16 @@ def check_file(ncfile, if_delete=False):
393
410
 
394
411
  def convert_longitude(ds, lon_name="longitude", convert=180):
395
412
  """
396
- 将经度数组转换为指定的范围。
397
-
398
- 参数:
399
- ds (xarray.Dataset): 包含经度数据的xarray数据集。
400
- lon_name (str): 经度变量的名称,默认为"longitude"。
401
- convert (int): 转换目标范围,可以是180或360,默认为180。
402
-
403
- 返回值:
404
- xarray.Dataset: 经度转换后的xarray数据集。
413
+ Description:
414
+ Convert the longitude array to a specified range.
415
+
416
+ Parameters:
417
+ ds (xarray.Dataset): The xarray dataset containing the longitude data.
418
+ lon_name (str): The name of the longitude variable, default is "longitude".
419
+ convert (int): The target range to convert to, can be 180 or 360, default is 180.
420
+
421
+ Returns:
422
+ xarray.Dataset: The xarray dataset with the converted longitude.
405
423
  """
406
424
  to_which = int(convert)
407
425
  if to_which not in [180, 360]:
@@ -417,18 +435,17 @@ def convert_longitude(ds, lon_name="longitude", convert=180):
417
435
 
418
436
  def isel(ncfile, dim_name, slice_list):
419
437
  """
420
- Description: Choose the data by the index of the dimension
438
+ Description:
439
+ Choose the data by the index of the dimension
421
440
 
422
441
  Parameters:
423
442
  ncfile: str, the path of the netCDF file
424
443
  dim_name: str, the name of the dimension
425
444
  slice_list: list, the index of the dimension
426
445
 
427
- slice_list example: slice_list = [[y*12+m for m in range(11,14)] for y in range(84)]
428
- or
429
- slice_list = [y * 12 + m for y in range(84) for m in range(11, 14)]
430
-
431
446
  Example:
447
+ slice_list = [[y*12+m for m in range(11,14)] for y in range(84)]
448
+ slice_list = [y * 12 + m for y in range(84) for m in range(11, 14)]
432
449
  isel(ncfile, 'time', slice_list)
433
450
  """
434
451
  ds = xr.open_dataset(ncfile)
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oafuncs
3
- Version: 0.0.86
4
- Summary: My short description for my project.
3
+ Version: 0.0.87
4
+ Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
7
7
  Author-email: liukun0312@stu.ouc.edu.cn
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: Implementation :: CPython
17
17
  Classifier: Programming Language :: Python :: Implementation :: PyPy
18
- Requires-Python: >=3.9.0
18
+ Requires-Python: >=3.7.0
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE.txt
21
21
  Requires-Dist: matplotlib
@@ -3,8 +3,8 @@ oafuncs/oa_cmap.py,sha256=azVg9QR_IlG9lXCCXXVs1LS1kFci8yjxDmb_VA_TdTQ,7408
3
3
  oafuncs/oa_data.py,sha256=2MkWCsESVPjZPnLnbQIwrBJUhcF9x-WXbZhni3I44ss,15617
4
4
  oafuncs/oa_draw.py,sha256=PUk8DdGBUapCXrOVQ-d_DD6EccB_eHAX3r6jwrnQTk8,11126
5
5
  oafuncs/oa_file.py,sha256=-AdRnFEtRTpIMXr5geYe5fEhyiMOFad5ethi_lF-Ogo,12277
6
- oafuncs/oa_help.py,sha256=zQEYXFn6eCiEgzSy_gSjhdP3u-KRK4Hl-iGIvPC8EAs,3729
7
- oafuncs/oa_nc.py,sha256=OeWtv__oPsLNLBS6mOIUCvb8X9GEj4qjjc10lJE-IHE,16432
6
+ oafuncs/oa_help.py,sha256=DsX6rFPZ-ZMaexcyCXeGeB3h1zPScY6ijH-uLNVWidA,3988
7
+ oafuncs/oa_nc.py,sha256=b8pbiPSRDi7Te42UcnR0AlW1sQEVtn5VU9ERiAdX-yY,17501
8
8
  oafuncs/oa_python.py,sha256=XPTP3o7zTFzfJR_YhsKfQksa3bSYwXsne9YxlJplCEA,3994
9
9
  oafuncs/data_store/OAFuncs.png,sha256=w2pR7MUyeeWrT8BVTSy40EIRDIrfpdo1QvWvvjLOgjM,3258809
10
10
  oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
@@ -19,8 +19,8 @@ oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
19
19
  oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
20
20
  oafuncs/oa_tool/__init__.py,sha256=IKOlqpWlb4cMDCtq2VKR_RTxQHDNqR_vfqqsOsp_lKQ,466
21
21
  oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
22
- oafuncs-0.0.86.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
23
- oafuncs-0.0.86.dist-info/METADATA,sha256=Bg1Cg7-c-UUc0gGBDqR3HsrbnK6Sz5JgEKz3vdz9SzA,3303
24
- oafuncs-0.0.86.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
25
- oafuncs-0.0.86.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
26
- oafuncs-0.0.86.dist-info/RECORD,,
22
+ oafuncs-0.0.87.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
23
+ oafuncs-0.0.87.dist-info/METADATA,sha256=s_MdtiHoS3sPMPmK2J1se2gWXs34fA2tHSjQ4NqH-cs,3300
24
+ oafuncs-0.0.87.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
25
+ oafuncs-0.0.87.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
26
+ oafuncs-0.0.87.dist-info/RECORD,,