Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if np.isscalar(c) and not isinstance(c, slice):
item[i] = slice(c, c+1)
squeezax.append(i)
# add a slice in the 4th dim
item.insert(self.ds, slice(0, self._ds_shape+1))
item = tuple(item)
# get data
vars = self.nc.variables
with ScaledVar(vars['TK']) as var:
tk = var[item]
with ScaledVar(vars['P']) as p, ScaledVar(vars['PB']) as pb:
p = p[item] + pb[item]
with ScaledVar(vars['QVAPOR']) as var:
q = var[item]
with ScaledVar(vars['PH']) as ph, ScaledVar(vars['PHB']) as phb:
z = (ph[item] + phb[item]) / 9.81
return np.squeeze(_ncl_slp(z, tk, p, q), axis=tuple(squeezax))
def __getitem__(self, item):
with ScaledVar(self.nc.variables['PRCP_NC']) as p1, \
ScaledVar(self.nc.variables['PRCP_C']) as p2:
return p1[item] + p2[item]
def __getitem__(self, item):
with ScaledVar(self.nc.variables['T']) as var:
return var[item] + 300.
def __getitem__(self, item):
with ScaledVar(self.nc.variables['P']) as p, \
ScaledVar(self.nc.variables['PB']) as pb:
res = p[item] + pb[item]
if p.units == 'Pa':
res /= 100
elif p.units == 'hPa':
pass
return res
item = list(indexing.expanded_indexer(item, len(self.dimensions)))
# we need the empty dims for _ncl_slp() to work
squeezax = []
for i, c in enumerate(item):
if np.isscalar(c) and not isinstance(c, slice):
item[i] = slice(c, c+1)
squeezax.append(i)
# add a slice in the 4th dim
item.insert(self.ds, slice(0, self._ds_shape+1))
item = tuple(item)
# get data
vars = self.nc.variables
with ScaledVar(vars['TK']) as var:
tk = var[item]
with ScaledVar(vars['P']) as p, ScaledVar(vars['PB']) as pb:
p = p[item] + pb[item]
with ScaledVar(vars['QVAPOR']) as var:
q = var[item]
with ScaledVar(vars['PH']) as ph, ScaledVar(vars['PHB']) as phb:
z = (ph[item] + phb[item]) / 9.81
return np.squeeze(_ncl_slp(z, tk, p, q), axis=tuple(squeezax))
was_scalar = True
# Ok, get the indexes right
start = sl.start or 0
stop = sl.stop or self._ds_shape
if stop < 0:
stop += self._ds_shape-1
stop = np.clip(stop+1, 0, self._ds_shape)
itemr = copy.deepcopy(item)
if was_scalar:
item[self.ds] = start
itemr[self.ds] = start+1
else:
item[self.ds] = slice(start, stop-1)
itemr[self.ds] = slice(start+1, stop)
with ScaledVar(self.ncvar) as var:
return 0.5*(var[tuple(item)] + var[tuple(itemr)])
def __getitem__(self, item):
with ScaledVar(self.nc.variables['PRCP_NC']) as p1, \
ScaledVar(self.nc.variables['PRCP_C']) as p2:
return p1[item] + p2[item]