oafuncs 0.0.94__py2.py3-none-any.whl → 0.0.96__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.
Binary file
oafuncs/oa_data.py CHANGED
@@ -18,10 +18,11 @@ import multiprocessing as mp
18
18
  from concurrent.futures import ThreadPoolExecutor
19
19
 
20
20
  import numpy as np
21
+ import xarray as xr
21
22
  from scipy.interpolate import griddata
23
+ import salem
22
24
 
23
-
24
- __all__ = ["interp_2d", "ensure_list"]
25
+ __all__ = ["interp_2d", "ensure_list", "mask_shapefile"]
25
26
 
26
27
 
27
28
  def ensure_list(input_data):
@@ -44,7 +45,6 @@ def ensure_list(input_data):
44
45
  return [str(input_data)]
45
46
 
46
47
 
47
-
48
48
  def interp_2d(target_x, target_y, origin_x, origin_y, data, method="linear", parallel=True):
49
49
  """
50
50
  Perform 2D interpolation on the last two dimensions of a multi-dimensional array.
@@ -87,6 +87,8 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method="linear", par
87
87
  raise ValueError("Shape of data does not match shape of origin_x or origin_y.")
88
88
 
89
89
  # 创建网格和展平数据
90
+ target_x, target_y = np.array(target_x), np.array(target_y)
91
+ origin_x, origin_y = np.array(origin_x), np.array(origin_y)
90
92
  target_points = np.column_stack((target_y.ravel(), target_x.ravel()))
91
93
  origin_points = np.column_stack((origin_y.ravel(), origin_x.ravel()))
92
94
 
@@ -109,12 +111,38 @@ def interp_2d(target_x, target_y, origin_x, origin_y, data, method="linear", par
109
111
  elif len(data.shape) == 4:
110
112
  interpolated_data = np.stack([np.stack([interp_single(data[i, j], target_points, origin_points, method) for j in range(data.shape[1])]) for i in range(data.shape[0])])
111
113
 
112
- return np.array(interpolated_data)
114
+ return np.squeeze(np.array(interpolated_data))
115
+
113
116
 
117
+ def mask_shapefile(data: np.ndarray, lons: np.ndarray, lats: np.ndarray, shapefile_path: str) -> xr.DataArray:
118
+ """
119
+ Masks a 2D data array using a shapefile.
114
120
 
121
+ Parameters:
122
+ - data: 2D numpy array of data to be masked.
123
+ - lons: 1D numpy array of longitudes.
124
+ - lats: 1D numpy array of latitudes.
125
+ - shapefile_path: Path to the shapefile used for masking.
126
+
127
+ Returns:
128
+ - Masked xarray DataArray.
129
+ """
130
+ """
131
+ https://cloud.tencent.com/developer/article/1701896
132
+ """
133
+ try:
134
+ # import geopandas as gpd
135
+ # shp_f = gpd.read_file(shapefile_path)
136
+ shp_f = salem.read_shapefile(shapefile_path)
137
+ data_da = xr.DataArray(data, coords=[("latitude", lats), ("longitude", lons)])
138
+ masked_data = data_da.salem.roi(shape=shp_f)
139
+ return masked_data
140
+ except Exception as e:
141
+ print(f"An error occurred: {e}")
142
+ return None
115
143
 
116
- if __name__ == "__main__":
117
144
 
145
+ if __name__ == "__main__":
118
146
  pass
119
147
  """ import time
120
148
 
@@ -536,8 +536,10 @@ def _get_base_url(dataset_name, version_name, var, ymdh_str):
536
536
  mdh_str = ymdh_str[4:]
537
537
  # GLBy0.08 93.0
538
538
  # data time range in each year: year-01-01 12:00 to year+1-01-01 09:00
539
- if mdh_str <= "010109":
539
+ if "010100" <= mdh_str <= "010109":
540
540
  year_str = int(ymdh_str[:4]) - 1
541
+ else:
542
+ year_str = int(ymdh_str[:4])
541
543
  base_url = None
