In [1]:
# a little script for open multiple netCDF files using xray
import numpy as np
import pandas as pd
import xray as xr
from matplotlib import pyplot as plt
%matplotlib inline
In [2]:
#!wget http://oceandata.sci.gsfc.nasa.gov/cgi/getfile/A20110012011008.L3b_8D_CHL.nc
import xray
da1 = xray.open_dataset('A20110012011008.L3b_8D_CHL.nc', group='level-3_binned_data')
In [3]:
xr.open_dataset?
In [4]:
da1.variables
Out[4]:
In [6]:
da1.attrs
Out[6]:
In [7]:
da1.var
Out[7]:
In [8]:
print(da1)
In [9]:
da1.BinIndex[-5:]
Out[9]:
In [10]:
da1.BinList[-5:]
Out[10]:
In [32]:
7654961/ (20652302 - 240292) == 0.3750224010276303
#[Note]
# There are lots of missing data has been excluded from the dataset
# so there is going to be a lot of missing bin numbers!
############################################
# roughly is the percent of ":percent_data_bins = 32.21558f "
# this info : "percent_data_bins = 32.21558f"
# can be seen by da1 = xr.open_dataset('A20110012011008.L3b_8D_CHL.nc')
# da1.variabel
# or can be seen by directly using the ncdump command from netCDF4
###########################################
# the binListDim= 7654961 # number of total bins(has data) contained in this netcdf file
# this can be seen:
# da1 = xr.open_dataset('A20110012011008.L3b_8D_CHL.nc', group='level-3_binned_data')
# da1.var #
#
##########################################
# us the following:
# da1.BinList[5:]
# da1.BinList[-5:]
# one can see that the bin numbers at least run from 240,292 to 20,652,302
7654961/ (20652302 - 240292) == 0.3750224010276303
#########################################
# use the web: Integerized Sinusoidal Binning Scheme for Level 3 Data
# for resolution of 4.64 km, there are 4320 latitudinal rows, this agrees with
# binIndexDim: 4320,
# From the table on the same doc, there are totally 23,761,676 bins
#
# From da1 we know:
# binDataDim (or binListDim) is 7654961
#######
# so the theretical non-empty data ration is: 7654961/23761676 = 0.3221557688102472
# matches: percent_data_bins = 32.21558f
Out[32]:
In [ ]:
In [14]:
############## let's try to use python module netCDF4
In [ ]:
In [9]:
#from netCDF4 import Dataset
#da1_netcdf = Dataset('A20110012011008.L3b_8D_CHL.nc')
#da1_netcdf.variables
#da1_netcdf.ncattrs()
In [11]:
pd.__version__
Out[11]:
In [ ]:
# Try the level 2 data
# http://oceandata.sci.gsfc.nasa.gov/cgi/getfile/T2011001053500.L2_LAC_SST.nc
#l2_xray = xr.open_dataset('T2011001053500.L2_LAC_SST.nc')
#l2_xray.variables
#l2_xray.var
In [ ]:
### Now let's explore xarray a little bit
In [26]:
### Now let's try to open two files in xarray
In [16]:
# Let's try smi mapped data
da1_smi = xr.open_dataset('A20110012011008.L3m_8D_CHL_chlor_a_4km.nc')
In [15]:
da1_smi.var
Out[15]:
In [11]:
In [17]:
### Let's try to open multiple files in xarray (dask is required)
# http://xarray.pydata.org/en/stable/io.html
xr.open_mfdataset('A*.nc', concat_dim=['binDataDim', 'binIndexDim', 'binListDim'], group='level-3_binned_data')
# search code in: https://github.com/pydata/xarray/
# alright need to send a question to the xarray developer site
In [4]:
xr.open_dataset('A20110012011008.L3b_8D_CHL.nc', group='level-3_binned_data')
Out[4]:
In [7]:
test=xr.open_dataset('A20110092011016.L3b_8D_CHL.nc', group='level-3_binned_data')
test
Out[7]:
In [10]:
list(test.dims.keys())
Out[10]:
In [16]:
xr.open_mfdataset?
In [ ]: