Skip to content

Commit

Permalink
Merge branch 'master' into fernando
Browse files Browse the repository at this point in the history
  • Loading branch information
fspaolo authored Nov 7, 2018
2 parents 7f966d2 + 8af3970 commit 6289110
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 20 deletions.
27 changes: 23 additions & 4 deletions matlab/generic_ATL09_Quickview/plot_ATL09_cab.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function plot_ATL09_cab(ATL09, inName, figVis, saveFigures, outDir)
function plot_ATL09_cab(ATL09, inName, figVis, saveFigures, outDir, x_var)
% Function to plot ATL09 calibrated attenuated backscatter.
% Not as pretty as Steve Palm's plots, but it gets the message across.
%
Expand All @@ -14,6 +14,15 @@ function plot_ATL09_cab(ATL09, inName, figVis, saveFigures, outDir)
outDir = [];
end

%%
if ~exist('x_var','var')
x_var='delta_time';
xlabel_str='Delta Segment Time (seconds)';
subtract_min=true;
else
xlabel_str=strrep(x_var,'_','\_');
subtract_min=false;
end

%% Find and loop through the profile groups

Expand Down Expand Up @@ -48,7 +57,15 @@ function plot_ATL09_cab(ATL09, inName, figVis, saveFigures, outDir)
hold on

cmap = colormap(parula);
p = pcolor(ATL09.(profile).delta_time - min(ATL09.(profile).delta_time), cab_elevs, flipud(ATL09.(profile).cab_prof));

if subtract_min
x_prof=ATL09.(profile).(x_var) - min(ATL09.(profile).(x_var));
else
x_prof=ATL09.(profile).(x_var);
end

p = pcolor(x_prof, cab_elevs, flipud(ATL09.(profile).cab_prof));

shading flat
set(p,'DisplayName', 'CAB')
cdat = get(p, 'cdata');
Expand All @@ -67,14 +84,16 @@ function plot_ATL09_cab(ATL09, inName, figVis, saveFigures, outDir)

%% Plot labels

xlabel('Delta Segment Time (seconds)')
xlabel(xlabel_str)

ylabel('Elevation (meters)')
title({'Calibrated attenuated backscatter profile',...
[profile ' - ' inName]}, ...
'interpreter', 'none')
axis tight
legend('-DynamicLegend','Location','Best')
dragzoom()

%dragzoom()

%% Save figure(s)
% Uncomment savefig line if MATLAB figure desired. It will take longer
Expand Down
2 changes: 1 addition & 1 deletion matlab/generic_ATL09_Quickview/readATL09.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

profile = {'profile_1','profile_2','profile_3'};

vars = {'apparent_surf_reflec','bsnow_con','cab_prof','cloud_flag_asr','cloud_flag_atm','delta_time','latitude','layer_attr','layer_con','longitude','msw_flag','segment_id','solar_elevation'};
vars = {'apparent_surf_reflec','bsnow_con','cab_prof','cloud_flag_asr','cloud_flag_atm','delta_time','latitude','layer_attr','layer_con','longitude','msw_flag','prof_dist_x','segment_id','solar_elevation'};
vars_orbit = {'cycle_number','delta_time','orbit_number','rgt'};
vars_anc = {'data_end_utc';'data_start_utc';'end_cycle';'end_geoseg';'end_orbit';'end_region';'end_rgt';'granule_end_utc';'granule_start_utc';'start_cycle';'start_geoseg';'start_orbit';'start_region';'start_rgt'};

Expand Down
22 changes: 11 additions & 11 deletions python/photon_height.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ def photon_heights(infile, track, outroot, confidence, plot=False,
if verbose:
print(len(distance), "photons with confidence >=", confidence)
print(len(height), "photons with confidence >=", confidence)

outfile = outroot + ".txt"
try:
write_data(outfile, distance, height, overwrite=overwrite,
verbose=verbose)
except (IOError, RuntimeError) as err:
print("{0}: error: {1}".format(__file__, err), file=sys.stderr)
return 1
if outroot is not None:
outfile = outroot + ".txt"
try:
write_data(outfile, distance, height, overwrite=overwrite,
verbose=verbose)
except (IOError, RuntimeError) as err:
print("{0}: error: {1}".format(__file__, err), file=sys.stderr)
return 1

if plot:
"""
Expand Down Expand Up @@ -342,10 +342,10 @@ def cl_args(description):
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument("infile", type=str,
help="nput ATL03 file")
help="input ATL03 file")
parser.add_argument("track", type=str,
help="ground track: gt1l,gt1r,gt2l,gt2r,gt3l,gt3r,")
parser.add_argument("outroot", type=str,
parser.add_argument("-o", type=str, default=None,
help="output file root name")
parser.add_argument("-c", type=int, default=2,
help="minimum signal confidence to plot (0-4)"
Expand All @@ -367,7 +367,7 @@ def main(argv=None):

infile = args.infile
track = args.track
outroot = args.outroot
outroot = args.o
confidence_min = args.c
overwrite = args.f
plot = args.p
Expand Down
90 changes: 90 additions & 0 deletions python/run_ATL09_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env python3

import argparse
import subprocess
import sys
import re
import os
import shutil

description="Download ATL09 data from NSIDC." +\
" To use this, you must generate a token, using the setup_token script, which will be saved in a file called NSIDC_token.txt"+\
"The script will search for NSIDC_token.txt in the current directory (first) and in the directory where the script is located (second)."


parser=argparse.ArgumentParser(description=description)
parser.add_argument('-f', dest='full_file', default=False, action='store_true')
parser.add_argument('-o', dest='output_directory', type=str)
parser.add_argument('-d', dest='dry_run', default=False, action='store_true')
parser.add_argument('-t', dest='time_str', required=True, default=None, help="Time range for query. Format is YYYY-MM-DDTHH:MM:SS,YYYY-MM-DDTHH:MM:SS")
args=parser.parse_args()

# look for a NSIDC_identity.txt file in the current directory
try:
fh=open('NSIDC_token.txt','r')
except(FileNotFoundError):
# also look in the script's directory
fh=open(sys.path[0]+'/NSIDC_token.txt','r')

token=None
token_re=re.compile('<id>(.*)</id>')
for line in fh:
m=token_re.search(line)
if m is not None:
token=m.group(1)
if token is None:
raise RuntimeError('missing token string')

token_str='&token=%s' % token

if 'out_dir' in args:
os.chdir(args.output_directory)

if args.full_file:
subset_str="&agent=NO"
else:
subset_str=""

time_str="&time=%s" % args.time_str

# build the query to submit via curl
cmd_base='curl -O -J --dump-header response-header.txt "https://n5eil02u.ecs.nsidc.org/egi/request?short_name=ATL09&version=200&page_size=1000'
cmd=cmd_base+'%s%s%s"' % (token_str, subset_str, time_str)

print(cmd)

if args.dry_run:
# if this is a dry run, exit after reporting the string
exit()

# run the curl string
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
text=p.stdout.read()
retcode=p.wait()

# check the response header to get the filename with the output
zip_re=re.compile('filename="(.*.zip)"')
with open('response-header.txt') as ff:
for line in ff:
m=zip_re.search(line)
if m is not None:
zip_file=m.group(1)
zip_str=subprocess.check_output(['unzip',zip_file])
#print(zip_str)

# pull the indivicual h5 files into the current directory
cleanup_list=list()
for h5_file in re.compile('(\S+\.h5)').findall(zip_str.decode('utf-8')):
shutil.move(h5_file,'.')
thedir=os.path.dirname(h5_file)
if thedir not in cleanup_list:
cleanup_list.append( thedir)

# delete the directories that contained the hdf5 files
for entry in cleanup_list:
os.rmdir(entry)
os.remove(zip_file)




12 changes: 12 additions & 0 deletions python/setup_token
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env bash

if [ $# -eq 0]; then
echo "USAGE: setup_token username password ip_address"
fi

username=$1
password=$2
ip_address=$3

curl -X POST --header "Content-Type: application/xml" -d "<token><username>$username</username><password>$password</password><client_id>NSIDC_client_id</client_id><user_ip_address>$ip_address</user_ip_address></token>" https://api.echo.nasa.gov/echo-rest/tokens > NSIDC_token

4 changes: 0 additions & 4 deletions python/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<<<<<<< HEAD
Another test
=======
TEST
>>>>>>> d3ba45b... testing fork workflow

0 comments on commit 6289110

Please sign in to comment.