542
544
  for key, value in var_group.items():
543
545
  if var in value:
@@ -547,6 +549,13 @@ def _get_base_url(dataset_name, version_name, var, ymdh_str):
547
549
  print("Please ensure the var is in [u,v,temp,salt,ssh,u_b,v_b,temp_b,salt_b]")
548
550
  elif classification_method == "single_var_year_different":
549
551
  base_url = None
552
+ if dataset_name == "ESPC_D" and version_name == "V02":
553
+ mdh_str = ymdh_str[4:]
554
+ # ESPC-D-V02
555
+ if "010100" <= mdh_str <= "010109":
556
+ year_str = int(ymdh_str[:4]) - 1
557
+ else:
558
+ year_str = int(ymdh_str[:4])
550
559
  for key, value in single_var_group.items():
551
560
  if var in value:
552
561
  base_url = url_dict[key][str(year_str)]
@@ -1276,9 +1285,9 @@ if __name__ == "__main__":
1276
1285
 
1277
1286
  options = {
1278
1287
  "var": var_list,
1279
- "time_s": "2018010100",
1280
- "time_e": "2020123121",
1281
- "store_path": r"F:\Data\HYCOM\3hourly",
1288
+ "time_s": "2025010300",
1289
+ "time_e": "2025010321",
1290
+ "store_path": r"I:\Data\HYCOM\3hourly",
1282
1291
  "lon_min": 105,
1283
1292
  "lon_max": 130,
1284
1293
  "lat_min": 15,
@@ -1289,7 +1298,7 @@ if __name__ == "__main__":
1289
1298
  "level": None, # or 1-40 levels
1290
1299
  "ftimes": 1,
1291
1300
  # "idm_engine": r"D:\Programs\Internet Download Manager\IDMan.exe", # 查漏补缺不建议开启
1292
- "fill_time": False,
1301
+ "fill_time": None,
1293
1302
  }
1294
1303
 
1295
1304
  if single_var:
oafuncs/oa_nc.py CHANGED
@@ -254,13 +254,13 @@ def merge(file_list, var_name=None, dim_name=None, target_filename=None):
254
254
 
255
255
  merged_data = xr.Dataset(merged_data)
256
256
 
257
- print("Writing data to file ...")
257
+ print("\nWriting data to file ...")
258
258
  if os.path.exists(target_filename):
259
259
  print("Warning: The target file already exists.")
260
260
  print("Removing existing file ...")
261
261
  os.remove(target_filename)
262
262
  merged_data.to_netcdf(target_filename)
263
- print(f'File "{target_filename}" has been created.')
263
+ print(f'\nFile "{target_filename}" has been created.')
264
264
 
265
265
 
266
266
  def _modify_var(nc_file_path, variable_name, new_value):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: oafuncs
3
- Version: 0.0.94
3
+ Version: 0.0.96
4
4
  Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -27,9 +27,12 @@ Requires-Dist: pathlib
27
27
  Requires-Dist: requests
28
28
  Requires-Dist: bs4
29
29
  Requires-Dist: matplotlib
30
- Requires-Dist: Cartopy
31
30
  Requires-Dist: netCDF4
32
31
  Requires-Dist: xlrd
32
+ Requires-Dist: geopandas
33
+ Requires-Dist: Cartopy
34
+ Requires-Dist: rasterio
35
+ Requires-Dist: salem
33
36
  Dynamic: author
34
37
  Dynamic: author-email
35
38
  Dynamic: classifier
@@ -1,15 +1,15 @@
1
1
  oafuncs/__init__.py,sha256=glcIlhQ9xSK4WtL58dq7Od2S3JPqsuEyhUQ-VWO8hOc,1426
2
2
  oafuncs/oa_cmap.py,sha256=azVg9QR_IlG9lXCCXXVs1LS1kFci8yjxDmb_VA_TdTQ,7408
