Browse Source

Started work on korea 2023 inventory

Johannes 11 months ago
parent
commit
e85becfe3b

+ 481 - 0
UNFCCC_GHG_data/UNFCCC_reader/Republic_of_Korea/config_KOR_INV2023.py

@@ -0,0 +1,481 @@
+original_names = [
+    '총배출량',
+    '순배출량',
+    '에너지',
+    'A. 연료연소',
+    '1. 에너지산업',
+    'a. 공공전기 및 열 생산',
+    'b. 석유정제',
+    'c. 고체연료 제조 및 기타 에너지 산업',
+    '2. 제조업 및 건설업',
+    'a. 철강',
+    'b. 비철금속',
+    'c. 화학',
+    'd. 펄프, 제지 및 인쇄',
+    'e. 식음료품 가공 및 담배 제조',
+    'f. 기타',
+    '  1. 비금속',
+    '  2. 조립금속',
+    '  3. 나무 및 목재',
+    '  4. 건설',
+    '  5. 섬유 및 가죽',
+    '  6. 기타제조',
+    '3. 수송',
+    'a. 민간항공',
+    'b. 도로수송',
+    'c. 철도',
+    'd. 해운',
+    'e. 기타수송',
+    '4. 기타',
+    'a. 상업/공공',
+    'b. 가정',
+    'c. 농업/임업/어업',
+    '5. 미분류',
+    'B. 탈루',
+    '1. 고체연료',
+    '2.  석유 및 천연가스',
+    'a.  석유',
+    'b. 천연가스',
+    '산업공정',
+    'A. 광물산업',
+    '1. 시멘트생산',
+    '2. 석회생산',
+    '3. 석회석 및 백운석 소비',
+    '4. 소다회 생산 및 소비',
+    '5. 아스팔트 루핑',
+    '6. 아스팔트 도로포장',
+    'B. 화학산업',
+    'C. 금속산업',
+    '1. 철강생산',
+    '2. 합금철 생산',
+    '3. 알루미늄 생산',
+    '4. 마그네슘 생산의 SF6 소비',
+    'D. 기타산업',
+    'E. 할로카본 및 육불화황 생산',
+    '1. 부산물 배출',
+    '2. 탈루 배출',
+    'F. 할로카본 및 육불화황 소비',
+    '1.  냉장 및 냉방',
+    '2.  발포제',
+    '3.  소화기',
+    '4.  에어로졸',
+    '5.  용매',
+    '6.  기타 용도의 ODS 대체물질 사용',
+    '7.  반도체 제조',
+    '8.  중전기기',
+    '9.  기타(잠재배출량)',
+    '농업',
+    'A.  장내발효',
+    'A.1. 소',
+    'A.2. 물소',
+    'A.3. 양(면양)',
+    'A.4. 양(산양)',
+    'A.5. 낙타 및 라마',
+    'A.6. 말',
+    'A.7. 노새 및 당나귀',
+    'A.8. 돼지',
+    'A.9. 가금류',
+    'A.10. 기타 가축(사슴)',
+    'B.  가축분뇨처리',
+    'B.1. 소',
+    'B.2. 물소',
+    'B.3. 양(면양)',
+    'B.4. 양(산양)',
+    'B.5. 낙타 및 라마',
+    'B.6. 말',
+    'B.7. 노새 및 당나귀',
+    'B.8. 돼지',
+    'B.9. 가금류',
+    'B.10. 기타 가축(사슴)',
+    'B1. 소',
+    'B2. 물소',
+    'B3. 양(면양)',
+    'B4. 양(산양)',
+    'B5. 낙타 및 라마',
+    'B6. 말',
+    'B7. 노새 및 당나귀',
+    'B8. 돼지',
+    'B9. 가금류',
+    'B10. 기타 가축(사슴)',
+    'C.  벼재배',
+    '1. 관개',
+    '2. 천수답',
+    'D. 농경지토양',
+    '1. 직접배출',
+    '2. 목장, 방목구역, 분료(거름)',
+    '3. 간접배출',
+    'E. 사바나 소각',
+    'F. 작물잔사소각',
+    '1. 곡류',
+    '2. 두류(콩)',
+    '3. 근채류',
+    '4. 사탕수수',
+    '5. 기타',
+    'LULUCF',
+    'A. 산림지',
+    '1. 산림지로 유지된 산림지',
+    '2. 타토지에서 전용된 산림지',
+    '3. 산림지에서 질소 시비로 인한 N2O 배출',
+    '4. 산림지에서 배수로 인한 Non-CO2 배출',
+    '5. 산림지에서 바이오매스 연소에 의한 배출',
+    'B. 농경지',
+    '1. 농경지로 유지된 농경지',
+    '2. 타토지에서 전용된 농경지',
+    '3. 농경지로의 전용에 따른 N2O 배출',
+    '4. 농경지에서 농업용 석회시용으로 인한 CO2 배출',
+    '5. 농경지에서 바이오매스 연소에 의한 배출',
+    'C. 초지',
+    '1. 초지로 유지된 초지',
+    '2. 타토지에서 전용된 초지',
+    '3. 초지에서 농업용 석회시용으로 인한 CO2 배출',
+    '4. 초지에서 바이오매스 연소에 의한 배출',
+    'D. 습지',
+    '1. 습지로 유지된 습지',
+    '2. 타토지에서 전용된 습지',
+    '3. 습지에서 배수로 인한 Non-CO2 배출',
+    '4. 습지에서 바이오매스 연소에 의한 배출',
+    'E. 정주지',
+    'F. 기타토지',
+    '폐기물',
+    'A. 폐기물매립',
+    '1. 관리형 매립',
+    '2. 비관리형 매립',
+    'B. 하폐수처리',
+    '1. 폐수처리',
+    '2. 하수처리',
+    'C. 폐기물소각',
+    'D. 기타',
+    '별도항목(Memo Item)',
+    '분야·부문/연도',
+    'C. 국제벙커링 및 다국적 작전',
+    '1. 벙커링',
+    'a. 국제 항공',
+    'b. 국제 해운',
+    '2. 다국적 작전',
+    '* 참고 : NO = 배출활동 및 공정이 없는 경우, NE = 산정하지 아니하는 경우, NA = 자연적, 이론적으로 발생하지 않는 활동 및 공정의 경우, IE = 다른 항목에 포함하여 보고하는 경우, C = 기밀정보인 경우',
+    '3. 타토지로 전용된 농경지', # start of new codes in 2021 inventory
+    '4. 농경지로의 전용에 따른 N2O 배출',
+    '5. 농경지에서 농업용 석회시용으로 인한 CO2 배출',
+    '6. 농경지에서 바이오매스 연소에 의한 배출',
+    'G. 기타',
+]
+translations = [
+    ['Total emissions', 'M.0.EL'],
+    ['Net emissions', '0'],
+    ['energy', '1'],
+    ['A. Fuel combustion', '1.A'],
+    ['1. Energy industry', '1.A.1'],
+    ['a. Public electricity and heat production', '1.A.1.a'],
+    ['b. Oil refining', '1.A.1.b'],
+    ['c. Solid fuel manufacturing and other energy industries', '1.A.1.c'],
+    ['2. Manufacturing and construction', '1.A.2'],
+    ['a. steel', '1.A.2.a'],
+    ['b. Non-ferrous metal', '1.A.2.b'],
+    ['c. chemistry', '1.A.2.c'],
+    ['d. Pulp, paper and printing', '1.A.2.d'],
+    ['e. Food and beverage processing and tobacco manufacturing', '1.A.2.e'],
+    ['f. Etc', '1.A.2.f'],
+    ['  1. Non-metal', '1.A.2.f.1'],
+    ['  2. Assembly metal', '1.A.2.f.2'],
+    ['  3. Wood and timber', '1.A.2.f.3'],
+    ['  4. Construction', '1.A.2.f.4'],
+    ['  5. Textile and leather', '1.A.2.f.5'],
+    ['  6. Other manufacturing', '1.A.2.f.6'],
+    ['3. Transportation', '1.A.3'],
+    ['a. Civil aviation', '1.A.3.a.2'],
+    ['b. Road transport', '1.A.3.b'],
+    ['c. railroad', '1.A.3.c'],
+    ['d. shipping', '1.A.3.d.2'],
+    ['e. Other transport', '1.A.3.e'],
+    ['4. Other', '1.A.4'],
+    ['a. Commercial/Public', '1.A.4.a'],
+    ['b. home', '1.A.4.b'],
+    ['c. Agriculture/Forestry/Fishing', '1.A.4.c'],
+    ['5. Uncategorized', '1.A.5'],
+    ['B. Talu', '1.B'],
+    ['1. Solid fuel', '1.B.1'],
+    ['2. Oil and natural gas', '1.B.2'],
+    ['a. oil', '1.B.2.a'],
+    ['b. Natural gas', '1.B.2.b'],
+    ['Industrial process', '2'],
+    ['A. Mineral industry', '2.A'],
+    ['1. Cement production', '2.A.1'],
+    ['2. Lime production', '2.A.2'],
+    ['3. Limestone and Dolomite Consumption', '2.A.3'],
+    ['4. Soda ash production and consumption', '2.A.4'],
+    ['5. Asphalt roofing', '2.A.5'],
+    ['6. Asphalt road pavement', '2.A.6'],
+    ['B. Chemical industry', '2.B'],
+    ['C. Metal Industry', '2.C'],
+    ['1. Steel production', '2.C.1'],
+    ['2. Ferroalloy production', '2.C.2'],
+    ['3. Aluminum production', '2.C.3'],
+    ['4. SF6 consumption in magnesium production', '2.C.4'],
+    ['D. Other industries', '2.D'],
+    ['E. Production of halocarbons and sulfur hexafluoride', '2.E'],
+    ['1. Emission of by-products', '2.E.1'],
+    ['2. Fugitive discharge', '2.E.2'],
+    ['F. Consumption of halocarbons and sulfur hexafluoride', '2.F'],
+    ['1. Refrigeration and cooling', '2.F.1'],
+    ['2. Foaming agent', '2.F.2'],
+    ['3. Fire extinguisher', '2.F.3'],
+    ['4. Aerosol', '2.F.4'],
+    ['5. Solvent', '2.F.5'],
+    ['6. Use of ODS substitutes for other purposes', '2.F.6'],
+    ['7. Semiconductor manufacturing', '2.F.7'],
+    ['8. Heavy electric machine', '2.F.8'],
+    ['9. Others (potential emissions)', '2.F.9'],
+    ['Agriculture', '4'],
+    ['A. Intestinal fermentation', '4.A'],
+    ['A.1. cow', '4.A.1'],
+    ['A.2. Water buffalo', '4.A.2'],
+    ['A.3. Sheep (Cotton Sheep)', '4.A.3'],
+    ['A.4. Sheep (Goat)', '4.A.4'],
+    ['A.5. Camel and Llama', '4.A.5'],
+    ['A.6. Horse', '4.A.6'],
+    ['A.7. Mules and Donkeys', '4.A.7'],
+    ['A.8. Pig', '4.A.8'],
+    ['A.9. Poultry', '4.A.9'],
+    ['A.10. Other livestock (deer)', '4.A.10'],
+    ['B. Livestock manure treatment', '4.B'],
+    ['B.1. cow', '4.B.1'],
+    ['B.2. Water buffalo', '4.B.2'],
+    ['B.3. Sheep (Cotton Sheep)', '4.B.3'],
+    ['B.4. Sheep (Goat)', '4.B.4'],
+    ['B.5. Camel and Llama', '4.B.5'],
+    ['B.6. Horse', '4.B.6'],
+    ['B.7. Mules and Donkeys', '4.B.7'],
+    ['B.8. Pig', '4.B.8'],
+    ['B.9. Poultry', '4.B.9'],
+    ['B.10. Other livestock (deer)', '4.B.10'],
+    ['B.1. cow', '4.B.1'],
+    ['B.2. Water buffalo', '4.B.2'],
+    ['B.3. Sheep (Cotton Sheep)', '4.B.3'],
+    ['B.4. Sheep (Goat)', '4.B.4'],
+    ['B.5. Camel and Llama', '4.B.5'],
+    ['B.6. Horse', '4.B.6'],
+    ['B.7. Mules and Donkeys', '4.B.7'],
+    ['B.8. Pig', '4.B.8'],
+    ['B.9. Poultry', '4.B.9'],
+    ['B.10. Other livestock (deer)', '4.B.10'],
+    ['C. Rice cultivation', '4.C'],
+    ['1. irrigation', '4.C.1'],
+    ['2. Thousand answers', '4.C.4'],
+    ['D. Cropland soil', '4.D'],
+    ['1. Direct discharge', '4.D.1'],
+    ['2. Ranch, grazing area, manure (manure)', '4.D.2'],
+    ['3. Indirect emissions', '4.D.3'],
+    ['E. Savannah incineration', '4.E'],
+    ['F. Crop residue incineration', '4.F'],
+    ['1. Grains', '4.F.1'],
+    ['2. Beans (beans)', '4.F.2'],
+    ['3. Root vegetables', '4.F.3'],
+    ['4. Sugar cane', '4.F.4'],
+    ['5. Other', '4.F.5'],
+    ['LULUCF', '5'],
+    ['A. Forest land', '5.A'],
+    ['1. Forest land maintained as a forest land', '5.A.1'],  # categories differ from IPCC1996
+    ['2. Forest land converted from other lands', '5.A.2'],  # categories differ from IPCC1996
+    ['3. N2O emissions from nitrogen fertilization in forest areas', '5.A.3'],  # categories differ from IPCC1996
+    ['4. Non-CO2 emission due to drainage in forest areas', '5.A.4'],  # categories differ from IPCC1996
+    ['5. Emissions from biomass combustion in forest areas', '5.A.5'],  # categories differ from IPCC1996
+    ['B. Cropland', '5.B'],
+    ['1. Agricultural land maintained as agricultural land', '5.B.1'],  # categories differ from IPCC1996
+    ['2. Cropland converted from other lands', '5.B.2'],  # categories differ from IPCC1996
+    ['3. N2O emission due to conversion to agricultural land', '5.B.3'],  # categories differ from IPCC1996
+    ['4. CO2 emission from agricultural lime application in agricultural land', '5.B.4'],  # categories differ from IPCC1996
+    ['5. Emissions from biomass combustion in agricultural land', '5.B.5'],  # categories differ from IPCC1996
+    ['C. Grassland', '5.C'],
+    ['1. Grassland maintained as grassland', '5.C.1'],  # categories differ from IPCC1996
+    ['2. Grassland dedicated to Tatoji', '5.C.2'],  # categories differ from IPCC1996
+    ['3. CO2 emission from agricultural lime application in grassland', '5.C.3'],  # categories differ from IPCC1996
+    ['4. Emissions from biomass combustion in grassland', '5.C.4'],  # categories differ from IPCC1996
+    ['D. Wetlands', '5.D'],
+    ['1. Wetlands maintained as wetlands', '5.D.1'],  # categories differ from IPCC1996
+    ['2. Wetlands converted from Tatoji', '5.D.2'],  # categories differ from IPCC1996
+    ['3. Non-CO2 emission due to drainage in wetlands', '5.D.3'],  # categories differ from IPCC1996
+    ['4. Emissions from biomass combustion in wetlands', '5.D.4'],  # categories differ from IPCC1996
+    ['E. Jeongju-ji', '5.E'],
+    ['F. Other land', '5.F'],
+    ['waste', '6'],
+    ['A. Landfill of waste', '6.A'],
+    ['1. Managed landfill', '6.A.1'],
+    ['2. Unmanaged landfill', '6.A.2'],
+    ['B. Sewage water treatment', '6.B'],
+    ['1. Wastewater treatment', '6.B.1'],  # categories differ from IPCC1996
+    ['2. Sewage treatment', '6.B.2'],  # categories differ from IPCC1996
+    ['C. Waste incineration', '6.C'],
+    ['D. Other', '6.D'],
+    ['Memo Item', '\IGNORE'],
+    ['Field·Sector/Year', '\IGNORE'],
+    ['C. International bunkering and multinational operations', '\IGNORE'],
+    ['1. Bunkering', 'M.1'],
+    ['a. International aviation', 'M.1.A'],
+    ['b. International shipping', 'M.1.B'],
+    ['2. Multinational operations', 'M.2'],
+    ['', '\IGNORE'],
+    ['3. Farmland converted to Tato land', '5.B.3'],  # new codes in 2021 inventory start here
+    ['4. N2O emission due to conversion to agricultural land', '5.B.4'],
+    ['5. CO2 emission from agricultural lime application in agricultural land', '5.B.5'],
+    ['6. Emissions from burning biomass on agricultural land', '5.B.6'],
+    ['G. Others', '5.G'],
+]
+cat_name_translations = dict(zip(original_names, [cat[0] for cat in translations]))
+cat_codes = dict(zip(original_names, [cat[1] for cat in translations]))
+
+fix_rows = [
+    '1. 소',
+    '2. 물소',
+    '3. 양(면양)',
+    '4. 양(산양)',
+    '5. 낙타 및 라마',
+    '6. 말',
+    '7. 노새 및 당나귀',
+    '8. 돼지',
+    '9. 가금류',
+    '10. 기타 가축(사슴)',
+]
+
+remove_cats = [
+    '1.A.1.a', '1.A.1.b', '1.A.1.c', '1.A.2.f',
+    '2.A', '2.D',
+    '2.F', '2.G',
+    '4.C.1', '4.C.4',
+    '4.D',
+    '4.F.1', '4.F.2', '4.F.3', '4.F.4', '4.F.5',  # detail not in 2006 categories
+    '5.A', '5.A.1', '5.A.2', '5.A.3', '5.A.4', '5.A.5',  # don't not match IPCC
+    # categories
+    '5.B', '5.B.1', '5.B.2', '5.B.3', '5.B.4', '5.B.5',
+    '5.C', '5.C.1', '5.C.2', '5.C.3', '5.C.4',
+    '5.D', '5.D.1', '5.D.2', '5.D.3', '5.D.4',
+    '5.E', '5.F',
+    '5.G', '5.B.6', # for 2021 NIR
+]
+
+aggregate_before_mapping = {
+    '2006.2.D.4': {'sources': ['2.A.5', '2.A.6'], 'name': 'Other'},
+    '2006.3.C.4': {'sources': ['4.D.1', '4.D.2'],
+                   'name': 'Direct N2O Emissions from Managed Soils'},
+    '2006.M.3C1AG': {'sources': ['4.E', '4.F'], 'name': 'Biomass burning Agriculture'},
+    '2006.1.A.2.m': {'sources': ['1.A.2.f.2', '1.A.2.f.6'], 'name': 'Other'},
+}
+
+cat_mapping = {
+    '1.A.2.f.1': '1.A.2.f',
+    '1.A.2.f.3': '1.A.2.j',
+    '1.A.2.f.4': '1.A.2.k',
+    '1.A.2.f.5': '1.A.2.l',
+    '2006.1.A.2.m': '1.A.2.m',
+    '2.A.4': '2.B.7',  # add to 2.B
+    '2.A.3': '2.A.4',
+    '2.D': '2.H',
+    '2006.2.D.4': '2.D.4',
+    '2.E': '2.B.9',  # add to 2.B
+    '2.E.1': '2.B.9.a',
+    '2.E.2': '2.B.9.b',
+    #    '2.F', # remove?
+    '2.F.1': '2.F.1',  # just added here to avoid confusion
+    #    '2.F.2', '2.F.3', '2.F.4', '2.F.5',
+    '2.F.6': '2.E_1',
+    '2.F.7': '2.E_2',
+    '2.F.8': '2.G.1',
+    '2.F.9': '2.G.2',
+    '4': 'M.AG',
+    '4.A': '3.A.1',
+    '4.A.1': '3.A.1.a',
+    '4.A.2': '3.A.1.b',
+    '4.A.3': '3.A.1.c',
+    '4.A.4': '3.A.1.d',
+    '4.A.5': '3.A.1.e',
+    '4.A.6': '3.A.1.f',
+    '4.A.7': '3.A.1.g',
+    '4.A.8': '3.A.1.h',
+    '4.A.9': '3.A.1.i',
+    '4.A.10': '3.A.1.j',
+    '4.B': '3.A.2',
+    '4.B.1': '3.A.2.a',
+    '4.B.2': '3.A.2.b',
+    '4.B.3': '3.A.2.c',
+    '4.B.4': '3.A.2.d',
+    '4.B.5': '3.A.2.e',
+    '4.B.6': '3.A.2.f',
+    '4.B.7': '3.A.2.g',
+    '4.B.8': '3.A.2.h',
+    '4.B.9': '3.A.2.i',
+    '4.B.10': '3.A.2.j',
+    '4.C': '3.C.7',
+    '2006.3.C.4': '3.C.4',
+    '4.D.3': '3.C.5',
+    '2006.M.3C1AG': 'M.3.C.1.AG',
+    '5': 'M.LULUCF',
+    '6': '4',
+    '6.A': '4.A',
+    '6.A.1': '4.A.1',
+    '6.A.2': '4.A.2',
+    '6.B': '4.D',
+    '6.B.1': '4.D.1',
+    '6.B.2': '4.D.2',
+    '6.C': '4.C.1',
+    '6.D': '4.E',
+    'M.1': 'M.BK',
+    'M.1.A': 'M.BK.A',
+    'M.1.B': 'M.BK.M',
+}
+
+aggregate_after_mapping = {
+    '1.A.3.a': {'sources': ['1.A.3.a.2'], 'name': 'Civil Aviation'},  # aviation
+    '1.A.3.d': {'sources': ['1.A.3.d.2'], 'name': 'Water-borne Navigation'},  # shipping
+    '2.A': {'sources': ['2.A.1', '2.A.2', '2.A.4', '2.A.5', '2.A.6'],
+            'name': 'Mineral Industry'},
+    '2.B': {'sources': ['2.B', '2.B.7', '2.B.9'], 'name': 'Chemical Industry'},
+    '2.D': {'sources': ['2.D.4'], 'name': 'Other'},
+    '2.E': {'sources': ['2.E_1', '2.E_2'], 'name': 'Electronics Industry'},
+    '2.F': {'sources': ['2.F.1', '2.F.2', '2.F.3', '2.F.4', '2.F.5'],
+            'name': 'Product uses as Substitutes for Ozone Depleting Substances'},
+    '2.G': {'sources': ['2.G.1', '2.G.2'], 'name': 'Other Product Manufacture and Use'},
+    '3.A': {'sources': ['3.A.1', '3.A.2'], 'name': 'Livestock'},
+    '3.C': {'sources': ['3.C.4', '3.C.5', '3.C.7'],
+                 'name': 'Aggregate sources and non-CO2 emissions sources on land'},
+    'M.3.C.AG': {'sources': ['3.C.4', '3.C.5', '3.C.7'],
+                 'name': 'Aggregate sources and non-CO2 emissions sources on land ('
+                         'Agriculture)'},
+    'M.AG.ELV': {'sources': ['M.3.C.AG'], 'name': 'Agriculture excluding livestock'},
+    '4.C': {'sources': ['4.C.1'], 'name': 'Incineration and Open Burning of Waste'},
+}
+
+coords_terminologies_2006 = {
+    "area": "ISO3",
+    "category": "IPCC2006_PRIMAP",
+    "scenario": "PRIMAP",
+}
+
+filter_remove_2006 = {
+    "f1": {
+        "category (IPCC2006_PRIMAP)": "\IGNORE",
+    },
+    "livestock": {  # temp until double cat name problem is solved
+        "category (IPCC2006_PRIMAP)": [
+            '4.B.1', '4.B.10', '4.B.2', '4.B.3', '4.B.4',
+            '4.B.5', '4.B.6', '4.B.7', '4.B.8', '4.B.9',
+        ]
+    },
+    "fmap": {
+        "category (IPCC2006_PRIMAP)": remove_cats
+    },
+    "f_bef_map": {
+        "category (IPCC2006_PRIMAP)": [
+            '2.A.5', '2.A.6',  # combined to 2006.2.D.4
+            '4.D.1', '4.D.2',  # combined to 2006.3.C.4
+            '4.E', '4.F',  # 2006.M.3.C.1.AG
+            '1.A.2.f.2', '1.A.2.f.6',  # 2006.1.A.2.m
+        ]
+    }
+}
+
+filter_remove_after_agg = {
+    "tempCats": {
+        "category (IPCC2006_PRIMAP)": [
+            "2.E_1", "2.E_2"
+        ],
+    },
+}

