AttributeError: 'module' object has no attribute 'get_altitude' - python

This section of my pysolarrobot7.py code is throwing an AttributeError
def tomorrow_heading():
increment_min = 1
incrementeddatetime = 0
tomorrow_corrected = 90
if pysolar.get_altitude(maplat, maplon, datetime.datetime.utcnow()) < 0:
while pysolar.get_altitude(maplat, maplon, (datetime.datetime.utcnow() + datetime.timedelta(minutes=incrementeddatetime))) < 0:
incrementeddatetime = incrementeddatetime + increment_min
sunrise_time=(datetime.datetime.utcnow() + datetime.timedelta(minutes=incrementeddatetime))
tomorrow_heading = pysolar.GetAzimuth(maplat, maplon, sunrise_time)
if tomorrow_heading < 0:
if (tomorrow_heading >= -180):
tomorrow_corrected = ((tomorrow_heading * -1) + 180)
if (tomorrow_heading < -180):
tomorrow_corrected = ((tomorrow_heading * -1) - 180)
if tomorrow_heading >= 0:
The following is the error code
root#Primerpi:/tools# python3 solarrobot7-core.py
Traceback (most recent call last):
File "solarrobot7-core.py", line 237, in <module>
tomorrow_static = tomorrow_heading()
File "solarrobot7-core.py", line 176, in tomorrow_heading
if pysolar.get_altitude(maplat, maplon, datetime.datetime.utcnow()) < 0:
AttributeError: 'module' object has no attribute 'get_altitude'
I've been googling for a while now and can't seem to find the answer. The original code from solarrobot7.py used GetAltitude and Pysolar (PascalCase) and I changed it to get_altitude and pysolar (snake_case).

pysolar don't have an "get_altitude" method:
You want the sub-module "solar" :)
from pysolar import solar
solar.get_altitude #this will work :)

Related

Receiving error message in Python when using if statement(closed)

I am not sure why but i am receiving a syntax error in the following code segment:
def motor_sat(self, wheel_angular_velocities, limit_value):
phi1 = wheel_angular_velocities[0]
phi2 = wheel_angular_velocities[1]
phi3 = wheel_angular_velocities[2]
if phi1 < -limit_value
phi1_bar = -limit_value
elif phi1 <= limit_value and phi1 >= -limit_value
phi1_bar = phi1
elif phi1 > limit_value
phi1_bar = limit_value
The error message is:
[lab3demo1] Traceback (most recent call last):
[lab3demo1] File "lab3demo1.py", line 8, in <module>
[lab3demo1] from myRobot import *
[lab3demo1] File "/home/user/ele719/controllers/lab3demo1/myRobot.py", line 66
[lab3demo1] if phi1 < -limit_value
[lab3demo1] ^
[lab3demo1] SyntaxError: invalid syntax
You are missing colons(:) at the end of each if/elif statements, the correct code would be:
def motor_sat(self, wheel_angular_velocities, limit_value):
phi1 = wheel_angular_velocities[0]
phi2 = wheel_angular_velocities[1]
phi3 = wheel_angular_velocities[2]
if phi1 < -limit_value:
phi1_bar = -limit_value
elif phi1 <= limit_value and phi1 >= -limit_value:
phi1_bar = phi1
elif phi1 > limit_value:
phi1_bar = limit_value

TypeError: object of type 'filter' has no len()

When executing my Python script, I'm receiving the following error...
Traceback (most recent call last):
File "/usr/local/bin/jira-cycle-extract", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/cli.py", line 144, in main
cycle_data = q.cycle_data(verbose=args.verbose)
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/cycletime.py", line 141, in cycle_data
for snapshot in self.iter_changes(issue, False):
File "/usr/local/lib/python3.7/site-packages/jira_cycle_extract/query.py", line 114, in iter_changes
last_status = status_changes[0].fromString if len(status_changes) != 0 else issue.fields.status.name
TypeError: object of type 'filter' has no len()
I've tried to address this by adding the following code based on other research, and changing from > 0 to not empty or other forms to check for an empty list, but had no luck.
This is the code in question...
status_changes = filter(
lambda h: h.field == 'status',
itertools.chain.from_iterable([c.items for c in issue.changelog.histories])
)
last_status = status_changes[0].fromString if len(status_changes) != 0 else issue.fields.status.name
last_resolution = None
You can use the next function with a generator expression and a default value instead. The code in your question can be re-written as:
last_status = next((h.fromString for c in issue.changelog.histories for h in c.items if h.field == 'status'), issue.fields.status.name)
last_resolution = None