3
- oafuncs/oa_data.py,sha256=40cZsixCaMDW2kg8kzh60bvD9PPPFn9ZXlQuPr7QhpQ,6563
3
+ oafuncs/oa_data.py,sha256=Skhi70IY7T4lHd_eu3BxcSAfpXMH8SzUURR8gB7bj74,7679
4
4
  oafuncs/oa_draw.py,sha256=QypQp4vJIrbAyFddEVxd9K9Q4d85PRYqYQi9xDUmSZw,11150
5
5
  oafuncs/oa_file.py,sha256=EUL9osp7scZ3JTCwTUlKNfS1d_9xOsFrIkmFxzZAbdg,14233
6
6
  oafuncs/oa_help.py,sha256=loyzTbjU_0VpSIBvAEUA_tqxG8MVsO0xFE_2hgQ3zMw,4188
7
- oafuncs/oa_nc.py,sha256=pdc3vEI-5uFYnyzXHAIHNlyeci4MJkeWgKJwjHJ3olI,18343
7
+ oafuncs/oa_nc.py,sha256=SHjpGziWTIwzUHv4R5HaxL-7BC9j3y9XLThcbCD5bvc,18347
8
8
  oafuncs/oa_python.py,sha256=Q-6UGGw_dJff7Ef8i87fsLPoGeHV5jBzfb-7HP4THR0,4018
9
- oafuncs/data_store/OAFuncs.png,sha256=Cc0TDi9H5mWBporXYw9K0bUWC0oSsI-Qj3FGAXUtGKM,3332020
9
+ oafuncs/data_store/OAFuncs.png,sha256=y1_x-mUP3gFjcy6m8FqfvQO_HgjzPhQKfXjnSHjslZE,3436152
10
10
  oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
11
11
  oafuncs/oa_down/__init__.py,sha256=kRX5eTUCbAiz3zTaQM1501paOYS_3fizDN4Pa0mtNUA,585
12
- oafuncs/oa_down/hycom_3hourly.py,sha256=9ge6l8xMB-VBzCd1Fr4pIDZfUY_PbrBkWyvur0V27bs,64941
12
+ oafuncs/oa_down/hycom_3hourly.py,sha256=lCdbYQd7o_2jMgwmbrClNo5omrj5b5cnWnp6lnXMloQ,65307
13
13
  oafuncs/oa_down/hycom_3hourly_20250129.py,sha256=zbUp5NNBMzDXEqSC0-Z9H_EoM6Fg-6tXymK0AXH9qRk,65553
14
14
  oafuncs/oa_down/idm.py,sha256=XfYCNnQWADxOhhJd-T8sNYN0nGiRrAs7zbQcsB5-UmI,1668
15
15
  oafuncs/oa_down/literature.py,sha256=2bF9gSKQbzcci9LcKE81j8JEjIJwON7jbwQB3gDDA3E,11331
@@ -22,8 +22,8 @@ oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw
22
22
  oafuncs/oa_tool/__init__.py,sha256=bNTy9abznDhg3k_Irx0YieXl37r-oDRMtTAxf57Stzs,487
23
23
  oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
24
24
  oafuncs/oa_tool/parallel.py,sha256=kYbiIFDB7EoxasmXGSomaEDVUsg9Rfvdgbw93lBOY7o,3770
25
- oafuncs-0.0.94.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
26
- oafuncs-0.0.94.dist-info/METADATA,sha256=rKL0f-sli0TN2wL2WAU_-bA89eGzVu0aTyCK5K38RLU,3545
27
- oafuncs-0.0.94.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
28
- oafuncs-0.0.94.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
29
- oafuncs-0.0.94.dist-info/RECORD,,
25
+ oafuncs-0.0.96.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
26
+ oafuncs-0.0.96.dist-info/METADATA,sha256=Nh6i-B0Mt9WoTMNYRZ8-bTj9cjHXK_7NDPaZxEPOLk0,3618
27
+ oafuncs-0.0.96.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
28
+ oafuncs-0.0.96.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
29
+ oafuncs-0.0.96.dist-info/RECORD,,