+ 27 - 12
UNFCCC_GHG_data/UNFCCC_reader/Republic_of_Korea/read_KOR_2023-Inventory_from_xlsx.py

@@ -6,8 +6,8 @@ import sys
 import pandas as pd
 import primap2 as pm2
 
-from config_KOR_BUR4 import cat_name_translations, cat_codes
-from config_KOR_BUR4 import remove_cats, aggregate_before_mapping, cat_mapping, \
+from config_KOR_INV2023 import cat_name_translations, cat_codes, fix_rows
+from config_KOR_INV2023 import remove_cats, aggregate_before_mapping, cat_mapping, \
     aggregate_after_mapping, coords_terminologies_2006, filter_remove_2006, \
     filter_remove_after_agg
 from UNFCCC_GHG_data.helper import downloaded_data_path, extracted_data_path
@@ -25,11 +25,11 @@ if not output_folder.exists():
 
 output_filename = 'KOR_2023-Inventory_2023_'
 
-inventory_file = 'Republic_of_Korea_National_GHG_Inventory_(1990_2020).xlsx'
+inventory_file = 'Republic_of_Korea_National_GHG_Inventory_(1990_2021).xlsx'
 years_to_read = range(1990, 2020 + 1)
 
 sheets_to_read = ['온실가스', 'CO2', 'CH4', 'N2O', 'HFCs', 'PFCs', 'SF6']
