Skip to content

Use native Python double precision float for SFR2#300

Closed
mwtoews wants to merge 9 commits into
modflowpy:developfrom
mwtoews:sfr-mods
Closed

Use native Python double precision float for SFR2#300
mwtoews wants to merge 9 commits into
modflowpy:developfrom
mwtoews:sfr-mods

Conversation

@mwtoews
Copy link
Copy Markdown
Contributor

@mwtoews mwtoews commented Feb 28, 2018

Flopy's SFR2 package adds superfluous digits to output files from native Python float types, which is double precision. Let me demonstrate:

>>> import numpy as np
>>> import flopy
>>> m = flopy.modflow.Modflow()
>>> d = flopy.modflow.ModflowDis(m)
>>> s = flopy.modflow.ModflowSfr2(m, nstrm=4, nss=2)
>>> s.reach_data['rchlen'] = [101.1, 202.2, 103.4, 193.2]
>>> s.reach_data['rchlen']
array([ 101.09999847,  202.19999695,  103.40000153,  193.19999695], dtype=float32)
>>> s.segment_data[0]['flow'] = [543.4, 987.6]
>>> s.segment_data[0]['flow']
array([ 543.40002441,  987.59997559], dtype=float32)
>>> s.write_file('x.sfr')

And the x.sfr output file:

# SFR package for  MODFLOW-2005, generated by Flopy.
4 2 0 0 86400.00000000 0.00010000 0 0
1 1 1 0 0 101.099998474
1 1 1 0 0 202.199996948
1 1 1 0 0 103.400001526
1 1 1 0 0 193.199996948
2 0 0
0 0 0 0 543.400024414 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 987.599975586 0 0 0
0 0 0 0 0
0 0 0 0 0

The fix that I've put together in this PR is to switch from float32 (a.k.a. real) to float (a.k.a. double precision).

I haven't dug down to SFR2's writer/formatter, but it's possible to get Numpy to output float32 (or any other data type) as it should:

>>> for x in s.segment_data[0]['flow']:
...     print(x)
...
543.4
987.6
>>> print(s.segment_data[0]['flow'])
[ 543.40002441  987.59997559]

Other fixes in this PR add other floats to NC_PRECISION_TYPE. Also np.int64 was corrected from "i4" to "i8".

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 28, 2018

Coverage Status

Coverage remained the same at 69.807% when pulling 1a1e857 on mwtoews:sfr-mods into 0875d48 on modflowpy:develop.

@mwtoews
Copy link
Copy Markdown
Contributor Author

mwtoews commented Apr 2, 2018

Closing as this issue with SFR2 formatting is primarily addressed in #313

However, there are potentially outstanding issues with NC_PRECISION_TYPE, i.e. it should have np.int64: "i8"

@mwtoews mwtoews closed this Apr 2, 2018
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.

3 participants