ITS_LIVE: calculate Metric 1

ITS_LIVE: calculate Metric 1

This notebook calculates δu and δv for all ITS_LIVE velocity maps.

To reproduce this workflow, make sure you have downloaded all necessary input files (velocity maps and static terrain geometries) from https://doi.org/10.17605/OSF.IO/HE7YR and have updated the Vx and Vy columns in notebooks/results_ITSLIVE.csv or notebooks/manifest_ITSLIVE.csv with the downloaded file paths before starting the analysis.

import glaft
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import netCDF4 as nc
# df = pd.read_csv('../manifest_ITSLIVE.csv', dtype=str)
df = pd.read_csv('../results_ITSLIVE.csv', dtype=str)
# df
# static area
in_shp = '/home/jovyan/Projects/PX_comparison/shapefiles/bedrock_V2_EPSG3413.shp'

Locate the assigned error value in the metadata of the original NetCDF files:

for idx, row in df.iterrows():
    ncfname_processed = row.Vx[:-7]
    ncfname_list = ncfname_processed.split('/')
    ncfname_list.append(ncfname_list[-1])
    ncfname_list[-2] = 'raw_nc'
    ncfname = '/'.join(ncfname_list)
    with nc.Dataset(ncfname) as ds:
        vxd = ds['vx']
        xe = vxd.__dict__['error']
        # print(xe)
        vyd = ds['vy']
        ye = vyd.__dict__['error']
        # print(ye)
        df.loc[idx, 'Assigned-x-error'] = xe
        df.loc[idx, 'Assigned-y-error'] = ye
        
# df

Here’s a demo for calculating Metric 1 for an ITS_LIVE velocity map:

exp = glaft.Velocity(vxfile=df.loc[4, 'Vx'], vyfile=df.loc[4, 'Vy'], 
                     static_area=in_shp, kde_gridsize=60, thres_sigma=2.0, 
                     velocity_unit='m/yr')
exp.static_terrain_analysis(plot='full')
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
../../_images/metric_static-area-velo-ITSLIVE_7_1.png

Now let’s batch process all the maps:

fig, ax2 = plt.subplots(7, 5, figsize=(20, 28))
n = 0 

