-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkingConcept.py
More file actions
75 lines (57 loc) · 2.09 KB
/
Copy pathworkingConcept.py
File metadata and controls
75 lines (57 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import warnings
warnings.simplefilter("ignore")
import os
import pyart
import matplotlib.pyplot
import matplotlib as mpl
import numpy as np
import gzip
import shutil
import xarray as xr
from funcs import read_casa_netcdf
import json
import pandas as pd
# import gyzip
#import gridded netcdf data from a file
grid_file = 'xmdl_grid.nc'
#read netcdf data
grid = pyart.io.grid_io.read_grid('xmdl_grid.nc')
#open dataset within gridded file
dataset = xr.open_dataset(grid_file)
#set the list of all the variables in the dataset to another variable
variables = list(dataset.variables)
#get the longitude, latitude and horizontal reflectivity of the data into variables
lats = grid.point_latitude['data']
lons = grid.point_longitude['data']
zh = grid.fields['Reflectivity']['data']
# time = grid.variables['units']
#create empty arrays for holding the latitude, longitude, reflectivity and timestamp data
latitude = []
longitude = []
reflectivity = []
times = []
# print(variables)
# print(grid.origin_longitude['data'][0])
#Create an array with all of the data in a stacked format compatible with converting to JSON
latLonRefArray = np.stack([lats.ravel(), lons.ravel(), zh.ravel()], axis = 1)
# arrangedArray = pd.DataFrame(latLonRefArray, columns=['latitude', 'longitude', 'zh'])
# arrangedArray= arrangedArray.dropna()
# print(latLonRefArray)
# print(lats)
# print(lons)
# f = open("jsonVersionTest.json", "w+")
#create an object of all of the data and save it to a variable called results
results = {"outputData": latLonRefArray.tolist()}
#format the data with indentation
json_string = json.dumps(results, indent=2)
#encode the json string into utf-8 format
json_bytes = json_string.encode('utf-8')
# json_string = json.dumps(results, indent=2)
# f.write(json_string)
# with gzip.open("outputTest.json", 'w+') as fout:
# # json_string = json.dumps(results, indent=2)
# fout.write(json_string)
#write the resulting JSON to a zipped file
with gzip.GzipFile("nextTest.json.gz", 'w') as fout:
fout.write(json_bytes)
# arrangedArray.to_json('pandasFileTest.json', index=False, orient='table', double_precision=6)