Skip to content
Open
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
8 changes: 5 additions & 3 deletions python/packages/nisar/antenna/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from nisar.mixed_mode.logic import PolChannelSet
from nisar.products.readers.antenna import AntennaParser
from nisar.products.readers.instrument import InstrumentParser
from nisar.products.readers.Raw import Raw
from nisar.products.readers.Raw import Raw, chirpcorrelator_caltype_from_raw
from nisar.antenna import TxTrmInfo, RxTrmInfo, TxBMF, RxDBF
from nisar.antenna.beamformer import get_pulse_index
import numpy as np
Expand Down Expand Up @@ -114,8 +114,10 @@ def build_tx_trm(raw: Raw, pulse_times: np.ndarray, freq_band: str,
"""Build TxTrmInfo object """
# Parse Tx-related Cal stuff used for Tx BMF
tx_chanl = raw.getListOfTxTRMs(freq_band, tx_pol)
corr_tap2 = raw.getChirpCorrelator(freq_band, tx_pol)[..., 1]
cal_type = raw.getCalType(freq_band, tx_pol)
# get chirp correlator and cal type for co-pol product
chp_corr, cal_type = chirpcorrelator_caltype_from_raw(
raw, txrx_pol=2 * tx_pol)
corr_tap2 = chp_corr[..., 1]
# build TxTRM from Tx Cal stuff w/o optional "tx_phase"
return TxTrmInfo(pulse_times, tx_chanl, corr_tap2,
cal_type)
Expand Down
39 changes: 30 additions & 9 deletions python/packages/nisar/noise/noise_estimation_from_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from nisar.antenna import get_calib_range_line_idx
from nisar.log import set_logger
from isce3.core import DateTime, TimeDelta
from nisar.products.readers.Raw import (
chirpcorrelator_caltype_from_raw,
is_raw_quad_pol,
first_tx_pol_for_quad,
opposite_pol
)

# Global Noise-related Constants
# Min number of range bins recommended per noise range block
Expand Down Expand Up @@ -203,7 +209,7 @@ def extract_noise_only_lines(raw, freq_band, txrx_pol, max_lines=18944):
# special RCIDs (NISAR mode numbers) to be treated as noise-only product
rcid_special = (1, 2, 3)
# get noise-only range lines if any
cal_path_mask = raw.getCalType(freq_band, tx=txrx_pol[0])
_, cal_path_mask = chirpcorrelator_caltype_from_raw(raw, txrx_pol=txrx_pol)
_, _, _, noise_index = get_calib_range_line_idx(cal_path_mask)
# check if it is a special case with RCID=1,2,3 where there is no
# noise-only range line and TX=OFF.
Expand Down Expand Up @@ -456,7 +462,11 @@ def est_noise_power_from_raw(
f'Number of range blocks is smaller than min {n_rg_blk_min}'
)
logger.info(f'Number of range blocks -> {num_rng_block}')

# check if product is quad
is_quad_pol = is_raw_quad_pol(raw)
if is_quad_pol:
first_tx_pol = first_tx_pol_for_quad(raw)
logger.info(f'Quad pol product w/ first {first_tx_pol}-pol TX!')
# container for all noise products
noise_prods = []
# if quad pol, then do MVE or MEE
Expand All @@ -467,8 +477,9 @@ def est_noise_power_from_raw(
# L-band NISAR.
# loop over freq bands
for freq_band in frq_pol:
# check if it is QP and product differentiation is set to True
if dif_quad and _is_quad_pol(frq_pol[freq_band]):
# check if it contains all linear pol combination and
# product differentiation is set to True
if dif_quad and _contains_all_linear_pols(frq_pol[freq_band]):
logger.info('The difference of co-pol and cx-pol with'
' the same RX pol will be used in Noise est!')
# let's combine datasets with the same RX Pol
Expand Down Expand Up @@ -559,7 +570,9 @@ def est_noise_power_from_raw(
)
noise_prods.append(ns_prod)

else: # other pol types than QP
else: # no polarimetric diff!
# For qaud pol, use noise range lines of the
# first TX pol for the other TX pol.
for txrx_pol in frq_pol[freq_band]:
logger.info(
'Processing individually frequency band '
Expand All @@ -575,12 +588,20 @@ def est_noise_power_from_raw(
# calculate approximate ENBW for relatively white noise!
enbw = enbw_from_raw(raw, freq_band, txrx_pol[0])
logger.info(f'Approximate ENBW in (MHz) -> {enbw * 1e-6}')
# check if quad pol per telemetry then use the oppsoite
# TX pol for noise range lines if that pol is not the
# first TX pol.
txrx_p = txrx_pol
if is_quad_pol and txrx_pol[0] != first_tx_pol:
txrx_p = opposite_pol(txrx_pol[0]) + txrx_pol[1]
logger.warning(f'Use noise-only range lines from {txrx_p} '
f'for {txrx_pol}!')
# parse one noise dataset
# loop over several AZ blocks of noise-only range lines
noise_power_azblk = []
az_dt_utc = []
for (dset_noise, idx_rgl_ns) in extract_noise_only_lines(
raw, freq_band, txrx_pol, max_lines):
raw, freq_band, txrx_p, max_lines):
if exclude_first_last:
logger.info(
'Exclude the first and last noise range lines.')
Expand Down Expand Up @@ -641,10 +662,10 @@ def _pow2db(p: float) -> float:
return 10 * np.log10(p)


def _is_quad_pol(txrx_pols):
def _contains_all_linear_pols(txrx_pols):
"""
Whether the list of two-char TxRx Pols represents linear quad
polarization or not.
Whether the list of two-char TxRx Pols represents all
combinations of linear polarizations or not.

Parameters
----------
Expand Down
Loading
Loading