-cols_to_read = range(1, 2020 - 1990 + 3)
+cols_to_read = range(1, 2021 - 1990 + 3)
 
 # columns for category UNFCCC_GHG_data and original category name
 index_cols = ['분야·부문/연도']
@@ -92,21 +92,22 @@ filter_remove = {
     "f1": {
         "category (IPCC1996_KOR_INV)": "\IGNORE",
     },
-    "livestock": { # temp until double cat name problem is solved
-        "category (IPCC1996_KOR_INV)": [
-            '4.B.1', '4.B.10', '4.B.2', '4.B.3', '4.B.4',
-            '4.B.5', '4.B.6', '4.B.7', '4.B.8', '4.B.9',
-        ]
-    }
+    # "livestock": { # temp until double cat name problem is solved
+    #     "category (IPCC1996_KOR_INV)": [
+    #         '4.B.1', '4.B.10', '4.B.2', '4.B.3', '4.B.4',
+    #         '4.B.5', '4.B.6', '4.B.7', '4.B.8', '4.B.9',
+    #     ]
+    # }
 }
 
 filter_keep = {}
 
 meta_data = {
-    "references": "http://www.gir.go.kr/home/file/readDownloadFile.do?fileId=5810&fileSeq=3",
+    "references": "http://www.gir.go.kr/home/board/read.do?pagerOffset=0&maxPageItems=10&maxIndexPages="
+                  "10&searchKey=&searchValue=&menuId=36&boardId=62&boardMasterId=2&boardCategoryId=",
     "rights": "",
     "contact": "mail@johannes-guetschow.de",
-    "title": "Republic of Korea: National Greenhouse Gas Inventory Report 2022",
+    "title": "Republic of Korea: National Greenhouse Gas Inventory Report 2023",
     "comment": "Read fom xlsx file by Johannes Gütschow",
     "institution": "Republic of Korea, Ministry of Environment, Greenhouse Gas Inventory and Research Center",
 }
@@ -129,6 +130,7 @@ os.chdir(script_dir_name)
 df_all = None
 
 for sheet in sheets_to_read:
+    print(f"Reading sheet {sheet}.")
     # read current sheet (one sheet per gas)
     df_current = pd.read_excel(input_folder / inventory_file, sheet_name=sheet, skiprows=3, nrows=146, usecols=cols_to_read,
                                engine="openpyxl")
@@ -139,6 +141,19 @@ for sheet in sheets_to_read:
     # df_current = df_current.set_index(index_cols)
     # make sure all col headers are str
     df_current.columns = df_current.columns.map(str)
+
+    # fix the double category issue in livestock
+    lastrow = None
+    for i, row in df_current.iterrows():
+        if row["분야·부문/연도"] in fix_rows:
+            if lastrow == 'A.  장내발효':
+                df_current.iloc[i]["분야·부문/연도"] = f'A.{df_current.iloc[i]["분야·부문/연도"]}'
+            elif lastrow == 'B.  가축분뇨처리':
+                df_current.iloc[i]["분야·부문/연도"] = f'B.{df_current.iloc[i]["분야·부문/연도"]}'
+            else:
+                raise ValueError(f'Row to fix, but no fix defined {lastrow}, {row["분야·부문/연도"]}')
+        else:
+            lastrow = row["분야·부문/연도"]
     # add columns
     for col in sheet_metadata.keys():
         df_current.insert(1, col, sheet_metadata[col][sheet])

