by Daniel Buscombe
from IPython.display import Image
Image('http://skeptic.smugmug.com/Nature/Costa-Rica-2011/i-xHQVnkv/0/L/IMG_1800-L.jpg')
!wget http://skeptic.smugmug.com/Nature/Costa-Rica-2011/i-xHQVnkv/0/L/IMG_1800-L.jpg
--2013-08-11 21:06:36-- http://skeptic.smugmug.com/Nature/Costa-Rica-2011/i-xHQVnkv/0/L/IMG_1800-L.jpg Resolving skeptic.smugmug.com (skeptic.smugmug.com)... 68.177.32.56, 68.177.32.18 Connecting to skeptic.smugmug.com (skeptic.smugmug.com)|68.177.32.56|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 223002 (218K) [image/jpeg] Saving to: ‘IMG_1800-L.jpg’ 100%[======================================>] 223,002 807KB/s in 0.3s 2013-08-11 21:06:36 (807 KB/s) - ‘IMG_1800-L.jpg’ saved [223002/223002]
!convert IMG_1800-L.jpg sun:image.ras
!gmt2rgb image.ras -Lr -Gimage%c.grd -I1/1
! man grdfft
GRDFFT(1gmt) Generic Mapping Tools GRDFFT(1gmt) NNAAMMEE grdfft - Perform mathematical operations on grid files in the wavenumber (or frequency) domain SSYYNNOOPPSSIISS ggrrddfffftt _i_n___g_r_d_f_i_l_e --GG_o_u_t___g_r_d_f_i_l_e [ --AA_a_z_i_m_u_t_h ] [ --CC_z_l_e_v_e_l ] [ --DD[_s_c_a_l_e||gg] ] [ --EE[xx||yy][ww] ] [ --FF[xx|yy]_p_a_r_a_m_s ] [ --II[_s_c_a_l_e||gg] ] [ --LL ] [ --MM ] [ --NN_s_t_u_f_f ] [ --SS_s_c_a_l_e ] [ --TT_t_e_/_r_l_/_r_m_/_r_w_/_r_i ] [ --VV ] DDEESSCCRRIIPPTTIIOONN ggrrddfffftt will take the 2-D forward Fast Fourier Transform and perform one or more mathematical operations in the frequency domain before transforming back to the space domain. An option is provided to scale the data before writing the new values to an output file. The horizontal dimensions of the grid are assumed to be in meters. Geographical grids may be used by specifying the --MM option that scales degrees to meters. If you have grids with dimensions in km, you could change this to meters using ggrrddeeddiitt or scale the output with ggrrddmmaatthh. _i_n___g_r_d_f_i_l_e 2-D binary grid file to be operated on. (See GRID FILE FOR‐ MATS below). --GG Specify the name of the output grid file. (See GRID FILE FORMATS below). OOPPTTIIOONNSS No space between the option flag and the associated arguments. --AA Take the directional derivative in the _a_z_i_m_u_t_h direction measured in degrees CW from north. --CC Upward (for _z_l_e_v_e_l > 0) or downward (for _z_l_e_v_e_l < 0) con‐ tinue the field _z_l_e_v_e_l meters. --DD Differentiate the field, i.e., take d(field)/dz. This is equivalent to multiplying by kr in the frequency domain (kr is radial wave number). Append a scale to multiply by (kr * _s_c_a_l_e) instead. Alternatively, append gg to indicate that your data are geoid heights in meters and output should be gravity anomalies in mGal. [Default is no scale]. --EE Estimate power spectrum in the radial direction. Place xx or yy immediately after --EE to compute the spectrum in the x or y direction instead. No grid file is created; f (i.e., fre‐ quency or wave number), power[f], and 1 standard deviation in power[f] are written to stdout. Append ww to write wave‐ length instead of frequency. --FF Filter the data. Place xx or yy immediately after --FF to fil‐ ter _x or _y direction only; default is isotropic. Choose between a cosine-tapered band-pass, a Gaussian band-pass filter, or a Butterworth band-pass filter. Cosine-taper: Specify four wavelengths _l_c/_l_p/_h_p/_h_c in correct units (see --MM) to design a bandpass filter: wavelengths greater than _l_c or less than _h_c will be cut, wavelengths greater than _l_p and less than _h_p will be passed, and wavelengths in between will be cosine-tapered. E.g., --FF1000000/250000/50000/10000 --MM will bandpass, cutting wavelengths > 1000 km and < 10 km, passing wavelengths between 250 km and 50 km. To make a highpass or lowpass filter, give hyphens (-) for _h_p/_h_c or _l_c/_l_p. E.g., --FFxx-/-/50/10 will lowpass _x, passing wave‐ lengths > 50 and rejecting wavelengths < 10. --FFyy1000/250/-/- will highpass _y, passing wavelengths < 250 and rejecting wavelengths > 1000. Gaussian band-pass: Append _l_o/_h_i, the two wavelengths in correct units (see --MM) to design a bandpass filter. At the given wavelengths the Gaussian filter weights will be 0.5. To make a highpass or lowpass filter, give a hyphen (-) for the _h_i or _l_o wave‐ length, respectively. E.g., --FF-/30 will lowpass the data using a Gaussian filter with half-weight at 30, while --FF400/- will highpass the data. Butterworth band-pass: Append _l_o/_h_i/_o_r_d_e_r, the two wavelengths in correct units (see --MM) and the filter order (an integer) to design a band‐ pass filter. At the given wavelengths the Butterworth fil‐ ter weights will be 0.5. To make a highpass or lowpass fil‐ ter, give a hyphen (-) for the _h_i or _l_o wavelength, respec‐ tively. E.g., --FF-/30/2 will lowpass the data using a 2nd- order Butterworth filter, with half-weight at 30, while --FF400/-/2 will highpass the data. --II Integrate the field, i.e., compute integral_over_z (field * dz). This is equivalent to divide by kr in the frequency domain (kr is radial wave number). Append a scale to divide by (kr * _s_c_a_l_e) instead. Alternatively, append gg to indi‐ cate that your data set is gravity anomalies in mGal and output should be geoid heights in meters. [Default is no scale]. --LL Leave trend alone. By default, a linear trend will be removed prior to the transform. --MM Map units. Choose this option if your grid file is a geo‐ graphical grid and you want to convert degrees into meters. If the data are close to either pole, you should consider projecting the grid file onto a rectangular coordinate sys‐ tem using ggrrddpprroojjeecctt. --NN Choose or inquire about suitable grid dimensions for FFT. --NNff will force the FFT to use the dimensions of the data. --NNqq will inQuire about more suitable dimensions. --NN_n_x_/_n_y will do FFT on array size _n_x_/_n_y (Must be >= grid file size). Default chooses dimensions >= data which optimize speed, accuracy of FFT. If FFT dimensions > grid file dimensions, data are extended and tapered to zero. --SS Multiply each element by _s_c_a_l_e in the space domain (after the frequency domain operations). [Default is 1.0]. --TT Compute the isostatic compensation from the topography load (input grid file) on an elastic plate of thickness _t_e. Also append densities for load, mantle, water, and infill in SI units. If _t_e == 0 then the Airy response is returned. --TT implicitly sets --LL. --VV Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. GGRRIIDD FFIILLEE FFOORRMMAATTSS By default GGMMTT writes out grid as single precision floats in a COARDS-complaint netCDF file format. However, GGMMTT is able to pro‐ duce grid files in many other commonly used grid file formats and also facilitates so called "packing" of grids, writing out floating point data as 2- or 4-byte integers. To specify the precision, scale and offset, the user should add the suffix ==_i_d[//_s_c_a_l_e//_o_f_f_‐ _s_e_t[//_n_a_n]], where _i_d is a two-letter identifier of the grid type and precision, and _s_c_a_l_e and _o_f_f_s_e_t are optional scale factor and offset to be applied to all grid values, and _n_a_n is the value used to indicate missing data. When reading grids, the format is gener‐ ally automatically recognized. If not, the same suffix can be added to input grid file names. See ggrrddrreeffoorrmmaatt(1) and Section 4.17 of the GMT Technical Reference and Cookbook for more information. When reading a netCDF file that contains multiple grids, GGMMTT will read, by default, the first 2-dimensional grid that can find in that file. To coax GGMMTT into reading another multi-dimensional vari‐ able in the grid file, append ??_v_a_r_n_a_m_e to the file name, where _v_a_r_‐ _n_a_m_e is the name of the variable. Note that you may need to escape the special meaning of ?? in your shell program by putting a back‐ slash in front of it, or by placing the filename and suffix between quotes or double quotes. The ??_v_a_r_n_a_m_e suffix can also be used for output grids to specify a variable name different from the default: "z". See ggrrddrreeffoorrmmaatt(1) and Section 4.18 of the GMT Technical Ref‐ erence and Cookbook for more information, particularly on how to read splices of 3-, 4-, or 5-dimensional grids. EEXXAAMMPPLLEESS To upward continue the sea-level magnetic anomalies in the file mag_0.grd to a level 800 m above sealevel: ggrrddfffftt mag_0.grd --CC800 --VV --GGmag_800.grd To transform geoid heights in m (geoid.grd) on a geographical grid to free-air gravity anomalies in mGal: ggrrddfffftt geoid.grd --DDgg --VV --GGgrav.grd To transform gravity anomalies in mGal (faa.grd) to deflections of the vertical (in micro-radians) in the 038 direction, we must first integrate gravity to get geoid, then take the directional deriva‐ tive, and finally scale radians to micro-radians: ggrrddfffftt faa.grd --IIgg38 --SS1e6 --VV --GGdefl_38.grd Second vertical derivatives of gravity anomalies are related to the curvature of the field. We can compute these as mGal/m^2 by dif‐ ferentiating twice: ggrrddfffftt gravity.grd --DD --DD --VV --GGgrav_2nd_derivative.grd The first order gravity anomaly (in mGal) due to the compensating surface caused by the topography load topo.grd (in m) on a 20 km thick elastic plate, assumed to be 4 km beneath the observation level can be computed as ggrrddfffftt topo.grd --TT20000/2800/3330/1030/2300 --SS0.022 --CC4000 --GGcomp_faa.grd where 0.022 is the scale needed for the first term in Parker's expansion for computing gravity from topography (= 2 * PI * G * (rhom - rhol)). SSEEEE AALLSSOO _G_M_T(1), _g_r_d_e_d_i_t(1), _g_r_d_m_a_t_h(1), _g_r_d_p_r_o_j_e_c_t(1) GMT 4.5.7 15 Jul 2011 GRDFFT(1gmt)
!grdfft imager.grd -Ew > fft
pspectrum=!cat fft
type(pspectrum)
IPython.utils.text.SList
%pylab inline
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline]. For more information, type 'help(pylab)'.
ax = pylab.axes()
ax.plot(pspectrum.fields(0),pspectrum.fields(1), 'm', lw=1)
ax.set_title('Radial Spectrum of IMG_1800-L.jpg')
ax.set_xlabel('Wavelength in pixels')
ax.set_ylabel('Power Spectral Density (pixel/Hz)')
<matplotlib.text.Text at 0x6b56650>
img=matplotlib.image.imread('IMG_1800-L.jpg')
ax = pylab.axes()
plt.imshow(img)
ax.plot((200, 300),(400, 400), 'k', lw=2)
ax.set_xlim(0, 600)
ax.set_ylim(0, 600)
(0, 600)
Image('http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-Kg2WnjB/1/XL/DSC03045-XL.jpg')
!wget http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-Kg2WnjB/1/XL/DSC03045-XL.jpg
--2013-08-11 22:07:33-- http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-Kg2WnjB/1/XL/DSC03045-XL.jpg Resolving skeptic.smugmug.com (skeptic.smugmug.com)... 68.177.32.56, 68.177.32.18 Connecting to skeptic.smugmug.com (skeptic.smugmug.com)|68.177.32.56|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 386371 (377K) [image/jpeg] Saving to: ‘DSC03045-XL.jpg’ 100%[======================================>] 386,371 1.15MB/s in 0.3s 2013-08-11 22:07:33 (1.15 MB/s) - ‘DSC03045-XL.jpg’ saved [386371/386371]
!convert DSC03045-XL.jpg sun:image.ras
!gmt2rgb image.ras -Lr -Gimage%c.grd -I1/1
!grdfft imager.grd -Ew > fft
pspectrum=!cat fft
ax = pylab.axes()
ax.plot(pspectrum.fields(0),pspectrum.fields(1), 'm', lw=1)
ax.set_title('Radial Spectrum of DSC03045-XL.jpg')
ax.set_xlabel('Wavelength in pixels')
ax.set_ylabel('Power Spectral Density (pixel/Hz)')
<matplotlib.text.Text at 0x6b4d390>
ax = pylab.axes()
ax.semilogx(pspectrum.fields(0),pspectrum.fields(1), 'm', lw=1)
ax.set_title('Radial Spectrum of DSC03045-XL.jpg')
ax.set_xlabel('Wavelength in pixels')
ax.set_ylabel('Power Spectral Density (pixel/Hz)')
<matplotlib.text.Text at 0x6ae10d0>
img=matplotlib.image.imread('DSC03045-XL.jpg')
ax = pylab.axes()
plt.imshow(img)
ax.plot((400, 400),(280, 340), 'k', lw=2)
ax.set_xlim(200, 700)
ax.set_ylim(200, 700)
(200, 700)
Image('http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-c5cC5gQ/1/XL/DSC03057-XL.jpg')
!wget http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-c5cC5gQ/1/XL/DSC03057-XL.jpg
--2013-08-11 22:29:30-- http://skeptic.smugmug.com/Nature/Sea-Rim-State-Park-Texas-2003/i-c5cC5gQ/1/XL/DSC03057-XL.jpg Resolving skeptic.smugmug.com (skeptic.smugmug.com)... 68.177.32.18, 68.177.32.56 Connecting to skeptic.smugmug.com (skeptic.smugmug.com)|68.177.32.18|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 385839 (377K) [image/jpeg] Saving to: ‘DSC03057-XL.jpg’ 100%[======================================>] 385,839 1.10MB/s in 0.3s 2013-08-11 22:29:30 (1.10 MB/s) - ‘DSC03057-XL.jpg’ saved [385839/385839]
!convert DSC03057-XL.jpg sun:image.ras
!gmt2rgb image.ras -Lr -Gimage%c.grd -I1/1
!grdfft imager.grd -Ew > fft
pspectrum=!cat fft
ax = pylab.axes()
ax.semilogx(pspectrum.fields(0),pspectrum.fields(1), 'm', lw=1)
ax.set_title('Radial Spectrum of DSC03057-XL.jpg')
ax.set_xlabel('Wavelength in pixels')
ax.set_ylabel('Power Spectral Density (pixel/Hz)')
<matplotlib.text.Text at 0x79ca410>
img=matplotlib.image.imread('DSC03057-XL.jpg')
ax = pylab.axes()
plt.imshow(img)
ax.plot((400, 350),(280, 380), 'k', lw=2) #100 pixel line
ax.plot((500, 470),(320, 380), 'b', lw=2) #60 pixel line
ax.plot((600, 580),(380, 420), 'r', lw=2) #30 pixel line
ax.set_xlim(200, 700)
ax.set_ylim(200, 700)
(200, 700)