Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev - Nuew Functionalities Added. #10

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 18 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
<img src="images/csk_frame_grid.png" class="align-center" style="width:50.0%" alt="image" />
<img src="images/csk_frame_grid_zoom.png" class="align-center" style="width:50.0%" alt="image" />
---
<p float="left">
<img src="data/images/example.jpg" class="align-center" style="width:90.0%" alt="image" />
</p>


----

### 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.][]
Expand All @@ -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
Expand Down
Binary file added data/images/example.jpg
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 data/images/example.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 data/images/grid_CSG1_197_STR-005_DES.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 data/images/grid_CSG1_235_STR-007_ASC.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 removed images/csk_frame_grid.png
Binary file not shown.
Binary file removed images/csk_frame_grid_zoom.png
Binary file not shown.
28 changes: 23 additions & 5 deletions mapitaly_at_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion rm_z_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""


Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/test_generate_grid.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/test_rm_z_coords.py
Original file line number Diff line number Diff line change
@@ -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))
Loading