10
10
maccrad_csv_dir = os .path .join (".." , ".." , ".." , "pvlib_data" , "MACC-RAD" , "carpentras" )
11
11
maccrad_csv_path = os .path .join (maccrad_csv_dir , maccrad_csv )
12
12
13
- #data_maccrad = read_maccrad(maccrad_csv, output='loc')
14
-
15
-
16
- ## if data is on remotely on github
17
-
18
- import urllib
19
-
20
- #f = urllib.request.urlopen(maccrad_url_full)
21
-
22
- #from urllib.parse import urlparse
23
- #response = urlparse(maccrad_url_full)
24
-
25
-
26
- from urllib .request import urlopen
27
- response = urlopen (maccrad_url_full )
28
- response = response .decode ('utf-8' )
29
-
30
-
31
-
32
-
33
- req = urllib .request .urlopen (maccrad_url_full )
34
- charset = req .info ().get_content_charset ()
35
- content = req .read ().decode (charset )
36
-
37
- data = urllib .request .urlopen (maccrad_url_full ).read ()
38
-
39
- lines = data .splitlines (True )
40
- # http://stackoverflow.com/questions/23131227/how-to-readlines-from-urllib
41
-
42
-
43
-
44
- import requests
45
-
46
- response = requests .get (maccrad_url_full ).text
47
-
48
- for line in response :
49
- # print (line)
50
- if line .startswith ( "# Latitude" ):
51
- # lat_line = line
52
- # lat = float(lat_line.split(':')[1])
53
- lat = float (line .split (':' )[1 ])
54
- if line .startswith ( "# Longitude" ):
55
- # lon_line = line
56
- # lon = float(lon_line.split(':')[1])
57
- lon = float (line .split (':' )[1 ])
58
- # if line.startswith( "# Altitude"):
59
- if "Altitude" in line :
60
- alt_line = line
61
- alt = float (alt_line .split (':' )[1 ])
62
- # alt = float(line.split(':')[1])
63
-
64
-
65
- ## if file is on local drive
66
- f = open (maccrad_csv_path )
67
- for line in f :
68
- if "Latitude" in line :
69
- # print (line)
13
+ data_maccrad = read_maccrad (maccrad_csv_path , output = 'loc' )
14
+
15
+ maccrad_loc = data_maccrad [0 ]
16
+ maccrad_df = data_maccrad [1 ]
17
+
18
+ def test_location_coord ():
19
+ assert (44.0830 , 5.0590 , 97.00 ) == (maccrad_loc .latitude , maccrad_loc .longitude ,
20
+ maccrad_loc .altitude )
21
+
22
+
23
+ def test_location_tz ():
24
+ assert 'Europe/Paris' == maccrad_loc .tz
25
+
26
+
27
+ def test_maccrad_recolumn ():
28
+ assert 'Clear sky GHI' in maccrad_df .columns
29
+
30
+ def test_maccrad_norecolumn ():
31
+ assert 'Clear sky GHI' in maccrad_df .columns
32
+
33
+ def test_maccrad_coerce_year ():
34
+ coerce_year = 2010
35
+ assert (maccrad_df .index .year [0 ] == coerce_year )
36
+
37
+
38
+ def test_maccrad ():
39
+ read_maccrad (maccrad_csv_path )
40
+
41
+ ##FIXME: this still crashes
42
+ ### if data is on remotely on github
43
+ #
44
+ #
45
+ #import urllib
46
+ #
47
+ ##f = urllib.request.urlopen(maccrad_url_full)
48
+ #
49
+ ##from urllib.parse import urlparse
50
+ ##response = urlparse(maccrad_url_full)
51
+ #
52
+ #
53
+ ##from urllib.request import urlopen
54
+ ##response = urlopen(maccrad_url_full)
55
+ ##response = response.decode('utf-8')
56
+ #
57
+ #
58
+ #
59
+ ## http://stackoverflow.com/questions/4981977/how-to-handle-response-encoding-from-urllib-request-urlopen
60
+ #req=urllib.request.urlopen(maccrad_url_full)
61
+ #charset=req.info().get_content_charset()
62
+ #response=req.read().decode(charset)
63
+ #
64
+ ##data = urllib.request.urlopen(maccrad_url_full).read()
65
+ #
66
+ #lines = response.splitlines(True)
67
+ ## http://stackoverflow.com/questions/23131227/how-to-readlines-from-urllib
68
+ #
69
+ #
70
+ #
71
+ ##import requests
72
+ ##response = requests.get(maccrad_url_full).text
73
+ #
74
+ #for line in response:
75
+ ## print (line)
70
76
# if line.startswith( "# Latitude"):
71
- lat_line = line
72
- lat = float (lat_line .split (':' )[1 ])
77
+ ## lat_line = line
78
+ ## lat = float(lat_line.split(':')[1])
73
79
# lat = float(line.split(':')[1])
74
- if "Longitude" in line :
75
80
# if line.startswith( "# Longitude"):
76
- lon_line = line
77
- lon = float (lon_line .split (':' )[1 ])
78
- lon = float (line .split (':' )[1 ])
81
+ ## lon_line = line
82
+ ## lon = float(lon_line.split(':')[1])
83
+ # lon = float(line.split(':')[1])
79
84
# if line.startswith( "# Altitude"):
80
- if "Altitude" in line :
81
- alt_line = line
82
- alt = float (alt_line .split (':' )[1 ])
83
- # alt = float(line.split(':')[1])
84
-
85
-
86
- from timezonefinder import TimezoneFinder
87
- tf = TimezoneFinder ()
88
- tz = tf .timezone_at (lng = lon , lat = lat )
85
+ ## if "Altitude" in line:
86
+ # alt_line = line
87
+ # alt = float(alt_line.split(':')[1])
88
+ ## alt = float(line.split(':')[1])
89
89
90
- from pvlib .location import Location
91
90
92
- location = Location (lat , lon , name = maccrad_csv .split ('.' )[0 ], altitude = alt ,
93
- tz = tz )
0 commit comments