You are on page 1of 8

28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [3]: 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 [4]: f=nc.Dataset('C:/Users/Pc/Desktop/Geologia/GeoFisica/Python/POLARGAP_P18A.nc', 'r


In [5]: 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 [6]: print(f)

( ) p ( µ )
'polarised_pulse_SPHV_data': Radar data for the processed (coherent) pola
rised (SPHV) pulse (1 µs)

Abbreviations are as follows:

PPVV: Port to Port, Vertical to Vertical, 4us Chirp

SSHH: Starboard to Starboard, Horizontal to Horizontal, 4us Chirp

SPHV: Starboard to Port, Horizontal to Vertical, 1us Pulse

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

IMPORTANT: Please note that the two chirp radar variables ('polarised_chi
rp_PPVV_data' and 'polarised_chirp_SSHH_data') do NOT have the same length as
the pulse radar variable 'polarised_pulse_SPHV_data'

as the pulse data was processed with a greater amount of decimation compa
red with the two chirp variables, with the consequence that the pulse data va
riable

contain more elements than the two chirp data variables and the associate
d 1-D variables in this NetCDF. All 1-D variables found here are thus aligned
to the trace number

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

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

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


print(dim)

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

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

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

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

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


rdinates', 'polarised_chirp_PPVV_data', 'polarised_chirp_SSHH_data', 'polarised
_pulse_SPHV_data', 'PriNumber_chirp', 'PriNumber_pulse', 'longitude_layerData',
'latitude_layerData', 'UTC_time_layerData', 'aircraft_altitude_layerData', 'ter
rainClearanceAircraft_layerData', 'surface_source_layerData', 'surface_altitude
_layerData', 'surface_pick_layerData', 'bed_altitude_layerData', 'bed_pick_laye
rData', 'land_ice_thickness_layerData'])

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 1/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [14]: # radar variables


traces_ncC = f.variables['traces_chirp'][:].data # read in traces array
traces_ncP = f.variables['traces_pulse'][:].data # read in traces array
chirpData = f.variables['polarised_chirp_PPVV_data'][:].data # read in chirp radar
pulseData = f.variables['polarised_pulse_SPHV_data'][:].data # read in pulse radar

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


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

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

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
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 a
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 su
bed_elevation = f.variables['bed_altitude_layerData'][:].data # read in bed altitu
surface_elevation[surface_elevation == -9999] = 'nan' # convert -9999 to NaNs for
bed_elevation[bed_elevation == -9999] = 'nan' # convert -9999 to NaNs for plotting

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 2/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [15]: 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[15]: <matplotlib.colorbar.Colorbar at 0x1f6d4043a60>

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 3/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [16]: 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[16]: <matplotlib.colorbar.Colorbar at 0x1f6daf268c0>

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 4/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 5/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

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


fig2, (ax3, ax4) = plt.subplots(1, 2) # Specify how many plots you want

# first plot the radargram with specific trace marked as red vertical line
radar_im = ax3.imshow(chirpData[:600,:],cmap='Greys', vmin = 10, vmax = 60, aspec
ax3.plot(surf_pick,'r--', linewidth=2) # plot surface pick
ax3.plot(bed_pick, 'b--', linewidth=2) # plot surface pick
ax3.xaxis.set_major_locator(ticker.LinearLocator(6)) # set x-axis tick limits
ax3.axvline(x=1850, color='r', linestyle='-') # plot position of trace in second
ax3.autoscale(enable=True, axis='x', tight=True) # tighten up x axis

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

# then plot trace plot with amplitude and sampling window
ax4.plot(chirpData[:600,1850])
plt.title('Trace 1850 - Radar Data', fontsize = 20, fontweight = 'bold') # set t
plt.xlabel('Fast Time Sample Number', fontsize = 16) # set axis title
plt.ylabel('Amplitude (dB)', fontsize = 16) # set axis title
plt.ylim([10,60]) # set limit of y-axis
plt.show()

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 6/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [18]: plt.rcParams['figure.figsize'] = [10,10] # Set the size of the inline plot



fig3, ax5 = plt.subplots(1,1)
plt.scatter(x_nc_km, y_nc_km, marker='o', s=1) # plot entire profile
plt.scatter(x_nc_km[1850], y_nc_km[1850], marker='o',color=['red'], s=100) # plot

ax5.set_title("Position of Trace 1850", fontsize = 18, fontweight = 'bold') # set
ax5.set_xlabel("X (km)", fontsize = 14) # set axis title
ax5.set_ylabel("Y (km)", fontsize = 14) # set axis title

Out[18]: Text(0, 0.5, 'Y (km)')

localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3 7/8
28/11/22, 22:40 Untitled4 - Jupyter Notebook

In [24]: plt.rcParams['figure.figsize'] = [10,10] # Set the size of the inline plot



fig4, ax6 = plt.subplots(1,1)
ax6.plot(traces_ncC, surface_elevation) # plot surface elevation for entire profi
ax6.plot(traces_ncC, bed_elevation) # plot bed elevation for entire profile

ax6.set_title("Elevation Profile for flightline G06", fontsize = 18, fontweight =
ax6.set_xlabel("Trace Number", fontsize = 14) # set axis title
ax6.set_ylabel("Elevation (meters WGS84)", fontsize = 14) # set axis title

Out[24]: Text(0, 0.5, 'Elevation (meters WGS84)')

In [ ]: ​

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

You might also like