What is wrong with my function that contains a "Attribute error"

Hey I'm getting this error on my code but I'm not sure why
my code for this function is:
def rotateImage90(image):
ei = EmptyImage(image.getHeight(), image.getWidth())
for i in range (image.getWidth()):
for j in range(image.getHeight()):
orginal = image.getPixel(i, j)
ei.setPixel(image.getHeight() - j - 1, i, orginal)
return ei
the error im getting is
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
drawImage("Spiderman", [spiderman, rotateImage90(spiderman)])
File "/Users/luisarroyo/Documents/project 7.py", line 52, in rotateImage90
orginal = image.getPixel(i, j)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cImage.py", line 310, in getTkPixel
p = [int(j) for j in self.im.get(x,y).split()]
AttributeError: 'tuple' object has no attribute 'split'

How to solve the error message : 'NoneType' object has no attribute 'DataFrame'

I copy a section of code from the the official website of 'Bokeh':
import numpy as np
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.transform import linear_cmap
from bokeh.util.hex import hexbin
n = 50000
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)
bins = hexbin(x, y, 0.1)
p = figure(tools="wheel_zoom,reset", match_aspect=True, background_fill_color='#440154')
p.grid.visible = False
p.hex_tile(q="q", r="r", size=0.1, line_color=None, source=bins,
fill_color=linear_cmap('counts', 'Viridis256', 0, max(bins.counts)))
output_file("hex_tile.html")
show(p)
When i ran this program , i got a error message about this:
enter image description here
> Traceback (most recent call last):
> File "d:\vscode-text-files\hex_tile.py", line 12, in 'module'
> bins = hexbin(x, y, 0.1)
> File "D:\Program Files\Python37\lib\site-packages\bokeh\util\hex.py",
> line 198, in hexbin
> df = pd.DataFrame(dict(r=r, q=q))
> AttributeError: 'NoneType' object has no attribute 'DataFrame'
How can i solve this problem?

TypeError: object of type 'int' has no len() when using sop.brute

I use the Python3.6 and I've been confused about this question for a long time..so here is my code.
def fo(x,y):
z=np.sin(x)+0.05*x**2+np.cos(y)+0.05*y**2
if output == True:
print("%8.4f %8.4f %8.4f" % (x,y,z))
return z
import scipy.optimize as sop
sop.brute(fo,(-10,10.1,5),(-10,10.1,5),finish = None)
Here is the error I get:
Traceback (most recent call last):
File "<ipython-input-12-c7886e35ff4b>", line 1, in <module>
sop.brute(fo,(-10,10.1,5),(-10,10.1,5),finish = None)
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 2811, in brute
if len(lrange[k]) < 3:
TypeError: object of type 'int' has no len()
here's another try:
r1=slice(-10,10.1,5)
r2=slice(-10,10.1,5)
sop.brute(fo,r1,r2,finish = None)
and the error:
Traceback (most recent call last):
File "<ipython-input-48-230c07265998>", line 1, in <module>
sop.brute(fo,r1,r2,finish = None)
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 2804, in brute
N = len(ranges)
TypeError: object of type 'slice' has no len()
sop.brute(fo,(r1,r2),finish = None)
TypeError: fo() missing 1 required positional argument: 'y'
I'm new to here and sorry if I ask a stupid question but I cant' work it out T.T thx a lot
def fo(p):
x, y = p
z = np.sin(x)+0.05*x**2+np.sin(y)+0.05*y**2
if output == True:
print('%8.4f %8.4f %8.4f' % (x,y,z))
return z
unpack tuple like in the code

Categories