+ 0 - 43
downloaded_data/non-UNFCCC/Republic_of_Korea/2023-Inventory/Republic_of_Korea_National_GHG_Inventory_(1990_2020).xlsx

@@ -1,43 +0,0 @@
-
-
-
-
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>시스템장애 발생</title>
-<style type="text/css">
-<!--
-#errorBg {
-
-    color:#FF3300;
-    margin:0 auto;
-    background:url('/images/error/errorBg.jpg') no-repeat;
-    width: 514px;
-    height: 219px;
-	position:relative;
-	font-weight:bold;
-}
-#errorBg .message {position:absolute; top:90px; left:230px; width:250px; height:60px; text-align:center;}
-#errorBg .errorBtn {
-	text-align:center;
-	position:absolute; top:160px; left:230px; width:250px; height:30px;
-	display:block;
-}
--->
-</style>
-</head>
-<body>
-<div id="errorBg">
-	<p class="message">
-		예상치 못한 예외가 발생했습니다.
-	</p>
-	<div class="errorBtn">
-		<a href="javascript:history.back();" class="btn"><span>뒤로가기</span></a>
-		<a href="javascript:window.location.reload();" class="btn"><span>새로고침</span></a>
-	</div>
-</div>
-</body>
-</html>

+ 1 - 0
downloaded_data/non-UNFCCC/Republic_of_Korea/2023-Inventory/Republic_of_Korea_National_GHG_Inventory_(1990_2021).pdf

@@ -0,0 +1 @@
+../../../../.git/annex/objects/fX/zW/MD5E-s1830575--1e3b68a368cb93660039716f2eb610e9.pdf/MD5E-s1830575--1e3b68a368cb93660039716f2eb610e9.pdf

+ 1 - 0
downloaded_data/non-UNFCCC/Republic_of_Korea/2023-Inventory/Republic_of_Korea_National_GHG_Inventory_(1990_2021).xlsx

@@ -0,0 +1 @@
+../../../../.git/annex/objects/1k/QM/MD5E-s875254--c8b96bdb8992936d32fba438b2cb3fb3.xlsx/MD5E-s875254--c8b96bdb8992936d32fba438b2cb3fb3.xlsx