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

Enable user-specified output directories in Proj #105

Merged
merged 2 commits into from
Nov 1, 2016

Conversation

spencerkclark
Copy link
Collaborator

@spencerkclark spencerkclark commented Oct 28, 2016

This PR provides the quick fix discussed in #103. It also adds local test data files, which add some basic test coverage to Calc and also verify that output files are saved to the right places.

@spencerkclark
Copy link
Collaborator Author

spencerkclark commented Oct 28, 2016

@spencerahill I was a bit clumsy getting the tests configured properly (it took me a while to realize how to set up the paths to the test data on Travis), but I think I've got things working. Let me know if you're on board with how I made the changes in Calc, and if you're good with the test structure. Thanks!

@spencerkclark
Copy link
Collaborator Author

@spencerahill just so you know, I just rebased / squashed the commits offline to clean up the commit message


class TestBasicCalc(unittest.TestCase):
def setUp(self):
print os.getcwd()
Copy link
Owner

Choose a reason for hiding this comment

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

Did you want to keep this in? If so, include from __future__ import print_function and then use print(os.getcwd()) for Python 3 compatibility.

@spencerahill
Copy link
Owner

Strange, something with my local setup is causing errors when I try to run the new test (even though they're working on Travis): https://gist.github.com/spencerahill/90e751781812266f21dfdd01d3a4a426

I have seen that fp error from scipy before, but can't recall precisely what causes it. I have confirmed that the test netcdf files are in place and not corrupted.

I'll have to come back to this.

@spencerkclark
Copy link
Collaborator Author

@spencerahill How did you go about setting up your environment? One thing that stands out immediately is that it seems it doesn't have dask installed, which is required for a call that gets made to xr.open_mfdataset in model.py. netCDF4 is also a requirement to run the tests now (it wasn't in the past); it is needed for decoding CF attributes. Check out the new ci/environement-py27.yml, for the comprehensive list.

Addressing the import errors may fix everything (the failed tests are simply due to the fact that files are not produced, because of errors upstream -- the import errors could account for all of that since all the calculations start by reading in grid files).

That said, you seem to be using python 3.5 and until now we didn't have Travis set up to test in that environment. I added that to our set up, but as you can see, there are issues with imports of the test aospy object libraries within the test modules that prevent the tests even from being fully collected (for python 3.5 but not python 2.7). I'm not sure what's causing that (in your local environment that doesn't seem to have been a problem).

@spencerkclark
Copy link
Collaborator Author

spencerkclark commented Oct 30, 2016

@spencerahill Things seem to be working as we'd expect now for python 3.5; all I needed to do was switch from implicit relative imports to explicit ones in test_objs/. E.g. go from this:

import models

to this:

from . import models

The only thing is that there are now some "unexpected success" tests in the test_aospy module associated with division. How should we handle those?

@spencerahill
Copy link
Owner

unexpected success" tests in the test_aospy module associated with division.

Let's just remove the decorator. Probably at some point I screwed up the division logic, saw the tests were failing and slapped it on, and then forgot to change the tests whenever it was fixed again!

@spencerahill
Copy link
Owner

netCDF4 is also a requirement to run the tests now (it wasn't in the past); it is needed for decoding CF attributes.

Yes, sorry, this was my rookie mistake...borrowing my wife's computer and apparently forgot to install netCDF4.

I'm now getting 100% passing tests on 2.7 and 3.5 with the aforementioned expected failures fix. That resolved, will finally turn to the actual substance of what you've done!

self._save_files(data, dtype_out_time)
if save_tar_files:
self._save_tar_files(dtype_out_time)
logging.info('\t{}'.format(self.path_out[dtype_out_time]))

def _load_from_scratch(self, dtype_out_time, dtype_out_vert=False,
Copy link
Owner

Choose a reason for hiding this comment

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

Let's rename this too... _load_from_disk? All "scratch" references should be gone.

@@ -897,7 +897,7 @@ def _load_from_scratch(self, dtype_out_time, dtype_out_vert=False,

def _load_from_archive(self, dtype_out_time, dtype_out_vert=False):
Copy link
Owner

Choose a reason for hiding this comment

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

Let's rename _load_from_tar. Is any of this logic unique to /archive other than the dmget call? For the time being, add a try/except guard around the dmget call here as well, in case anybody tries using this from outside GFDL.

@spencerkclark
Copy link
Collaborator Author

spencerkclark commented Oct 31, 2016

Probably at some point I screwed up the division logic, saw the tests were failing and slapped it on, and then forgot to change the tests whenever it was fixed again!

There must be a python version dependence here though, since it fails in python 2.7, but not python 3.5? Maybe just skip them and fix things in a later PR?

@spencerahill
Copy link
Owner

There must be a python version dependence here though, since it fails in python 2.7, but not python 3.5? Maybe just skip them and fix things in a later PR?

Sorry, yet more rookie environment mistakes! I didn't have pytest installed for 2.7, and didn't realize that even though I had source activated my py27 env, it was still using the 3.5 pytest. You're right, they fail on 2.7. This is probably straightforward but not important right now (xref #50)...just do whatever you think is best.

One thing to keep in mind is that separate runs.py, models.py, etc. modules aren't strictly necessary: it could all be a single module, which may make more sense for small snippet-like projects such as the test one.

@spencerahill
Copy link
Owner

Final comment, then let's merge: directory naming; let's rename local_test_objs to data, with subdirectories netcdf and objects. (Just trying to emulate xarray's structure)

Another nice piece of work @spencerkclark, despite my best efforts to confuse you! Thanks, as always I really appreciate it.

@spencerkclark
Copy link
Collaborator Author

One thing to keep in mind is that separate runs.py, models.py, etc. modules aren't strictly necessary: it could all be a single module, which may make more sense for small snippet-like projects such as the test one.

Final comment, then let's merge: directory naming; let's rename local_test_objs to data, with subdirectories netcdf and objects. (Just trying to emulate xarray's structure)

Good thoughts, I have modified things accordingly. Perhaps the edits I needed to make to the path names to allow for this directory structure are not the most idiomatic, but they get the job done.

@spencerahill, if you're cool with those, I think we're all set!

TST Add simple tests and verify that results files are produced

TST Add tests for reg.av and reg.ts calcs

TST Remove unnecessary print statement

TST Add python 3.5 test environment

TST Switch to explicit relative imports in test_objs

Remove all references to scratch and archive in method names

TST Skip version dependent constant division operator tests

TST Refactor test objs into single module and rename directories
@spencerahill
Copy link
Owner

Awesome. Sorry, one last nit: let's make the example object names more explicit: example_proj, example_model, example_run. im is a little cryptic. Sorry I didn't catch that before.

@spencerahill
Copy link
Owner

Awesome, thanks @spencerkclark!

@spencerahill spencerahill merged commit d309506 into spencerahill:develop Nov 1, 2016
@spencerkclark spencerkclark deleted the direc-out2 branch November 2, 2016 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants