Skip to content

Commit 7cdc2e2

Browse files
committed
remove nan in the data by applying masks
1 parent 619236c commit 7cdc2e2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pinnicle/modeldata/netcdf_data.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ def __init__(self, parameters=SingleDataParameter()):
1414
Constants.__init__(self)
1515
super().__init__(parameters)
1616

17-
def get_ice_coordinates(self, mask_name=""):
17+
def get_ice_coordinates(self, mask=None):
1818
""" stack the coordinates `x` and `y`, assuming all the data in .mat
1919
are in the ice covered region. This function is currently only
2020
called by plotting to generate ice covered region.
2121
"""
2222
# get the coordinates
23-
X_mask = np.hstack([self.X_dict[k].flatten()[:,None] for k in self.parameters.X_map if k in self.X_dict])
23+
X_mask = np.hstack([self.X_dict[k][mask].flatten()[:,None] for k in self.parameters.X_map if k in self.X_dict])
2424

2525
return X_mask
2626

@@ -98,17 +98,19 @@ def prepare_training_data(self, data_size=None):
9898
self.X = {}
9999
self.sol = {}
100100

101-
# prepare x,y coordinates
102-
X_temp = self.get_ice_coordinates()
103-
max_data_size = X_temp.shape[0]
104-
105101
# go through all keys in data_dict
106102
for k in self.data_dict:
107103
# if datasize has the key, then add to X and sol
108104
if k in data_size:
109105
if data_size[k] is not None:
110-
# apply ice mask
111-
sol_temp = self.data_dict[k].flatten()[:,None]
106+
# apply nan mask
107+
_temp = self.data_dict[k].flatten()[:,None]
108+
mask = ~np.isnan(_temp)
109+
sol_temp = _temp[mask].flatten()[:,None]
110+
111+
# prepare x,y coordinates
112+
X_temp = self.get_ice_coordinates(mask=mask)
113+
112114
# random choose to a downscale sampling of the scatter data
113115
idx = down_sample(X_temp, data_size[k])
114116
self.X[k] = X_temp[idx, :]

0 commit comments

Comments
 (0)