diff --git a/README.md b/README.md index de60562..9be8862 100644 --- a/README.md +++ b/README.md @@ -4,107 +4,28 @@ Map Italy - Along Track Grid [![License][]][1] --- -### Naming Convention and Metadata +### Generate a regular grid along each COSMO-SkyMed track from the ASI MapItaly project. --- -image -image ---- +

+image +

+ +---- -### CSK Areas Of Interest +**Install Python Dependencies**: -| Area of Interest | ACR | -|-----------------------|-------| -| Milno_D | MIL_D | -| Milano_D | MIL_D | -| Firenze_A | FIR_A | -| Firenze_D | FIR_D | -| Venezia_A | VEN_A | -| Venezia_D | VEN_D | -| Pisa_A | PIS_A | -| Pisa_D | PIS_D | -| Andria_A | AND_A | -| Andria_D | AND_D | -| Etna_A | ETN_A | -| Etna_D | ETN_D | -| Volterra_A | VLE_A | -| Volterra_D | VLE_D | -| Matera_A | MAT_A | -| Matera_D | MAT_D | -| Vicenza_A | VIC_A | -| Vicenza_D | VIC_D | -| Siena_A | SIE_A | -| Siena_D | SIE_D | -| Treviglio_A | TRV_A | -| Treviglio_D | TRV_D | -| Ferrara_A | FER_A | -| Ferrara_D | FER_A | -| Mottola_A | MOT_A | -| Mottola_D | MOT_D | -| Ravenna_A | RVN_A | -| Ravenna_D | RVN_D | -| AbbadiaSanSalvatore_A | ASL_A | -| AbbadiaSanSalvatore_D | ASL_D | -| Verona_A | VER_A | -| Verona_D | VER_D | -| Torino_A | TOR_A | -| Torino_D | TOR_D | -| Aquileia_A | AQL_A | -| Aquileia_D | AQL_D | -| Chiavari_A | CHV_A | -| Chiavari_D | CHV_D | -| Modena_A | MOD_A | -| Modena_D | MOD_D | -| Urbino_A | URB_A | -| Urbino_D | URB_D | -| Colletorto_A | COL_A | -| Colletorto_D | COL_D | -| Cuneo_A | CUN_A | -| Cuneo_D | CUN_D | -| Sardegna | SRD_A | -| Sardegna | SRD_D | -| Belluno_A | BEL_A | -| Belluno_D | BEL_D | -| Assisi_A | ASS_A | -| Assisi_D | ASS_D | -| PiazzaArmerina | PAA_A | -| PiazzaArmerina | PAA_D | -| Crotone_A | CRO_A | -| Crotone_D | CRO_D | -| Tolmezzo_A | TOL_A | -| Tolmezzo_D | TOL_D | -| Noto_A | NTO_A | -| Noto_D | NTO_D | -| Bernina_A | BER_A | -| Bernina_D | BER_D | -| Celano_A | CLN_A | -| Celano_D | CLN_D | -| Genova_A | GEN_A | -| Genova_D | GEN_D | -| Bologna_A | BOL_A | -| Bologna_D | BOL_D | -| Pistoia_A | PST_A | -| Pistoia_D | PST_D | -| NoceraTerinese_A | NTR_A | -| NoceraTerinesa_D | NTR_D | -| Brennero_A | BRN_A | -| Brennero_D | BRN_D | -| Cortina_A | CRT_A | -| Cortina_D | CRT_D | -| Palermo_A | PAL_A | -| Palermo_D | PAL_D | -| Norcia_A | NRI_D | -| Norcia_D | NRI_D | -| Vulcano_A | VLA_A | -| Vulcano_D | VLA_D | -| Mattinata_A | MTI_A | -| Mattinata_D | MTI_D | -| ColliAlbani_A | COA_A | -| ColliAlbani_D | COA_D | +1. Setup minimal **conda** installation using [Miniconda][] ----- +2. Setup a Python Virtual Environment + > - Creating an environment with commands ([Link][]); + > - Creating an environment from an environment.yml file + > ([Link][2]); + + +---- #### PYTHON DEPENDENCIES: - [gdal: Python's GDAL binding.][] - [fiona: Fiona is GDAL’s neat and nimble vector API for Python programmers.][] @@ -117,7 +38,9 @@ Map Italy - Along Track Grid [Language]: https://img.shields.io/badge/python-%3E%3D%203.10-blue [License]: https://img.shields.io/bower/l/MI [1]: ..%20image::%20https://www.python.org/ - +[Miniconda]: https://docs.conda.io/en/latest/miniconda.html +[Link]: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands +[2]: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file [xarray: Labelled multi-dimensional arrays in Python.]:https://docs.xarray.dev [rasterio: access to geospatial raster data]:https://rasterio.readthedocs.io/en/latest/ [gdal: Python's GDAL binding.]: https://gdal.org/index.html diff --git a/data/images/example.jpg b/data/images/example.jpg new file mode 100644 index 0000000..82b43a3 Binary files /dev/null and b/data/images/example.jpg differ diff --git a/data/images/example.png b/data/images/example.png new file mode 100644 index 0000000..1d88186 Binary files /dev/null and b/data/images/example.png differ diff --git a/data/images/grid_CSG1_197_STR-005_DES.png b/data/images/grid_CSG1_197_STR-005_DES.png new file mode 100644 index 0000000..9e00966 Binary files /dev/null and b/data/images/grid_CSG1_197_STR-005_DES.png differ diff --git a/data/images/grid_CSG1_235_STR-007_ASC.png b/data/images/grid_CSG1_235_STR-007_ASC.png new file mode 100644 index 0000000..f84c6fc Binary files /dev/null and b/data/images/grid_CSG1_235_STR-007_ASC.png differ diff --git a/images/csk_frame_grid.png b/images/csk_frame_grid.png deleted file mode 100644 index e3e7b6b..0000000 Binary files a/images/csk_frame_grid.png and /dev/null differ diff --git a/images/csk_frame_grid_zoom.png b/images/csk_frame_grid_zoom.png deleted file mode 100644 index 5238d58..0000000 Binary files a/images/csk_frame_grid_zoom.png and /dev/null differ diff --git a/mapitaly_at_grid.py b/mapitaly_at_grid.py index 5211c1d..8b6c14f 100644 --- a/mapitaly_at_grid.py +++ b/mapitaly_at_grid.py @@ -3,8 +3,8 @@ Written by Enrico Ciraci' January 2024 -Generate a regular grid along each of COSMO-SkyMed tracks -from the MapItaly project. +Generate a regular grid along each COSMO-SkyMed track from +the ASI MapItaly project. See generate_grid.py for more details about the grid generation algorithm. @@ -54,6 +54,7 @@ from tqdm import tqdm import geopandas as gpd from matplotlib import pyplot as plt +import matplotlib.patches as mpatches import cartopy.crs as ccrs # - Custom Dependencies from generate_grid import generate_grid @@ -76,7 +77,7 @@ def main() -> None: help='Output directory.', default=os.getcwd()) # - Buffer distance parser.add_argument('--buffer_dist', '-B', type=float, - help='Buffer distance.', default=2e3) + help='Buffer distance.', default=5e3) # - Number of Cells # - Along Track parser.add_argument('--az_res', '-R', type=float, @@ -158,12 +159,29 @@ def main() -> None: gdf_grid.plot(ax=ax, linewidth=0.2, facecolor="none", edgecolor="b", zorder=2) p_gdf.plot(ax=ax, linewidth=0.1, - facecolor="r", edgecolor="r", zorder=1, alpha=0.5) + facecolor="r", edgecolor="r", zorder=1) ax.set_extent(extent) - gl = ax.gridlines(draw_labels=True) + gl = ax.gridlines(draw_labels=True, linewidth=0.4, color='k', + alpha=0.7, linestyle='--') gl.top_labels = False gl.right_labels = False ax.set_title(f"{sat} - {p} - {s_mode} - {pass_geom}") + # place a text box in upper left in axes coords + text_str = f"{buffer_dist / 1e3} km buffer." + props = dict(boxstyle='square', facecolor='wheat', + alpha=0.5) + plt.text(5.5, 47.7, text_str, transform=ccrs.PlateCarree(), + fontsize=6, verticalalignment='top', weight='bold', + bbox=props) + + lc_colors = { + 'MapItaly Track': "r", # value=0 + 'AT Grid': "b", # value=1 + } + labels, handles = zip( + *[(k, mpatches.Rectangle((0, 0), 1, 1, facecolor=v)) for k, v + in lc_colors.items()]) + ax.legend(handles, labels, loc=4, framealpha=1) plt.savefig(os.path.join(out_dir, f"{out_name}" .replace(".shp", ".png")), dpi=300, bbox_inches='tight') diff --git a/rm_z_coord.py b/rm_z_coord.py index 9b00528..35d93d1 100644 --- a/rm_z_coord.py +++ b/rm_z_coord.py @@ -6,7 +6,8 @@ January 2024 Remove z coordinate from a GeoDataFrame. -Convert a GeoDataFrame with z coordinate to a GeoDataFrame without z coordinate. +Convert a GeoDataFrame with z coordinate to a GeoDataFrame +without z coordinate. """ diff --git a/run.sh b/run.sh index 4c10be9..727ae29 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,2 @@ #!/bin/sh -python generate_grid.py ./data/shapefiles/csk_frame_map_italy_epsg4326.shp --out_dir="/Users/enricociraci/Desktop/test" +python generate_grid.py C:\Users\e.ciraci\Desktop\MapItaly\146.shp --out_dir="C:\Users\e.ciraci\Desktop\MapItaly\test" --plot diff --git a/test/test_generate_grid.py b/test/test_generate_grid.py index 766b182..b68c1a3 100644 --- a/test/test_generate_grid.py +++ b/test/test_generate_grid.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +""" Unit tests for the generate_grid function. """ import geopandas as gpd from shapely.geometry import Polygon from generate_grid import generate_grid diff --git a/test/test_rm_z_coords.py b/test/test_rm_z_coords.py new file mode 100644 index 0000000..02e9092 --- /dev/null +++ b/test/test_rm_z_coords.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +""" Unit tests for the rm_z_coord function. """ +import geopandas as gpd +from shapely.geometry import Polygon +from rm_z_coord import rm_z_coord + + +def test_rm_z_coord(): + # Create a GeoDataFrame for testing + data = {'geometry': [Polygon([(0, 0, 1), (1, 0, 2), + (1, 1, 3), (0, 1, 4)])]} + gdf = gpd.GeoDataFrame(data, crs='EPSG:4326') + + # Apply the function + result_gdf = rm_z_coord(gdf.copy()) + + # Check if the z-coordinate is removed from the geometry + assert all(result_gdf['geometry'].apply(lambda geom: + len(geom.exterior.coords[0]) == 2))