Advertisement
MARSHAL327

value in point

Sep 11th, 2023
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import json
  2. import xarray as xr
  3. import time
  4. from tqdm import tqdm
  5.  
  6. logTime = time.time()
  7. file_path = "data_16.08.23/wrfout_d01_2023-08-17_18_00_00.nc"
  8.  
  9. ds = xr.open_dataset(file_path)
  10. data_var = ds["T2"].isel(Time=0) - 273.5
  11. # data_var = data_var[:20]
  12.  
  13. y = ds.XLAT
  14. x = ds.XLONG
  15.  
  16. lat = y.isel(Time=0)
  17. lon = x.isel(Time=0)
  18.  
  19. # print(lon[:].data)
  20. coordValues = []
  21. for i in tqdm(range(len(data_var) - 1)):
  22.     for j in range(len(data_var[i]) - 1):
  23.         lonValue = lon[0][j].data
  24.         latValue = lat[i][0].data
  25.  
  26.         coordValue = {}
  27.  
  28.         coordValue["lon"] = float(lonValue)
  29.         coordValue["lat"] = float(latValue)
  30.         coordValue["value"] = round(float(data_var[i, j].data), 1)
  31.  
  32.         coordValues.append(coordValue)
  33.  
  34. with open('coordValues.json', 'w') as outfile:
  35.     json.dump(coordValues, outfile)
  36.  
  37.  
  38. print("\n--- %s seconds ---" % (time.time() - logTime))
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement