|
7 | 7 |
|
8 | 8 | import h5py |
9 | 9 | import isce3 |
10 | | -from isce3.product.cf_conventions import get_grid_mapping_name |
11 | 10 | import journal |
12 | 11 | import numpy as np |
13 | 12 | from isce3.core.types import complex32, to_complex32 |
14 | 13 | from isce3.io import HDF5OptimizedReader, optimize_chunk_size |
15 | 14 | from nisar.h5 import cp_h5_meta_data |
| 15 | +from nisar.products.projection import build_projection_dataset_attrs_dict |
16 | 16 | from nisar.products.readers import SLC |
17 | | -from osgeo import osr |
18 | 17 |
|
19 | 18 |
|
20 | 19 | def get_dataset_output_options(cfg: dict): |
@@ -769,100 +768,19 @@ def set_get_geo_info(hdf5_obj, root_ds, geo_grid, z_vect=None, |
769 | 768 | shape=(), |
770 | 769 | dtype=np.uint32, |
771 | 770 | data=epsg_code) |
772 | | - # Set up osr for wkt |
773 | | - srs = osr.SpatialReference() |
774 | | - srs.ImportFromEPSG(epsg_code) |
| 771 | + |
| 772 | + projds_attrs = build_projection_dataset_attrs_dict(epsg_code) |
| 773 | + projds.attrs.update(projds_attrs) |
775 | 774 |
|
776 | 775 | # Add projection description |
777 | 776 | projds.attrs['description'] = np.bytes_('Product map grid projection: EPSG code, ' |
778 | 777 | 'with additional projection information as HDF5 Attributes') |
779 | 778 |
|
780 | | - # WGS84 ellipsoid |
781 | | - projds.attrs['semi_major_axis'] = 6378137.0 |
782 | | - projds.attrs['inverse_flattening'] = 298.257223563 |
783 | | - projds.attrs['ellipsoid'] = np.bytes_("WGS84") |
784 | | - |
785 | | - # Additional fields |
786 | | - projds.attrs['epsg_code'] = epsg_code |
787 | | - |
788 | | - # CF 1.7+ requires this attribute to be named "crs_wkt" |
789 | | - # spatial_ref is old GDAL way. Using that for testing only. |
790 | | - # For NISAR replace with "crs_wkt" |
791 | | - projds.attrs['spatial_ref'] = np.bytes_(srs.ExportToWkt()) |
792 | | - |
793 | | - # Here we have handcoded the attributes for the different cases |
794 | | - # Recommended method is to use pyproj.CRS.to_cf() as shown above |
795 | | - # To get complete set of attributes. |
796 | | - |
797 | | - sr = osr.SpatialReference() |
798 | | - sr.ImportFromEPSG(epsg_code) |
799 | | - |
800 | | - projds.attrs['grid_mapping_name'] = np.bytes_(get_grid_mapping_name(sr)) |
801 | | - |
802 | | - # Set up units |
803 | | - # Geodetic latitude / longitude |
804 | | - if epsg_code == 4326: |
805 | | - # Set up grid mapping |
806 | | - projds.attrs['longitude_of_prime_meridian'] = 0.0 |
807 | | - else: |
808 | | - # UTM zones |
809 | | - if ((epsg_code > 32600 and |
810 | | - epsg_code < 32661) or |
811 | | - (epsg_code > 32700 and |
812 | | - epsg_code < 32761)): |
813 | | - # Set up grid mapping |
814 | | - projds.attrs['utm_zone_number'] = epsg_code % 100 |
815 | | - projds.attrs["longitude_of_central_meridian"] = srs.GetProjParm( |
816 | | - osr.SRS_PP_CENTRAL_MERIDIAN) |
817 | | - projds.attrs["scale_factor_at_central_meridian"] = srs.GetProjParm( |
818 | | - osr.SRS_PP_SCALE_FACTOR) |
819 | | - |
820 | | - # Polar Stereo North |
821 | | - elif epsg_code == 3413: |
822 | | - # Set up grid mapping |
823 | | - projds.attrs['latitude_of_projection_origin'] = 90.0 |
824 | | - projds.attrs['standard_parallel'] = 70.0 |
825 | | - projds.attrs['straight_vertical_longitude_from_pole'] = -45.0 |
826 | | - |
827 | | - # Polar Stereo south |
828 | | - elif epsg_code == 3031: |
829 | | - # Set up grid mapping |
830 | | - projds.attrs['latitude_of_projection_origin'] = -90.0 |
831 | | - projds.attrs['standard_parallel'] = -71.0 |
832 | | - projds.attrs['straight_vertical_longitude_from_pole'] = 0.0 |
833 | | - |
834 | | - # EASE 2 for soil moisture L3 |
835 | | - elif epsg_code == 6933: |
836 | | - # Set up grid mapping |
837 | | - projds.attrs['longitude_of_central_meridian'] = 0.0 |
838 | | - projds.attrs['standard_parallel'] = 30.0 |
839 | | - |
840 | | - # Europe Equal Area for Deformation map (to be implemented in isce3) |
841 | | - elif epsg_code == 3035: |
842 | | - # Set up grid mapping |
843 | | - projds.attrs['standard_parallel'] = -71.0 |
844 | | - projds.attrs['straight_vertical_longitude_from_pole'] = 0.0 |
845 | | - |
846 | | - else: |
847 | | - raise NotImplementedError( |
848 | | - f'EPSG {epsg_code} waiting for implementation / not supported in ISCE3') |
849 | | - |
| 779 | + if epsg_code != 4326: |
850 | 780 | # Setup common parameters |
851 | 781 | xds.attrs['long_name'] = np.bytes_("X coordinate of projection") |
852 | 782 | yds.attrs['long_name'] = np.bytes_("Y coordinate of projection") |
853 | 783 |
|
854 | | - projds.attrs['false_easting'] = sr.GetProjParm(osr.SRS_PP_FALSE_EASTING) |
855 | | - projds.attrs['false_northing'] = sr.GetProjParm( |
856 | | - osr.SRS_PP_FALSE_NORTHING) |
857 | | - |
858 | | - projds.attrs['longitude_of_projection_origin'] = sr.GetProjParm( |
859 | | - osr.SRS_PP_LONGITUDE_OF_ORIGIN) |
860 | | - |
861 | | - if epsg_code not in [3413, 3031]: |
862 | | - projds.attrs['latitude_of_projection_origin'] = sr.GetProjParm( |
863 | | - osr.SRS_PP_LATITUDE_OF_ORIGIN) |
864 | | - |
865 | | - |
866 | 784 | if z_vect is not None: |
867 | 785 | return zds, yds, xds |
868 | 786 | return yds, xds |
@@ -924,25 +842,33 @@ def add_radar_grid_cubes_to_hdf5(hdf5_obj, cube_group_name, geogrid, |
924 | 842 | cube_group, 'losUnitVectorX', np.float32, cube_shape, |
925 | 843 | zds=zds, yds=yds, xds=xds, |
926 | 844 | long_name='LOS unit vector X', |
927 | | - descr='East component of unit vector of LOS from target to sensor', |
| 845 | + descr='East component of the line-of-sight (LOS) unit vector, defined from ' \ |
| 846 | + 'the target to the sensor, expressed in the east-north-up (ENU) coordinate ' \ |
| 847 | + 'system with its origin at the target location', |
928 | 848 | units='1', valid_min=-1.0, valid_max=1.0, **create_dataset_kwargs) |
929 | 849 | los_unit_vector_y_raster = _get_raster_from_hdf5_ds( |
930 | 850 | cube_group, 'losUnitVectorY', np.float32, cube_shape, |
931 | 851 | zds=zds, yds=yds, xds=xds, |
932 | 852 | long_name='LOS unit vector Y', |
933 | | - descr='North component of unit vector of LOS from target to sensor', |
| 853 | + descr='North component of the line-of-sight (LOS) unit vector, defined from ' \ |
| 854 | + 'the target to the sensor, expressed in the east-north-up (ENU) coordinate ' \ |
| 855 | + 'system with its origin at the target location', |
934 | 856 | units='1', valid_min=-1.0, valid_max=1.0, **create_dataset_kwargs) |
935 | 857 | along_track_unit_vector_x_raster = _get_raster_from_hdf5_ds( |
936 | 858 | cube_group, 'alongTrackUnitVectorX', np.float32, cube_shape, |
937 | 859 | zds=zds, yds=yds, xds=xds, |
938 | 860 | long_name='Along-track unit vector X', |
939 | | - descr='East component of unit vector along ground track', |
| 861 | + descr='East component of the along-track unit vector at the target location, ' \ |
| 862 | + 'expressed in the east-north-up (ENU) coordinate system and projected ' \ |
| 863 | + 'onto the horizontal plane (i.e., excluding the up component)', |
940 | 864 | units='1', valid_min=-1.0, valid_max=1.0, **create_dataset_kwargs) |
941 | 865 | along_track_unit_vector_y_raster = _get_raster_from_hdf5_ds( |
942 | 866 | cube_group, 'alongTrackUnitVectorY', np.float32, cube_shape, |
943 | 867 | zds=zds, yds=yds, xds=xds, |
944 | 868 | long_name='Along-track unit vector Y', |
945 | | - descr='North component of unit vector along ground track', |
| 869 | + descr='North component of the along-track unit vector at the target location, ' \ |
| 870 | + 'expressed in the east-north-up (ENU) coordinate system and projected ' \ |
| 871 | + 'onto the horizontal plane (i.e., excluding the up component)', |
946 | 872 | units='1', valid_min=-1.0, valid_max=1.0, **create_dataset_kwargs) |
947 | 873 | elevation_angle_raster = _get_raster_from_hdf5_ds( |
948 | 874 | cube_group, 'elevationAngle', np.float32, cube_shape, |
|
0 commit comments