for idx, row in df.iterrows():
    label = row.Label
    ax_sel = ax2[n // 5, n % 5]
    ax_sel.axis('equal')
    exp = glaft.Velocity(vxfile=row.Vx, vyfile=row.Vy, static_area=in_shp, kde_gridsize=60, thres_sigma=2.0, velocity_unit='m/yr')
    exp.static_terrain_analysis(plot='zoomed', ax=ax_sel)
    ax_sel.set_xlim(-250, 250)
    ax_sel.set_ylim(-250, 250)
    titletext = ax_sel.get_title()
    titletext = label + '\n' + titletext
    ax_sel.set_title(titletext)
    
    df.loc[idx, 'SAV-uncertainty-x'] = exp.metric_static_terrain_x
    df.loc[idx, 'SAV-uncertainty-y'] = exp.metric_static_terrain_y
    df.loc[idx, 'SAV-peak-x'] = exp.kdepeak_x
    df.loc[idx, 'SAV-peak-y'] = exp.kdepeak_y
    df.loc[idx, 'SAV-outlier-percent'] = exp.outlier_percent * 100
    
    print('xstd: {}; xSAVuncer: {}'.format(np.std(exp.xy[0, :]), exp.metric_static_terrain_x))
    print('ystd: {}; ySAVuncer: {}'.format(np.std(exp.xy[1, :]), exp.metric_static_terrain_y))
    
    n += 1
    
plt.tight_layout()
fig.patch.set_facecolor('xkcd:white')
fig.savefig('figs/ITSLVE-SAV.png')
Click to show
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 39.496883392333984; xSAVuncer: 51.14884809068558
ystd: 33.03361511230469; ySAVuncer: 44.548996724145496
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 121.10285186767578; xSAVuncer: 124.23576847338722
ystd: 82.7453384399414; ySAVuncer: 108.70629741421381
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 83.20791625976562; xSAVuncer: 147.2743251306507
ystd: 48.203582763671875; ySAVuncer: 81.3884428353596
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 62.919288635253906; xSAVuncer: 87.40320419594698
ystd: 54.23698043823242; ySAVuncer: 76.12537139646994
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 87.47274017333984; xSAVuncer: 113.65691626279659
ystd: 68.39109802246094; ySAVuncer: 98.99150771275833
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 25.722091674804688; xSAVuncer: 35.0747509574137
ystd: 23.562461853027344; ySAVuncer: 35.0747509574137
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 32.857200622558594; xSAVuncer: 32.09119015557933
ystd: 29.302839279174805; ySAVuncer: 32.091190155579326
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 37.6147575378418; xSAVuncer: 45.61249553922913
ystd: 38.26398849487305; ySAVuncer: 42.66975389153693
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 30.37626838684082; xSAVuncer: 34.59215661796891
ystd: 29.359336853027344; ySAVuncer: 29.187132146411276
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 79.85745239257812; xSAVuncer: 111.24892229271488
ystd: 64.9723892211914; ySAVuncer: 97.34280700612553
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 47.33998489379883; xSAVuncer: 71.80031695195302
ystd: 26.141939163208008; ySAVuncer: 40.75153124300036
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 49.47611618041992; xSAVuncer: 85.59893683463575
ystd: 30.588346481323242; ySAVuncer: 50.89666514491856
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 88.64006805419922; xSAVuncer: 111.98173725009379
ystd: 71.50811004638672; ySAVuncer: 90.98516151570121
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 39.34418869018555; xSAVuncer: 71.06871664051958
ystd: 31.399913787841797; ySAVuncer: 52.2564092944997
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 45.485145568847656; xSAVuncer: 80.18436377393455
ystd: 37.78843307495117; ySAVuncer: 63.175559337039346
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 106.7762451171875; xSAVuncer: 143.29049063187358
ystd: 91.39488220214844; ySAVuncer: 117.23767415335114
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 40.76557540893555; xSAVuncer: 31.69440809263544
ystd: 29.749011993408203; ySAVuncer: 26.742156828161157
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 35.86577606201172; xSAVuncer: 22.66838605896973
ystd: 29.2535457611084; ySAVuncer: 24.231723028553855
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 82.30934143066406; xSAVuncer: 92.56655580391845
ystd: 97.32573699951172; ySAVuncer: 118.48519142901563
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 47.411888122558594; xSAVuncer: 56.41430248588669
ystd: 44.754249572753906; ySAVuncer: 58.35962326126208
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 76.93824005126953; xSAVuncer: 100.88883292199213
ystd: 59.234413146972656; ySAVuncer: 77.15028399917045
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 57.759334564208984; xSAVuncer: 79.28522176251826
ystd: 45.62628173828125; ySAVuncer: 66.89690586212478
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 51.058326721191406; xSAVuncer: 71.8164070544946
ystd: 41.2814826965332; ySAVuncer: 56.58262373990484
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 92.22754669189453; xSAVuncer: 141.10830077527197
ystd: 72.22838592529297; ySAVuncer: 103.7561035112294
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 72.83692932128906; xSAVuncer: 93.4422738259384
ystd: 65.63919067382812; ySAVuncer: 78.8419185406355
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 55.69933319091797; xSAVuncer: 58.95959131277702
ystd: 54.03276443481445; ySAVuncer: 63.02577002400302
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 24.717741012573242; xSAVuncer: 25.687939383940375
ystd: 23.67876434326172; ySAVuncer: 28.440218603648276
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 31.067092895507812; xSAVuncer: 41.70414109052437
ystd: 26.959758758544922; ySAVuncer: 23.04702533950031
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 31.331037521362305; xSAVuncer: 37.848589665372636
ystd: 32.315574645996094; ySAVuncer: 36.586970009860224
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 29.311100006103516; xSAVuncer: 40.71174912001661
ystd: 24.886030197143555; ySAVuncer: 32.07592354910399
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 70.9832763671875; xSAVuncer: 82.0364088955474
ystd: 74.93070220947266; ySAVuncer: 87.69409226765411
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 68.39533996582031; xSAVuncer: 95.278771151358
ystd: 73.4205551147461; ySAVuncer: 95.278771151358
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 52.98209762573242; xSAVuncer: 73.46944327276843
ystd: 57.83235549926758; ySAVuncer: 83.96507802602105
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 67.14309692382812; xSAVuncer: 89.86318574406062
ystd: 69.16436004638672; ySAVuncer: 83.87230669445657
Running clip_static_area
Running calculate_xystd
Running calculate_bandwidth
Running calculate_kde
Running construct_crude_mesh
Running eval_crude_mesh
Running construct_fine_mesh
Running eval_fine_mesh
Running thresholding_fine_mesh
Running thresholding_metric
Running cal_outlier_percent
xstd: 80.27301788330078; xSAVuncer: 75.88787787203856
ystd: 78.3895034790039; ySAVuncer: 75.88787787203856
../../_images/metric_static-area-velo-ITSLIVE_9_1.png

df.to_csv('../results_ITSLIVE.csv', index=False)
# df