Issues with "Making groundwater inflow a function of lake water level"

24 views
Skip to first unread message

Oscar Matias Benavente Zolezzi

unread,
Feb 6, 2017, 3:53:42 PM2/6/17
to pitlakq-users
Dear Mike,

After running the first two examples of pitlakq (i.e. pilakq_tut, pitlakq_tut_qual), I've been stuck with pitlakq_gwh project for several days. The problems are related to the sript in the file gwh.py. (C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.py)

At the beggining I received error messages when python was trying to read the flows, zones and conc sheets from the gwh.xlsx file, but I was able to fix this. Apparently you wrote the script using another syntaxis (an old one?) to get the information from the generator-type objects that are created when using the openpyxl toolbox. In the attached file you can see what I did.

The sad part of the story is that I received another error message from the same file (gwh.py), and I do not know how to fix it:   File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.py", line 156, in _make_zone_mapping TypeError: 'NoneType' object is not iterable

Could you give me a hand with this, please?

I'm using  WIN7-64b.

Cheers,
Oscar


PS: The following is what appears in my comsol when trying to run the project:

(pitlakq34) C:\Users\obenavente\pitlakq_work\models\pitlakq_tut_gwh>pitlakq run
pitlakq_tut_gwh
Using C:\Users\obenavente\.pitlakq
setting new values for couplings
setting new values for general
setting new values for gw
setting new values for erosion
setting new values for phreeqc
setting new values for dual_porosity
setting new values for modmst
setting new values for lake
setting new values for loading
setting new values for sediment
setting new values for sediment
setting new values for output
setting new values for treatment
setting new values for phreeqc
setting new values for general
setting new values for gw
setting new values for couplings
setting new values for lake
init lake
start of module lake
setting new values for transport_scheme
setting new values for tributaries
setting new values for hydraulic_coefficients
setting new values for calculations
setting new values for waterbody_coordinates
setting new values for times
setting new values for wind
setting new values for ice_cover
setting new values for interpolations
setting new values for general
setting new values for dead_sea
setting new values for branch_geometry
setting new values for bounds
setting new values for constituent_computations
setting new values for active_constituents
setting new values for sediment
setting new values for coliform
setting new values for inorganic_carbon
setting new values for phosphorus
setting new values for cbod
setting new values for sediment_oxygen_demand
setting new values for algae
setting new values for oxygen_limit
setting new values for dissolved_organic_matter
setting new values for suspended_solids
setting new values for stoichiometry
setting new values for ammonia
setting new values for iron
setting new values for nitrate
setting new values for extinction_coefficients
setting new values for particulate_organic_matter
setting new values for suspended_solids
setting new values for extinction_coefficients
setting new values for sediment
setting new values for coliform
setting new values for inorganic_carbon
setting new values for stoichiometry
setting new values for constituent_computations
setting new values for phosphorus
setting new values for cbod
setting new values for ammonia
setting new values for sediment_oxygen_demand
setting new values for nitrate
setting new values for active_constituents
setting new values for iron
setting new values for algae
setting new values for oxygen_limit
setting new values for dissolved_organic_matter
setting new values for particulate_organic_matter
setting new values for bathymetry
setting new values for meteorology
setting new values for precipitation
setting new values for precipitation_temperature
setting new values for precipitation_concentration
setting new values for tributary_inflow
setting new values for tributary_temperature
setting new values for tributary_concentration
setting new values for branch_inflow
setting new values for branch_outflow
setting new values for branch_inflow_concentration
setting new values for branch_inflow_temperature
setting new values for initial_conditions
setting new values for initial_concentrations
setting new values for general
setting new values for bounds
setting new values for times
setting new values for bathymetry
updated starting_water_level: with 165
setting new values for ice_cover
setting new values for calculations
setting new values for tributaries
setting new values for initial_conditions
setting new values for waterbody_coordinates
setting new values for branch_geometry
setting new values for constituent_computations
setting new values for active_constituents
setting new values for suspended_solids
setting new values for sediment
setting new values for coliform
setting new values for inorganic_carbon
setting new values for stoichiometry
setting new values for phosphorus
setting new values for cbod
setting new values for ammonia
setting new values for sediment_oxygen_demand
setting new values for nitrate
setting new values for algae
setting new values for iron
setting new values for oxygen_limit
setting new values for dissolved_organic_matter
setting new values for particulate_organic_matter
setting new values for suspended_solids
setting new values for sediment
setting new values for coliform
setting new values for inorganic_carbon
setting new values for stoichiometry
setting new values for constituent_computations
setting new values for phosphorus
setting new values for cbod
setting new values for ammonia
setting new values for sediment_oxygen_demand
setting new values for nitrate
setting new values for active_constituents
setting new values for iron
setting new values for algae
setting new values for oxygen_limit
setting new values for dissolved_organic_matter
setting new values for particulate_organic_matter
setting new values for initial_concentrations
setting new values for meteorology
setting new values for precipitation
setting new values for precipitation_temperature
setting new values for precipitation_concentration
one branch only
notused ctr
notused cpr
deleted tributary_concentration
deleted precipitation_concentration
deleted tributary_temperature
deleted meteorology
deleted precipitation
deleted branch_inflow_concentration
deleted branch_inflow
deleted precipitation_temperature
deleted branch_outflow
deleted tributary_inflow
deleted branch_inflow_temperature
str title
str wtype
elws [ 165.  165.  165.  165.  165.  165.  165.  165.  165.  165.  165.  165.
  165.  165.  165.  165.  165.  165.  165.  165.  165.]
ds [11]
us [6]
uhs [0]
dhs [0]
kt 37
kb [ 0  0  0  0 38 38 45 50 50 45 41 41  0  0  0  0  0  0  0  0  0]
charge balancing solution...
mean water level: 165.000002212

runtime: 0:00:09.343534
Traceback (most recent call last):
  File "C:\Anaconda3\envs\pitlakq34\Scripts\pitlakq-script.py", line 11, in <mod
ule>
    load_entry_point('PITLKAQ==1.3.2', 'console_scripts', 'pitlakq')()
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\metamodel\running\
run_pitlakq.py", line 517, in main
    args.func(args)
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\metamodel\running\
run_pitlakq.py", line 450, in run_project
    run(args.project_name)
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\metamodel\running\
run_pitlakq.py", line 539, in run
    config.mineral_rates)
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\metamodel\running\
run_pitlakq.py", line 100, in __init__
    self.init_sub_models()
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\metamodel\running\
run_pitlakq.py", line 305, in init_sub_models
    self.gwh.read_data()
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.p
y", line 48, in read_data
  File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.p
y", line 156, in _make_zone_mapping
TypeError: 'NoneType' object is not iterable

(pitlakq34) C:\Users\obenavente\pitlakq_work\models\pitlakq_tut_gwh>

gwh_changed_OB.py

Mike Müller

unread,
Feb 6, 2017, 8:19:31 PM2/6/17
to pitlak...@googlegroups.com
Hi Oscar,

Am 06.02.17 um 21:53 schrieb Oscar Matias Benavente Zolezzi:
Dear Mike,

After running the first two examples of pitlakq (i.e. pilakq_tut, pitlakq_tut_qual), I've been stuck with pitlakq_gwh project for several days. The problems are related to the sript in the file gwh.py. (C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.py)

I just ran pitlakq_tut_gwh. I works for me with openpyxl 2.3.1.


At the beggining I received error messages when python was trying to read the flows, zones and conc sheets from the gwh.xlsx file, but I was able to fix this.

What was the error and how did you fix it?


Apparently you wrote the script using another syntaxis (an old one?) to get the information from the generator-type objects that are created when using the openpyxl toolbox. In the attached file you can see what I did.

Everything runs with Python 3. The problem is a change in the openpyxl library.
Your changes seem to introduces some error:

For example, you changed my line:

header = [cell.value for cell in worksheet.rows[0] if cell.value]

into this:

# tratando de mejorar el script
        aux1=worksheet.rows
        aux2=worksheet.columns
        nrow=len(next(aux1))
        ncol=len(next(aux2))

        header = []

        for i in range(1,nrow+1):
                header.append(worksheet.cell(row = 1, column = i).value)

This is doing nearly the same thing, but you also take empty cells.
My `if cell.value` filters out these empty cells. Seems like one of the empty cells
causes a follow-up problem.

The cause for the problem is the openpyxl library. They changed worksheet.rows and
worksheet.columns. These are now generators. This happened between versions 2.3 and 2.4.
Since this is quite a big change, it should at least emit a warning for several version that
this will change in the future.

The easiest is to convert them into lists with `list()`.

So, at all places where you access a worksheet like here:

    worksheet = self.workbook.get_sheet_by_name('Flow')

add this:

    rows = list(worksheet.rows)
    columns = list(worksheet.columns )

from than on, replace all occurrences of:

    worksheet.rows

with:

    rows

and:

     worksheet.columns

with:

   columns

for the rest of each method body.

For example:

    header = [cell.value for cell in rows[0] if cell.value]

instead of:

    header = [cell.value for cell in worksheet.rows[0] if cell.value]

You can undo all your other changes.



The sad part of the story is that I received another error message from the same file (gwh.py), and I do not know how to fix it:   File "C:\Anaconda3\envs\pitlakq34\lib\site-packages\pitlakq\submodels\gw\gwh.py", line 156, in _make_zone_mapping TypeError: 'NoneType' object is not iterable

Could you give me a hand with this, please?

I'm using  WIN7-64b.
You might get other error messages about wrong encodings or unicode.
In this case go to this directory:

pitlakq/resources/

open these files in Wordpad++ and save them with UTF-8 encoding (without BOM):

const_names.txt       
mineral_names.txt
kinetics.txt       
rates.txt

Best,
Mike
--
You received this message because you are subscribed to the Google Groups "pitlakq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pitlakq-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Dr. Mike Mueller

unread,
Feb 7, 2017, 2:01:22 AM2/7/17
to pitlak...@googlegroups.com
A quick fix would be downgrading of openpyxl:

conda install openpyxl=2.3

After this, the original version should work.

Am 07.02.17 um 02:19 schrieb Mike Müller:
>> */_line 156, in _make_zone_mapping TypeError: 'NoneType' object is not
>> iterable_/*
>>
>> Could you give me a hand with this, please?
>>
>> I'm using WIN7-64b.
> You might get other error messages about wrong encodings or unicode.
> In this case go to this directory:
>
> pitlakq/resources/
>
> open these files in Wordpad++ and save them with UTF-8 encoding (without BOM):
>
> const_names.txt
> mineral_names.txt
> kinetics.txt
> rates.txt
>
> Best,
> Mike
>>
>> Cheers,
>> Oscar
>>
>>
>> PS: The following is what appears in my comsol when trying to run the project:
>>
>> /(pitlakq34) C:\Users\obenavente\pitlakq_work\models\pitlakq_tut_gwh>pitlakq run
>> (pitlakq34) C:\Users\obenavente\pitlakq_work\models\pitlakq_tut_gwh>/
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pitlakq-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to pitlakq-user...@googlegroups.com
>> <mailto:pitlakq-user...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pitlakq-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pitlakq-user...@googlegroups.com
> <mailto:pitlakq-user...@googlegroups.com>.

Oscar Matias Benavente Zolezzi

unread,
Feb 7, 2017, 3:04:10 PM2/7/17
to pitlakq-users, mmue...@hydrocomputing.com
Dear Mike,

Thank you very much for your quick answer. At the end was a problem related with the openpyxl version. I just downgraded it from the one installed by default (2.4.1) to the version suggested by you (2.3.1).
Nevertheless I will analyze your previous answer and try to run it using my version of the ghw.py file.


Cheers,
Oscar
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pitlakq-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pitlakq-user...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages