Skip to content

Commit

Permalink
add sampling for cutting depth
Browse files Browse the repository at this point in the history
  • Loading branch information
xumi1993 committed May 25, 2024
1 parent a35ed3e commit ac037a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
32 changes: 19 additions & 13 deletions pytomoatt/attarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def from_xarray(cls, dataset):
ds = cls(dataset.data_vars, dataset.coords)
return ds

def interp_dep(self, depth:float, field:str):
def interp_dep(self, depth:float, field:str, samp_interval=0):
"""Interpolate map view with given depth
:param depth: Depth in km
Expand All @@ -28,27 +28,33 @@ def interp_dep(self, depth:float, field:str):
"""
if field not in self.data_vars.keys():
raise ValueError('Error field name of {}'.format(field))
idx = np.where(self.coords['dep'].values == depth)[0]
# resample self of xarray with given interval of ``samp_interval``

if samp_interval > 0:
resampled = self.isel(t=slice(0, None, samp_interval), p=slice(0, None, samp_interval))
else:
resampled = self
idx = np.where(resampled.coords['dep'].values == depth)[0]
if idx.size > 0:
offset = 0
data = np.zeros([self.coords['lat'].size*self.coords['lon'].size, 3])
for i, la in enumerate(self.coords['lat'].values):
for j, lo in enumerate(self.coords['lon'].values):
data[offset] = [lo, la, self.data_vars[field].values[idx[0], i, j]]
data = np.zeros([resampled.coords['lat'].size*resampled.coords['lon'].size, 3])
for i, la in enumerate(resampled.coords['lat'].values):
for j, lo in enumerate(resampled.coords['lon'].values):
data[offset] = [lo, la, resampled.data_vars[field].values[idx[0], i, j]]
offset += 1
else:
rad = 6371 - depth
points = np.zeros([self.coords['lat'].size*self.coords['lon'].size, 4])
points = np.zeros([resampled.coords['lat'].size*resampled.coords['lon'].size, 4])
offset = 0
for _, la in enumerate(self.coords['lat'].values):
for _, lo in enumerate(self.coords['lon'].values):
for _, la in enumerate(resampled.coords['lat'].values):
for _, lo in enumerate(resampled.coords['lon'].values):
points[offset] = [rad, la, lo, 0.]
offset += 1
points[:, 3] = interpn(
(self.coords['rad'].values,
self.coords['lat'].values,
self.coords['lon'].values),
self.data_vars[field].values,
(resampled.coords['rad'].values,
resampled.coords['lat'].values,
resampled.coords['lon'].values),
resampled.data_vars[field].values,
points[:, 0:3]
)
data = points[:, [2, 1, 3]]
Expand Down
15 changes: 8 additions & 7 deletions pytomoatt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ def to_ani(self):
"""Convert to anisotropic strength (epsilon) and azimuth (phi)
"""
self.epsilon = np.sqrt(self.eta**2+self.xi**2)
self.phi = np.zeros_like(self.epsilon)
idx = np.where(self.xi <= 0)
self.phi[idx] = 90 + 0.5*atand(self.eta[idx]/self.xi[idx])
idx = np.where((self.xi > 0) & (self.eta <= 0))
self.phi[idx] = 180 + 0.5*atand(self.eta[idx]/self.xi[idx])
idx = np.where((self.xi > 0) & (self.eta > 0))
self.phi[idx] = 0.5*atand(self.eta[idx]/self.xi[idx])
# self.phi = np.zeros_like(self.epsilon)
self.phi = np.rad2deg(0.5*np.arctan2(self.eta, self.xi))
# idx = np.where(self.xi <= 0)
# self.phi[idx] = 90 + 0.5*atand(self.eta[idx]/self.xi[idx])
# idx = np.where((self.xi > 0) & (self.eta <= 0))
# self.phi[idx] = 180 + 0.5*atand(self.eta[idx]/self.xi[idx])
# idx = np.where((self.xi > 0) & (self.eta > 0))
# self.phi[idx] = 0.5*atand(self.eta[idx]/self.xi[idx])

def to_xarray(self):
"""Convert to xarray
Expand Down

0 comments on commit ac037a0

Please sign in to comment.