-
Notifications
You must be signed in to change notification settings - Fork 17
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
Added RSF writer and tests #301
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #301 +/- ##
=======================================
Coverage 99.29% 99.30%
=======================================
Files 84 86 +2
Lines 6714 6771 +57
=======================================
+ Hits 6667 6724 +57
Misses 47 47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
A couple small things then should be good to merge when you are happy with it.
Thanks, those are good changes. I have gone ahead and made them. We still
do not have test coverage for a file that is not int or float input
(frequency, for example), so one line of code is not covered in the tests.
Do you have an example test dataset with complex numbers, for example?
Also one for integer data?
*Aaron Girard*
…On Wed, Nov 22, 2023 at 7:30 AM Derrick Chambers ***@***.***> wrote:
***@***.**** requested changes on this pull request.
A couple small things then should be good to merge when you are happy with
it.
------------------------------
In dascore/io/rsf/core.py
<#301 (comment)>:
> + if np.issubdtype(dtype, np.integer):
+ file_formt = 'data_format="native_int"'
+ elif np.issubdtype(dtype, np.floating):
+ file_formt = 'data_format="native_float"'
+ else:
+ raise ValueError("Data format is not integer or floating.")
Since we now explicitly convert to float32 dtype I think these lines can
just be file_format = "native_float" right?
------------------------------
In dascore/io/rsf/core.py
<#301 (comment)>:
> + Write a patch to RSF format.
+
+ if no data_path is NOT specified, the header and binary will be
+ packed together
+ data_path needs to be bindata_file.rsf or /location/of/bindata_file.rsf
+ (NO '@')
+
+ path needs to be hdr_file.rsf or /location/of/hdr_file.rsf
+
+ spool needs to have a single patch in it
So this will generate a nice API doc page, we need a parameter section:
Parameters----------------spool
The input spool to convert to rsf, must have exactly one patch. path
Path to create the rsf filedata_path
If data and rsf header information are to be separate, the location of the data file. Needs to be
bindata_file.rsf or /location/of/bindata_file.rsf (no '@')
Notes--------- Patch datatype is converted to float32 for compatibility with Madagascar (may be able to keep dytpe in the future)
------------------------------
In dascore/io/rsf/__init__.py
<#301 (comment)>:
> +Notes
+-----
+-
delete empty section, or add some notes here if you have any. Maybe the
version of Madagascar you used to test the output?
------------------------------
In dascore/io/rsf/core.py
<#301 (comment)>:
> + ########################
+ # Add a way to read in rsf files.
+ # May need a way to get absolute time stamp,
+ # like hide it in header file when writing out an RSF file.
+ ########################
Is this resolved?
------------------------------
In tests/test_io/test_rsf/test_rsf.py
<#301 (comment)>:
> +"""Tests for RSF format."""
+
+import os
+from pathlib import Path
+
+import numpy as np
+
+import dascore as dc
+from dascore.io.rsf import RSFV1
+
+
+class TestRsfWrite:
+ """testing the rSF write out function."""
+
+ def test_write_nopath(self, random_patch, tmp_path):
+ """Test write function."""
maybe:
"""test write function with no data path specified"""
------------------------------
In tests/test_io/test_rsf/test_rsf.py
<#301 (comment)>:
> +
+ def test_write_nopath(self, random_patch, tmp_path):
+ """Test write function."""
+ spool = dc.spool(random_patch)
+ path = tmp_path / "test_hdrdata.rsf"
+ RSFV1().write(spool, path)
+
+ assert path.exists()
+ test_data = random_patch.data.astype(np.float32)
+ dtype = np.dtype(test_data.dtype)
+ file_esize = dtype.itemsize
+ datasize = test_data.size * file_esize
+ assert os.path.getsize(path) >= datasize
+
+ def test_write_path(self, random_patch, tmp_path):
+ """Test write function."""
"Test write function with separate data path"
—
Reply to this email directly, view it on GitHub
<#301 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEX7T345WLZKY5O5RS7FCFLYFYEALAVCNFSM6AAAAAA7VI5VX2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONBUGUZTAOJUGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
We can use But I think we are not supporting that now? This line explicitly converts any data type to float 32. If this is what you want to do you can essentially remove lines 68-73 and just have |
The only problem then is in line 72-73, if someone ever tries to export a complex valued data set it cannot export because
|
This is a bug. I will open another issue. The dtype conversion will probably fail if it is complex, but should work fine with ints (it will just cast the ints to floats, which is probably fine). |
see #303. Once we get that fixed we can either explicitly support the complex type or just raise an error if the array dtype is complex. You can check it with |
it looks like #304 fixed the complex values to spool issue, so I changed the RSF write and the test. However, now there another issue for writing integers to spool.
|
I think that is actually the expected behavior. The problem is Try this: import numpy as np
import dascore as dc
int_patch = random_patch.new(data=np.ones_like(random_patch.data)) |
…not those two types.
Description
Added a method to write out RSF files and included tests for the code.
Checklist
I have (if applicable):