Skip to content
Snippets Groups Projects
Commit 8f313398 authored by Greg Quinn's avatar Greg Quinn
Browse files

Add convert_ccast_sdr.py and convert_ccast_geo.py

parent 3432d9a5
No related branches found
No related tags found
No related merge requests found
"""convert_ccast_geo"""
import sys
import h5py
import numpy as np
from scipy.io import loadmat
from collocation import earthrad, geod2geoc, ll2v, v2ll
def main():
if len(sys.argv) != 2:
print 'usage: python %s <ccast_geo_file>' % sys.argv[0]
sys.exit(1)
filename = sys.argv[1]
mat = loadmat(filename)
lat = twist(mat['fovLat'].transpose())
lon = twist(mat['fovLon'].transpose())
scpos = scpos_from_latlon(lat, lon)
output_filename = filename[:-4] + '.h5'
write_output(output_filename, lat, lon, scpos)
def twist(a):
num_scans, num_fors = a.shape
assert num_scans % 3 == 0
num_scans /= 3
assert num_fors % 3 == 0
num_fors /= 3
assert num_fors == 30
a = a.reshape([num_scans, 3, num_fors, 3])
a = a.transpose([0, 2, 1, 3])
a = a.reshape([num_scans, num_fors, 9])
return a
def scpos_from_latlon(lat, lon):
# take FOV 5 from the middle 2 FORs of each scan line
lat = lat[:,14:16,4]
lon = lon[:,14:16,4]
# see which scan lines have NaNs for either of the middle 2 FOVs
nans = np.logical_or(np.isnan(lat), np.isnan(lon)).any(axis=1)
# set up our output array (num_scans by 3)
output = np.empty([len(lat), 3], np.float32)
# loop over each scan line
for lat_pair, lon_pair, has_nan, out in zip(lat, lon, nans, output):
# any NaNs? then just set to fill
if has_nan:
out[:] = -9999.0
continue
# find the position vector of the center of the scan
vecs = []
for i in range(2):
lat_geoc = geod2geoc(lat_pair[i])
vecs.append(ll2v(lat_geoc, lon_pair[i], earthrad(lat_geoc)))
gnd_pos = (vecs[0] + vecs[1]) / 2
# find the offset vector from the ground point to the satellite
# using a nominal alitutde of 824 km
vecs = []
for i in range(2):
vecs.append(ll2v(lat_pair[i], lon_pair[i], 824))
sat_off = (vecs[0] + vecs[1]) / 2
# add the two to get the satellite position vector
sat_pos = gnd_pos + sat_off
# set our output values; they're in meters
out[:] = [1000.0 * val for val in [sat_pos.x, sat_pos.y, sat_pos.z]]
return output
def write_output(filename, lat, lon, scpos):
f = h5py.File(filename, 'w')
g = f.create_group('All_Data')
g = g.create_group('CrIS-SDR-GEO_All')
g.create_dataset('Latitude', lat.shape, np.float32, lat)
g.create_dataset('Longitude', lon.shape, np.float32, lon)
g.create_dataset('SCPosition', data=scpos)
if __name__ == '__main__':
main()
"""convert_ccast_sdr"""
import sys
import h5py
from scipy.io import loadmat
def main():
if len(sys.argv) != 2:
print 'usage: python %s <ccast_sdr_file>' % sys.argv[0]
sys.exit(1)
filename = sys.argv[1]
mat = loadmat(filename)
lw = mat['ES_RealLW'].transpose()
mw = mat['ES_RealMW'].transpose()
sw = mat['ES_RealSW'].transpose()
output_filename = filename[:-4] + '.h5'
f = h5py.File(output_filename, 'w')
g = f.create_group('All_Data')
g = g.create_group('CrIS-SDR_All')
g.create_dataset('ES_RealLW', data=lw)
g.create_dataset('ES_RealMW', data=mw)
g.create_dataset('ES_RealSW', data=sw)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment