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

convert coord btw. UTM and lat/lon #1052

Merged
merged 1 commit into from
Aug 1, 2023
Merged

convert coord btw. UTM and lat/lon #1052

merged 1 commit into from
Aug 1, 2023

Conversation

yunjunz
Copy link
Member

@yunjunz yunjunz commented Aug 1, 2023

Description of proposed changes

Reminders

  • Pass Pre-commit check (green)
  • Pass Codacy code review (green)
  • Pass Circle CI test (green)
  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • If modifying functionality, describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

+ utils.utils0.py: add the following functions to convert coordinates between UTM and lat/lon:
   - utm2latlon()
   - latlon2utm()
   - utm_zone2epsg_code(): bugfix if the latitude letter is not N or S
   - get_lat_lon(): convert UTM to lat/lon to ensure lat/lon output for hyp3 products

+ add utm to the dependency files, since 1) it depends on numpy only; and 2) it's available on PyPI and conda-forge
   - requirements.txt
   - setup.py
@yunjunz yunjunz added this to the UTM coordinate support milestone Aug 1, 2023
@yunjunz yunjunz merged commit 308024a into insarlab:main Aug 1, 2023
4 checks passed
@yunjunz yunjunz deleted the utm branch August 1, 2023 12:34
crs = CRS.from_dict({
'proj': 'utm',
'zone': int(utm_zone[:-1]),
'south': utm_zone[-1].upper() < 'N',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is utm_zone[-1].upper() either "S" or "N"? If so, then this is always false:

>>> 'N' < 'N'
False
>>> 'S' < 'N'
False

Copy link
Contributor

@scottstanie scottstanie Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, this is for the "UTM Zone Designators" from here http://www.jaworski.ca/utmzones.htm ? I had only seen them called "Latitude Bands" as part of MGRS https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system#Latitude_bands

Copy link
Member Author

@yunjunz yunjunz Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have asked for your review here. The UTM_ZONE attribute is grabbed using gdal here. So I am not sure if the last letter is the zone designator (latitude band), or just N / S. The change here assumes the zone designator.

TBH, I don't like the above two, which can be confusing. After searching gdal, the GetUTMZone() seems like a nice solution, with a negative value for the southern hemisphere, which is enough since the zone designator is not really needed for the coordinate conversion. Shall we use this convention instead for UTM_ZONE attribute? How does OPERA handle this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've been trying to just use EPSG codes, since they are more general than UTM and are just as easy to use with pyproj or gdal to warp coordinates due to the nice from_user_input and from_epsg:

In [1]: from pyproj import CRS
# e.g. the EPSG code 32617 is zone 17N
In [2]: CRS.from_epsg(32617) == CRS.from_user_input("epsg:32617") == CRS.from_user_input("32617")
Out[2]: True

In [3]: CRS.from_epsg(32617)
Out[3]:
<Derived Projected CRS: EPSG:32617>
Name: WGS 84 / UTM zone 17N
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Between 84°W and 78°W, northern hemisphere between equator and 84°N, onshore and offshore. Bahamas. Ecuador - north of equator. Canada - Nunavut; Ontario; Quebec. Cayman Islands. Colombia. Costa Rica. Cuba. Jamaica. Nicaragua. Panama. United States (USA).
- bounds: (-84.0, 0.0, -78.0, 84.0)
Coordinate Operation:
- name: UTM zone 17N
- method: Transverse Mercator
Datum: World Geodetic System 1984 ensemble
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

I'm now seeing how the confusion arose... it's very unfortunate that the utm python package links to http://www.jaworski.ca/utmzones.htm , since I'm >90% sure those "Zone designators" are not part of UTM, but rather MGRS:

https://cove.army.gov.au/article/smart-soldier-understanding-military-grid-reference-system

A UTM coordinate comprises a zone number, a hemisphere (N/S), an easting and a northing. [....]

UTM zones are divided in the same way MGRS zones are divided, although there is no letter designation after the zone number. Instead this letter indicator is replaced with an ‘N’ or ‘S’ depending on which hemisphere the map is within.

MGRS is built on top of UTM, so the initial zones are the same... but there's not the latitude bands, just "north/south". I think MGRS the added extra specifiers as a way to quickly communicate locations on maps.

Copy link
Member Author

@yunjunz yunjunz Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the examples and links. We should use EPSG code then as the primary metadata; and the UTM_ZONE without the latitude band as the secondary metadata (to calculate EPSG code if missing), while converting coordinates.

I will fix the utm_zone2epsg_code() with a PR right away.

It seems that pyproj may be enough for the coordinate conversion, and we do not really need the utm package (although it seems faster than pyproj, the speed is not our concern here since the conversion will be rare). Converting UTM to lat/lon seems straightforward, as a similar function already exists (utils.utils0.to_latlon()).

I will work on the function to convert lat/lon to UTM without utm package when I find time. utm provides an solution on calculating the UTM zone number given a lat/lon here.

@yunjunz yunjunz mentioned this pull request Aug 2, 2023
5 tasks
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 7, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 7, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 7, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 7, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 8, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 8, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 8, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in insarlab#1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
yunjunz added a commit that referenced this pull request Aug 8, 2023
+ tropo_pyaps3: bugfix for hyp3 products in UTM coordinates:
   - calc_delay_timeseries(): remove the call of `ut.to_latlon()` while preparing the pixel-wised 2D lat/lon matrices, as `ut.get_lat_lon()` handled the UTM/latlon conversion already in #1052

+ replace `ut.to_latlon()` with `ut.utm2latlon()` as the later supported more file types, in the following occurrences:
   - tropo_pyaps3.get_bounding_box()
   - utils.utils.prepare_geo_los_geometry()

+ utils.utils0.get_lat_lon(): print out UTM/latlon conversion message, to help future tracking/diagnose

+ prep_hyp3: convert UTM to lat/lon for LAT/LON_REF1/2/3/4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hdfeos5: latitude/longitude missing for hyp3 product
2 participants