How to use the sarpy.deprecated.io.complex.sicd.MetaNode function in sarpy

To help you get started, we’ve selected a few sarpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
for current_collect in collects:
                    if hasattr(current_collect, 'Parameter'):
                        if isinstance(current_collect.Parameter, list):
                            # Multiple parameters
                            current_index = next((int(k.value) for k in current_collect.Parameter
                                                 if k.name.strip() == 'CURRENT_INSTANCE'), None)
                        elif current_collect.Parameter.name.strip() == 'CURRENT_INSTANCE':
                            current_index = int(current_collect.Parameter.value)
                        else:
                            current_index = None
                    else:
                        current_index = None
                    if current_index is not None:
                        matchtype.CurrentIndex = current_index
                    else:
                        matchcollection = MetaNode()
                        if hasattr(current_collect, 'CoreName'):  # Required field
                            matchcollection.CoreName = current_collect.CoreName
                        if hasattr(current_collect, 'Parameter'):
                            matchcollection.Parameter = current_collect.Parameter
                        matchtype.MatchCollection.append(matchcollection)
                if len(matchtype.MatchCollection) == 0:
                    del matchtype.MatchCollection
                newMatchInfo.MatchType.append(matchtype)
            sicd_meta.MatchInfo = newMatchInfo

        # Add AzimAng and LayoverAng to SCPCOA
        sicd_meta = derived_fields(sicd_meta)
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
# Antenna.Tx/Rcv/TwoWay.HPBW no longer a valid field in version 1.0.
        if hasattr(sicd_meta, 'Antenna'):
            if (hasattr(sicd_meta.Antenna, 'Tx') and
                    hasattr(sicd_meta.Antenna.Tx, 'HPBW')):
                del sicd_meta.Antenna.Tx.HPBW
            if (hasattr(sicd_meta.Antenna, 'Rcv') and
                    hasattr(sicd_meta.Antenna.Rcv, 'HPBW')):
                del sicd_meta.Antenna.Rcv.HPBW
            if (hasattr(sicd_meta.Antenna, 'TwoWay') and
                    hasattr(sicd_meta.Antenna.TwoWay, 'HPBW')):
                del sicd_meta.Antenna.TwoWay.HPBW

        # NoiseLevel got its own substructure between SICD 0.5 and SICD 1.0
        if (hasattr(sicd_meta, 'Radiometric') and
                hasattr(sicd_meta.Radiometric, 'NoisePoly')):
            sicd_meta.Radiometric.NoiseLevel = MetaNode()
            sicd_meta.Radiometric.NoiseLevel.NoisePoly = \
                sicd_meta.Radiometric.NoisePoly
            del sicd_meta.Radiometric.NoisePoly
            if hasattr(sicd_meta.Radiometric, 'NoiseLevelType'):
                sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = \
                    sicd_meta.Radiometric.NoiseLevelType
                del sicd_meta.Radiometric.NoiseLevelType
            else:
                # Even if NoiseLevelType wasn't given, we know that relative noise
                # levels should be 1 at SCP.
                if abs(sicd_meta.Radiometric.NoiseLevel.NoisePoly.flatten()[0]-1) < np.spacing(1):
                    sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = 'RELATIVE'
                else:
                    sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = 'ABSOLUTE'

        # MatchInfo
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
del sicd_meta.Radiometric.NoisePoly
            if hasattr(sicd_meta.Radiometric, 'NoiseLevelType'):
                sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = \
                    sicd_meta.Radiometric.NoiseLevelType
                del sicd_meta.Radiometric.NoiseLevelType
            else:
                # Even if NoiseLevelType wasn't given, we know that relative noise
                # levels should be 1 at SCP.
                if abs(sicd_meta.Radiometric.NoiseLevel.NoisePoly.flatten()[0]-1) < np.spacing(1):
                    sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = 'RELATIVE'
                else:
                    sicd_meta.Radiometric.NoiseLevel.NoiseLevelType = 'ABSOLUTE'

        # MatchInfo
        if hasattr(sicd_meta, 'MatchInfo'):
            newMatchInfo = MetaNode()  # Clear this out so we can reconstruct it
            # MatchType was optional field in 0.5
            if hasattr(sicd_meta.MatchInfo, 'Collect'):
                if not isinstance(sicd_meta.MatchInfo.Collect, list):
                    sicd_meta.MatchInfo.Collect = [sicd_meta.MatchInfo.Collect]
                # Making a set to remove duplicates
                types = set(i.MatchType for i in sicd_meta.MatchInfo.Collect)
            else:
                types = set([''])  # TypeID (equivalent of MatchType) required in 1.0
            newMatchInfo.NumMatchTypes = len(types)
            newMatchInfo.MatchType = []
            for current_type in types:
                collects = [j for j in sicd_meta.MatchInfo.Collect
                            if hasattr(j, 'MatchType') and j.MatchType == current_type]
                matchtype = MetaNode()
                matchtype.TypeID = current_type.strip()
                # SICD version 0.5 included current instance as one of the
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
# We might use center processed frequency later
    if (hasattr(meta, 'ImageFormation') and
       hasattr(meta.ImageFormation, 'TxFrequencyProc') and
       hasattr(meta.ImageFormation.TxFrequencyProc, 'MinProc') and
       hasattr(meta.ImageFormation.TxFrequencyProc, 'MaxProc') and
       (not hasattr(meta.RadarCollection, 'RefFreqIndex') or
       (meta.RadarCollection.RefFreqIndex == 0))):
        fc = (meta.ImageFormation.TxFrequencyProc.MinProc +
              meta.ImageFormation.TxFrequencyProc.MaxProc)/2
    # DERIVED: GeoData.SCP
    if (hasattr(meta, 'GeoData') and hasattr(meta.GeoData, 'SCP') and
            hasattr(meta.GeoData.SCP, 'ECF') and not hasattr(meta.GeoData.SCP, 'LLH')):
        llh = gc.ecf_to_geodetic([meta.GeoData.SCP.ECF.X,
                                  meta.GeoData.SCP.ECF.Y,
                                  meta.GeoData.SCP.ECF.Z])[0]
        meta.GeoData.SCP.LLH = MetaNode()
        meta.GeoData.SCP.LLH.Lat = llh[0]
        meta.GeoData.SCP.LLH.Lon = llh[1]
        meta.GeoData.SCP.LLH.HAE = llh[2]
    if (hasattr(meta, 'GeoData') and hasattr(meta.GeoData, 'SCP') and
            hasattr(meta.GeoData.SCP, 'LLH') and not hasattr(meta.GeoData.SCP, 'ECF')):
        ecf = gc.geodetic_to_ecf([meta.GeoData.SCP.LLH.Lat,
                                  meta.GeoData.SCP.LLH.Lon,
                                  meta.GeoData.SCP.LLH.HAE])[0]
        meta.GeoData.SCP.ECF = MetaNode()
        meta.GeoData.SCP.ECF.X = ecf[0]
        meta.GeoData.SCP.ECF.Y = ecf[1]
        meta.GeoData.SCP.ECF.Z = ecf[2]
    # Many fields (particularly in SCPCOA) can be DERIVED from ARPPos, ARPVel and SCP
    if (hasattr(meta, 'SCPCOA') and hasattr(meta.SCPCOA, 'ARPPos') and
            hasattr(meta.SCPCOA, 'ARPVel') and hasattr(meta, 'GeoData') and
            hasattr(meta.GeoData, 'SCP') and hasattr(meta.GeoData.SCP, 'ECF')):
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
if (hasattr(sicd_meta, 'RadarCollection') and
           hasattr(sicd_meta.RadarCollection, 'Area') and
           not hasattr(sicd_meta.RadarCollection.Area, 'Corner') and
           hasattr(sicd_meta.RadarCollection.Area, 'Plane')):
            try:  # If Plane substructure is misformed, this may fail
                plane = sicd_meta.RadarCollection.Area.Plane  # For concise notation
                ref_pt = np.array([plane.RefPt.ECF.X, plane.RefPt.ECF.Y, plane.RefPt.ECF.Z])
                x_uvect = np.array([plane.XDir.UVectECF.X, plane.XDir.UVectECF.Y,
                                    plane.XDir.UVectECF.Z])
                y_uvect = np.array([plane.YDir.UVectECF.X, plane.YDir.UVectECF.Y,
                                    plane.YDir.UVectECF.Z])
                x_offsets = np.array([plane.XDir.FirstLine, plane.XDir.FirstLine,
                                      plane.XDir.NumLines, plane.XDir.NumLines])
                y_offsets = np.array([plane.YDir.FirstSample, plane.YDir.NumSamples,
                                      plane.YDir.NumSamples, plane.YDir.FirstSample])
                sicd_meta.RadarCollection.Area.Corner = MetaNode()
                sicd_meta.RadarCollection.Area.Corner.ACP = [MetaNode() for _ in range(4)]
                for i in range(4):
                    acp_ecf = ref_pt + \
                        x_uvect * plane.XDir.LineSpacing * (x_offsets[i] - plane.RefPt.Line) + \
                        y_uvect * plane.YDir.SampleSpacing * (y_offsets[i] - plane.RefPt.Sample)
                    acp_llh = gc.ecf_to_geodetic(acp_ecf).squeeze()
                    sicd_meta.RadarCollection.Area.Corner.ACP[i].Lat = acp_llh[0]
                    sicd_meta.RadarCollection.Area.Corner.ACP[i].Lon = acp_llh[1]
                    sicd_meta.RadarCollection.Area.Corner.ACP[i].HAE = acp_llh[2]
            except AttributeError:  # OK.  Just means fields missing
                pass
            except ImportError:  # ecf_to_geodetic module not in expected place
                pass  # Just continue without computing corners

        # PolarizationHVAnglePoly no longer a valid field in version 1.0.
        if (hasattr(sicd_meta, 'RadarCollection') and
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
def sicd_update_meta_0_5(sicd_meta):
        """Update a SICD metadata structure from version 0.5 to current version
        (whatever that may be)"""
        # Add RadarCollection.TxPolarization, now required, but optional prior to version 1.0
        if (hasattr(sicd_meta, 'RadarCollection') and
                not hasattr(sicd_meta.RadarCollection, 'TxPolarization') and
                hasattr(sicd_meta.RadarCollection, 'RcvChannels') and
                hasattr(sicd_meta.RadarCollection.RcvChannels, 'ChanParameters')):
            ChanPars = sicd_meta.RadarCollection.RcvChannels.ChanParameters  # Shorten notation
            if isinstance(ChanPars, list):
                sicd_meta.RadarCollection.TxPolarization = 'SEQUENCE'
                # Set comprehension to avoid repeats.  Conversion to list lets us index into it.
                tx_pols = list(set(i.TxRcvPolarization[0] for i in ChanPars))
                if not hasattr(sicd_meta.RadarCollection, 'TxSequence'):
                    sicd_meta.RadarCollection.TxSequence = MetaNode()
                if not hasattr(sicd_meta.RadarCollection.TxSequence, 'TxStep'):
                    # Should always be a list for SEQUENCE
                    sicd_meta.RadarCollection.TxSequence.TxStep = []
                for i in range(len(tx_pols)):
                    if (i + 1) > len(sicd_meta.RadarCollection.TxSequence.TxStep):
                        sicd_meta.RadarCollection.TxSequence.TxStep.append(MetaNode())
                    sicd_meta.RadarCollection.TxSequence.TxStep[i].TxPolarization = tx_pols[i]
                # Note: If there are multiple waveforms and multiple polarizations,
                # there is no deconfliction done here.
            else:
                sicd_meta.RadarCollection.TxPolarization = ChanPars.TxRcvPolarization[0]

        # RadarCollection.Area.Corner was optional in version 0.5, but required in
        # version 1.0.  Fortunately, Corner is easily derived from Plane.
        if (hasattr(sicd_meta, 'RadarCollection') and
           hasattr(sicd_meta.RadarCollection, 'Area') and
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
not hasattr(sicd_meta.RadarCollection, 'TxPolarization') and
                hasattr(sicd_meta.RadarCollection, 'RcvChannels') and
                hasattr(sicd_meta.RadarCollection.RcvChannels, 'ChanParameters')):
            ChanPars = sicd_meta.RadarCollection.RcvChannels.ChanParameters  # Shorten notation
            if isinstance(ChanPars, list):
                sicd_meta.RadarCollection.TxPolarization = 'SEQUENCE'
                # Set comprehension to avoid repeats.  Conversion to list lets us index into it.
                tx_pols = list(set(i.TxRcvPolarization[0] for i in ChanPars))
                if not hasattr(sicd_meta.RadarCollection, 'TxSequence'):
                    sicd_meta.RadarCollection.TxSequence = MetaNode()
                if not hasattr(sicd_meta.RadarCollection.TxSequence, 'TxStep'):
                    # Should always be a list for SEQUENCE
                    sicd_meta.RadarCollection.TxSequence.TxStep = []
                for i in range(len(tx_pols)):
                    if (i + 1) > len(sicd_meta.RadarCollection.TxSequence.TxStep):
                        sicd_meta.RadarCollection.TxSequence.TxStep.append(MetaNode())
                    sicd_meta.RadarCollection.TxSequence.TxStep[i].TxPolarization = tx_pols[i]
                # Note: If there are multiple waveforms and multiple polarizations,
                # there is no deconfliction done here.
            else:
                sicd_meta.RadarCollection.TxPolarization = ChanPars.TxRcvPolarization[0]

        # RadarCollection.Area.Corner was optional in version 0.5, but required in
        # version 1.0.  Fortunately, Corner is easily derived from Plane.
        if (hasattr(sicd_meta, 'RadarCollection') and
           hasattr(sicd_meta.RadarCollection, 'Area') and
           not hasattr(sicd_meta.RadarCollection.Area, 'Corner') and
           hasattr(sicd_meta.RadarCollection.Area, 'Plane')):
            try:  # If Plane substructure is misformed, this may fail
                plane = sicd_meta.RadarCollection.Area.Plane  # For concise notation
                ref_pt = np.array([plane.RefPt.ECF.X, plane.RefPt.ECF.Y, plane.RefPt.ECF.Z])
                x_uvect = np.array([plane.XDir.UVectECF.X, plane.XDir.UVectECF.Y,
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
meta.GeoData.ImageCorners = MetaNode()
    corner_latlons = point.image_to_ground_geo(
        [[0, 0],
         [0, meta.ImageData.NumCols-1],
         [meta.ImageData.NumRows-1, meta.ImageData.NumCols-1],
         [meta.ImageData.NumRows-1, 0]], meta)
    if not hasattr(meta.GeoData.ImageCorners, 'FRFC'):
        meta.GeoData.ImageCorners.FRFC = MetaNode()
    meta.GeoData.ImageCorners.FRFC.Lat = corner_latlons[0, 0]
    meta.GeoData.ImageCorners.FRFC.Lon = corner_latlons[0, 1]
    if not hasattr(meta.GeoData.ImageCorners, 'FRLC'):
        meta.GeoData.ImageCorners.FRLC = MetaNode()
    meta.GeoData.ImageCorners.FRLC.Lat = corner_latlons[1, 0]
    meta.GeoData.ImageCorners.FRLC.Lon = corner_latlons[1, 1]
    if not hasattr(meta.GeoData.ImageCorners, 'LRLC'):
        meta.GeoData.ImageCorners.LRLC = MetaNode()
    meta.GeoData.ImageCorners.LRLC.Lat = corner_latlons[2, 0]
    meta.GeoData.ImageCorners.LRLC.Lon = corner_latlons[2, 1]
    if not hasattr(meta.GeoData.ImageCorners, 'LRFC'):
        meta.GeoData.ImageCorners.LRFC = MetaNode()
    meta.GeoData.ImageCorners.LRFC.Lat = corner_latlons[3, 0]
    meta.GeoData.ImageCorners.LRFC.Lon = corner_latlons[3, 1]
github ngageoint / sarpy / sarpy / deprecated / io / complex / sicd.py View on Github external
if hasattr(meta, 'RMA') and hasattr(meta.RMA, 'ImageType'):
                    rmatype = meta.RMA.ImageType.upper()
                    # RMAT/RMCR cases
                    if rmatype in ('RMAT', 'RMCR'):
                        if set_default_values:
                            if not hasattr(meta.Grid, 'ImagePlane'):
                                meta.Grid.ImagePlane = 'SLANT'
                            if not hasattr(meta.Grid, 'Type'):
                                # DEFAULT: XCTYAT grid is the natural result of RMA/RMAT
                                if rmatype == 'RMAT':
                                    meta.Grid.Type = 'XCTYAT'
                                # DEFAULT: XRGYCR grid is the natural result of RMA/RMCR
                                elif rmatype == 'RMCR':
                                    meta.Grid.Type = 'XRGYCR'
                            if not hasattr(meta.RMA, rmatype):
                                setattr(meta.RMA, rmatype, MetaNode())
                            # DEFAULT: Set PosRef/VelRef to SCPCOA Pos/Vel
                            rmafield = getattr(meta.RMA, rmatype)
                            if not hasattr(rmafield, 'PosRef'):
                                setattr(rmafield, 'PosRef', copy.deepcopy(meta.SCPCOA.ARPPos))
                            if not hasattr(rmafield, 'VelRef'):
                                setattr(rmafield, 'VelRef', copy.deepcopy(meta.SCPCOA.ARPVel))
                        if hasattr(meta.RMA, rmatype):
                            if (hasattr(getattr(meta.RMA, rmatype), 'PosRef') and
                               hasattr(getattr(meta.RMA, rmatype), 'VelRef')):
                                rmafield = getattr(meta.RMA, rmatype)
                                PosRef = np.array([rmafield.PosRef.X,
                                                   rmafield.PosRef.Y,
                                                   rmafield.PosRef.Z])
                                VelRef = np.array([rmafield.VelRef.X,
                                                   rmafield.VelRef.Y,
                                                   rmafield.VelRef.Z])