-
Notifications
You must be signed in to change notification settings - Fork 58
Change dfs datatype #830
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
Merged
Merged
Change dfs datatype #830
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95802a6
change datatype function and test
otzi5300 41a13ef
more info in docstring
otzi5300 e291ad4
test identical (almost) values
otzi5300 77e508e
update notebook
otzi5300 61a8dff
type hint fix
otzi5300 d2bb422
simplification of data copy
otzi5300 d243656
remove dfsu test
otzi5300 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,18 @@ | |
import pandas as pd | ||
import mikeio | ||
from mikeio import generic | ||
from mikeio.generic import scale, diff, sum, extract, avg_time, fill_corrupt, add | ||
from mikeio.generic import ( | ||
scale, | ||
diff, | ||
sum, | ||
extract, | ||
avg_time, | ||
fill_corrupt, | ||
add, | ||
change_datatype, | ||
) | ||
import pytest | ||
from mikecore.DfsFileFactory import DfsFileFactory | ||
|
||
|
||
def test_add_constant(tmp_path: Path) -> None: | ||
|
@@ -638,3 +648,52 @@ def test_fill_corrupt_data(tmp_path: Path) -> None: | |
orig = mikeio.read(infile) | ||
extracted = mikeio.read(fp) | ||
assert extracted.n_timesteps == orig.n_timesteps | ||
|
||
|
||
def test_change_datatype_dfs0(tmp_path: Path) -> None: | ||
infilename = "tests/testdata/random.dfs0" | ||
outfilename = str(tmp_path / "random_datatype107.dfs0") | ||
OUT_DATA_TYPE = 107 | ||
|
||
change_datatype(infilename, outfilename, datatype=OUT_DATA_TYPE) | ||
dfs_out = DfsFileFactory.DfsGenericOpen(outfilename) | ||
dfs_in = DfsFileFactory.DfsGenericOpen(infilename) | ||
|
||
n_timesteps_in = dfs_in.FileInfo.TimeAxis.NumberOfTimeSteps | ||
n_timesteps_out = dfs_out.FileInfo.TimeAxis.NumberOfTimeSteps | ||
datatype_out = dfs_out.FileInfo.DataType | ||
|
||
dfs_out.Close() | ||
dfs_in.Close() | ||
|
||
assert datatype_out == OUT_DATA_TYPE | ||
assert n_timesteps_in == n_timesteps_out | ||
# Also check that data is not modified | ||
org = mikeio.read(infilename).to_numpy() | ||
new = mikeio.read(outfilename).to_numpy() | ||
assert np.allclose(org, new, rtol=1e-08, atol=1e-10, equal_nan=True) | ||
|
||
|
||
def test_change_datatype_dfsu(tmp_path: Path) -> None: | ||
|
||
infilename = "tests/testdata/oresund_sigma_z.dfsu" | ||
outfilename = str(tmp_path / "oresund_sigma_z_datatype107.dfsu") | ||
OUT_DATA_TYPE = 107 | ||
|
||
change_datatype(infilename, outfilename, datatype=OUT_DATA_TYPE) | ||
dfs_out = DfsFileFactory.DfsGenericOpen(outfilename) | ||
dfs_in = DfsFileFactory.DfsGenericOpen(infilename) | ||
|
||
n_timesteps_in = dfs_in.FileInfo.TimeAxis.NumberOfTimeSteps | ||
n_timesteps_out = dfs_out.FileInfo.TimeAxis.NumberOfTimeSteps | ||
datatype_out = dfs_out.FileInfo.DataType | ||
|
||
dfs_out.Close() | ||
dfs_in.Close() | ||
|
||
assert datatype_out == OUT_DATA_TYPE | ||
assert n_timesteps_in == n_timesteps_out | ||
|
||
# Also check that data is not modified | ||
org = mikeio.read(infilename).to_numpy() | ||
new = mikeio.read(outfilename).to_numpy() | ||
assert np.allclose(org, new, rtol=1e-08, atol=1e-10, equal_nan=True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 can done in a simpler way, take a look at this example from mikecore: https://github.com/DHI/mikecore-python/blob/6ebbb1a1abebb88cd2060346611fa628eac57a82/tests/examples_misc.py#L59-L63
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, yes i had the feeling it could be simplified