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

Add 'one_dir_freq' file read-in option #31

Merged
merged 4 commits into from
Nov 12, 2015
Merged
Changes from 2 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
33 changes: 33 additions & 0 deletions aospy/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,30 @@ def __init__(self, calc_interface):

self.data_out = {}

def _get_input_data_paths_one_dir_freq(self, name, data_in_direc, n=0):
"""Get the names of netCDF files when all in same directory.
Allow the use to specify the separate output frequencies.
"""
if isinstance(self.data_in_files[n][self.intvl_in][name], str):
data_in_files = [self.data_in_files[n][self.intvl_in][name]]
else:
data_in_files = self.data_in_files[n][self.intvl_in][name]
# data_in_files may hold absolute or relative paths
paths = []
for nc in data_in_files:
full = '/'.join([data_in_direc, nc]).replace('//', '/')
Copy link
Owner

Choose a reason for hiding this comment

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

The best way to do this is os.path.join(data_in_direc, nc) (only recently learned that...you were probably just keeping consistent with the existing code. Do as I say, not as I do ;))

if os.path.isfile(nc):
paths.append(nc)
elif os.path.isfile(full):
paths.append(full)
else:
print("Warning: specified netCDF file `{}` "
"not found".format(nc))
# Remove duplicate entries.
files = list(set(paths))
files.sort()
return files

def _get_input_data_paths_one_dir(self, name, data_in_direc, n=0):
"""Get the names of netCDF files when all in same directory."""
if isinstance(self.data_in_files[n][name], str):
Expand Down Expand Up @@ -298,6 +322,15 @@ def _get_input_data_paths(self, var, start_date=False,
pass
else:
break
elif self.data_in_dir_struc[n] == 'one_dir_freq':
try:
files = self._get_input_data_paths_one_dir_freq(
name, data_in_direc, n=n
)
except KeyError:
pass
else:
break
elif self.data_in_dir_struc[n].lower() == 'gfdl':
try:
files = self._get_input_data_paths_gfdl_dir_struct(
Expand Down