home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 430232027

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2488#issuecomment-430232027 https://api.github.com/repos/pydata/xarray/issues/2488 430232027 MDEyOklzc3VlQ29tbWVudDQzMDIzMjAyNw== 16838898 2018-10-16T13:13:13Z 2018-10-16T13:13:13Z NONE

%%time def group_lat(x): # x is a DataFrame of group values # now find the value of the longitude box to append to the dictionary key value = np.ones(1) value[0] = x.lon.mean() idx = (np.abs(lon_cent - value)).argmin() lokey = lon_cent[idx] # longitude value of the box

# compute groups for the latitude
y = x.groupby_bins('lat', lat_bin, labels=lat_cent)
y = dict(y)
# replace the old key with the new key: lon,lat
key = np.asarray((list(y.keys()))) # get dict keys as array
newkey = np.stack((np.ones(len(key))*lokey,key),axis=1)
newkey = tuple(newkey.tolist())
key = tuple(y.keys()) # get dict keys as list

for i in range(len(key)):
    y[tuple(newkey[i])] = y[key[i]]
    del y[key[i]]  
return y

geop_mean = geop1.groupby_bins('lon', lon_bin, labels=lon_cent).apply(group_lat)

geop_mean = geop1.groupby_bins('lon', lon_bin, labels=lon_cent) geop_mean = dict(geop_mean)

group into lat boxes

l = 0 geo_grid = dict()

for x in list(geop_mean.keys()): y = group_lat(geop_mean[x]) if l == 0: geo_grid = y else: geo_grid.update(y) l += 1

Now the data is sorted into boxes and still contains all metadata

Now get the mean values for each box

l = 0 m = np.zeros((len(tuple(geo_grid.keys())),4)) d = np.asarray(list(geo_grid.keys()))

gp = xr.Dataset({'geopot': (['lat','lon'], np.ones((lat_cent.shape[0], lon_cent.shape[0]))), 'z': (['lat','lon'], np.ones((lat_cent.shape[0], lon_cent.shape[0])))}, coords={'lon': (['lon'],lon_cent), 'lat': (['lat'],lat_cent)})

for k in range(d.shape[0]): e = tuple(d[k]) #m[l,2] = geo_grid[e].z.mean() gp['geopot'].loc[dict(lat=d[k][1], lon=d[k][0])] = geo_grid[e].geopot.mean() gp['z'].loc[dict(lat=d[k][1], lon=d[k][0])] = geo_grid[e].z.mean() #gp.loc[dict(lat=m[0,1], lon=m[0,0])] l +=1

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  370183554
Powered by Datasette · Queries took 395.437ms · About: xarray-datasette