Skip to content

Commit

Permalink
clean-up (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow authored May 30, 2024
1 parent da559e5 commit 90ad5c8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 61 deletions.
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="griml",
version="0.1.0",
version="0.1.1",
author="Penelope How",
author_email="pho@geus.dk",
description="A workflow for classifying lakes from satellite imagery and compiling lake inventories",
Expand Down Expand Up @@ -34,4 +34,9 @@
package_data={"griml.test": ["*"]},
python_requires=">=3.8",
install_requires=['geopandas', 'pandas', 'scipy', 'Shapely', 'rasterio'],
entry_points={
'console_scripts': [
'griml = griml.test.process_cli:griml'
],
},
)
9 changes: 3 additions & 6 deletions src/griml/convert/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from griml.convert import raster_to_vector
import glob
import glob, os
from pathlib import Path

def convert(indir, proj, band_info, startdate, enddate, outdir=None):
Expand Down Expand Up @@ -41,15 +41,12 @@ def convert(indir, proj, band_info, startdate, enddate, outdir=None):

if __name__ == "__main__":

# Define file attributes
indir = list(glob.glob('/home/pho/Desktop/python_workspace/GrIML/other/iml_2017/binary_images/*.tif'))
outdir = '/home/pho/Desktop/python_workspace/GrIML/other/iml_2017/vectors/'
infile = os.path.join(os.path.dirname(griml.__file__),'test/test_north_greenland.tif')
proj = 'EPSG:3413'
band_info = [{'b_number':1, 'method':'VIS', 'source':'S2'},
{'b_number':2, 'method':'SAR', 'source':'S1'},
{'b_number':3, 'method':'DEM', 'source':'ARCTICDEM'}]
start='20170701'
end='20170831'

# Perform conversion
convert(indir, outdir, proj, band_info, start, end)
convert([infile], proj, band_info, start, end)
9 changes: 4 additions & 5 deletions src/griml/filter/filter_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from griml.load import load
import geopandas as gpd
from pathlib import Path
import os

def filter_vectors(inlist, margin_file, outdir=None, min_area=0.05):
'''Filter vectors by area and margin proximity
Expand Down Expand Up @@ -66,8 +67,6 @@ def filter_vectors(inlist, margin_file, outdir=None, min_area=0.05):


if __name__ == "__main__":
infile1 = '../test/test_icemask.shp'
margin_buff = gpd.read_file(infile1)

infile2 = ['../test/test_filter.shp']
filter_vectors(infile2, margin_buff)
infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_filter.shp')
infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_icemask.shp')
filter_vectors([infile1], infile2)
8 changes: 3 additions & 5 deletions src/griml/load/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ def is_geo_object(typ):
else:
return False

if __name__ == "__main__":
infile1 = '../test/test_icemask.shp'
if __name__ == "__main__":

infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_icemask.shp')
test1 = load(infile1)

g = gpd.read_file(infile1)
test2 = load(g)

infile2 = '../test/test_icemsak.shp'
test2 = load(infile2)
6 changes: 3 additions & 3 deletions src/griml/merge/merge_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ def _dissolve_vectors(gdf):
return gdf2

if __name__ == "__main__":
infile1 = '../test/test_merge_1.shp'
infile2 = '../test/test_merge_2.shp'
vectors = merge_vectors([infile1,infile2])
infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_1.shp')
infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp')
merge_vectors([infile1,infile2])
14 changes: 4 additions & 10 deletions src/griml/metadata/add_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ def add_metadata(iml, names, regions, outfile=None):


if __name__ == "__main__":
# indir = "/home/pho/python_workspace/GrIML/other/iml_2017/merged_vectors/griml_2017_inventory.shp"
indir = "/home/pho/python_workspace/GrIML/other/iml_2017/inspected_vectors/lakes_all-0000000000-0000037888_filtered.shp"


infile_names = '/home/pho/python_workspace/GrIML/other/datasets/placenames/oqaasileriffik_placenames.shp'
infile_regions = '/home/pho/python_workspace/GrIML/other/datasets/drainage_basins/greenland_basins_polarstereo.shp'


outfile = "/home/pho/python_workspace/GrIML/other/iml_2017/metadata_vectors/griml_2017_inventory_final.shp"
add_metadata(indir, infile_names, infile_regions, outfile)
infile1 = os.path.join(os.path.dirname(griml.__file__),'test/test_merge_2.shp')
infile2 = os.path.join(os.path.dirname(griml.__file__),'test/test_placenames.shp')
infile3 = os.path.join(os.path.dirname(griml.__file__),'test/greenland_basins_polarstereo.shp')
add_metadata(infile1, infile2, infile3)
13 changes: 1 addition & 12 deletions src/griml/metadata/assign_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,4 @@ def _compile_names(gdf):
placenames.append(v['Alternativ'])
else:
placenames.append(None)
return placenames


if __name__ == "__main__":

# Define file attributes
infile = '/home/pho/Desktop/python_workspace/GrIML/src/griml/test/test_merge_1.shp'
names = '/home/pho/Desktop/python_workspace/GrIML/other/datasets/placenames/oqaasileriffik_placenames_polarstereo.shp'


# Perform conversion
a = assign_names(infile, names)
return placenames
17 changes: 1 addition & 16 deletions src/griml/metadata/assign_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,4 @@ def _get_nearest_polygon(gdfA, gdfB, gdfB_cols=['subregion'], distance=100000.0)
gdf.loc[gdf['dist']>=distance, 'subregion'] = 'Unknown'

gdf = gdf.drop(columns=['dist'])
return gdf


if __name__ == "__main__":

# Define file attributes
infile = '/home/pho/Desktop/python_workspace/GrIML/src/griml/test/test_merge_1.shp'
regions = '/home/pho/python_workspace/GrIML/other/datasets/drainage_basins/greenland_basins_polarstereo.shp'
regions=gpd.read_file(regions)

regions_dissolve = regions.dissolve(by='subregion')


# Perform conversion
a = assign_regions(infile, regions)

return gdf
6 changes: 4 additions & 2 deletions src/griml/test/process_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def parse_griml_arguments():
help='File path to ice margin for spatial filtering')
parser.add_argument('-n', '--names_file', type=str, required=True,
help='File path to placenames file for metadata population')
parser.add_argument('-r', '--regions_file', type=str, required=True,
help='File path to regions/drainage basin file for metadata population')
parser.add_argument('-p', '--proj', type=str, default='EPSG:3413',
required=False, help='Projection (of input and output)')
parser.add_argument('-s', '--steps', type=str, default='1111',
Expand All @@ -46,7 +48,7 @@ def check_dir(d):
os.mkdir(d)


def griml_process():
def griml():
'''Perform processing workflow'''
args = parse_griml_arguments()

Expand Down Expand Up @@ -127,6 +129,6 @@ def griml_process():
print('Reading from ' + src)
print('Writing to ' + str(dest))

add_metadata(src, args.names_file, str(dest))
add_metadata(src, args.names_file, args.regions_file, str(dest))

print('Finished')
3 changes: 2 additions & 1 deletion src/griml/test/process_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
print('Writing to ' + dest)

infile_names = str(root_dir.joinpath('datasets/placenames/oqaasileriffik_placenames.shp'))
infile_basins = str(root_dir.joinpath('datasets/drainage_basins/greenland_basins_polarstereo.shp'))

add_metadata(src, infile_names, dest)
add_metadata(src, infile_names, infile_basins, dest)

print('Finished')

0 comments on commit 90ad5c8

Please sign in to comment.