import xarray as xr
import numpy as np

#fill_value = 1.267651e30
fill_value = 1e30
#fill_value = 9.96921e36

ds = xr.open_dataset("test2.nc")

# Substituir fill_value por NaN
mdepth_valid = ds.mdepth.where(ds.mdepth != fill_value, np.nan)

# Criar máscara usando isclose para evitar problemas de precisão
#mdepth_valid = ds.mdepth.where(~np.isclose(ds.mdepth, fill_value), np.nan)

# Considerar apenas profundidades menores que 20.000 m (limite seguro)
#mdepth_valid = ds.mdepth.where(ds.mdepth < 2e4, np.nan)

# Valores mínimo e máximreais ignorando os NaN
min_depth = np.nanmin(mdepth_valid.values)
max_depth = np.nanmax(mdepth_valid.values)

print("Profundidade mínima:", min_depth)
print("Profundidade máxima:", max_depth)
