In [ ]:
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
In [ ]:
#First lets import the libraries we require
from pprint import pprint
import podaac.podaac as podaac
import podaac.podaac_utils as utils
In [ ]:
#Then we can create instances of the classes we will use
p = podaac.Podaac()
u = utils.PodaacUtils()
In [ ]:
#Print a list of CYGNSS dataset id's
print('\nHeres list_all_available_granule_search_dataset_ids()')
result = u.list_all_available_granule_search_dataset_ids()
dsetId = [i for i in result if 'CYG' in i]
pprint(dsetId)
In [ ]:
#Print a list of CYGNSS dataset short names
print('\nHeres list_all_available_granule_search_dataset_short_names()')
result = u.list_all_available_granule_search_dataset_short_names()
dsetShortName = [i for i in result if 'CYG' in i]
pprint(dsetShortName)
In [ ]:
#Perform a search on dataset
#NOTE: dataset_id=dsetID pulled up nothing, had to use short_name=
print('\nHeres p.dataset_search()')
result = p.dataset_search(short_name=dsetShortName[0])
#Cache the dataset landing page URL
searchStr = 'http://podaac.jpl.nasa.gov/dataset/'
dataset_landing_page = [ str(i) for i in result.strip().split() if searchStr in i ][0]
pprint(result)
In [ ]:
#Print total number of GYGNSS Level 2 granules
print('\nHeres total results using p.granule_search()')
maxResultsPerPage = '400'
result = p.granule_search(dataset_id=dsetId[1],items_per_page=maxResultsPerPage)
searchStr = 'totalResults'
numResultsStr = [ str(i) for i in result.strip().split() if searchStr in i ]
print(numResultsStr)
In [ ]:
#print('\nHeres the length of file listing: '+str(len(fileStrL))+'\n')
searchStr = '<title>cyg'
fileStrL = [ str(i) for i in result.strip().split() if searchStr in i ]
podaacL3 = [ i.replace('<title>','').replace('</title>','') for i in fileStrL ]
pprint(podaacL3)
In [ ]:
#Lets execute a search for specific granules from the following dataset
# MetOp-A ASCAT Level 2 Ocean Surface Wind Vectors Optimized for Coastal Ocean
# https://podaac.jpl.nasa.gov/dataset/ASCATA-L2-Coastal
# ...based upon temporal (start and end) and spatial contraints.
#note that no subsetting is available for these granules as of yet.
result = p.granule_search(dataset_id='PODAAC-ASOP2-12C01',
start_time='2017-06-01T00:00:00Z',
end_time='2017-10-31T00:00:00Z',
bbox='-105,5,-10,50',
sort_by='timeAsc',
format='atom',
pretty='true')
searchStr = 'totalResults'
numResultsStr = [ str(i) for i in result.strip().split() if searchStr in i ]
print(numResultsStr)
In [ ]:
#Now lets subset and download one of those granules
import os
print(os.path.dirname(os.path.abspath('__file__')) + "/subset.json")
print(os.path.dirname(os.path.abspath('__file__')))
result = p.granule_subset(os.path.dirname(os.path.abspath('__file__')) + "/subset.json", path=os.path.dirname(os.path.abspath('__file__')))
In [ ]:
#Again, using Elsevier's Scopus Search, lets see other CYGNSS resources we can retreive.
url = 'https://api.elsevier.com/content/search/scopus?query=ALL:cygnss&APIKey=715b412c00f0b95e918a3e7abe6e6ee4'
import requests
try:
metadata = requests.get(url)
status_codes = [404, 400, 503, 408]
if metadata.status_code in status_codes:
metadata.raise_for_status()
except requests.exceptions.HTTPError as error:
print(error)
raise
pprint(metadata.text)
In [ ]: