oemof / feedinlib

This repository contains implementations of photovoltaic models to calculate electricity generation from a pv installation based on given solar radiation. Furthermore it contains all necessary pre-calculations.
MIT License
102 stars 44 forks source link

ConnectionException for openFRED location table #47

Open c-koehl opened 4 years ago

c-koehl commented 4 years ago

Hey, I'm trying to read the openFRED data:

from feedinlib.open_FRED import Weather
from feedinlib.open_FRED import defaultdb
from shapely.geometry import Point, Polygon

lat = 52.4
lon = 13.5
location = Point(lon, lat)
open_FRED_weather_data = Weather(
    start='2017-06-01', stop='2017-07-01',
    locations=[location],
    variables="pvlib",
    **defaultdb())

but somehow I receive a connection exception (even though I used my token):

oedialect.engine.ConnectionException: HTTP 400 (Bad Request): Table sandbox.openfred_locations not found

But if I run following code, I can get access to the location`s data:

import oedialect
from sqlalchemy import Table, create_engine, MetaData, Column
from sqlalchemy.orm import sessionmaker

engine = create_engine('postgresql+oedialect://MYUSERNAME:MYTOKEN@openenergy-platform.org')

Session = sessionmaker()
session = Session(bind=engine)

metadata = MetaData(bind=engine)

loc = Table("openfred_locations", metadata,
    Column("id"),
    Column("point"),
    schema="climate")

q = session.query(loc).limit(10)

So it doesn't seem to be a database bug. Can you fix this problem or am I doing something wrong? I was trying to find the bug, but I'm quite new to database structures, so I wasn't able to find anything. Thanks!

P.S.: Here is the entire error message:

Traceback (most recent call last):
  File "/Volumes/Consolinno/feedinlib/test_fred.py", line 60, in <module>
    **defaultdb())
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/feedinlib/open_FRED.py", line 138, in __init__
    if locations is not None
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/feedinlib/open_FRED.py", line 137, in <dictcomp>
    {(l.x, l.y): self.location(l) for l in locations}
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/feedinlib/open_FRED.py", line 307, in location
    .order_by(self.db["Location"].point.distance_centroid(point))
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3300, in first
    ret = list(self[0:1])
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3078, in __getitem__
    return list(res)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3405, in __iter__
    return self._execute_and_instances(context)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3430, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 984, in execute
    return meth(self, multiparams, params)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 293, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1103, in _execute_clauseelement
    distilled_params,
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1288, in _execute_context
    e, statement, parameters, cursor, context
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1485, in _handle_dbapi_exception
    util.raise_(exc_info[1], with_traceback=exc_info[2])
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/oedialect/engine.py", line 338, in execute
    requires_connection_id=requires_connection_id)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/oedialect/engine.py", line 355, in __execute_by_post
    requires_connection_id=requires_connection_id)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/oedialect/engine.py", line 232, in post
    process_returntype(ans, json_response)
  File "/Volumes/Consolinno/feedinlib/pvenv/lib/python3.7/site-packages/oedialect/engine.py", line 241, in process_returntype
    raise ConnectionException('HTTP %d (%s): %s'%(response.status_code,response.reason, message))
oedialect.engine.ConnectionException: HTTP 400 (Bad Request): Table sandbox.openfred_locations not found
gnn commented 4 years ago

Thanks for the report. The first code block which you posted should definitely work and we need to fix that. Are you installing the package from source? If so, based on which branch? And then there's something in the output which doesn't match up with what I expected. I have to look into that.

c-koehl commented 4 years ago

I cloned the repository and installed the dependencies. I remember having issues installing it via pip (3 weeks ago). Apparently if you install it via pip, an older version will be installed, because some files were missing and were different compared to the dev branch in github!

nick-harder commented 4 years ago

Hi, is there a solution for this issue already? I have tried running it on my PC and also on Binder, it doesn't work.

Also, when I run following code: open_FRED_weather_windpowerlib_single_location = Weather( start=start_date, stop=end_date, locations=[location], heights=heights, variables=variables, **defaultdb())

I get following error: `--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

in 3 heights=heights, 4 variables=variables, ----> 5 **defaultdb()) C:\ProgramData\Anaconda3\lib\site-packages\feedinlib\open_FRED.py in __init__(self, start, stop, locations, heights, variables, regions, session, db) 148 location_ids = [ 149 l.id --> 150 for l in chain(self.locations.values(), *self.regions.values()) 151 ] 152 C:\ProgramData\Anaconda3\lib\site-packages\feedinlib\open_FRED.py in (.0) 148 location_ids = [ 149 l.id --> 150 for l in chain(self.locations.values(), *self.regions.values()) 151 ] 152 AttributeError: 'NoneType' object has no attribute 'id'`
p-snft commented 4 years ago

I can reproduce the issue as reported by @nick-harder, also for the current dev. However, I do not have the appropriate knowledga about open_FRED, to fix it. @oemof/feedinlib, could anyone of you help?

gnn commented 4 years ago

Sorry for taking so long to fix this and thanks for continuously prodding me. The issue that @nick-harder experienced and which @p-snft reproduced is different from the one originally reported. I'll try to reproduce both and probably will open a new issue for the former. In the long run, I'm hoping to have both issues fixed in a month.

ADai528 commented 3 years ago

hi, @nick-harder. I also encountered the same problem, did you finally solve this problem?