def from_netcdf_1dsplice(infile, height_ind, lat_ind, lon_ind):
    """ Uses ncreadfile_dic which returns a dictionary of all data from netcdf"""

    ###nc readin/out
    df = EcoFOCI_netCDF(infile)
    nchandle = df._getnchandle_()

    params = df.get_vars() #gets all of them

    print "Parameters available: " 
    #print params
    
    ncdata = ncreadfile_dic_slice(nchandle, params, height_ind=height_ind, lat_ind=lat_ind, lon_ind=lon_ind)
    df.close()
    
    return ncdata
Beispiel #2
0
    def load(self):
        self.data = {}
        for ind, ncfile in enumerate(self.files_path):
            print("Working on {0}").format(ncfile)

            df = EcoFOCI_netCDF(ncfile)
            df.get_global_atts()
            vars_dic = df.get_vars()
            if self.plot_var in vars_dic:
                ncdata = df.ncreadfile_dic()
                df.close()
                ncdata[self.plot_var][np.where(
                    ncdata[self.plot_var] > 1e34)] = np.nan
            else:
                continue

            self.ncdata = ncdata  #only save last file
            self.data[self.pointer_dic['nominal_depth'][ind]] = {
                'data': ncdata[self.plot_var][:, 0, 0, 0],
                'time': EPIC2Datetime(ncdata['time'], ncdata['time2'])
            }
parser.add_argument('sourcefile',
                    metavar='sourcefile',
                    type=str,
                    help='complete path to netcdf file')
parser.add_argument('-m360',
                    '--m360',
                    action="store_true",
                    help='make range 0-360')

args = parser.parse_args()

###nc readin
ncfile = args.sourcefile
df = EcoFOCI_netCDF(ncfile)
global_atts = df.get_global_atts()
vars_dic = df.get_vars()
data = df.ncreadfile_dic()

if 'lon' in df.variables.keys():
    if args.m360:
        df.variables['lon'][:] = -1. * df.variables['lon'][:] + 360
    else:
        df.variables['lon'][:] = -1. * df.variables['lon'][:]
    vars_dic['lon'].units = 'degree_east'
elif 'longitude' in df.variables.keys():
    if args.m360:
        df.variables['longitude'][:] = -1. * df.variables['longitude'][:] + 360
    else:
        df.variables['longitude'][:] = -1. * df.variables['longitude'][:]
    vars_dic['longitude'].units = 'degree_east'
else:
Beispiel #4
0
if args.multi:

    ### cycle through all files, retrieve data and plot
    print files_path
    writer = pd.ExcelWriter('data/' + MooringID + '_' + plot_var + '.xlsx',
                            engine='xlsxwriter',
                            datetime_format='YYYY-MM-DD HH:MM:SS')
    label_thin = []
    for ind, ncfile in enumerate(files_path):
        print "Working on {activefile}".format(activefile=ncfile)

        #open/read netcdf files
        df = EcoFOCI_netCDF(ncfile)
        global_atts = df.get_global_atts()
        vars_dic = df.get_vars()
        ncdata = df.ncreadfile_dic()
        df.close()

        nctime = EPIC2Datetime(ncdata['time'], ncdata['time2'])

        #find and replace missing values with nans so they don't plot
        try:
            ncdata[plot_var][np.where(ncdata[plot_var] > 1e30)] = np.nan
            try:
                label_thin = label_thin + [label[ind]]
            except TypeError:
                label_thin = label_thin + ['']

        except KeyError:
            pass