-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-flask.py
61 lines (55 loc) · 1.69 KB
/
python-flask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# A very simple Flask Hello World app for you to get started with...
from flask import Flask, request
import pandas as pd
import pvlib
from datetime import date
from datetime import timedelta
from flask_cors import CORS, cross_origin
import sys
# from pvlib import location
# from pvlib.bifacial.pvfactors import pvfactors_timeseries
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['GET'])
def home():
lat = float(request.args.get("lat"))
lon = float(request.args.get("lon"))
today = date.today()
yesterday = today - timedelta(days = 1)
today = str(today)
yesterday = str(yesterday)
# lat = 51
# lon = 0
times = pd.date_range(yesterday, today, freq='1H', tz='Etc/GMT+5')
loc = pvlib.location.Location(latitude=lat, longitude=lon, tz=times.tz)
sp = loc.get_solarposition(times)
cs = loc.get_clearsky(times)
# example array geometry
pvrow_height = 1
pvrow_width = 4
pitch = 10
gcr = pvrow_width / pitch
albedo = 0.2
irrad = pvlib.bifacial.pvfactors.pvfactors_timeseries(
solar_azimuth=sp['azimuth'],
solar_zenith=sp['apparent_zenith'],
surface_azimuth=180, # south-facing array
surface_tilt=20,
axis_azimuth=90, # 90 degrees off from surface_azimuth. 270 is ok too
timestamps=times,
dni=cs['dni'],
dhi=cs['dhi'],
gcr=gcr,
pvrow_height=pvrow_height,
pvrow_width=pvrow_width,
albedo=albedo,
n_pvrows=3,
index_observed_pvrow=1
)
# turn into pandas DataFrame
irrad = pd.concat(irrad, axis=1)
labels = []
for hr in times:
labels.append(hr.hour)
irrad['labels'] = labels
return irrad.to_json()