Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always close NetCDF resources #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@
"identifier": "10.1016/j.cageo.2021.104803",
"relation": "cites"
}
],
"contributors": [
{
"type": "Software Engineer",
"name": "Slater, Chris",
"affiliation": "Cooperative Institute for Research in Environmental Sciences (CIRES) at the University of Colorado Boulder"
}
]
}
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Contributors
* @BillMills: - PR #47, re-introduce Argo density inversion as inherited QCCheck.
- PR #53, update fuzzy logic to handle edge-case NaNs rather than masks.
- Reported bug that resulted on PR #61.
* Chris Slater: PR #66, Release oceansdb / NetCDF file resources
12 changes: 7 additions & 5 deletions cotede/qctests/cars_normbias.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def cars_normbias(data, varname, attrs=None, use_standard_error=False):

depth = extract_depth(data)

db = CARS()
# This must go away. This was a trick to handle Seabird CTDs, but
# now that seabird is a different package it should be handled there.
if isinstance(varname, str) and (varname[-1] == "2"):
Expand All @@ -88,10 +87,13 @@ def cars_normbias(data, varname, attrs=None, use_standard_error=False):
raise IndexError
elif not idx.all():
valid_depth = depth[idx]
if mode == "track":
cars = db[vtype].track(var=cars_vars, doy=doy, depth=valid_depth, **kwargs)
else:
cars = db[vtype].extract(var=cars_vars, doy=doy, depth=valid_depth, **kwargs)

cars = None
with CARS() as db:
if mode == "track":
cars = db[vtype].track(var=cars_vars, doy=doy, depth=valid_depth, **kwargs)
else:
cars = db[vtype].extract(var=cars_vars, doy=doy, depth=valid_depth, **kwargs)

if not np.all(depth == valid_depth):
for v in cars.keys():
Expand Down
16 changes: 8 additions & 8 deletions cotede/qctests/location_at_sea.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ def location_at_sea(data, cfg=None):
return flag_bad

try:
ETOPO = oceansdb.ETOPO()
etopo = ETOPO["topography"].extract(
var="height", lat=data.attrs["LATITUDE"], lon=data.attrs["LONGITUDE"]
)
etopo = None
with oceansdb.ETOPO() as ETOPO:
etopo = ETOPO["topography"].extract(
var="height", lat=data.attrs["LATITUDE"], lon=data.attrs["LONGITUDE"]
)
h = etopo["height"]

flag = np.zeros(h.shape, dtype="i1")
Expand All @@ -105,10 +106,9 @@ def get_bathymetry(lat, lon, resolution="5min"):
"""
assert np.shape(lat) == np.shape(lon), "Lat & Lon shape mismatch"

db = oceansdb.ETOPO(resolution=resolution)

etopo = db["topography"].track(var="height", lat=lat, lon=lon)
return {"bathymetry": -etopo["height"].astype("i")}
with oceansdb.ETOPO(resolution=resolution) as db:
etopo = db["topography"].track(var="height", lat=lat, lon=lon)
return {"bathymetry": -etopo["height"].astype("i")}


class LocationAtSea(QCCheck):
Expand Down
12 changes: 7 additions & 5 deletions cotede/qctests/woa_normbias.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def woa_normbias(data, varname, attrs=None, use_standard_error=False):

depth = extract_depth(data)

db = WOA()
# This must go away. This was a trick to handle Seabird CTDs, but
# now that seabird is a different package it should be handled there.
if isinstance(varname, str) and (varname[-1] == "2"):
Expand All @@ -96,10 +95,13 @@ def woa_normbias(data, varname, attrs=None, use_standard_error=False):
raise IndexError
elif not idx.all():
valid_depth = depth[idx]
if mode == "track":
woa = db[vtype].track(var=woa_vars, doy=doy, depth=valid_depth, **kwargs)
else:
woa = db[vtype].extract(var=woa_vars, doy=doy, depth=valid_depth, **kwargs)

woa = None
with WOA() as db:
if mode == "track":
woa = db[vtype].track(var=woa_vars, doy=doy, depth=valid_depth, **kwargs)
else:
woa = db[vtype].extract(var=woa_vars, doy=doy, depth=valid_depth, **kwargs)

if not np.all(depth == valid_depth):
for v in woa.keys():
Expand Down
2 changes: 1 addition & 1 deletion cotede/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def convert_021_to_022(cfg):
is now explicit so that the user has the freedom to choose alternatives.
"""
assert ("revision" in cfg) and (cfg["revision"] == "0.21")
cfg["revision"] = 0.22
cfg["revision"] = "0.22"

for v in cfg["variables"]:
procedures = [f for f in cfg["variables"][v] if f in ("fuzzylogic", "morello2014")]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy>=1.16
scipy>=0.18.0
oceansdb>=0.8.13
oceansdb>=0.8.15
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
zip_safe=False,
extras_require = {
'GSW': ["gsw>=3.0.6"],
'OceansDB': ["oceansdb>=0.8.13"],
'OceansDB': ["oceansdb>=0.8.15"],
'manualqc': ["matplotlib"],
'regional': ["Shapely>=1.6.4"]
}
Expand Down