You are on page 1of 8

28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [1]: import netCDF4 as nc


from obspy.io.segy.segy import _read_segy
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib import transforms
import numpy as np

In [2]: f=nc.Dataset('C:/Users/Pc/Desktop/Geologia/GeoFisica/Python/POLARGAP_P27A.nc','r'

In [3]: print(f.ncattrs())

['title', 'summary', 'history', 'keywords', 'Conventions', 'standard_name_vocab


ulary', 'acknowlegement', 'institution', 'license', 'location', 'instrument',
'platform', 'source', 'time_coverage_start', 'time_coverage_end', 'flight', 'ca
mpaign', 'creator_name', 'geospatial_lat_min', 'geospatial_lat_max', 'geospatia
l_lon_min', 'geospatial_lon_max', 'radar_parameters', 'antenna', 'digitiser',
'processing', 'resolution', 'GPS', 'projection', 'references', 'metadata_link',
'related_datasets', 'publisher_name', 'publisher_type', 'publisher_email', 'pub
lisher_link', 'comment']

In [4]: print(f)

More information on the radar system and processing can be found in: Corr
et al. 2007 (Terra Antartica Reports, 13, 55-63) and Heliere et al. 2007 (do
i: 10.1109/TGRS.2007.897433)

history: This NetCDF contains the deep-sounding chirp and the shallow-sou
nding pulse-acquired data (see the 'radar_parameters' attribute below) in the
following structure:

'chirp_data': Radar data for the processed (coherent) chirp

'pulse_data': Radar data for the processed (coherent) pulse

Note that from flight line P24- onwards, there is no polarised data for t
his survey.

IMPORTANT: Please note that the chirp radar variable ('chirp_data') does
NOT have the same length as the pulse radar variable 'pulse_data'

as the pulse data was processed with a greater amount of decimation compa
red with the chirp variable, with the consequence that the pulse data variabl
e

contain more elements than the chirp data variable and the associated 1-D
variables in this NetCDF. All 1-D variables found here are thus aligned to th
e trace number

in the chirp data variable and cannot be used to match the same trace num
In [5]: print(f.dimensions.keys())

dict_keys(['traces_chirp', 'traces_pulse', 'fast_time'])

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 1/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [6]: for dim in f.dimensions.values():


print(dim)

<class 'netCDF4._netCDF4.Dimension'>: name = 'traces_chirp', size = 32047

<class 'netCDF4._netCDF4.Dimension'>: name = 'traces_pulse', size = 499920

<class 'netCDF4._netCDF4.Dimension'>: name = 'fast_time', size = 1536

In [7]: print(f.variables.keys())

dict_keys(['traces_chirp', 'traces_pulse', 'fast_time', 'x_coordinates', 'y_coo


rdinates', 'chirp_data', 'pulse_data', 'PriNumber_chirp', 'PriNumber_pulse', 'l
ongitude_layerData', 'latitude_layerData', 'UTC_time_layerData', 'aircraft_alti
tude_layerData', 'terrainClearanceAircraft_layerData', 'surface_source_layerDat
a', 'surface_altitude_layerData', 'surface_pick_layerData', 'bed_altitude_layer
Data', 'bed_pick_layerData', 'land_ice_thickness_layerData'])

In [8]: for var in f.variables.values():


print(var)

float32 bed_pick_layerData(traces_chirp)

_FillValue: -9999.0

long_name: Location down trace of bed pick (BAS system)

short_name: botPickLoc

units: microseconds

unlimited dimensions:

current shape = (32047,)

filling on

<class 'netCDF4._netCDF4.Variable'>

float32 land_ice_thickness_layerData(traces_chirp)

_FillValue: -9999.0

long_name: Ice thickness for the trace number obtained by multiplying the
two-way travel-time between the picked ice surface and ice sheet bed by 168
m/microseconds and applying a 10 meter correction for the firn layer

standard_name: land_ice_thickness

short_name: iceThick

units: m

unlimited dimensions:

current shape = (32047,)

filling on

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 2/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [10]: # radar variables


traces_nc = f.variables['traces_pulse'][:].data # read in traces array
chirpData = f.variables['chirp_data'][:].data # read in chirp radar data array
pulseData = f.variables['pulse_data'][:].data # read in pulse radar data array

chirpData = 10*np.log10(chirpData) # convert the data from power to decibels usin
pulseData = 10*np.log10(pulseData) # convert the data from power to decibels usin

# X and Y coordinates
x_nc = f.variables['x_coordinates'][:].data # read in x positions array (Polar St
y_nc = f.variables['y_coordinates'][:].data # read in y positions array (Polar St
x_nc_km = np.divide(x_nc,1000) # transform meters to kilometers
y_nc_km = np.divide(y_nc,1000) # transform meters to kilometers

# surface and bed picks
surf_pick = f.variables['surface_pick_layerData'][:].data # read in surface pick
bed_pick = f.variables['bed_pick_layerData'][:].data # read in bed pick array
surf_pick[surf_pick == -9999] = 'nan' # convert -9999 to NaNs for plotting
bed_pick[bed_pick == -9999] = 'nan' # convert -9999 to NaNs for plotting

# surface and bed elevations
surface_elevation = f.variables['surface_altitude_layerData'][:].data # read in s
bed_elevation = f.variables['bed_altitude_layerData'][:].data # read in bed altit
surface_elevation[surface_elevation == -9999] = 'nan' # convert -9999 to NaNs for
bed_elevation[bed_elevation == -9999] = 'nan' # convert -9999 to NaNs for plottin

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 3/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [11]: plt.rcParams['figure.figsize'] = [20,12] # set the size of the inline plot

fig1, ax1 = plt.subplots()


radar_im = ax1.imshow(chirpData[:600,:], cmap='Greys', vmin = 10, aspect='auto') #
ax1.plot(surf_pick,'r--', linewidth=2) # plot surface pick
ax1.plot(bed_pick, 'b--', linewidth=2) # plot bed pick
ax1.xaxis.set_major_locator(ticker.LinearLocator(6)) # set x-axis tick limits

ax1.set_title("Radar Data - Chirp (NetCDF)", fontsize = 20, fontweight = 'bold') #


ax1.set_xlabel("Trace Number", fontsize = 16) # set axis title
ax1.set_ylabel("Fast Time Sample Number", fontsize = 16) # set axis title
fig1.colorbar(radar_im, ax = ax1) # plot colorbar

Out[11]: <matplotlib.colorbar.Colorbar at 0x225683351e0>

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 4/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [12]: # radar variables


traces_nc = f.variables['traces_chirp'][:].data # read in traces array
chirpData = f.variables['chirp_data'][:].data # read in chirp radar data array
pulseData = f.variables['pulse_data'][:].data # read in pulse radar data array

chirpData = 10*np.log10(chirpData) # convert the data from power to decibels usin
pulseData = 10*np.log10(pulseData) # convert the data from power to decibels usin

# X and Y coordinates
x_nc = f.variables['x_coordinates'][:].data # read in x positions array (Polar St
y_nc = f.variables['y_coordinates'][:].data # read in y positions array (Polar St
x_nc_km = np.divide(x_nc,1000) # transform meters to kilometers
y_nc_km = np.divide(y_nc,1000) # transform meters to kilometers

# surface and bed picks
surf_pick = f.variables['surface_pick_layerData'][:].data # read in surface pick
bed_pick = f.variables['bed_pick_layerData'][:].data # read in bed pick array
surf_pick[surf_pick == -9999] = 'nan' # convert -9999 to NaNs for plotting
bed_pick[bed_pick == -9999] = 'nan' # convert -9999 to NaNs for plotting

# surface and bed elevations
surface_elevation = f.variables['surface_altitude_layerData'][:].data # read in s
bed_elevation = f.variables['bed_altitude_layerData'][:].data # read in bed altit
surface_elevation[surface_elevation == -9999] = 'nan' # convert -9999 to NaNs for
bed_elevation[bed_elevation == -9999] = 'nan' # convert -9999 to NaNs for plottin

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 5/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [13]: plt.rcParams['figure.figsize'] = [20,12] # set the size of the inline plot



fig1, ax1 = plt.subplots()
radar_im = ax1.imshow(chirpData[:600,:], cmap='Greys', vmin = 10, aspect='auto')
ax1.plot(surf_pick,'r--', linewidth=2) # plot surface pick
ax1.plot(bed_pick, 'b--', linewidth=2) # plot bed pick
ax1.xaxis.set_major_locator(ticker.LinearLocator(6)) # set x-axis tick limits

ax1.set_title("Radar Data - Chirp (NetCDF)", fontsize = 20, fontweight = 'bold')
ax1.set_xlabel("Trace Number", fontsize = 16) # set axis title
ax1.set_ylabel("Fast Time Sample Number", fontsize = 16) # set axis title
fig1.colorbar(radar_im, ax = ax1) # plot colorbar

Out[13]: <matplotlib.colorbar.Colorbar at 0x2256ff7db70>

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 6/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [14]: plt.rcParams['figure.figsize'] = [20,20] # set the size of the inline plot



fig2, ax2 = plt.subplots()
radar_im = ax2.imshow(pulseData[:600,:], cmap = 'Greys', aspect='auto') # plot d
ax2.plot(surf_pick,'r--', linewidth=2) # plot surface pick
ax2.plot(bed_pick, 'b--', linewidth=1) # plot bed pick
ax2.xaxis.set_major_locator(ticker.LinearLocator(6)) # set x-axis tick limits

ax2.set_title("Radar Data - pulse (NetCDF)", fontsize = 20, fontweight = 'bold')
ax2.set_xlabel("Trace Number", fontsize = 16) # set axis title
ax2.set_ylabel("Fast Time Sample Number", fontsize = 16) # set axis title
fig2.colorbar(radar_im, ax = ax2) # plot colorbar

Out[14]: <matplotlib.colorbar.Colorbar at 0x2257003f730>

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 7/8
28/11/22, 12:23 Untitled3 - Jupyter Notebook

In [ ]: ​

localhost:8888/notebooks/Untitled3.ipynb?kernel_name=python3# 8/8

You might also like