@@ -756,66 +756,81 @@ def convert_to_int(swath):
756
756
vectorized_convert = np .vectorize (convert_to_int )
757
757
swathNumber = vectorized_convert (ap_swath )
758
758
759
- dim_0 = max (np .bincount (swathNumber ))
760
- max_length = max (array .shape [0 ] for array in ap_elevationAngle )
761
- dim_1 = max_length
759
+ dim_azimuthTime = max (np .bincount (swathNumber ))
760
+ dim_slantRangeTime = max (array .shape [0 ] for array in ap_elevationAngle )
761
+
762
+ include_roll = len (ap_roll ) != 0
762
763
763
764
# Create 2Ds arrays
764
- elevAngle2d = np .full ((len (ap_elevationAngle ), max_length ), np .nan )
765
- gain2d = np .full ((len (ap_elevationPattern ), max_length ), np .nan )
766
- slantRangeTime2d = np .full ((len (ap_slantRangeTime ), max_length ), np .nan )
767
- incAngle2d = np .full ((len (ap_incidenceAngle ), max_length ), np .nan )
765
+ elevAngle2d = np .full ((len (ap_elevationAngle ), dim_slantRangeTime ), np .nan )
766
+ gain2d = np .full ((len (ap_elevationPattern ), dim_slantRangeTime ), np .nan )
767
+ slantRangeTime2d = np .full ((len (ap_slantRangeTime ), dim_slantRangeTime ), np .nan )
768
+ incAngle2d = np .full ((len (ap_incidenceAngle ), dim_slantRangeTime ), np .nan )
768
769
770
+
769
771
for i in range (len (ap_elevationAngle )):
770
772
elevAngle2d [i , :ap_elevationAngle [i ].shape [0 ]] = ap_elevationAngle [i ]
771
- gain2d [i , :ap_elevationAngle [i ].shape [0 ]] = np .sqrt (ap_elevationPattern [i ][::2 ]** 2 + ap_elevationPattern [i ][1 ::2 ]** 2 )
773
+
774
+ if ap_elevationAngle [i ].shape [0 ] != ap_elevationPattern [i ].shape [0 ] :
775
+ gain2d [i , :ap_elevationAngle [i ].shape [0 ]] = np .sqrt (ap_elevationPattern [i ][::2 ]** 2 + ap_elevationPattern [i ][1 ::2 ]** 2 )
776
+ else :
777
+ #logging.warn("antenna pattern is not given in complex values. You probably use an old file\n" + e)
778
+ gain2d [i , :ap_elevationAngle [i ].shape [0 ]] = ap_elevationPattern [i ]
779
+
772
780
slantRangeTime2d [i , :ap_slantRangeTime [i ].shape [0 ]] = ap_slantRangeTime [i ]
773
781
incAngle2d [i , :ap_incidenceAngle [i ].shape [0 ]] = ap_incidenceAngle [i ]
774
782
775
783
776
- swath_number_2d = np .full ((len (np .unique (swathNumber )), dim_0 ), np .nan )
777
- roll_angle_2d = np .full ((len (np .unique (swathNumber )), dim_0 ), np .nan )
778
- azimuthTime_2d = np .full ((len (np .unique (swathNumber )), dim_0 ), np .nan )
779
- terrainHeight_2d = np .full ((len (np .unique (swathNumber )), dim_0 ), np .nan )
784
+ swath_number_2d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime ), np .nan )
785
+ roll_angle_2d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime ), np .nan )
786
+ azimuthTime_2d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime ), np .nan )
787
+ terrainHeight_2d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime ), np .nan )
780
788
781
- slantRangeTime_2d = np .full ((len (np .unique (swathNumber )), dim_1 ), np .nan )
789
+ slantRangeTime_2d = np .full ((len (np .unique (swathNumber )), dim_slantRangeTime ), np .nan )
782
790
783
- elevationAngle_3d = np .full ((len (np .unique (swathNumber )), dim_0 , dim_1 ), np .nan )
784
- incidenceAngle_3d = np .full ((len (np .unique (swathNumber )), dim_0 , dim_1 ), np .nan )
785
- gain3d = np .full ((len (np .unique (swathNumber )), dim_0 , dim_1 ), np .nan )
791
+ elevationAngle_3d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime , dim_slantRangeTime ), np .nan )
792
+ incidenceAngle_3d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime , dim_slantRangeTime ), np .nan )
793
+ gain3d = np .full ((len (np .unique (swathNumber )), dim_azimuthTime , dim_slantRangeTime ), np .nan )
786
794
795
+
787
796
for i , swath_number in enumerate (np .unique (swathNumber )):
788
- for j in range (0 , max_length ):
789
- length_dim0 = len (ap_roll [swathNumber == swath_number ])
790
- swath_number_2d [i , :length_dim0 ] = swathNumber [swathNumber == swath_number ]
791
- roll_angle_2d [i , :length_dim0 ] = ap_roll [swathNumber == swath_number ]
792
- azimuthTime_2d [i , :length_dim0 ] = ap_azimuthTime [swathNumber == swath_number ]
793
- terrainHeight_2d [i , :length_dim0 ] = ap_terrainHeight [swathNumber == swath_number ]
794
- elevationAngle_3d [i ,:length_dim0 ,j ]= elevAngle2d [swathNumber == swath_number ,j ]
795
- incidenceAngle_3d [i ,:length_dim0 ,j ]= incAngle2d [swathNumber == swath_number ,j ]
796
- gain3d [i ,:length_dim0 ,j ]= gain2d [swathNumber == swath_number ,j ]
797
+ length_dim0 = len (ap_azimuthTime [swathNumber == swath_number ])
798
+ swath_number_2d [i , :length_dim0 ] = swathNumber [swathNumber == swath_number ]
799
+ azimuthTime_2d [i , :length_dim0 ] = ap_azimuthTime [swathNumber == swath_number ]
800
+ terrainHeight_2d [i , :length_dim0 ] = ap_terrainHeight [swathNumber == swath_number ]
797
801
slantRangeTime_2d [i , :] = slantRangeTime2d [i , :]
798
802
803
+ if include_roll :
804
+ roll_angle_2d [i , :length_dim0 ] = ap_roll [swathNumber == swath_number ]
799
805
806
+ for j in range (0 , dim_slantRangeTime ):
807
+ elevationAngle_3d [i ,:length_dim0 ,j ]= elevAngle2d [swathNumber == swath_number ,j ]
808
+ incidenceAngle_3d [i ,:length_dim0 ,j ]= incAngle2d [swathNumber == swath_number ,j ]
809
+ gain3d [i ,:length_dim0 ,j ]= gain2d [swathNumber == swath_number ,j ]
810
+
800
811
azimuthTime_2d = azimuthTime_2d .astype ('datetime64[ns]' )
801
812
802
813
# return a Dataset
803
814
ds = xr .Dataset ({
804
- 'slantRangeTime' : (['swath_nb' , 'dim_1 ' ], slantRangeTime_2d ),
805
- 'swath' : (['swath_nb' , 'dim_0 ' ], swath_number_2d ),
806
- 'roll' : (['swath_nb' , 'dim_0 ' ], roll_angle_2d ),
807
- 'azimuthTime' : (['swath_nb' , 'dim_0 ' ], azimuthTime_2d ),
808
- 'terrainHeight' : (['swath_nb' , 'dim_0 ' ], terrainHeight_2d ),
809
- 'elevationAngle' : (['swath_nb' , 'dim_0 ' ,'dim_1 ' ],elevationAngle_3d ),
810
- 'incidenceAngle' : (['swath_nb' , 'dim_0 ' ,'dim_1 ' ],incidenceAngle_3d ),
811
- 'gain' : (['swath_nb' , 'dim_0 ' ,'dim_1 ' ],gain3d ),
815
+ 'slantRangeTime' : (['swath_nb' , 'dim_slantRangeTime ' ], slantRangeTime_2d ),
816
+ 'swath' : (['swath_nb' , 'dim_azimuthTime ' ], swath_number_2d ),
817
+ 'roll' : (['swath_nb' , 'dim_azimuthTime ' ], roll_angle_2d ),
818
+ 'azimuthTime' : (['swath_nb' , 'dim_azimuthTime ' ], azimuthTime_2d ),
819
+ 'terrainHeight' : (['swath_nb' , 'dim_azimuthTime ' ], terrainHeight_2d ),
820
+ 'elevationAngle' : (['swath_nb' , 'dim_azimuthTime ' ,'dim_slantRangeTime ' ],elevationAngle_3d ),
821
+ 'incidenceAngle' : (['swath_nb' , 'dim_azimuthTime ' ,'dim_slantRangeTime ' ],incidenceAngle_3d ),
822
+ 'gain' : (['swath_nb' , 'dim_azimuthTime ' ,'dim_slantRangeTime ' ],gain3d ),
812
823
},
813
824
coords = {'swath_nb' : np .unique (swathNumber )}
814
825
)
815
- ds .attrs ["dim_0" ] = "max dimension of azimuthTime for a swath"
816
- ds .attrs ["dim_1" ] = "max dimension of slantRangeTime for a swath"
817
- ds .attrs ["comment" ] = "for example, if swath Y is smaller than swath X, user has to remove nan to get the dims of the swath"
818
-
826
+ ds .attrs ["dim_azimuthTime" ] = "max dimension of azimuthTime for a swath"
827
+ ds .attrs ["dim_slantRangeTime" ] = "max dimension of slantRangeTime for a swath"
828
+ ds .attrs ["comment" ] = "The antenna pattern data set record contains a list of vectors of the \
829
+ antenna elevation pattern values that have been updated along track\
830
+ and used to correct the radiometry during image processing."
831
+ ds .attrs ["example" ] = "for example, if swath Y is smaller than swath X, user has to remove nan to get the dims of the swath"
832
+ ds .attrs ["source" ] = "Sentinel-1 Product Specification"
833
+
819
834
return ds
820
835
821
836
def swath_merging (sm_swath ,sm_nbPerSwat ,sm_azimuthTime ,sm_firstAzimuthLine ,sm_lastAzimuthLine ,sm_firstRangeSample ,sm_lastRangeSample ):
@@ -843,15 +858,19 @@ def convert_to_int(swath):
843
858
swathNumber = vectorized_convert (repeated_swaths )
844
859
845
860
ds = xr .Dataset ({
846
- 'swaths' : (['dim_0 ' ], swathNumber ),
847
- 'azimuthTime' : (['dim_0 ' ], sm_azimuthTime ),
848
- 'firstAzimuthLine' : (['dim_0 ' ], sm_firstAzimuthLine ),
849
- 'lastAzimuthLine' : (['dim_0 ' ], sm_lastAzimuthLine ),
850
- 'firstRangeSample' : (['dim_0 ' ], sm_firstRangeSample ),
851
- 'lastRangeSample' : (['dim_0 ' ], sm_lastRangeSample ),
861
+ 'swaths' : (['dim_azimuthTime ' ], swathNumber ),
862
+ 'azimuthTime' : (['dim_azimuthTime ' ], sm_azimuthTime ),
863
+ 'firstAzimuthLine' : (['dim_azimuthTime ' ], sm_firstAzimuthLine ),
864
+ 'lastAzimuthLine' : (['dim_azimuthTime ' ], sm_lastAzimuthLine ),
865
+ 'firstRangeSample' : (['dim_azimuthTime ' ], sm_firstRangeSample ),
866
+ 'lastRangeSample' : (['dim_azimuthTime ' ], sm_lastRangeSample ),
852
867
},
853
868
)
854
- ds .attrs ["comment" ] = "the order of information is preserved in the dataset"
869
+ ds .attrs ["comment" ] = "The swath merging data set record contains information about how \
870
+ multiple swaths were stitched together to form one large contiguous \
871
+ swath. This data set record only applies to IW and EW GRD \
872
+ products"
873
+ ds .attrs ["source" ] = "Sentinel-1 Product Specification"
855
874
856
875
return ds
857
876
0 commit comments