-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprisms.py
81 lines (66 loc) · 2.69 KB
/
prisms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
import xarray as xr
import boule as bl
class PrismGen:
def __init__(self, density_dict):
self.ice_dens = density_dict['ice']
self.water_dens = density_dict['water']
self.rock_dens = density_dict['rock']
# prisms.py
import numpy as np
class PrismGen:
def make_prisms(self, ds, bed, msk, ice):
"""
Create prisms based on mask and bed data.
Parameters:
- ds: xarray Dataset containing grid information.
- bed: 2D NumPy array representing bed elevation.
- msk: Mask type, e.g., 'inv'.
- ice: Boolean indicating if ice prisms should be created.
Returns:
- prisms: List of prism definitions.
- densities: List of densities corresponding to each prism.
"""
# Use 'inv_mask' instead of 'dist_msk'
inv_mask = ds.inv_mask.data # Shape: (ny, nx)
# Water prisms mask
water_msk = np.where(((ds.mask == 0) ^ (ds.mask == 3)) & (inv_mask == True), True, False)
# Initialize lists to store prisms and densities
prisms = []
densities = []
# Define densities
water_density = 1027 # kg/m^3
ice_density = 917 # kg/m^3
rock_density = 2670 # kg/m^3
# Process water prisms
if np.any(water_msk):
water_bed = bed[water_msk]
prisms.extend(water_bed.flatten())
densities.extend([water_density] * water_bed.size)
# Ice prisms mask (if applicable)
if ice:
ice_msk = np.where(((ds.mask == 3) ^ (ds.mask == 2)) & (inv_mask == True), True, False)
if np.any(ice_msk):
ice_bed = bed[ice_msk]
prisms.extend(ice_bed.flatten())
densities.extend([ice_density] * ice_bed.size)
# Rock prisms mask (assuming mask == 2 indicates rock)
rock_msk = np.where(ds.mask == 2, True, False)
if np.any(rock_msk):
rock_bed = bed[rock_msk]
prisms.extend(rock_bed.flatten())
densities.extend([rock_density] * rock_bed.size)
return prisms, densities
def split_prisms(self, prisms):
'''
Function to split prisms above and below the ellipsoid.
Rerturns combined prisms and an index of which ones are above the ellipsoid.
'''
prisms_pos = prisms[prisms[:,5] >= 0, :]
prisms_neg = prisms[prisms[:,4] < 0, :]
prisms_pos[prisms_pos[:,4] < 0, 4] = 0.0
prisms_neg[prisms_neg[:,5] > 0, 5] = 0.0
prisms = np.vstack([prisms_pos, prisms_neg])
idx_pos = np.full(prisms.shape[0], False)
idx_pos[:prisms_pos.shape[0]] = True
return prisms, idx_pos