-
Notifications
You must be signed in to change notification settings - Fork 7
/
enduse_func.py
1594 lines (1356 loc) · 46.8 KB
/
enduse_func.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
"""Contains the `Enduse` Class. This is the most important class
where the change in enduse specific energy demand is simulated
depending on scenaric assumptions"""
import logging
import math
import numpy as np
from energy_demand.profiles import load_factors as lf
from energy_demand.technologies import diffusion_technologies
from energy_demand.technologies import fuel_service_switch
from energy_demand.technologies import tech_related
from energy_demand.basic import testing_functions
from energy_demand.basic import basic_functions
from energy_demand.basic import lookup_tables
class Enduse(object):
"""Enduse Class for all endueses in each SubModel
For every region and sector, a different instance
is generated. In this class, first the change in
energy demand is calculated on a annual temporal scale.
Calculations are performed in a cascade (e.g. first
reducing climate change induced savings, then substracting
further behavioral savings etc.). After annual calculations,
the demand is converted to hourly demand.
Also within this function, the fuel inputs are converted
to energy service (short: service) and converted back to
fuels (e.g. electricit).
Arguments
----------
submodel : str
Submodel
region : str
Region name
scenario_data : dict
Scenario data
assumptions : dict
Assumptions
load_profiles : dict
Load profile stock
base_yr : int
Base year
curr_yr : int
Current year
enduse : str
Enduse name
sector : str
Sector name
fuel : array
Yearly fuel data for different fueltypes
tech_stock : object
Technology stock of region
heating_factor_y : array
Distribution of fuel within year to days (yd) (directly correlates with HDD)
cooling_factor_y : array
Distribution of fuel within year to days (yd) (directly correlates with CDD)
fuel_tech_p_by : dict
Fuel tech assumtions in base year
sig_param_tech : dict
Sigmoid parameters
regional_lp_stock : object
Load profile stock
dw_stock : object,default=False
Dwelling stock
reg_scen_drivers : bool,default=None
Scenario drivers per enduse
flat_profile_crit : bool,default=False
Criteria of enduse has a flat shape or not
make_all_flat : bool
Crit to make everything flat
Note
----
- Load profiles are assigned independently of the fueltype, i.e.
the same profiles are assumed to hold true across different fueltypes
- ``self.fuel_y`` is always overwritten
in the cascade of calculations
Warning
-------
Not all enduses have technologies assigned. Load peaks are derived
from techstock in case technologies are defined. Otherwise enduse load
profiles are used.
"""
def __init__(
self,
submodel,
region,
scenario_data,
assumptions,
load_profiles,
base_yr,
curr_yr,
enduse,
sector,
fuel,
tech_stock,
heating_factor_y,
cooling_factor_y,
fuel_tech_p_by,
sig_param_tech,
criterias,
strategy_vars,
non_regional_strategy_vars,
fueltypes_nr,
fueltypes,
dw_stock=False,
reg_scen_drivers=None,
flat_profile_crit=False,
make_all_flat=False
):
"""Enduse class constructor
"""
self.region = region
self.enduse = enduse
self.fuel_y = fuel
self.flat_profile_crit = flat_profile_crit
self.techs_fuel_yh = None
#If enduse has no fuel return empty shapes
if np.sum(fuel) == 0:
self.flat_profile_crit = True
self.fuel_y = fuel
self.fuel_yh = 0
self.enduse_techs = []
else:
#print("------INFO {} {} {}".format(self.enduse, region, curr_yr))
# Get technologies of enduse
self.enduse_techs = get_enduse_techs(fuel_tech_p_by)
# -----------------------------
# Cascade of annual calculations
# -----------------------------
_fuel_new_y = apply_climate_change(
enduse,
self.fuel_y,
cooling_factor_y,
heating_factor_y,
assumptions.enduse_space_heating,
assumptions.ss_enduse_space_cooling)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train B0: " + str(np.sum(self.fuel_y)))
_fuel_new_y = apply_smart_metering(
enduse,
self.fuel_y,
assumptions.smart_meter_assump,
strategy_vars,
curr_yr)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train C0: " + str(np.sum(self.fuel_y)))
_fuel_new_y = apply_specific_change(
enduse,
self.fuel_y,
strategy_vars,
curr_yr)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train D0: " + str(np.sum(self.fuel_y)))
_fuel_new_y = apply_scenario_drivers(
enduse,
sector,
self.fuel_y,
dw_stock,
region,
scenario_data['gva_industry_service'],
scenario_data['gva_per_head'],
scenario_data['population'],
reg_scen_drivers,
base_yr,
curr_yr)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train E0: " + str(np.sum(self.fuel_y)))
# Apply cooling scenario variable
_fuel_new_y = apply_cooling(
enduse,
self.fuel_y,
strategy_vars,
assumptions.cooled_ss_floorarea_by,
curr_yr)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train E1: " + str(np.sum(self.fuel_y)))
# Industry related change
_fuel_new_y = industry_enduse_changes(
enduse,
sector,
base_yr,
curr_yr,
strategy_vars,
self.fuel_y,
assumptions)
self.fuel_y = _fuel_new_y
#logging.debug("... Fuel train E2: " + str(np.sum(self.fuel_y)))
# ----------------------------------
# Hourly Disaggregation
# ----------------------------------
if self.enduse_techs == []:
"""If no technologies are defined for an enduse, the load profiles
are read from dummy shape, which show the load profiles of the whole enduse.
No switches can be implemented and only overall change of enduse.
"""
if flat_profile_crit:
pass
else:
fuel_yh = assign_lp_no_techs(
enduse,
sector,
load_profiles,
self.fuel_y,
make_all_flat=make_all_flat)
# Demand management for non-technology enduse
self.fuel_yh = demand_management(
enduse,
base_yr,
curr_yr,
strategy_vars,
fuel_yh,
mode_constrained=False,
make_all_flat=make_all_flat)
else:
"""If technologies are defined for an enduse
"""
# ----
# Get enduse specific configurations
# ----
mode_constrained = get_enduse_configuration(
criterias['mode_constrained'],
enduse,
assumptions.enduse_space_heating)
# ------------------------------------
# Calculate regional energy service
# ------------------------------------
s_tot_y_cy, s_tech_y_by = fuel_to_service(
enduse,
self.fuel_y,
fuel_tech_p_by,
tech_stock,
fueltypes,
mode_constrained)
#logging.debug("Service A " + str(np.sum(s_tot_y_cy)))
# ------------------------------------
# Reduction of service because of heat recovery
# ------------------------------------
s_tot_y_cy, s_tech_y_cy = apply_heat_recovery(
enduse,
strategy_vars,
s_tot_y_cy,
s_tech_y_by,
curr_yr)
#logging.debug("Service B " + str(np.sum(s_tot_y_cy)))
# ------------------------------------
# Reduction of service because of improvement in air leakeage
# ------------------------------------
s_tot_y_cy, s_tech_y_cy = apply_air_leakage(
enduse,
strategy_vars,
s_tot_y_cy,
s_tech_y_cy,
curr_yr)
# --------------------------------
# Switches
# Calculate services per technology for cy based on fitted parameters
# --------------------------------
s_tech_y_cy = calc_service_switch(
enduse,
s_tech_y_cy,
self.enduse_techs,
sig_param_tech,
curr_yr,
base_yr,
sector,
assumptions.crit_switch_happening)
#logging.debug("Service D " + str(np.sum(s_tot_y_cy)))
# -------------------------------------------
# Convert annual service to fuel per fueltype
# -------------------------------------------
self.fuel_y, fuel_tech_y = service_to_fuel(
enduse,
s_tech_y_cy,
tech_stock,
fueltypes_nr,
fueltypes,
mode_constrained)
#logging.debug("... Fuel train H0: " + str(np.sum(self.fuel_y)))
# Delete all technologies with no fuel assigned
for tech, fuel_tech in fuel_tech_y.items():
if np.sum(fuel_tech) == 0:
self.enduse_techs.remove(tech)
# ------------------------------------------
# Assign load profiles
# ------------------------------------------
if self.flat_profile_crit:
pass
else:
fuel_yh = calc_fuel_tech_yh(
enduse,
sector,
self.enduse_techs,
fuel_tech_y,
load_profiles,
fueltypes_nr,
fueltypes,
mode_constrained)
# --------------------------------------
# Demand Management
# --------------------------------------
if mode_constrained:
self.techs_fuel_yh = {}
for tech in fuel_yh:
self.techs_fuel_yh[tech] = demand_management(
enduse,
base_yr,
curr_yr,
strategy_vars,
fuel_yh[tech],
mode_constrained=True,
make_all_flat=make_all_flat)
self.fuel_yh = None
else:
self.fuel_yh = demand_management(
enduse,
base_yr,
curr_yr,
strategy_vars,
fuel_yh,
mode_constrained=False,
make_all_flat=make_all_flat)
def demand_management(
enduse,
base_yr,
curr_yr,
strategy_vars,
fuel_yh,
mode_constrained,
make_all_flat=False
):
"""Demand management. This function shifts peak per of this enduse
depending on peak shifting factors. So far only inter day load shifting
Arguments
----------
enduse : str
Enduse
base_yr : int
Base year
curr_yr : int
Current year
strategy_vars : dict
Assumptions of strategy variables
fuel_yh : array
Fuel per hours
enduse_techs : list
Enduse specfic technologies
sector : str
Sector
tech_stock : obj
Technology stock
load_profiles : obj
Load profiles
mode_constrained : bool
Running mode
If mode_constrained, always only one technology imported
make_all_flat : bool
If true, all shapes are flat
Returns
-------
fuel_yh : array
Fuel of yh
"""
key_name = 'demand_management_improvement__{}'.format(enduse)
if key_name in strategy_vars.keys():
# Get assumed load shift
if strategy_vars[key_name][curr_yr] == 0:
pass # no load management
else:
# load management
# Calculate average for every day
if mode_constrained:
average_fuel_yd = np.average(fuel_yh, axis=1)
else:
average_fuel_yd = np.average(fuel_yh, axis=2)
# Calculate load factors (only inter_day load shifting as for now)
loadfactor_yd_cy = lf.calc_lf_d(
fuel_yh, average_fuel_yd, mode_constrained)
# Load factor improvement parameter in current year
param_lf_improved_cy = strategy_vars[key_name][curr_yr]
# Calculate current year load factors
lf_improved_cy = calc_lf_improvement(
param_lf_improved_cy,
loadfactor_yd_cy,)
fuel_yh = lf.peak_shaving_max_min(
lf_improved_cy, average_fuel_yd, fuel_yh, mode_constrained)
# -------------------------------------------------
# Convert all load profiles into flat load profiles
# -------------------------------------------------
if make_all_flat:
if mode_constrained:
sum_fueltypes_days = np.sum(fuel_yh) #sum over all hours
average_fueltype = sum_fueltypes_days / 8760 # Average
fuel_yh_empty = np.ones((fuel_yh.shape))
fuel_yh = fuel_yh_empty * average_fueltype
else:
sum_fueltypes_days_h = np.sum(fuel_yh, 2) #sum over all hours
sum_fueltypes_days = np.sum(sum_fueltypes_days_h, 1) #sum over all days
average_fueltype = sum_fueltypes_days / 8760 #Average per fueltype
fuel_yh_empty = np.ones((fuel_yh.shape))
fuel_yh = fuel_yh_empty * average_fueltype[:, np.newaxis, np.newaxis]
return fuel_yh
def calc_lf_improvement(
param_lf_improved_cy,
loadfactor_yd_cy,
):
"""Calculate load factor improvement
Arguments
---------
lf_improvement_ey : dict
Load factor improvement until end year
loadfactor_yd_cy : float
Yd Load factor of current year
Returns
-------
lf_improved_cy : str
Improved load factor of current year
peak_shift_crit : bool
True: Peak is shifted, False: Peak isn't shifed
"""
# Add load factor improvement to current year load factor
lf_improved_cy = loadfactor_yd_cy + param_lf_improved_cy
# Where load factor larger than zero, set to 1
lf_improved_cy[lf_improved_cy > 1] = 1
return lf_improved_cy
def assign_lp_no_techs(
enduse,
sector,
load_profiles,
fuel_y,
make_all_flat
):
"""Assign load profiles for an enduse which has no technologies defined
Arguments
---------
enduse : str
Enduse
sector : str
Enduse
load_profiles : obj
Load profiles
fuel_y : array
Fuels
Returns
-------
fuel_yh : array (fueltype, 365, 24)
Fuel yh
"""
# Load profile for all fueltypes
load_profile = load_profiles.get_lp(
enduse, sector, 'placeholder_tech', 'shape_yh')
fuel_yh = load_profile[:np.newaxis] * fuel_y[:, np.newaxis, np.newaxis]
# Convert all load profiles into flat load profiles
if make_all_flat:
sum_fueltypes_days_h = np.sum(fuel_yh, 2) #sum over all hours
sum_fueltypes_days = np.sum(sum_fueltypes_days_h, 1) #sum over all days
average_fueltype = sum_fueltypes_days / 8760 #Average per fueltype
fuel_yh_empty = np.ones((fuel_yh.shape))
fuel_yh = fuel_yh_empty * average_fueltype[:, np.newaxis, np.newaxis]
return fuel_yh
def get_running_mode(enduse, mode_constrained, enduse_space_heating):
"""Checks which mode needs to be run for an enduse.
Arguments
-----------
mode_constrained : bool
Criteria of running mode
enduse_space_heating : dict
All heating enduses across all models
Returns
-------
bool : bool
The return value
Note
----
If 'crit_mode' == True, then overall heat is provided to
the supply model not specified for technologies. Otherwise,
heat demand is supplied per technology
"""
if mode_constrained:
return True
elif not mode_constrained and enduse in enduse_space_heating:
return False
elif not mode_constrained and enduse not in enduse_space_heating:
# All other not constrained enduses where technologies are defined
# are run in 'constrained' mode (e.g. lighting)
return True
def get_enduse_configuration(
mode_constrained,
enduse,
enduse_space_heating,
):
"""Get enduse specific configuration
Arguments
---------
mode_constrained : bool
Constrained mode criteria
enduse : str
Enduse
enduse_space_heating : list
All endueses classified as space heating
base_yr, curr_yr : int
Base, current, year
"""
mode_constrained = get_running_mode(
enduse,
mode_constrained,
enduse_space_heating)
return mode_constrained
def get_peak_day_all_fueltypes(fuel_yh):
"""Iterate yh and get day containing the hour
with the largest demand (across all fueltypes).
Arguments
---------
fuel_yh : array (fueltype, 365, 24)
Fuel for every yh (fueltypes, yh)
Return
------
peak_day_nr : int
Day with most fuel or service across all fueltypes
"""
fuel_8760 = fuel_yh.reshape(fuel_yh.shape[0], 8760)
# Sum all fuel across all fueltypes for every hour in a year
all_fueltypes_tot_h = np.sum(fuel_8760, axis=0)
if np.sum(all_fueltypes_tot_h) == 0:
logging.warning("No peak can be found because no fuel assigned")
return 0
else:
# Get day with maximum hour
peak_day_nr = basic_functions.round_down(np.argmax(all_fueltypes_tot_h) / 24, 1)
return int(peak_day_nr)
def get_peak_day(fuel_yh):
"""Iterate an array with entries and get
entry nr with hightest value
Arguments
---------
fuel_yh : array (hours)
Fuel for every day
Return
------
peak_day_nr : int
Day with most fuel or service
"""
if np.sum(fuel_yh) == 0:
#logging.info("No peak can be found because no fuel assigned")
# Return first entry of element (which is zero)
return 0
else:
# Sum fuel within every hour for every day and get day with maximum fuel
peak_day_nr = np.argmax(fuel_yh)
return int(peak_day_nr)
def get_peak_day_single_fueltype(fuel_yh):
"""Iterate yh and get day with highes fuel for a single fueltype
The day with most fuel is considered to
be the peak day. Over the simulation period,
the peak day may change date in a year.
Arguments
---------
fuel_yh : array (365, 24) or array (8760)
Fuel for every yh (yh)
Return
------
peak_day_nr : int
Day with most fuel or service
peak_h : float
Peak hour value
"""
fuel_yh_8760 = fuel_yh.reshape(8760)
if np.sum(fuel_yh_8760) == 0:
#logging.info("No peak can be found because no fuel assigned")
# Return first entry of element (which is zero)
return 0, 0
else:
# Sum fuel within every hour for every day and get day with maximum fuel
peak_day_nr = basic_functions.round_down(np.argmax(fuel_yh_8760) / 24, 1)
peak_h = np.max(fuel_yh_8760)
return int(peak_day_nr), peak_h
def get_enduse_techs(fuel_tech_p_by):
"""Get all defined technologies of an enduse
Arguments
----------
fuel_tech_p_by : dict
Percentage of fuel per enduse per technology
Return
------
enduse_techs : list
All technologies
Note
----
All technologies are read out, including those which
are potentially defined in fuel or service switches.
If for an enduse a dummy technology is defined,
the technologies of an enduse are set to an empty
list.
Warning
-------
For every enduse technologes must either be defined
for no fueltype or for all fueltypes
"""
enduse_techs = []
for tech_fueltype in fuel_tech_p_by.values():
if 'placeholder_tech' in tech_fueltype.keys():
return []
else:
enduse_techs += tech_fueltype.keys()
return list(set(enduse_techs))
def calc_fuel_tech_yh(
enduse,
sector,
enduse_techs,
fuel_tech_y,
load_profiles,
fueltypes_nr,
fueltypes,
mode_constrained
):
"""Iterate fuels for each technology and assign shape yd and yh shape
Arguments
----------
fuel_tech_y : dict
Fuel per technology in enduse
tech_stock : object
Technologies
load_profiles : object
Load profiles
fueltypes_nr : dict
Nr of fueltypes
fueltypes : dict
Fueltypes lookup
mode_constrained : bool
Mode criteria
Return
------
fuels_yh : array
Fueltype storing hourly fuel for every fueltype (fueltype, 365, 24)
"""
if mode_constrained:
fuels_yh = {}
for tech in enduse_techs:
load_profile = load_profiles.get_lp(
enduse, sector, tech, 'shape_yh')
fuels_yh[tech] = fuel_tech_y[tech] * load_profile
else:
# --
# Unconstrained mode, i.e. not technolog specific.
# Store according to fueltype and heat
# --
fuels_yh = np.zeros((fueltypes_nr, 365, 24), dtype="float")
for tech in enduse_techs:
load_profile = load_profiles.get_lp(
enduse, sector, tech, 'shape_yh')
# If no fuel for this tech and not defined in enduse
fuel_tech_yh = fuel_tech_y[tech] * load_profile
fuels_yh[fueltypes['heat']] += fuel_tech_yh
# ----------
# Testing if negative value
# ----------
if testing_functions.test_if_minus_value_in_array(fuels_yh):
raise Exception("Error: Negative entry")
return fuels_yh
def service_to_fuel(
enduse,
service_tech,
tech_stock,
fueltypes_nr,
fueltypes,
mode_constrained
):
"""Convert yearly energy service to yearly fuel demand.
For every technology the service is taken and converted
to fuel based on efficiency of current year
Arguments
------
enduse : str
Enduse
service_tech : dict
Service per fueltype and technology
tech_stock : object
Technological stock
fueltypes_nr : int
Number of fueltypes
fueltypes : dict
Fueltypes
mode_constrained : bool
Mode running criteria
Returns
-------
fuel_y : array
Fuel per fueltype
fuel_per_tech : dict
Fuel per technology
Note
-----
- Fuel = Energy service / efficiency
"""
fuel_tech_y = {}
fuel_y = np.zeros((fueltypes_nr), dtype="float")
if mode_constrained:
for tech, service in service_tech.items():
tech_eff = tech_stock.get_tech_attr(
enduse, tech, 'eff_cy')
fueltype_int = tech_stock.get_tech_attr(
enduse, tech, 'fueltype_int')
# Convert to fuel
fuel_tech = service / tech_eff
# Add fuel
fuel_tech_y[tech] = fuel_tech
fuel_y[fueltype_int] += fuel_tech
#logging.debug("S --> F: tech: {} eff: {} fuel: {} fuel {}".format(tech, tech_eff, fuel_y[fueltype_int], fuel_tech))
else:
for tech, fuel_tech in service_tech.items():
fuel_y[fueltypes['heat']] += fuel_tech
fuel_tech_y[tech] = fuel_tech
return fuel_y, fuel_tech_y
def fuel_to_service(
enduse,
fuel_y,
fuel_tech_p_by,
tech_stock,
fueltypes,
mode_constrained
):
"""Converts fuel to energy service. Calculate energy service
of each technology based on assumptions about base year fuel
shares of an enduse (`fuel_tech_p_by`).
Arguments
----------
enduse : str
Enduse
fuel_y : array
Fuel per fueltype
fuel_tech_p_by : dict
Fuel composition of base year for every fueltype for each
enduse (assumtions for national scale)
tech_stock : object
Technology stock of region
fueltypes : dict
Fueltype look-up
mode_constrained : bool
Criteria about mode
Return
------
tot_s_y : array
Total annual energy service per technology
s_tech_y : dict
Total annual energy service per technology
Note
-----
- Efficiency changes of technologis are considered.
- Energy service = fuel * efficiency
- This function can be run in two modes, depending on `mode_constrained`
- The base year efficiency is taken because the actual service can
only be calculated with base year.
Efficiencies are only considered if converting back to fuel
The 'self.fuel_y' is taken because the actual
service was reduced e.g. due to smart meters or temperatur changes
"""
s_tech_y = {}
s_tot_y = 0
# Calculate share of service
for fueltype_int, tech_list in fuel_tech_p_by.items():
# Get technologies to iterate
if tech_list == {} and fuel_y[fueltype_int] == 0: # No technology or fuel defined
techs_with_fuel = {}
elif tech_list == {} and fuel_y[fueltype_int] > 0: # Fuel defined but no technologies
fueltype_str = tech_related.get_fueltype_str(fueltypes, fueltype_int)
placeholder_tech = 'placeholder_tech__{}'.format(fueltype_str)
techs_with_fuel = {placeholder_tech: 1.0}
else:
techs_with_fuel = tech_list
for tech, fuel_share in techs_with_fuel.items():
if mode_constrained:
"""Constrained version
"""
tech_eff = tech_stock.get_tech_attr(enduse, tech, 'eff_by')
# Get fuel share and convert fuel to service per technology
s_tech = fuel_y[fueltype_int] * fuel_share * tech_eff
s_tech_y[tech] = s_tech
# Sum total yearly service
s_tot_y += s_tech #(y)
#logging.debug("F --> S: tech: {} eff: {} fuel: {} service {}".format(tech, tech_eff, fuel_y[fueltype_int], s_tech))
else:
"""Unconstrained version
efficiencies are not considered, because not technology
specific service calculation
"""
# Calculate fuel share
fuel_tech = fuel_y[fueltype_int] * fuel_share
s_tech_y[tech] = fuel_tech
# Sum total yearly service
s_tot_y += fuel_tech
return s_tot_y, s_tech_y
def apply_heat_recovery(
enduse,
strategy_vars,
service,
service_techs,
curr_yr
):
"""Reduce heating demand according to assumption on heat reuse
Arguments
----------
enduse : str
Enduse
strategy_vars : dict
Strategy variables
service : dict or array
Service of current year
crit_dict : str
Criteria to run function differently
curr_yr : int
Current year
Returns
-------
service_reduced : dict or array
Reduced service after assumption on reuse
Note
----
A standard sigmoid diffusion is assumed from base year to end year
"""
key_name = "heat_recoved__{}".format(enduse)
if key_name in strategy_vars.keys():
# Fraction of heat recovered in current year
heat_recovered_p_cy = strategy_vars[key_name][curr_yr]
if heat_recovered_p_cy == 0:
return service, service_techs
else:
# Apply to technologies each stored in dictionary
service_reduced_techs = {}
for tech, service_tech in service_techs.items():
service_reduced_techs[tech] = service_tech * (1.0 - heat_recovered_p_cy)
# Apply to array
service_reduced = service * (1.0 - heat_recovered_p_cy)
return service_reduced, service_reduced_techs
else:
# no recycling defined
return service, service_techs
def apply_air_leakage(
enduse,
strategy_vars,
service,
service_techs,
curr_yr
):
"""Reduce heating demand according to assumption on
improvements in air leaking
Arguments
----------
enduse : str
Enduse
strategy_vars : dict
Strategy variables
service : dict or array
Service of current year
crit_dict : str
Criteria to run function differently
curr_yr : int
Current year
Returns
-------
service_reduced : dict or array
Service after assumptions on air leaking improvements
Note
----
A standard sigmoid diffusion is assumed from base year to end year
"""
key_name = "air_leakage__{}".format(enduse)
if key_name in strategy_vars.keys():
# Fraction of heat recovered in current year
air_leakage_improvement_cy = strategy_vars[key_name][curr_yr]
if air_leakage_improvement_cy == 0:
return service, service_techs
else:
air_leakage_by = 1