"Find swaths" with scripts
"Find swaths" with scripts
Hi,
I would like to know if there's a way to find MODIS swaths for a given area automatically in a script, just like the "Find swaths" button does.
Is it possible actually ?
Many thanks
I would like to know if there's a way to find MODIS swaths for a given area automatically in a script, just like the "Find swaths" button does.
Is it possible actually ?
Many thanks
Filters:
-
- Subject Matter Expert
- Posts: 147
- Joined: Tue Feb 09, 2021 8:19 am America/New_York
"Find swaths" with scripts
Hi,
The browse code was not explicitly set up for this, but it is possible with a little
parsing of the html that the browser sends back. If you are using bash or a similar
shell, the following example will download Aqua/MODIS level-2 files that cover
the Argentine Sea in 2018.
There was a forum discussion on this topic some years ago.
https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?pid=19165
Regards,
Norman
The browse code was not explicitly set up for this, but it is possible with a little
parsing of the html that the browser sends back. If you are using bash or a similar
shell, the following example will download Aqua/MODIS level-2 files that cover
the Argentine Sea in 2018.
url=https://oceancolor.gsfc.nasa.gov/cgi/browse.pl
wget -qO - \
$url'?sub=level1or2list&sen=am&per=YR&day=17532&n=-40&s=-54&w=-70&e=-54&dnm=D' \
| perl -n -0777 \
-e 'if(/filenamelist&id=(\d+\.\d+)/){' \
-e 'print `wget "'$url'?sub=filenamelist&id=$1&prm=CHL" -qO -`;' \
-e '}' \
-e 'elsif(/(A\d+\.L2_LAC_OC.nc)/){' \
-e 'print "$1\n";' \
-e '}' \
| wget -B https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/ \
--content-disposition -i -
There was a forum discussion on this topic some years ago.
https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?pid=19165
Regards,
Norman
"Find swaths" with scripts
I have some issues using wget with oceancolor server.
So here's a quick and dirty way to do the same with shell and curl.
--------------------------------------------------------------------------
url='https://oceancolor.gsfc.nasa.gov/cgi/browse.pl'
curl -o "curl.dat" -s -L -O \
$url'?sub=level1or2list&sen=v0&per=DAY&day=15400&n=-49&s=-51&w=70&e=73' \
| perl -n -0777 \
-e 'if(/filenamelist&id=(\d+\.\d+)/){' \
-e 'print `wget "'$url'?sub=filenamelist&id=$1&prm=CHL" -qO -`;' \
-e '}' \
-e 'elsif(/(V\d+\.L2_NPP_OC)/){' \
-e 'print "$1\n";' \
-e '}' \
cat curl.dat | grep colspan | grep file | sed -e s/"&"/" "/g >tmp.dat
rm list.dat
# Loop on lines
while l= read -r line ;do
# Loop on words
for w in $line;do
# Search "file" keyword
echo `echo $w | sed -e s/'\='/' '/` | read args
if [ `echo $args | awk '{print $1}'` == "file" ];then
echo `echo $args | awk '{print $2}'` >> list.dat
fi
done
done <"tmp.dat"
rm curl.dat
rm tmp.dat
cat list.dat
-------------------------------------------
Output :
V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS
Best,
So here's a quick and dirty way to do the same with shell and curl.
--------------------------------------------------------------------------
url='https://oceancolor.gsfc.nasa.gov/cgi/browse.pl'
curl -o "curl.dat" -s -L -O \
$url'?sub=level1or2list&sen=v0&per=DAY&day=15400&n=-49&s=-51&w=70&e=73' \
| perl -n -0777 \
-e 'if(/filenamelist&id=(\d+\.\d+)/){' \
-e 'print `wget "'$url'?sub=filenamelist&id=$1&prm=CHL" -qO -`;' \
-e '}' \
-e 'elsif(/(V\d+\.L2_NPP_OC)/){' \
-e 'print "$1\n";' \
-e '}' \
cat curl.dat | grep colspan | grep file | sed -e s/"&"/" "/g >tmp.dat
rm list.dat
# Loop on lines
while l= read -r line ;do
# Loop on words
for w in $line;do
# Search "file" keyword
echo `echo $w | sed -e s/'\='/' '/` | read args
if [ `echo $args | awk '{print $1}'` == "file" ];then
echo `echo $args | awk '{print $2}'` >> list.dat
fi
done
done <"tmp.dat"
rm curl.dat
rm tmp.dat
cat list.dat
-------------------------------------------
Output :
V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061190600.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061105400.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS
V2012061110000.L2_SNPP_OC_CHLOR_A_BRS
V2012061091800.L2_SNPP_OC_CHLOR_A_BRS
Best,
-
- Subject Matter Expert
- Posts: 147
- Joined: Tue Feb 09, 2021 8:19 am America/New_York
"Find swaths" with scripts
Note that, in your version, you could leave out the pipe to perl since you
direct your output to a file (curl.dat), and there is nothing for the perl command
to parse.
Note also that, instead of downloading files, your version is producing a list
of browse file names. (We do not actually distribute any of our level-1 or level-2
browse files. They are for internal use only).
Nevertheless, as the Perl motto says, "TMTOWTDI". :-)
Best,
Norman
direct your output to a file (curl.dat), and there is nothing for the perl command
to parse.
Note also that, instead of downloading files, your version is producing a list
of browse file names. (We do not actually distribute any of our level-1 or level-2
browse files. They are for internal use only).
Nevertheless, as the Perl motto says, "TMTOWTDI". :-)
Best,
Norman