Skip to content

Commit

Permalink
Mv _crop to seismic_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Feb 6, 2020
1 parent 3d6f4e3 commit 8be1c34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ max-line-length=120
max-attributes=8
max-args=10
max-locals=25
good-names = ix, ax, df, fs, im, lc, rc, xc, yc
good-names = ix, ax, df, fs, im, lc, rc, xc, xy, yc
variable-rgx=([a-z_][a-z0-9_]{2,30}|[a-z_])$ # snake_case + single letters
argument-rgx=([a-z_][a-z0-9_]{2,30}|[a-z_])$ # snake_case + single letters

Expand Down
32 changes: 28 additions & 4 deletions seismicpro/src/seismic_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
check_unique_fieldrecord_across_surveys)
from .file_utils import write_segy_file
from .plot_utils import IndexTracker, spectrum_plot, seismic_plot, statistics_plot, gain_plot
from .seismic_batch_tools import _crop

INDEX_UID = 'TRACE_SEQUENCE_FILE'

Expand Down Expand Up @@ -1337,6 +1336,32 @@ def equalize(self, index, src, dst, params, survey_id_col=None):
getattr(self, dst)[pos] = equalized_field
return self

def _crop(self, image, coords, shape):
""" Perform crops from the image.
Number of crops is defined by the number of elements in `coords` parameter.
Parameters
----------
image : np.array
Image to crop from.
coords: list of tuples
The list of top-left (x,y) coordinates for each crop.
shape: tuple of ints
Crop shape.
Returns
-------
res: np.array, dtype='O'
Array with crops.
"""
res = np.empty((len(coords), ), dtype='O')
for i, (x, y) in enumerate(coords):
if (x + shape[0] > image.shape[0]) or (y + shape[1] > image.shape[1]):
print(x, y, shape, image.shape)
raise ValueError('Resulting crop shape is less than expected.')
res[i] = image[x:x+shape[0], y:y+shape[1]]
return res

@action
@inbatch_parallel(init='_init_component')
def random_crop(self, index, src, num_crops, shape, dst=None):
Expand Down Expand Up @@ -1389,11 +1414,10 @@ def random_crop(self, index, src, num_crops, shape, dst=None):

for isrc, idst in zip(src, dst):
field = getattr(self, isrc)[pos]
getattr(self, idst)[pos] = _crop(field, xy, shape)
getattr(self, idst)[pos] = self._crop(field, xy, shape)

return self


@action
@inbatch_parallel(init='_init_component')
@apply_to_each_component
Expand Down Expand Up @@ -1442,7 +1466,7 @@ def crop(self, index, src, coords, shape, dst=None):
raise ValueError('Coords not specified correctly')

field = getattr(self, src)[pos]
getattr(self, dst)[pos] = _crop(field, xy, shape)
getattr(self, dst)[pos] = self._crop(field, xy, shape)

@inbatch_parallel(init='_init_component', target="threads")
def shift_pick_phase(self, index, src, src_traces, dst=None, shift=1.5, threshold=0.05):
Expand Down
28 changes: 0 additions & 28 deletions seismicpro/src/seismic_batch_tools.py

This file was deleted.

0 comments on commit 8be1c34

Please sign in to comment.