-
Notifications
You must be signed in to change notification settings - Fork 2
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
Active interface for cf python: add active.do_active
attribute and uri_analyzer()
function
#69
base: main
Are you sure you want to change the base?
Changes from all commits
2aeaf0e
a3106ca
5e2c7b1
2b9d3ec
4ef232b
a39822c
884ecee
4bae515
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,44 @@ | |||||
from activestorage import netcdf_to_zarr as nz | ||||||
|
||||||
|
||||||
def uri_analyzer(uri): | ||||||
"""Run a first-pass examination on the file with given uri. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
uri: str | ||||||
input ile URI. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Returns | ||||||
------- | ||||||
bool | ||||||
Boolean that sets other methods/attributes in Active. | ||||||
|
||||||
Raises | ||||||
------ | ||||||
ValueError | ||||||
if file URI is None | ||||||
if file URI is pointing to a nonexistent file | ||||||
""" | ||||||
#TODO probably best placed in an acctive_tools library | ||||||
result = True | ||||||
if uri is None: | ||||||
raise ValueError(f"Must use a valid file for uri. Got {uri}") | ||||||
else: | ||||||
if not os.path.isfile(uri): | ||||||
raise ValueError(f"Must use existing file for uri. " | ||||||
f"{uri} not found") | ||||||
else: | ||||||
# bogus condition until we fix criteria | ||||||
if "cow" in uri: | ||||||
print("This file doesn't support active storage.") | ||||||
result = False | ||||||
else: | ||||||
print("This file supports active storage.") | ||||||
|
||||||
return result | ||||||
|
||||||
|
||||||
class Active: | ||||||
""" | ||||||
Instantiates an interface to active storage which contains either zarr files | ||||||
|
@@ -43,10 +81,15 @@ def __init__(self, uri, ncvar, missing_value=None, _FillValue=None, valid_min=No | |||||
""" | ||||||
# Assume NetCDF4 for now | ||||||
self.uri = uri | ||||||
if self.uri is None: | ||||||
raise ValueError(f"Must use a valid file for uri. Got {self.uri}") | ||||||
if not os.path.isfile(self.uri): | ||||||
raise ValueError(f"Must use existing file for uri. {self.uri} not found") | ||||||
self.do_active = True | ||||||
# run in active storage mode only if the uri analyzer returns True | ||||||
uri_analyzer_result = uri_analyzer(self.uri) | ||||||
self.do_active = uri_analyzer_result | ||||||
# otherwise just get out and return active.do_active = False | ||||||
if not self.do_active: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi V - I thought that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeps indeed, I followed up on your change request, thanks, bud! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit - this was a defunct version of this comment - I shall rewrite it below ....
|
||||||
self._version = 1 | ||||||
else: | ||||||
self._version = 2 | ||||||
self.ncvar = ncvar | ||||||
if self.ncvar is None: | ||||||
raise ValueError("Must set a netCDF variable name to slice") | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to assess if active storage reductions are possible, not just that the file exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! But how do we do that? We need a set of standards here to get conditions in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below ....