Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions pyfesom2/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def add_timedim(data, date="1970-01-01"):
return data


def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):
def ice_ext(data, mesh, hemisphere="N", threshold=0.15, attrs={}):
""" Compute sea ice extent.

Parameters
Expand All @@ -50,7 +50,7 @@ def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):
FESOM2 mesh object.
hemisphere: str
can be ether 'N' or 'S'
threshhold: float
threshold: float
default is 0.15
attrs: dict
dictionary of attributes that will be put in the resulting
Expand All @@ -74,7 +74,7 @@ def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):

if isinstance(data, xr.DataArray):
# Create binary ice extent field: 1 where ice >= threshold, 0 where < threshold, NaN stays NaN
ice_binary = xr.where(data >= threshhold, 1, 0)
ice_binary = xr.where(data >= threshold, 1, 0)
ice_binary = ice_binary.where(~np.isnan(data)) # Preserve NaN values (land)

finite_mask = ~np.isnan(ice_binary.squeeze().values)
Expand All @@ -88,7 +88,7 @@ def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):
else:
logger.debug(data)
# Create binary ice extent field: 1 where ice >= threshold, 0 where < threshold, NaN stays NaN
ice_binary = np.where(data >= threshhold, 1, 0).astype(float)
ice_binary = np.where(data >= threshold, 1, 0).astype(float)
ice_binary[np.isnan(data)] = np.nan # Preserve NaN values (land)

finite_mask = ~np.isnan(ice_binary.squeeze())
Expand Down Expand Up @@ -140,8 +140,8 @@ def ice_vol(data, mesh, hemisphere="N", attrs={}):
return vol


def ice_area(data, mesh, hemisphere="N", attrs={}):
""" Compute sea ice volume.
def ice_area(data, mesh, hemisphere="N", threshold=0., attrs={}):
""" Compute sea ice area.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it's a good idea to put threshhold=0.15 - this is something we use for ice_extent, but definition of the area it the total area covered by sea ice, and at leas in my mind this is what I would want to see by default. Adding threshold is totally fine, but I would put 0 as a default.


Parameters
----------
Expand Down Expand Up @@ -175,13 +175,25 @@ def ice_area(data, mesh, hemisphere="N", attrs={}):
hemis_mask = mesh.y2 < 0

if isinstance(data, xr.DataArray):
vol = (data[:, hemis_mask] * mesh.lump2[hemis_mask]).sum(axis=1)
# Create ice area field: data where ice >= threshold, 0 where < threshold, NaN stays NaN
ice_field = xr.where(data >= threshold, data, 0)
ice_field = ice_field.where(~np.isnan(data)) # Preserve NaN values (land)

finite_mask = ~np.isnan(ice_field.squeeze().values)

area = (ice_field[:, hemis_mask & finite_mask] * mesh.lump2[hemis_mask & finite_mask]).sum(axis=1)
da = xr.DataArray(
vol, dims=["time"], coords={"time": data.time}, name=varname, attrs=attrs
area, dims=["time"], coords={"time": data.time}, name=varname, attrs=attrs
)
return da

else:
area = (data[:, hemis_mask] * mesh.lump2[hemis_mask]).sum(axis=1)
# Create ice area field: data where ice >= threshold, 0 where < threshold, NaN stays NaN
ice_field = np.where(data >= threshold, data, 0).astype(float)
ice_field[np.isnan(data)] = np.nan # Preserve NaN values (land)

finite_mask = ~np.isnan(ice_field.squeeze())
area = (ice_field[:, hemis_mask & finite_mask] * mesh.lump2[hemis_mask & finite_mask]).sum(axis=1)
return area


Expand Down
Loading