Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b66767c
Added KUJ_polygons and the match_dates notebook.
speitzer Jan 10, 2024
bd1e39f
Merge pull request #1 from speitzer/feature-branch
speitzer Jan 10, 2024
eea43b8
Finished creating a time series from the ITS_LIVE rasters.
speitzer Jan 17, 2024
a5d2760
Merge pull request #2 from speitzer/feature-branch
speitzer Jan 17, 2024
e459f3b
Adding the directory with my time series results.
speitzer Jan 17, 2024
ff55c24
Merge pull request #3 from speitzer/feature-branch
speitzer Jan 17, 2024
531cc3c
Merge https://github.com/speitzer/its_live_tutorial into kevin
shahinmg Feb 6, 2024
bc47cbe
multiprocessing
shahinmg Feb 6, 2024
10c5fec
attempt to parallel with dask
shahinmg Feb 7, 2024
50d1025
edit gitignore
shahinmg Feb 7, 2024
a886bb8
edit gitignore
shahinmg Feb 7, 2024
7444b92
add lagrangain poly sample and gdf concat
shahinmg Feb 14, 2024
f4d9d8d
add area filter
shahinmg Feb 16, 2024
07e0822
post meeting 02-20-24
shahinmg Feb 20, 2024
6083983
langrangian test
shahinmg Feb 20, 2024
d6691b8
gdf merge fix
shahinmg Mar 5, 2024
0999785
ec2
shahinmg Mar 5, 2024
8f8787f
ec2
shahinmg Mar 5, 2024
2f7d668
ec2
shahinmg Mar 5, 2024
3834f13
eqi_test
Mar 5, 2024
a07dbf7
new eqi test
Mar 21, 2024
88ed81a
gpkgs
shahinmg Mar 21, 2024
8d48ef6
gpkgs
shahinmg Mar 21, 2024
d4a42b9
add new csvs
Mar 21, 2024
66e7c39
term_poly_dfs
shahinmg Mar 21, 2024
3f91b52
add datacube_loader to process strain rates
Apr 3, 2024
279f8b1
strain rate calc updates
Apr 3, 2024
ca441e8
test
Apr 3, 2024
c2da518
datacube strain rates
shahinmg Apr 3, 2024
ab76925
edit scopes
shahinmg Apr 3, 2024
b13633a
fix issue
Apr 3, 2024
fbcab69
fix scopes again
shahinmg Apr 3, 2024
040d97d
conflicts
Apr 3, 2024
cff5309
fix conflicts
Apr 3, 2024
3a84900
fix indent
shahinmg Apr 3, 2024
523a51b
fix indent
shahinmg Apr 3, 2024
6dd7717
weird extra code
shahinmg Apr 3, 2024
da805fa
change scope again
shahinmg Apr 3, 2024
7302c2c
remove duplicated code
shahinmg Apr 3, 2024
f5ef8d7
change interp
shahinmg Apr 3, 2024
9f8e2a1
clip datacube to total bounds of terminus polygons
shahinmg Apr 4, 2024
0305404
structure change and strain rates
shahinmg Apr 5, 2024
a57f586
structure change and strain rates
shahinmg Apr 5, 2024
ec0caa8
save before rm
shahinmg Apr 5, 2024
c9e5da4
strain test?
shahinmg Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Ignore everything
/*
!.gitignore
!its_live_web_app_tutorial.ipynb
!/geoms
!/images
!environment.yml
!store_its_live_velocities_2022.json
!ITS_LIVE API_tutorial.ipynb
!its_live_datacube_term_poly_tutorial.ipynb
!its_live_datacube_tutorial.ipynb
!term_poly_gpkgs
!/csv_outputs
!/poly_sample
!/term_poly_data_viz
!/figs
!gdf_concat.py
310 changes: 0 additions & 310 deletions ITS_LIVE API_tutorial.ipynb

This file was deleted.

210 changes: 210 additions & 0 deletions csv_outputs/AVA_velocity_strains.csv

Large diffs are not rendered by default.

317 changes: 317 additions & 0 deletions csv_outputs/EQI_velocity_strains.csv

Large diffs are not rendered by default.

1,545 changes: 1,545 additions & 0 deletions csv_outputs/HEL_velocity_strains.csv

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions csv_outputs/KAN_velocity_strains.csv

Large diffs are not rendered by default.

271 changes: 271 additions & 0 deletions csv_outputs/KUJ_velocity_strains.csv

Large diffs are not rendered by default.

888 changes: 888 additions & 0 deletions csv_outputs/ava_df.csv

Large diffs are not rendered by default.

1,614 changes: 1,614 additions & 0 deletions csv_outputs/eqi_df.csv

Large diffs are not rendered by default.

5,080 changes: 5,080 additions & 0 deletions csv_outputs/hel_df.csv

Large diffs are not rendered by default.

830 changes: 830 additions & 0 deletions csv_outputs/kan_df.csv

Large diffs are not rendered by default.

620 changes: 620 additions & 0 deletions csv_outputs/kuj_df.csv

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions environment.yml

This file was deleted.

Binary file added figs/AVA_time_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/EQI_time_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/HEL_time_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/KAN_time_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/KUJ_time_series.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions gdf_concat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 13 17:40:43 2024

@author: laserglaciers
"""

import geopandas as gpd
import os

glacier_names = ['KUJ', 'AVA','KAN','EQI']

for name in glacier_names:
shp_file_path = f'/media/laserglaciers/upernavik/its_live_tutorial/{name}_polygons/'
os.chdir(shp_file_path)
gdfs_dates = [(gpd.read_file(fn), gpd.pd.to_datetime(fn[:10].replace('_','-'))) for fn in sorted(os.listdir(shp_file_path)) if fn.endswith('shp')] #

gdfs, dates = zip(*gdfs_dates)

rdf = gpd.GeoDataFrame(gpd.pd.concat(gdfs, ignore_index=True), crs=gdfs[0].crs)
rdf['date'] = dates

if 'FID' in rdf.columns:
rdf.drop(columns=['FID'], inplace=True)
rdf.to_crs(crs=None,epsg=3413,inplace=True)
elif 'col1' in rdf.columns:
rdf.drop(columns=['col1'], inplace=True)
rdf.to_crs(crs=None,epsg=3413,inplace=True)

op = '/media/laserglaciers/upernavik/its_live_tutorial/merged_geoms/'
rdf.to_file(f'{op}{name}_merged.gpkg',driver='GPKG',crs="EPSG:3413")
Binary file removed geoms/2020_12_10_term_polygon.shx
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/2020_12_11_term_polygon.prj

This file was deleted.

Binary file removed geoms/2020_12_11_term_polygon.shp
Binary file not shown.
Binary file removed geoms/2020_12_11_term_polygon.shx
Binary file not shown.
Binary file removed geoms/helheim_pt_3413.gpkg
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/helheim_pt_4326.cpg

This file was deleted.

Binary file removed geoms/helheim_pt_4326.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/helheim_pt_4326.prj

This file was deleted.

Binary file removed geoms/helheim_pt_4326.qix
Binary file not shown.
Binary file removed geoms/helheim_pt_4326.shp
Binary file not shown.
Binary file removed geoms/helheim_pt_4326.shx
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/sample_points.cpg

This file was deleted.

Binary file removed geoms/sample_points.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/sample_points.prj

This file was deleted.

Binary file removed geoms/sample_points.qix
Binary file not shown.
Binary file removed geoms/sample_points.shp
Binary file not shown.
Binary file removed geoms/sample_points.shx
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/store_poly.cpg

This file was deleted.

Binary file removed geoms/store_poly.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion geoms/store_poly.prj

This file was deleted.

Binary file removed geoms/store_poly.qix
Binary file not shown.
Binary file removed geoms/store_poly.shp
Binary file not shown.
Binary file removed geoms/store_poly.shx
Binary file not shown.
Binary file removed images/2020_image_pair_not_smooth.png
Binary file not shown.
Binary file removed images/2020_image_pair_smooth.png
Binary file not shown.
Binary file removed images/filter_images.png
Binary file not shown.
Binary file removed images/polygon.png
Binary file not shown.
Binary file removed images/web_portal_3413.png
Binary file not shown.
5,737 changes: 0 additions & 5,737 deletions its_live_datacube_term_poly_tutorial.ipynb

This file was deleted.

12,796 changes: 0 additions & 12,796 deletions its_live_datacube_tutorial.ipynb

This file was deleted.

316 changes: 0 additions & 316 deletions its_live_web_app_tutorial.ipynb

This file was deleted.

95 changes: 95 additions & 0 deletions poly_sample/datacube_poly_sample_multiprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 4 15:45:50 2024

@author: laserglaciers
"""
import os
import json
import geopandas as gpd
from shapely.geometry import Point
from shapely.geometry import Polygon
import pandas as pd
import numpy as np
import xarray as xr
import rioxarray as rxr
import geoviews as gv
import geoviews.feature as gf
# import hvplot.pandas
import s3fs
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime, timedelta
from multiprocessing import Pool, cpu_count
import dask
from dask.distributed import Client, progress, LocalCluster
import dask.array as da
import geopandas as gpd
from shapely import box
from datacube_strain_rates_serial_function import *
# %%

def grab_cube(its_live_catalog, term_poly_path):

term_poly_path_abs = './term_poly_gpkgs/'
term_poly = gpd.read_file(f'{term_poly_path_abs}{term_poly_path}')
term_centroid = term_poly.centroid.to_crs(crs='EPSG:4326')
term_centroid = gpd.GeoDataFrame(geometry=term_centroid,crs=4326)
granule = its_live_catalog.sjoin(term_centroid, how='inner')
url = granule['zarr_url'].values[0]


cube = read_in_s3(url)
cube = cube.chunk({"mid_date": len(cube.mid_date)}) # setting the mid_date chunksize to the time dimensions helps A LOT
cube = cube.sortby('mid_date')
cube.rio.write_crs('EPSG:3413',inplace=True)

total_bounds = term_poly.total_bounds
bounding_box = box(*total_bounds)
cube = cube.rio.clip([bounding_box],term_poly.crs, drop=True,invert=False,all_touched=True)



cube_dates = cube.mid_date.dt.date.data # get the mid_dates
term_dates_pd = term_poly['date'].dt.date.values # get the polygon dates
matched_idx = np.where(np.isin(cube_dates,term_dates_pd))[0] # returns the indices of the matched dates so we can just use an isel (integer select) on the data cube
cube = cube.isel(mid_date=matched_idx) # use isel to grab the data we want

days = cube.date_dt.compute() # get the dt_array
days = days.data.astype('timedelta64[D]') # convert to days using .astype
day_filter = np.timedelta64(100, 'D') # the day separation we filter by
matched_date_dt_idx = np.where(days<=day_filter)[0] # get this indices
cube = cube.isel(mid_date=matched_date_dt_idx) # use isel to grab the data we want
term_poly.to_crs(crs="EPSG:3413",inplace=True)

return cube, term_poly, term_poly_path[:3]


catalog = gpd.read_file('https://its-live-data.s3.amazonaws.com/datacubes/catalog_v02.json') # ITS_LIVE data catalog where all the paths are defined
term_poly_path = './term_poly_gpkgs/'

terminus_poly_list = [file for file in os.listdir(term_poly_path) if file.endswith('gpkg')]

cube_list = []
for term_poly in terminus_poly_list:
filtered_cube = grab_cube(catalog,term_poly)
cube_list.append(filtered_cube)

# %%

for data in cube_list:

poly_sample(*data)

# %%
def worker(cube, term_poly,glacier_abbr):
proc = poly_sample(cube, term_poly,glacier_abbr)
proc.wait()


if __name__ == "__main__":
with Pool(processes=cpu_count()-6) as pool:
results = pool.starmap(worker, cube_list[:2])


Loading