modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

Error using binaryfile.py to get data from a .cbb file #392

Closed edimunv closed 6 years ago

edimunv commented 6 years ago

Hi,

I'm trying to get data from a cbb file for a MODFLOW-USG model. This is the code:

import flopy.utils.binaryfile as bf cbb = bf.CellBudgetFile('TS_E2.cbb') times = cbb.get_kstpkper() cbb.list_records() rec = cbb.get_data(kstpkper=times[-1], text='DRAINS')

but i get this error:

File "C:\Users\emunozv\AppData\Local\Continuum\anaconda3\lib\site-packages\flopy\utils\binaryfile.py", line 856, in get_record self.file.seek(ipos, 0)

TypeError: only integer scalar arrays can be converted to a scalar index

I can see the cbb list records, but i have problems with cbb.get_data. Any idea of this error?

Thanks

langevin-usgs commented 6 years ago

Can you paste in the very last part of list_records() and also what is contained in times[-1]?

edimunv commented 6 years ago

The last part of the list:

(10, 12, b' FLOW JA FACE ', 4821630, 1, 1, 0, 0., 0., 0.) (10, 12, b' WELLS', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' DRAINS', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' RIVER LEAKAGE', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' RECHARGE', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b'CNST H MASS FLUX', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' WELL MASS FLUX', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' DRN MASS FLUX', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' RIV MASS FLUX', 698594, 1, 1, 0, 0., 0., 0.) (10, 12, b' RCH MASS FLUX', 698594, 1, 1, 0, 0., 0., 0.)

and times[-1] = (9,11).

I've tried using kstpkper = (10,12) or (12,10) but only get an empty list for rec. I've used compact and uncompact cbb file.

Thank you

langevin-usgs commented 6 years ago

Try leaving off text='DRAINS' and see if that gives you back something.

edimunv commented 6 years ago

It gives me the same error that i explained in the first post.

I think the error is related to how self.file.seek(ipos,0) works (line 856 of binaryfile.py). I added this lines to my code, trying to understand the error:

idxc = cbb.get_indices(text = 'DRAINS') iposs = cbb.iposarray[idxc]

and it creates arrays that seems correct (idxc and iposs are arrays type int64). Then i do

cbb.file.seek(iposs,0)

and i get the same error:

TypeError: only integer scalar arrays can be converted to a scalar index.

Any other idea? Thanks for trying to help Chris.

spaulins-usgs commented 6 years ago

Based on the line numbers you mention in binaryfile.py it looks like you are using Flopy version 3.2.5. I recommend trying the latest Flopy release (3.2.9) or try using the develop branch. Some of the Flopy code around where you are getting the error has changed since version 3.2.5.

edimunv commented 6 years ago

Thank you spaulins-usgs. With Flopy release 3.2.9 works ok, but now i have a problem reading hds file. Using flopy 3.2.5 with this code

hfile = bf.HeadFile('model.hds') times = hfile.get_times()

i got all the times saved in hds file. Now with flopy 3.2.9 only i get the first time. Do you know why? Is there a way to solve that problem?

edimunv commented 6 years ago

I found the solution. I have to use HeadUFile class.

Thanks for everything