<jupyter_start><jupyter_text>RGI-07: Region 9 (Russian Arctic) <NAME> & <NAME>, June 2021<jupyter_code>import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
import subprocess
import os
from utils import mkdir<jupyter_output><empty_output><jupyter_text>Files and storage paths<jupyter_code># Region of interest
reg = 9

# go down from rgi7_scripts/workflow
data_dir = '../../rgi7_data/'

# Level 2 GLIMS files
l2_dir = os.path.join(data_dir, 'l2_sel_reg_tars')

# Output directories
output_dir = mkdir(os.path.join(data_dir, 'l3_rgi7a'))
output_dir_tar = mkdir(os.path.join(data_dir, 'l3_rgi7a_tar'))

# RGI v6 file for comparison later 
rgi6_reg_file = os.path.join(data_dir, 'l0_RGIv6', '09_rgi60_RussianArctic.zip')<jupyter_output><empty_output><jupyter_text>Load the input data<jupyter_code># Read L2 files
shp = gpd.read_file('tar://' + l2_dir + f'/RGI{reg:02d}.tar.gz/RGI{reg:02d}/RGI{reg:02d}.shp')<jupyter_output><empty_output><jupyter_text>Apply selection criteria to create the RGI7 data subset<jupyter_code># For this region RGI07 shall be equal to RGI06 so...
#...extract RGI06 from GLIMS by 'subm_id' 567 which refers to data by Moholdt et al. 2012
rgi7 = shp.loc[shp['subm_id']== 567].copy()<jupyter_output><empty_output><jupyter_text>Write out and tar<jupyter_code>dd = mkdir(f'{output_dir}/RGI{reg:02d}/', reset=True)

print('Writing...')
rgi7.to_file(dd + f'RGI{reg:02d}.shp')

print('Taring...')
print(subprocess.run(['tar', '-zcvf', f'{output_dir_tar}/RGI{reg:02d}.tar.gz', '-C', output_dir, f'RGI{reg:02d}']))<jupyter_output><empty_output><jupyter_text>New RGI-file created - Check result!  load reference data (here RGI6) to enable comparison<jupyter_code># Just to know the name of the file to open from zip
import zipfile
with zipfile.ZipFile(rgi6_reg_file, "r") as z:
    for f in z.filelist:
        if '.shp' in f.filename:
            fname = f.filename

# load reference data
ref_odf = gpd.read_file('zip://' + rgi6_reg_file + '/' + fname)<jupyter_output><empty_output><jupyter_text>Compare new RGI-file and reference data set   Number of elements (differences do not necessarily depict major problems)<jupyter_code>print('Number of glaciers in new RGI subset:', len(rgi7))
print('Number of glaciers in reference data:', len(ref_odf))
print('Difference:', len(rgi7)-len(ref_odf))
print ('number of glaciers without unique id in RGI06:', len(ref_odf)-len(ref_odf['GLIMSId'].unique()))
print ('number of glaciers without unique id in RGI06 from GLIMS data base:', len(rgi7)-len(rgi7['glac_id'].unique()))<jupyter_output><empty_output><jupyter_text>How many nominal glaciers were there in RGI06-R09?<jupyter_code>len(ref_odf.loc[ref_odf.Status == 2])<jupyter_output><empty_output><jupyter_text>Total area<jupyter_code># add an area field to RGI_ss and reference data
rgi7['area'] = rgi7.to_crs({'proj':'cea'}).area
ref_odf['area'] = ref_odf.to_crs({'proj':'cea'}).area
# print and compare area values
Area_RGI = rgi7['area'].sum() * 1e-6
print('Area RGI [km²]:', Area_RGI)
Area_ref = ref_odf['area'].sum() * 1e-6
print('Area Ref [km²]:', Area_ref)
d = (Area_RGI - Area_ref)
print('Area difference [km²]:',d)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14577442664153314, 'fraction_numerical': 0.02607602890355011, 'mean_word_length': 6.37037037037037, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '112156', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1251, 'n_words': 280, 'path': 'workflow/RGI09.ipynb', 'repo_name': 'franra9/rgi7_scripts', 'size': '3190'}