-
Notifications
You must be signed in to change notification settings - Fork 27
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
General opener, using file info. #198
Conversation
51fca12
to
8bcd303
Compare
I separated out |
164eb7a
to
d753414
Compare
Rebased this. The opener is now such a minor contribution that one might as well look at this one... (especially as I changed the |
I think this is getting ready for prime time! |
OK, with some further cleanup, I think this is ready. But probably good to have a thorough review, since this new |
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.
Highly incomplete review - will add more tonight.
baseband/core.py
Outdated
""" | ||
if format is None: | ||
format = tuple(FILE_FORMATS.keys()) | ||
All keyword arguments passed in and are classified, ending up in one of |
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.
"passed in and are classified" -> "passed in are classified"
elif key == 'nchan': | ||
sample_shape = info_dict.get('sample_shape') | ||
if sample_shape is not None: | ||
# If we passed nchan, and info doesn't have it, but does have a |
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.
Not sure I'm happy with nchan
being treated like the total size of the sample shape - couldn't the user, for a two channel, two thread file pass nthread = 2, nchan = 2
? In that case, this check would return inconsistent.
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.
I guess one could allow if if either sample_shape.nchan == nchan
or sample_shape.nchan == 1
and the product equals nchan. I guess for a consistency check one does not have to be all that strict.
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.
Actually, on second thought I think what's below is fine (I was pretty sleep-deprived when looking at this yesterday).
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.
I still changed it to be a bit more generous: sample_shape.nchan == nchan
should be OK too.
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.
Overall looks good, and I found no problems reading some sample files of various formats. The only non-nitpick I have is I'd like it to be recorded somewhere (maybe in Getting Started?) that only GSB timestamp files are recognized by the file info and general opener routines.
elif key == 'nchan': | ||
sample_shape = info_dict.get('sample_shape') | ||
if sample_shape is not None: | ||
# If we passed nchan, and info doesn't have it, but does have a |
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.
Actually, on second thought I think what's below is fine (I was pretty sleep-deprived when looking at this yesterday).
|
||
|
||
@pytest.mark.parametrize('sample', (SAMPLE_M4, SAMPLE_M5B)) | ||
def test_open_missing_args(sample): |
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.
Maybe:
def test_open_missing_args(sample):
with pytest.raises(TypeError) as excinfo:
baseband_open(sample, 'rs')
assert "missing required arguments" in str(excinfo.value)
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.
good idea
baseband/tests/test_core.py
Outdated
# reader, but then fail on an incorrect sample rate. | ||
mark4_args = {'nchan': 8, | ||
'ref_time': Time('2014-01-01')} | ||
with pytest.raises(ValueError): # wrong sample_rate |
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.
As above, would be nice to also test that "arguments inconsistent" or "got unexpected keyword" show up in the error messages. I don't think it's essential to check these (or the above), but I feel it's more precise and also helps a bit when reading the tests at a later date.
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.
Given that I felt the need to add comments to the tests, this is a good point. I made the checks somewhat minimal, though, as I don't like to be stuck with particular error messages.
- Added a general file opener, ``baseband.open`` which for a set of formats | ||
will check whether the file is of that format, and then load it using the | ||
corresponding module. [#198] | ||
|
||
API Changes | ||
----------- | ||
|
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.
In "Other Changes and Additions" should mention that sample data files now listed in the documentation.
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.
done
docs/data/index.rst
Outdated
.. _data: | ||
|
||
***************** | ||
Sample data files |
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.
"Sample data files" -> "Sample Data Files"
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.
we're not consistent with the capitalization (top level index.rst
doesn't do it), but changed anyway.
@@ -51,15 +51,17 @@ troubleshooting help and APIs for each. | |||
Core framework and utilities |
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.
Nothing to do with this PR, but seems silly not to fix considering the table of contents is being modified anyway: in the Overview section "authors_for_sphinx" is still listed, which repeats the authors and contributors listed under Project Details.
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.
Removed.
This tutorial covers the basic features of Baseband. It assumes that | ||
`NumPy <http://www.numpy.org/>`_ and the `Astropy`_ units module have been | ||
imported:: | ||
For some file formats, one can simply import baseband and use `baseband.open` to |
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.
This is great!
docs/tutorials/getting_started.rst
Outdated
basics of :ref:`inspecting files <getting_started_inspecting>`, :ref:`reading | ||
<getting_started_reading>` from and :ref:`writing <getting_started_writing>` | ||
to files, and :ref:`converting <getting_started_converting>` from one format | ||
to another. We assume that baseband as well as `NumPy |
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.
Nitpick: "baseband" should be capitalized for consistency (though I admit that capitalizing at all is a personal preference).
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.
Since we do it for astropy and numpy in this context, let's do it here too. I have not capitalized it in "baseband module", though...
docs/tutorials/getting_started.rst
Outdated
formats. When opening Mark 4 and Mark 5B files, however, some additional | ||
arguments may need to be passed (as was the case above for inspecting a Mark | ||
5B file). Notes on such features and quirks of individual formats can be | ||
found in the API entries of their ``open`` functions, and within the |
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.
Could also note that file_info
can also return missing arguments that are necessary.
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.
ok, done
docs/tutorials/getting_started.rst
Outdated
As shown at the very start, files can be opened with the general | ||
`baseband.open` function. This will try to determine the file type using | ||
`~baseband.file_info`, load the corresponding baseband module, and then open | ||
the file using that modele's master input/output function. |
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.
"modele" -> "module"
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.
done
In particular, decade, kday, and ref_time should be consistent with the file being opened, and nchan with the sample_shape.
Also make sure ``data`` is documented.
My fun project for the evening. It does somewhat work, though clearly at least the sample rate should be checked: