Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import xarray as xr
- import time
- from tqdm import tqdm
- logTime = time.time()
- file_path = "data_16.08.23/wrfout_d01_2023-08-17_18_00_00.nc"
- ds = xr.open_dataset(file_path)
- data_var = ds["T2"].isel(Time=0) - 273.5
- # data_var = data_var[:20]
- y = ds.XLAT
- x = ds.XLONG
- lat = y.isel(Time=0)
- lon = x.isel(Time=0)
- # print(lon[:].data)
- coordValues = []
- for i in tqdm(range(len(data_var) - 1)):
- for j in range(len(data_var[i]) - 1):
- lonValue = lon[0][j].data
- latValue = lat[i][0].data
- coordValue = {}
- coordValue["lon"] = float(lonValue)
- coordValue["lat"] = float(latValue)
- coordValue["value"] = round(float(data_var[i, j].data), 1)
- coordValues.append(coordValue)
- with open('coordValues.json', 'w') as outfile:
- json.dump(coordValues, outfile)
- print("\n--- %s seconds ---" % (time.time() - logTime))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement