-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindTrace_onshore.py
1743 lines (1602 loc) · 94.7 KB
/
WindTrace_onshore.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import bw2data as bd
import bw2io as bi
from geopy.distance import geodesic
import random
from typing import Optional, List, Literal, Tuple
from stats_arrays import NormalUncertainty
from statistics import linear_regression
import sys
import consts_wt
# create a bw25 project, import ecoinvent v.3.9.1 and create an empty database 'new_db'
bd.projects.set_current(consts_wt.PROJECT_NAME)
bi.bw2setup()
spold_files = consts_wt.SPOLD_FILES
if "cutoff391" not in bd.databases:
ei = bi.SingleOutputEcospold2Importer(spold_files, "cutoff391", use_mp=False)
ei.apply_strategies()
ei.write_database()
cutoff391 = bd.Database("cutoff391")
if consts_wt.NEW_DB_NAME not in bd.databases:
new_db = bd.Database(consts_wt.NEW_DB_NAME)
new_db.register()
new_db = bd.Database(consts_wt.NEW_DB_NAME)
biosphere3 = bd.Database('biosphere3')
def steel_turbine(plot_mat: bool = False):
"""
It returns a dictionary 'materials_polyfits' that contains the fitting curve of steel (mass vs hub height). The
dictionary has the keys 'polyfit' and 'confidence_95%' where the values are stored. The uncertainty (to be added
to the lci) is stored as 'std_dev' also in the same dictionary and corresponds to the standard deviation of the
residuals. If plot_mat is set to True, all the materials fitting plots will be shown.
"""
vestas_data = pd.read_excel(consts_wt.VESTAS_FILE, sheet_name="1_MATERIALS_TURBINE", dtype=None, decimal=";", header=0)
short_vestas_data = vestas_data[vestas_data['Hub height'] <= 84]
# Extracting columns
x = vestas_data['Hub height']
y = vestas_data['Low alloy steel']
# Remove NaN values
valid_indices = ~np.isnan(x) & ~np.isnan(y)
new_x = x[valid_indices]
new_y = y[valid_indices]
# Dictionary to save the polyfits and confidence intervals
materials_polyfits = {}
materials_polyfits_short = {}
# Linear regression (steel mass vs height) and statistics
fit_steel = np.polyfit(new_x, new_y, 1)
predict_steel = np.poly1d(fit_steel)
# Calculate residuals
residuals = new_y - predict_steel(new_x)
# Calculate standard error of the estimate
std_error = np.sqrt(np.mean(residuals ** 2))
# Calculate confidence intervals (95%) for interpolated x values
confidence = 1.96 * std_error # 95% confidence interval multiplier
residual_variance = np.mean(residuals ** 2)
residual_std_dev = np.sqrt(residual_variance)
# long_short = {}
polyfit_and_confidence = {'polyfit': predict_steel, 'confidence_95%': confidence, 'std_dev': residual_std_dev}
materials_polyfits['Low alloy steel'] = polyfit_and_confidence
# Extract short data
short_x = short_vestas_data['Hub height']
short_y = short_vestas_data['Low alloy steel']
slope, intercept = linear_regression(short_x, short_y, proportional=True)
# slope, intercept = linear_regression(short_x, short_y)
short_predict_steel = np.poly1d([slope, intercept])
# Calculate residuals
residuals = short_y - short_predict_steel(short_x)
# Calculate standard error of the estimate
std_error = np.sqrt(np.mean(residuals ** 2))
# Calculate confidence intervals (95%) for interpolated x values
confidence = 1.96 * std_error # 95% confidence interval multiplier
# residual_variance = np.mean(residuals ** 2)
residual_std_dev = np.sqrt(residual_variance)
# We mantain the same confidence and std_dev as the main function.
polyfit_and_confidence_short = {'polyfit': short_predict_steel, 'confidence_95%': confidence,
'std_dev': residual_std_dev}
if plot_mat:
plot_materials(x=short_x, y=short_y, residuals=residuals, interpolation_eq=short_predict_steel,
confidence=confidence,
xlabel='Hub height (m)', ylabel='Steel mass (t)', title='Steel')
materials_polyfits_short['Low alloy steel'] = polyfit_and_confidence_short
# where do the linear equations intersect?
intersection_poly = np.poly1d(short_predict_steel - predict_steel)
intersection_x = np.roots(intersection_poly)
intersection = {'Low alloy steel': intersection_x}
return vestas_data, materials_polyfits, materials_polyfits_short, intersection
def other_turbine_materials(plot_mat=False) -> (tuple, dict, dict):
"""
It returns a dictionary 'materials_polyfits' that contains the fitting curves of steel and turbine materials.
The dictionary has the keys 'polyfit' and 'confidence_95%' where the values are stored.
If plot_mat is set to True, all the materials fitting plots will be shown.
"""
vestas_data, materials_polyfits, materials_polyfits_short, intersection = steel_turbine()
columns = list(vestas_data)
last_index = columns.index('Lubricating oil')
initial_index = columns.index('Low alloy steel') + 1
while initial_index <= last_index:
short = False
materials_to_adjust_3mw = ['PUR', 'PVC']
materials_to_adjust_1mw = ['Low alloy steel', 'Chromium steel', 'Epoxy resin', 'Fiberglass', 'Rubber',
'Aluminium']
if columns[initial_index] in materials_to_adjust_3mw:
short_vestas_data = vestas_data[vestas_data['Power (MW)'] <= 3.0]
short = True
elif columns[initial_index] in materials_to_adjust_1mw:
short_vestas_data = vestas_data[vestas_data['Power (MW)'] <= 1.0]
short = True
x = vestas_data[columns[columns.index('Power (MW)')]] # power (MW)
y = vestas_data[columns[initial_index]] # material mass (t)
valid_indices = ~np.isnan(x) & ~np.isnan(y)
new_x = x[valid_indices]
new_y = y[valid_indices]
fit = np.polyfit(new_x, new_y, 1)
predict_mat = np.poly1d(fit)
residuals = new_y - predict_mat(new_x)
std_error = np.sqrt(np.mean(residuals ** 2))
confidence = 1.96 * std_error
residual_variance = np.mean(residuals ** 2)
residual_std_dev = np.sqrt(residual_variance)
polyfit_and_confidence = {'polyfit': predict_mat, 'confidence_95%': confidence, 'std_dev': residual_std_dev}
materials_polyfits[columns[initial_index]] = polyfit_and_confidence
if short:
short_x = short_vestas_data[columns[columns.index('Power (MW)')]]
short_y = short_vestas_data[columns[initial_index]]
valid_indices = ~np.isnan(x) & ~np.isnan(y)
short_x = short_x[valid_indices]
short_y = short_y[valid_indices]
slope, intercept = linear_regression(short_x, short_y, proportional=True)
# slope, intercept = linear_regression(short_x, short_y)
short_predict_mat = np.poly1d([slope, intercept])
residuals = short_y - short_predict_mat(short_x)
# Calculate standard error of the estimate
std_error = np.sqrt(np.mean(residuals ** 2))
# Calculate confidence intervals (95%) for interpolated x values
confidence = 1.96 * std_error # 95% confidence interval multiplier
# residual_variance = np.mean(residuals ** 2)
residual_std_dev = np.sqrt(residual_variance)
polyfit_and_confidence_short = {'polyfit': short_predict_mat, 'confidence_95%': confidence,
'std_dev': residual_std_dev}
materials_polyfits_short[columns[initial_index]] = polyfit_and_confidence_short
intersection_poly = np.poly1d(short_predict_mat - predict_mat)
intersection_x = np.roots(intersection_poly)
intersection[columns[initial_index]] = intersection_x
if plot_mat:
plot_materials(x=new_x, y=new_y, residuals=residuals, interpolation_eq=predict_mat, confidence=confidence,
xlabel='Power (MW)', ylabel=columns[initial_index] + ' (t)', title=columns[initial_index])
initial_index += 1
return materials_polyfits, materials_polyfits_short, intersection
def rare_earth(generator_type: Literal['dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig']):
"""
It returns a dictionary 'rare_earth_int' that contains the intensities of the rare earth materials according to the
generator type that the turbine uses.
Material intensity data according to Ferrara et al. (2020). Units: t/GW
generator_type: accepted arguments 'dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig'.
"""
rare_earth_int = {'Praseodymium': consts_wt.RARE_EARTH_DICT['Praseodymium'][generator_type],
'Neodymium': consts_wt.RARE_EARTH_DICT['Neodymium'][generator_type],
'Dysprosium': consts_wt.RARE_EARTH_DICT['Dysprosium'][generator_type],
'Terbium': consts_wt.RARE_EARTH_DICT['Terbium'][generator_type],
'Boron': consts_wt.RARE_EARTH_DICT['Boron'][generator_type]}
return rare_earth_int
def foundations_mat(mat_file: str, plot_mat=False):
"""
It returns a dictionary 'materials_polyfits' that contains the fitting curves of all the materials (steel, turbine
and foundations). The dictionary has the keys 'polyfit' and 'confidence_95%' where the values are stored.
If plot_mat is set to True, all the materials fitting plots will be shown.
"""
materials_polyfits, mat_polyfits_short, intersection = other_turbine_materials()
vestas_data = pd.read_excel(mat_file, sheet_name="1_MATERIALS_FOUNDATIONS", dtype=None, decimal=";", header=0)
columns = list(vestas_data)
last_index = columns.index('Concrete')
initial_index = columns.index('Low alloy steel')
while initial_index <= last_index:
x = vestas_data[
columns[columns.index('Power (MW)')]] # power (MW). Maybe in the future I use tip momentum (D^2*h)
y = vestas_data[columns[initial_index]] # material mass (t)
valid_indices = ~np.isnan(x) & ~np.isnan(y)
new_x = x[valid_indices]
new_y = y[valid_indices]
fit = np.polyfit(new_x, new_y, 1)
predict_mat = np.poly1d(fit)
residuals = new_y - predict_mat(new_x)
residual_variance = np.mean(residuals ** 2)
residual_std_dev = np.sqrt(residual_variance)
std_error = np.sqrt(np.mean(residuals ** 2))
confidence = 1.96 * std_error
polyfit_and_confidence = {}
polyfit_and_confidence['polyfit'] = predict_mat
polyfit_and_confidence['confidence_95%'] = confidence
polyfit_and_confidence['std_dev'] = residual_std_dev
materials_polyfits[columns[initial_index] + '_foundations'] = polyfit_and_confidence
if plot_mat:
plot_materials(x=new_x, y=new_y, residuals=residuals, interpolation_eq=predict_mat, confidence=confidence,
xlabel='Power (MW)', ylabel=columns[initial_index] + ' (t)', title=columns[initial_index])
initial_index += 1
return materials_polyfits, mat_polyfits_short, intersection
def plot_materials(x, y, residuals, interpolation_eq, confidence, xlabel: str, ylabel: str, title: str, grid=True,
adjusted_plot=True):
"""
for the scatter points of x and y, given the residuals, fitting curve (interpolation_eq), and confidence 95% (value
that stablishes the minimim and maximum deviation from the mean that guarantees that 95% of the values will fall in
that range), it shows the corresponding plot. It's not saving it, just showing.
Note:
The variable adjusted_plot allows to extend the plot from 0 to 15 MW.
"""
y_mean = np.mean(y)
ss_total = np.sum((y - y_mean) ** 2)
ss_residual = np.sum(residuals ** 2)
r_squared = 1 - (ss_residual / ss_total)
if adjusted_plot:
x_interpolate = np.linspace(min(x), max(x), 100)
y_interpolated = interpolation_eq(x_interpolate)
else:
x_interpolate = np.linspace(0, 15, 100)
y_interpolated = interpolation_eq(x_interpolate)
# Plot the data, fitted curve, and confidence interval
plt.figure(figsize=(10, 6))
plt.scatter(x, y, color='blue')
plt.plot(x_interpolate, y_interpolated, color='red')
plt.fill_between(x_interpolate, y_interpolated - confidence, y_interpolated + confidence,
color='red', alpha=0.2)
plt.annotate(f"R-squared = {r_squared:.2f}", xy=(0.05, 0.9), xycoords='axes fraction', fontsize=10)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.title(title)
plt.grid(grid)
plt.show()
def materials_mass(generator_type: Literal['dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig'],
turbine_power: float, hub_height: float):
"""
returns a dictionary 'mass_materials' with material names as keys and their masses in kg as values.
generator_type: it only accepts the models (strings) 'dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig'.
"""
mass_materials = {}
materials_polyfits, mat_polyfits_short, intersection = foundations_mat(consts_wt.VESTAS_FILE)
uncertainty = {}
turbine_power_is_larger = hub_height > intersection['Low alloy steel'].item()
if not turbine_power_is_larger:
materials_polyf = mat_polyfits_short
else:
materials_polyf = materials_polyfits
uncertainty['Low alloy steel'] = materials_polyf['Low alloy steel']['std_dev']
steel_mass_turbine = materials_polyf['Low alloy steel']['polyfit'](hub_height) * 1000
mass_materials['Low alloy steel'] = steel_mass_turbine
is_larger_true_list = []
for k in materials_polyfits.keys():
if k in intersection.keys():
turbine_power_is_larger = turbine_power > intersection[k].item()
is_larger_true_list.append(turbine_power_is_larger)
else:
is_larger_true_list.append(True)
counter = 0
for k in materials_polyfits.keys():
is_larger = is_larger_true_list[counter]
if not is_larger:
materials_polyf = mat_polyfits_short
else:
materials_polyf = materials_polyfits
uncertainty[k] = materials_polyf[k]['std_dev']
if k != 'Low alloy steel':
# in kg instead of tonnes
mass = materials_polyf[k]['polyfit'](turbine_power) * 1000
if mass < 0:
mass = 0.0
mass_materials[k] = mass
if k == 'Concrete_foundations':
# transform concrete mass (t) to volume in m3
volume = materials_polyf[k]['polyfit'](turbine_power) / 2.4
if volume < 0:
volume = 0.0
mass_materials[k] = volume
counter += 1
rare_earth_int = rare_earth(generator_type)
for k in rare_earth_int.keys():
# in kg
mass = rare_earth_int[k] * turbine_power
mass_materials[k] = mass
return mass_materials, uncertainty
def cabling_materials(turbine_power: float, rotor_diameter: float, number_of_turbines: int,
cu_density=8960, al_density=2700, pe_density=930, pvc_density=1400):
"""
It returns a dictionary 'cable_mat_mass' that contains the mass in kg of copper, aluminium, polyethylene (PE) and
polyvinyl chloride (PVC) of the cables.
:param: park_size, power of the park in MW.
Material densities data in kg/m3
Cable section data from Nexans. Nexans cables 33kV 3-core are assumed. Data from Nexans'
technical datasheets. Assumptions:
1. buried cables
2. 50% Cu - 50% Al
Data from the technical characteristics (thewindpower.net)
"""
distance_between_turbines = 8 * rotor_diameter # 8-12D is recommended by McKenna et al., (2022) and also the
# technical guidelines from ABB 'cuaderno técnico nº12 Planta eólicas' pp.16. We will consider that all the
# turbines are always in line, so we don't apply the crosswind recommended distance of 4-6D.
# To compensate we choose 8D, as it is the smallest distance in the range.
total_distance = distance_between_turbines * (number_of_turbines - 1)
section_y = np.array([50, 70, 95, 120, 150, 185, 240, 300, 400, 500])
al_power_x = np.array([5.247, 6.402, 7.656, 8.712, 9.735, 11.022, 12.804, 14.454, 16.566, 18.81])
cu_power_x = np.array([6.765, 8.25, 9.867, 11.235, 12.573, 14.223, 16.467, 18.579, 21.120, 23.694])
cu_fit = np.polyfit(cu_power_x, section_y, 2)
al_fit = np.polyfit(al_power_x, section_y, 2)
predict_cu = np.poly1d(cu_fit)
predict_al = np.poly1d(al_fit)
cu_section = predict_cu(turbine_power) * 3 # Nexans' cross-section is per individual core and cables are three-core
al_section = predict_al(turbine_power) * 3 # Nexans' cross-section is per individual core and cables are three-core
cu_mass = cu_section / 1000000 * (total_distance / 2) * cu_density
al_mass = al_section / 1000000 * (total_distance / 2) * al_density
pe_mass_total = (cu_section + al_section) * (total_distance / 2) / 1000000 / 0.61 * 0.3 * pe_density
pvc_mass_total = (cu_section + al_section) * (total_distance / 2) / 1000000 / 0.61 * 0.09 * pvc_density
cable_mat_mass = {'Copper': cu_mass, 'Aluminium': al_mass, 'PE': pe_mass_total, 'PVC': pvc_mass_total}
return cable_mat_mass
def mva500_transformer():
"""
It creates the activity "Power transformer TrafoStar 500 MVA" in the database 'new_db' in brightway2. It returns
the recently created transformer activity as a variable.
Data from ABB. Code credits to Romain Sacchi et al. (with small changes)
"""
if not [act for act in new_db if 'Power transformer TrafoStar 500 MVA' in act['name']]:
new_act = new_db.new_activity(name="Power transformer TrafoStar 500 MVA", unit='unit', code='TrafoStar_500')
new_act.save()
# electric steel
steel = cutoff391.get(code='b3d48f2f5446c645c128b06b5de93f21')
new_exc = new_act.new_exchange(input=steel.key, amount=99640.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# transformer oil
oil = cutoff391.get(code='92391c8c6958ada25b22935e3fa6f06f')
new_exc = new_act.new_exchange(input=oil.key, amount=63000.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# copper
copper = cutoff391.get(code='8b62f30ed586a5f23611ef196cc97b93')
new_exc = new_act.new_exchange(input=copper.key, amount=39960.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# insulation
insulation = cutoff391.get(code='1548660cbdd613eab4b00ddbd388c490')
new_exc = new_act.new_exchange(input=insulation.key, amount=6500.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# wood
wood = cutoff391.get(code='31d3bc7c09fc6efcd9c626cca48f6e47')
new_exc = new_act.new_exchange(input=wood.key, amount=15000.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# porcelain
porcelain = cutoff391.get(code='245eaef2fb637e428e0425deb295ec37')
new_exc = new_act.new_exchange(input=porcelain.key, amount=2650.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# construction steel
c_steel = cutoff391.get(code='d872e0d78319cb13e12b96de83e19dd7')
new_exc = new_act.new_exchange(input=c_steel.key, amount=53618.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# paint
paint = cutoff391.get(code='9291eac91d350e0a56be6f433a25ad3a')
new_exc = new_act.new_exchange(input=paint.key, amount=2200.0, unit="kilogram", type='technosphere')
new_exc.save()
new_act.save()
# electricity, medium
elec = cutoff391.get(code='0e4b280caeeba40d5644b8d28328b0de')
new_exc = new_act.new_exchange(input=elec.key, amount=750000.0, unit="kilowatt hour", type='technosphere')
new_exc.save()
new_act.save()
# heat
heat = cutoff391.get(code='e73087e282f26de5d3a9fec2edc19e61')
new_exc = new_act.new_exchange(input=heat.key, amount=1080000.0, unit="megajoule", type='technosphere')
new_exc.save()
new_act.save()
# output
new_exc = new_act.new_exchange(input=new_act.key, amount=1.0, unit="unit", type='production')
new_exc.save()
new_act.save()
transformer = new_db.get('TrafoStar_500')
return transformer
def manipulate_steel_activities(commissioning_year: int, recycled_share: float = None,
electricity_mix: Optional[Literal['Europe', 'Poland', 'Norway']] = None,
printed_warning: bool = False):
"""
This function creates a copy of the secondary and primary steel production activities in Ecoinvent
and adapts the location of its electricity and gas inputs. The adaptation is made according to the share of steel
production in Europe by country (between 2017 and 2021) reported in the European Steel in Figures Report 2022.
Then, a market activity with the recycled and primary steel inputs depending on the year of manufacturing is
created. If the turbine was manufactured before 2012, a mean value between data from 2012 and 2021 is taken.
Assumptions:
- Data refers to EU countries. Therefore, big producers outside the EU like Great Britain are excluded.
As a consequence, we assume that no steel is produced in GB for the turbine making.
- All countries produce the same share of recycled and non-recycled steel.
- The consumption amount of gas and electricity in the furnaces does not change between countries.
- The manufacture of the turbine takes place 1 year before the commissioning
:param: recycled_share -> needs to be inputted with a value from 0 to 1 (or None)
:param: electricity_mix -> ony accepts 'Europe', 'Poland' or 'Norway' (or None). For other values, 'Europe'
is applied by default.
"""
# test if the input variables are correct or not
if recycled_share is not None and not printed_warning:
if recycled_share > 1 or recycled_share < 0:
print('WARNING. The recycling share must be inputed with values from 0 to 1.')
sys.exit()
if electricity_mix is None:
print('WARNING. You did not select any electricity_mix. '
'The mean shares by country applied in the steel industry between 2017 and 2021 will be used')
elif electricity_mix not in ['Europe', 'Poland', 'Norway']:
print('WARNING. ' + str(electricity_mix) + ' is not an accepted input for the electricity_mix '
'variable. You can only use "Poland", '
'"Norway" or "Europe". A European electricity mix will '
'be applied by default!!')
if str(commissioning_year) not in list(
consts_wt.secondary_steel.keys()) and recycled_share is None and not printed_warning:
if commissioning_year > 2021:
print('WARNING. This wind turbine was commissioned after 2021 for which WindTrace '
'does not have data from the steel industry. '
'We recommend you to specify an expected recycling rate if you have an estimation. '
'Otherwise, 41.6% of recycled steel will be considered by default.')
print('Steel recycling share: 41.6%')
elif commissioning_year < 2012:
print('WARNING. This wind turbine was commissioned before 2012, for which WindTrace '
'does not have data from the steel industry. We recommend you to specify an expected recycling '
'rate if you have an estimation. Otherwise, 41.6% of recycled steel will be considered by '
'default.')
print('Steel recycling share: 41.6%')
if recycled_share is None and electricity_mix is None:
if not printed_warning:
print('WARNING. You did not select any electricity_mix. '
'The mean shares by country applied in the steel industry between 2017 and 2021 will be used')
print('Electricity mix: European mix provided by Eurofer')
act_name = "market for steel, low-alloyed, " + str(commissioning_year - 1)
code_name = "steel, " + str(commissioning_year - 1)
try:
steel_act = new_db.get(code=code_name)
except bd.errors.UnknownObject:
steel_act = None
else:
act_name = "market for steel, low-alloyed, defined " + str(recycled_share) + str(electricity_mix)
code_name = "steel, defined " + str(recycled_share) + str(electricity_mix)
try:
steel_act = new_db.get(code=code_name)
except bd.errors.UnknownObject:
steel_act = None
# check if we already created a steel market for that year and skip if we did
steel_act_check = 0
if steel_act is not None:
steel_act_check = len(steel_act.exchanges())
if steel_act_check == 0:
# find recycled steel production activity in Ecoinvent
recycled_ei = cutoff391.get(code='b3d48f2f5446c645c128b06b5de93f21',
name='steel production, electric, low-alloyed',
location='Europe without Switzerland and Austria')
# find primary steel production activity in Ecoinvent
primary_ei = cutoff391.get(code='89cb4e1a47b707fe43b99135b81fcaba',
name='steel production, converter, low-alloyed',
location='RER')
# Create a copy to manipulate them in the new_db database
recycled_act = recycled_ei.copy(database=consts_wt.NEW_DB_NAME)
primary_act = primary_ei.copy(database=consts_wt.NEW_DB_NAME)
acts = [recycled_act, primary_act]
# Manipulate both the primary and secondary activities in the same way
for act in acts:
# Calculate the total amount of gas and electricity inputs in the activity
elect_ex = [e for e in act.technosphere() if
e.input._data['name'] == 'market for electricity, medium voltage'
or e.input._data['name'] == 'market group for electricity, medium voltage']
gas_ex = [e for e in act.technosphere() if
e.input._data['name'] == 'market for natural gas, high pressure' or
e.input._data['name'] == 'market group for natural gas, high pressure']
total_elect_amount = sum([a['amount'] for a in elect_ex])
total_gas_amount = sum([a['amount'] for a in gas_ex])
# Delete current gas and electricity exchanges
for ex in elect_ex:
ex.delete()
for ex in gas_ex:
ex.delete()
# Add new exchanges with adjusted location. The total amount of gas and electricity inputs are maintained
# from the original Ecoinvent activity. The only main change is the share of each country.
if electricity_mix is None:
for country in consts_wt.steel_data_EU27.keys():
elect_act = cutoff391.get(code=consts_wt.steel_data_EU27[country]['elect_code'])
gas_act = cutoff391.get(code=consts_wt.steel_data_EU27[country]['gas_code'])
elect_amount = total_elect_amount * consts_wt.steel_data_EU27[country]['share'] / 100
gas_amount = total_gas_amount * consts_wt.steel_data_EU27[country]['share'] / 100
new_elect_ex = act.new_exchange(input=elect_act, amount=elect_amount, unit='kilowatt hour',
type='technosphere')
new_gas_ex = act.new_exchange(input=gas_act, amount=gas_amount, unit='cubic meter',
type='technosphere')
new_elect_ex.save()
new_gas_ex.save()
else:
# gas is always changed independently of the electricity mix chosen
for country in consts_wt.steel_data_EU27.keys():
gas_act = cutoff391.get(code=consts_wt.steel_data_EU27[country]['gas_code'])
gas_amount = total_gas_amount * consts_wt.steel_data_EU27[country]['share'] / 100
new_gas_ex = act.new_exchange(input=gas_act, amount=gas_amount, unit='cubic meter',
type='technosphere')
new_gas_ex.save()
if electricity_mix == 'Norway':
electricity_norway = [a for a in cutoff391 if
a._data['name'] == 'market for electricity, medium voltage' and a._data[
'location'] == 'NO'][0]
new_elect_ex = act.new_exchange(input=electricity_norway, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
elif electricity_mix == 'Poland':
electricity_poland = [a for a in cutoff391 if
a._data['name'] == 'market for electricity, medium voltage' and a._data[
'location'] == 'PL'][0]
new_elect_ex = act.new_exchange(input=electricity_poland, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
elif electricity_mix == 'Europe':
electricity_europe = [a for a in cutoff391 if
a._data['name'] == 'market group for electricity, medium voltage' and a._data[
'location'] == 'RER'][0]
new_elect_ex = act.new_exchange(input=electricity_europe, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
# if the electricity_mix variable inputed is not in the list ('Europe', 'Norway' or 'Poland'),
# Europe is chosen by default
else:
electricity_europe = [a for a in cutoff391 if
a._data['name'] == 'market group for electricity, medium voltage' and a._data[
'location'] == 'RER'][0]
new_elect_ex = act.new_exchange(input=electricity_europe, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
if electricity_mix is not None:
ch_act_name = 'market for steel, chromium steel 18/8' + str(electricity_mix)
ch_act = [a for a in new_db if a._data['name'] == ch_act_name]
if len(ch_act) == 0:
ch_steel_act_cutoff = [a for a in cutoff391 if a._data['name'] ==
'market for steel, chromium steel 18/8'][0]
ch_steel_act_newdb = ch_steel_act_cutoff.copy(database=consts_wt.NEW_DB_NAME)
ch_steel_act_newdb._data['name'] = 'market for steel, chromium steel 18/8' + str(electricity_mix)
ch_steel_act_newdb.save()
ch_steel_electric_input = [e.input for e in ch_steel_act_newdb.technosphere() if
'transport' not in e.input._data['name'] and e.input._data[
'location'] == 'RER'][0]
ch_steel_act = ch_steel_electric_input.copy(database=consts_wt.NEW_DB_NAME)
ch_steel_act._data['name'] = 'steel production, electric, chromium steel 18/8' + str(electricity_mix)
ch_steel_act.save()
# Calculate the total amount of electricity inputs in the activity
elect_ex = [e for e in ch_steel_act.technosphere() if
e.input._data['name'] == 'market for electricity, medium voltage'
or e.input._data['name'] == 'market group for electricity, medium voltage']
total_elect_amount = sum([a['amount'] for a in elect_ex])
for ex in elect_ex:
ex.delete()
if electricity_mix == 'Norway':
electricity_norway = [a for a in cutoff391 if
a._data['name'] == 'market for electricity, medium voltage' and a._data[
'location'] == 'NO'][0]
new_elect_ex = ch_steel_act.new_exchange(input=electricity_norway, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
elif electricity_mix == 'Poland':
electricity_poland = [a for a in cutoff391 if
a._data['name'] == 'market for electricity, medium voltage' and a._data[
'location'] == 'PL'][0]
new_elect_ex = ch_steel_act.new_exchange(input=electricity_poland, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
elif electricity_mix == 'Europe':
electricity_europe = [a for a in cutoff391 if
a._data['name'] == 'market group for electricity, medium voltage' and a._data[
'location'] == 'RER'][0]
new_elect_ex = ch_steel_act.new_exchange(input=electricity_europe, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
# if the electricity_mix variable inputted is not in the list ('Europe', 'Norway' or 'Poland'),
# Europe is chosen by default
else:
electricity_europe = [a for a in cutoff391 if
a._data['name'] == 'market group for electricity, medium voltage' and a._data[
'location'] == 'RER'][0]
new_elect_ex = ch_steel_act.new_exchange(input=electricity_europe, amount=total_elect_amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
original_inputs = [e for e in ch_steel_act_newdb.technosphere() if
'transport' not in e.input._data['name']]
for e in original_inputs:
name = e.input._data['name'] + str(electricity_mix)
new_db_act = [a for a in new_db if a._data['name'] == name][0]
amount = e.amount
new_elect_ex = ch_steel_act_newdb.new_exchange(input=new_db_act, amount=amount,
unit='kilowatt hour', type='technosphere')
new_elect_ex.save()
e.delete()
# Create an empty market activity in new_db
try:
steel_market = new_db.new_activity(name=act_name, code=code_name, unit='kilogram', location='RER')
steel_market.save()
except bd.errors.DuplicateNode:
steel_market = new_db.get(code=code_name)
# Add exchanges with the annual share of primary a secondary steel to the recently created activity
# Historic primary and secondary shares according to Eurofer data.
if recycled_share is None:
if str(commissioning_year - 1) in consts_wt.secondary_steel.keys():
# We assume that the turbine was manufactured a year before the commissioning date
secondary_amount = consts_wt.secondary_steel[str(commissioning_year - 1)]
primary_amount = 1 - secondary_amount
else:
secondary_amount = consts_wt.secondary_steel['other']
primary_amount = 1 - secondary_amount
# Add primary steel
primary_ex = steel_market.new_exchange(input=primary_act, amount=primary_amount, unit='kilogram',
type='technosphere')
primary_ex.save()
# Add secondary steel
secondary_ex = steel_market.new_exchange(input=recycled_act, amount=secondary_amount, unit='kilogram',
type='technosphere')
secondary_ex.save()
# Manually selected primary and secondary shares
else:
# Add primary steel
primary_share = 1 - recycled_share
primary_ex = steel_market.new_exchange(input=primary_act, amount=primary_share, unit='kilogram',
type='technosphere')
primary_ex.save()
# Add secondary steel
secondary_ex = steel_market.new_exchange(input=recycled_act, amount=recycled_share, unit='kilogram',
type='technosphere')
secondary_ex.save()
# Add production and save
production_exc = steel_market.new_exchange(input=steel_market.key, amount=1.0, unit="kilogram",
type='production')
production_exc.save()
steel_market.save()
ch_name = 'market for steel, chromium steel 18/8' + str(electricity_mix)
ch_steel_market = [a for a in new_db if a._data['name'] == ch_name]
return steel_market, ch_steel_market
elif steel_act_check == 3:
ch_name = 'market for steel, chromium steel 18/8' + str(electricity_mix)
ch_steel_market = [a for a in new_db if a._data['name'] == ch_name]
return steel_act, ch_steel_market
else:
print('Something went wrong during the creation of the steel market')
def lci_materials(park_name: str, park_power: float, number_of_turbines: int, park_location: str,
park_coordinates: tuple,
manufacturer: Literal['Vestas', 'Siemens Gamesa', 'Nordex', 'Enercon', 'LM Wind'],
rotor_diameter: float,
turbine_power: float, hub_height: float, commissioning_year: int,
recycled_share_steel: float = None,
lifetime: int = 20,
electricity_mix_steel: Optional[Literal['Norway', 'Europe', 'Poland']] = None,
generator_type: Literal['dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig'] = 'gb_dfig',
include_life_cycle_stages: bool = True,
comment: str = ''):
"""
It creates the activities 'park_name_single_turbine' (code: 'park_name_single_turbine'),
'park_name_cables' (code: 'park_name_intra_cables') and park (park_name) (code: park_name) in the
database 'new_db' in bw2. The park activity, contains as many turbines as there are in the park, the cable inputs
and the transformer activity scaled to the size of the park.
generator_type: it only accepts the models (strings) 'dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig'.
manufacturer: it only accepts 'Vestas', 'Siemens Gamesa', 'Nordex', 'Enercon', 'LM Wind'.
"""
# create the turbine activity and cables activity in bw2 including the production exchange
try:
turbine_act = new_db.new_activity(name=park_name + '_single_turbine', code=park_name + '_single_turbine',
location=park_location, unit='unit', comment=comment)
turbine_act.save()
new_exc = turbine_act.new_exchange(input=turbine_act.key, amount=1.0, unit="unit", type='production')
new_exc.save()
turbine_act.save()
except bd.errors.DuplicateNode:
print(
'An inventory for a park with the name ' + '"' + park_name + '"' + 'was already created before in the '
'database ')
print('"new_db". You may want to think about giving '
'another name to the wind park you are trying to '
'analyse. Otherwise, you may want to delete '
'the content of "new_db" by runing delete_new_db().')
print(
'WARNING: if you run delete_new_db() '
'ALL WIND PARKS STORED IN THAT DATABASE WILL '
'BE DELETED!')
sys.exit()
cables_act = new_db.new_activity(name=park_name + '_cables', code=park_name + '_intra_cables', unit='unit')
cables_act.save()
new_exc = cables_act.new_exchange(input=cables_act.key, amount=1.0, unit="unit", type='production')
new_exc.save()
cables_act.save()
# create an activity for each life cycle stage
if include_life_cycle_stages:
# 1. materials
materials_act = new_db.new_activity(name=park_name + '_materials', code=park_name + '_materials',
location=park_location, unit='unit')
materials_act.save()
new_exc = materials_act.new_exchange(input=materials_act.key, amount=1.0, unit="unit", type='production')
new_exc.save()
materials_act.save()
# 2. manufacturing
manufacturing_act = new_db.new_activity(name=park_name + '_manufacturing', code=park_name + '_manufacturing',
location=park_location, unit='unit')
manufacturing_act.save()
new_exc = manufacturing_act.new_exchange(input=manufacturing_act.key, amount=1.0, unit="unit",
type='production')
new_exc.save()
manufacturing_act.save()
# 3. transport
transport_act = new_db.new_activity(name=park_name + '_transport', code=park_name + '_transport',
location=park_location, unit='unit')
transport_act.save()
new_exc = transport_act.new_exchange(input=transport_act.key, amount=1.0, unit="unit",
type='production')
new_exc.save()
transport_act.save()
# 4. installation
installation_act = new_db.new_activity(name=park_name + '_installation', code=park_name + '_installation',
location=park_location, unit='unit')
installation_act.save()
new_exc = installation_act.new_exchange(input=installation_act.key, amount=1.0, unit="unit",
type='production')
new_exc.save()
installation_act.save()
# 5. operation & maintenance
om_act = new_db.new_activity(name=park_name + '_maintenance', code=park_name + '_maintenance',
location=park_location, unit='unit')
om_act.save()
new_exc = om_act.new_exchange(input=om_act.key, amount=1.0, unit="unit",
type='production')
new_exc.save()
om_act.save()
# 6. eol
eol_act = new_db.new_activity(name=park_name + '_eol', code=park_name + '_eol',
location=park_location, unit='unit')
eol_act.save()
new_exc = eol_act.new_exchange(input=eol_act.key, amount=1.0, unit="unit",
type='production')
new_exc.save()
eol_act.save()
materials_activity = materials_act
manufacturing_activity = manufacturing_act
else:
materials_activity = turbine_act
manufacturing_activity = turbine_act
# add materials from the turbine
if generator_type not in ['dd_eesg', 'dd_pmsg', 'gb_pmsg', 'gb_dfig']:
print(generator_type, 'is not an allowed value. We selected the default gb_dfig instead.')
generator_type = 'gb_dfig'
mass_materials, material_polyfits = materials_mass(generator_type, turbine_power, hub_height)
for material in mass_materials.keys():
if any(element in material for element in ['Praseodymium', 'Neodymium', 'Dysprosium', 'Terbium', 'Boron']):
inp = cutoff391.get(code=consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
ex.save()
materials_activity.save()
elif any(element in material for element in ['Low alloy steel', 'Low alloy steel_foundations']):
inp, ch = manipulate_steel_activities(commissioning_year=commissioning_year,
recycled_share=recycled_share_steel,
electricity_mix=electricity_mix_steel,
printed_warning=consts_wt.PRINTED_WARNING_STEEL)
consts_wt.PRINTED_WARNING_STEEL = True
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
# Uncertainty added as the standard deviation of the residuals
ex['uncertainty type'] = NormalUncertainty.id
ex['loc'] = mass_materials[material]
ex['scale'] = material_polyfits[material] * 1000
ex['minimum'] = 0
ex.save()
materials_activity.save()
elif (any(element in material for element in ['Chromium steel', 'Chromium steel_foundations'])
and electricity_mix_steel is not None):
steel, ch = manipulate_steel_activities(commissioning_year=commissioning_year,
recycled_share=recycled_share_steel,
electricity_mix=electricity_mix_steel,
printed_warning=consts_wt.PRINTED_WARNING_STEEL)
if ch:
inp = ch[0]
else:
inp = cutoff391.get(consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
# Uncertainty added as the standard deviation of the residuals
ex['uncertainty type'] = NormalUncertainty.id
ex['loc'] = mass_materials[material]
ex['scale'] = material_polyfits[material] * 1000
ex['minimum'] = 0
ex.save()
materials_activity.save()
elif material == 'Fiberglass':
inp = cutoff391.get(code=consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
# Mass includes 10% of waste produced in the manufacturing (Psomopoulos et al. 2019)
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material] * 1.1)
# Uncertainty added as the standard deviation of the residuals
ex['uncertainty type'] = NormalUncertainty.id
ex['loc'] = mass_materials[material]
ex['scale'] = material_polyfits[material] * 1000
ex['minimum'] = 0
ex.save()
materials_activity.save()
elif material == 'Concrete_foundations':
inp = cutoff391.get(code=consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
# Uncertainty added as the standard deviation of the residuals
ex['uncertainty type'] = NormalUncertainty.id
ex['loc'] = mass_materials[material]
ex['scale'] = material_polyfits[material] / 2.4
ex['minimum'] = 0
ex.save()
materials_activity.save()
else:
inp = cutoff391.get(code=consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
ex = materials_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
# Uncertainty added as the standard deviation of the residuals
ex['uncertainty type'] = NormalUncertainty.id
ex['loc'] = mass_materials[material]
ex['scale'] = material_polyfits[material] * 1000
ex['minimum'] = 0
ex.save()
materials_activity.save()
# add turbine and foundations material processing activities
processing_materials_list = ['Low alloy steel', 'Chromium steel', 'Cast iron', 'Aluminium', 'Copper',
'Low alloy steel_foundations', 'Chromium steel_foundations', 'Zinc']
for material in processing_materials_list:
if material == 'Low alloy steel':
# section bar rolling
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES['Steel_tower_rolling']['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
ex.save()
manufacturing_activity.save()
# welding
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES['Steel_tower_welding']['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=hub_height * 2)
ex.save()
manufacturing_activity.save()
elif material == 'Zinc':
# We need the tower area to be coated. This is the perimeter of the tower multiplied by the hub height.
# Perimeter of the tower: regression between the tower diameter and the power (data from Sacchi et al.)
tower_diameter = [5, 5.5, 5.75, 6.75, 7.75]
power = [3, 3.6, 4, 8, 10] # in MW
fit_diameter = np.polyfit(power, tower_diameter, 1)
f_fit_diameter = np.poly1d(fit_diameter)
outer_diameter = f_fit_diameter(turbine_power) # in m
perimeter = np.pi * outer_diameter
tower_surface_area = perimeter * hub_height
# create exchange
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES['Zinc coating']['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=tower_surface_area)
ex.save()
manufacturing_activity.save()
elif 'foundations' in material and 'alloy' not in material:
material_name = material[:material.index('_')]
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES[material_name]['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
ex.save()
manufacturing_activity.save()
elif 'foundations' in material and 'alloy' in material:
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES['Steel_tower_rolling']['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
ex.save()
manufacturing_activity.save()
else:
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES[material]['code'])
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=mass_materials[material])
ex.save()
manufacturing_activity.save()
# add electricity
power = [0.03, 0.15, 0.6, 0.8, 2] # in MW
electricity = [575, 3987, 17510, 17510, 67500] # in kWh
fit_electricity = np.polyfit(power, electricity, 1)
f_fit_diameter = np.poly1d(fit_electricity)
electricity_input = f_fit_diameter(turbine_power)
# find the closest manufacturer location
distance_dict = {}
if manufacturer is None or manufacturer not in ['Vestas', 'Siemens Gamesa', 'Nordex', 'Enercon', 'LM Wind']:
print(manufacturer, 'is not an allowed value. We chose LM Wind by default instead')
manufacturer = 'LM Wind'
for location_id in consts_wt.MANUFACTURER_LOC[manufacturer]:
location = consts_wt.MANUFACTURER_LOC[manufacturer][location_id]['location']
distance = geodesic(park_coordinates, location).kilometers
distance_dict[distance] = location_id
loc_id_min_distance = distance_dict[min(distance_dict.keys())]
closest_country = consts_wt.MANUFACTURER_LOC[manufacturer][loc_id_min_distance]['country']
inp = [a for a in cutoff391 if
'market for electricity, low voltage' in a._data['name'] and closest_country in a._data['location']][0]
ex = manufacturing_activity.new_exchange(input=inp, type='technosphere', amount=electricity_input)
ex.save()
manufacturing_activity.save()
# add materials from the cables
cable_mass = cabling_materials(turbine_power, rotor_diameter, number_of_turbines)
for material in cable_mass.keys():
inp = cutoff391.get(code=consts_wt.MATERIALS_EI391_ACTIVITY_CODES[material]['code'])
ex = cables_act.new_exchange(input=inp, type='technosphere', amount=cable_mass[material])
ex.save()
# add cable material processing activities
processing_materials_list = ['Aluminium_cables', 'Copper', 'PE', 'PVC']
for material in processing_materials_list:
if material == 'Aluminium_cables':
# copper wire drawing
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES['Copper']['code'])
ex = cables_act.new_exchange(input=inp, type='technosphere', amount=cable_mass['Aluminium'])
ex.save()
cables_act.save()
else:
inp = cutoff391.get(code=consts_wt.MATERIAL_PROCESSING_EI391_ACTIVITY_CODES[material]['code'])
ex = cables_act.new_exchange(input=inp, type='technosphere', amount=cable_mass[material])
ex.save()
cables_act.save()
# add exchanges (material and manufacturing stages) to the wind turbine activity, if needed
if include_life_cycle_stages:
materials_ex = turbine_act.new_exchange(input=materials_activity, type='technosphere', amount=1)
materials_ex.save()
manufacturing_ex = turbine_act.new_exchange(input=manufacturing_activity, type='technosphere', amount=1)
manufacturing_ex.save()
# create a new activity for the whole wind park
comment = 'Lifetime=' + str(lifetime) + ', Turbine power=' + str(turbine_power)
park_act = new_db.new_activity(name=park_name,
code=park_name + '_' + str(park_power), location=park_location, unit='unit',
comment=comment)
park_act.save()
# add turbines
turbine_ex = park_act.new_exchange(input=turbine_act, type='technosphere', amount=number_of_turbines)
turbine_ex.save()
# add cables
cables_ex = park_act.new_exchange(input=cables_act, type='technosphere', amount=1.0)
cables_ex.save()
# add materials from the transformer (downscaled from 500MVA to the park power)
transformer = mva500_transformer()
transformer_ex = park_act.new_exchange(input=transformer, type='technosphere', amount=park_power / 500)
transformer_ex.save()
# output
new_exc = park_act.new_exchange(input=park_act.key, amount=1.0, unit="unit", type='production')
new_exc.save()
park_act.save()
# convert single turbine mass_materials to total park mass and add cable_mass too
total_mass_turbines = {key: value * number_of_turbines for key, value in mass_materials.items()}
for key, value in cable_mass.items():
if key in total_mass_turbines:
total_mass_turbines[key] += value
else: