Hi Isabel
The return value is a Python dictionary with the variables stored under the different statistics (e.g. mean and std), but you can reorder this to store all statistics per variable:
Code: Select all
## extract st_lon, st_lat from ncf
ext = ac.shared.nc_extract_point(ncf, st_lon, st_lat, extract_datasets = None, shift_edge = False, box_size = 5)
## reorder extracted statistics per dataset
ext_per_ds = {ds: {'mean':ext['mean'][ds], 'std':ext['std'][ds], 'median':ext['median'][ds],'n':ext['n'][ds]} for ds in ext['datasets']}
Printing a single key then gives for example, print(ext_per_ds['rhot_492']):
Code: Select all
{'mean': 0.29368597, 'std': 0.0022542998, 'median': 0.2937, 'n': 121}
If you want to do multiple stations and files you'll need to construct a nested loop (1) over files and (2) over stations. For example, set up variables:
Code: Select all
## box dimensions in pixels
box = 11
## ACOLITE file type to extract data from L1R L2R L2W ST
file_type = 'L2W'
## directory of files
idir = '/path/to/your/ACOLITE/output/directory/'
## set up list of stations
stations = [{'name': 'station1', 'st_lon':2.9074, 'st_lat':51.2555},
{'name': 'station2', 'st_lon':2.9340, 'st_lat':51.2494,},
{'name': 'station3', 'st_lon':2.9198, 'st_lat':51.2395}]
and extract the data:
Code: Select all
## Import ACOLITE code
import sys, os
user_home = os.path.expanduser("~")
sys.path.append(user_home+'/git/acolite')
import acolite as ac
## search files files
import glob
files = glob.glob('{}/*_{}.nc'.format(idir, file_type))
files.sort()
## run through files and stations
results = {}
for file in files:
print('Extracting {}'.format(file))
bn = os.path.basename(file)
results[bn] = {}
for st in stations:
print('Extracting {}'.format(st['name']))
ext = ac.shared.nc_extract_point(file, st['st_lon'], st['st_lat'],
extract_datasets = None, shift_edge = False, box_size = box)
results[bn][st['name']] = {ds: {'mean':ext['mean'][ds],
'std':ext['std'][ds],
'median':ext['median'][ds],
'n':ext['n'][ds]} for ds in ext['mean']}
You could also replace the station dictionary with lists you index and files by a list of files:
Code: Select all
## Import ACOLITE code
import sys, os
user_home = os.path.expanduser("~")
sys.path.append(user_home+'/git/acolite')
import acolite as ac
files = ['/path/to/file1', '/path/to/file2', '/path/to/file3']
stations = ['station1', 'station2', 'station3']
lats = [51.2555, 51.2494, 51.2395]
lons = [2.9074, 2.9340, 2.9198]
results = {}
for file in files:
print('Extracting {}'.format(file))
bn = os.path.basename(file)
results[bn] = {}
for si, st in enumerate(stations):
print('Extracting {}'.format(st))
ext = ac.shared.nc_extract_point(file, lons[si], lats[si],
extract_datasets = None, shift_edge = False, box_size = box)
results[bn][st] = {ds: {'mean':ext['mean'][ds],
'std':ext['std'][ds],
'median':ext['median'][ds],
'n':ext['n'][ds]} for ds in ext['mean']}
I hope this helps!
Quinten