Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
geojunky committed Mar 20, 2024
1 parent 896b7fc commit a2d7550
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
44 changes: 1 addition & 43 deletions seismic/ASDFdatabase/asdf2salvus.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,10 @@
from seismic.ASDFdatabase.utils import remove_comments
from seismic.misc import split_list, recursive_glob
import click
from shapely.geometry.polygon import Polygon, Point
from tqdm import tqdm
import json
import tempfile

class StandardDomain():
def __init__(self, domain_json_file:str):
dom = json.load(open(domain_json_file, 'r'))
lat_center, lat_extent, lon_center, lon_extent = \
dom['lat_lon_box']['latitude_center'], \
dom['lat_lon_box']['latitude_extent'], \
dom['lat_lon_box']['longitude_center'], \
dom['lat_lon_box']['longitude_extent']

c = [lon_center, lat_center]
e = [lon_extent, lat_extent]

coords = ((c[0] - e[0], c[1] + e[1]),
(c[0] - e[0], c[1] - e[1]),
((c[0] + e[0]), c[1] - e[1]),
((c[0] + e[0]), c[1] + e[1]))
self.coords = np.array(coords)
self.bounding_polygon = Polygon(coords)
# end func

def contains(self, lon:float, lat:float):
p = Point((lon, lat))

return self.bounding_polygon.contains(p)
# end func
# end class

class Domain():
def __init__(self, domain_json_file:str):
dom = json.load(open(domain_json_file, 'r'))

coords = dom['features'][0]['geometry']['coordinates'][0]
self.bounding_polygon = Polygon(coords)
# end func

def contains(self, lon:float, lat:float):
p = Point((lon, lat))

return self.bounding_polygon.contains(p)
# end func
# end class
from seismic.ASDFdatabase.domain import StandardDomain, Domain

def get_validated_waveform(fds: FederatedASDFDataSet,
net, sta, loc, cha, st, et):
Expand Down
45 changes: 45 additions & 0 deletions seismic/ASDFdatabase/domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
from shapely.geometry.polygon import Polygon, Point

class StandardDomain():
def __init__(self, domain_json_file:str):
dom = json.load(open(domain_json_file, 'r'))
lat_center, lat_extent, lon_center, lon_extent = \
dom['lat_lon_box']['latitude_center'], \
dom['lat_lon_box']['latitude_extent'], \
dom['lat_lon_box']['longitude_center'], \
dom['lat_lon_box']['longitude_extent']

c = [lon_center, lat_center]
e = [lon_extent, lat_extent]

coords = ((c[0] - e[0], c[1] + e[1]),
(c[0] - e[0], c[1] - e[1]),
((c[0] + e[0]), c[1] - e[1]),
((c[0] + e[0]), c[1] + e[1]))
self.coords = np.array(coords)
self.bounding_polygon = Polygon(coords)
# end func

def contains(self, lon:float, lat:float):
p = Point((lon, lat))

return self.bounding_polygon.contains(p)
# end func
# end class

class Domain():
def __init__(self, domain_json_file:str):
dom = json.load(open(domain_json_file, 'r'))

coords = dom['features'][0]['geometry']['coordinates'][0]
self.bounding_polygon = Polygon(coords)
# end func

def contains(self, lon:float, lat:float):
if(lon < 0): lon += 360 # temporary hack to cater for dateline crossings
p = Point((lon, lat))

return self.bounding_polygon.contains(p)
# end func
# end class
2 changes: 1 addition & 1 deletion utils/shapefile_to_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def processFile(shpFileName, outputFileStem=None,

dom = None
if(salvus_domain is not None):
from seismic.ASDFdatabase.asdf2salvus import Domain
from seismic.ASDFdatabase.domain import Domain
dom = Domain(salvus_domain)
# end if

Expand Down

0 comments on commit a2d7550

Please sign in to comment.