Пример #1
0
def getMappedGlobcolour(data_dir, min_lon, min_lat, max_lon, max_lat, start_date, end_date):
    '''
    Extracts subset of globcolour data based on lat/lon bounds and dates in the
    iso format '2012-01-31'
    '''
    file_count = 0
    file_list = np.asarray(os.listdir(data_dir))
    file_dates = [re.split('[._]', nc_filename)[1] for filename in file_list]

    # Get Lat/Lon from first data file in list
    nc_dataset = Dataset(file_list[0],'r')
    lons = nc_dataset.variables["lon"][:]
    lats = nc_dataset.variables["lat"][:]

    # Get average of chlorophyl values from date range
    for data_file in file_list[date_idx]:
        current_file = os.path.join(data_dir,data_file)
        # import data as numpy array, then get columns
        nc_dataset = Dataset(data_file,'r')
        vals = nc_dataset.variables["CHL1_mean"][:][:]
        # create running sum of values
        if last_vals:
            vals = vals+last_vals
        last_vals = vals
        file_count += 1

    vals = vals/file_count #TODO simple average

    # date_list = np.zeros(len(nc_rows), dtype=(np.str_, 19))
    date_list[:] = str(datetime.datetime.strptime(file_date, '%Y%m%d'))

    # Mesh Lat/Lon the unravel to return lists
    #TODO make mesh optional (i.e. return grid or lists)
    lon_mesh, lat_mesh = np.meshgrid(lons,lats)
    nc_coord_ids = np.vstack([nc_rows,nc_cols])
    lons, lats = grid.isin_convert(coord=nc_coord_ids)

    # Print Globcolour Information
    print '\nChl-a Information'
    print '-------------------------------------------'
    print 'Start Date: ', start_date
    print 'End Date: ', end_date
    print 'Max Chl-a: ', np.amax(vals)
    print 'Min Chl-a: ', np.amin(vals)

    return lons, lats, chl_vals
Пример #2
0
        print datafile
        nc_filepath, nc_filename = os.path.split(datafile)
        file_date = re.split('[._]', nc_filename)[1]

        # import data as numpy array, then get colums
        #nc_dataset = Dataset(nc_file,'r')
        nc_dataset = Dataset(datafile, 'r')
        nc_rows = nc_dataset.variables["row"][:]
        nc_cols = nc_dataset.variables["col"][:]
        nc_vals = nc_dataset.variables["CHL1_mean"][:]
        date_list = np.zeros(len(nc_rows), dtype=(np.str_, 19))
        date_list[:] = str(datetime.datetime.strptime(file_date, '%Y%m%d'))

        nc_coord_ids = np.vstack([nc_rows, nc_cols])

        lons, lats = grid.isin_convert(coord=nc_coord_ids)
        #print lon.shape,lat.shape,nc_vals.shape

        #print 'lon\n',np.amax(lon), np.amin(lon), lon.shape
        #print 'lat\n',np.amax(lat), np.amin(lat), lat.shape
        #print 'ncvals\n',np.amax(nc_vals), np.amin(nc_vals), np.size(nc_vals)
        #print file_date
        #print date_list
        #print np.swapaxes(np.vstack([lon,lat,nc_vals]),0,1)

        #nc_all = np.vstack([file_date,nc_coord_ids,nc_vals])
        #grid_coords = isin.isin_convert(nparray_coords)
        #grid_chla =

        # Write CSV
        #coordFile = open('./test-coords.csv', 'wb')
Пример #3
0
        print datafile
        nc_filepath, nc_filename = os.path.split(datafile)
        file_date = re.split('[._]', nc_filename)[1]

        # import data as numpy array, then get colums
        #nc_dataset = Dataset(nc_file,'r')
        nc_dataset = Dataset(datafile,'r')
        nc_rows = nc_dataset.variables["row"][:]
        nc_cols = nc_dataset.variables["col"][:]
        nc_vals = nc_dataset.variables["CHL1_mean"][:]
        date_list = np.zeros(len(nc_rows), dtype=(np.str_, 19))
        date_list[:] = str(datetime.datetime.strptime(file_date, '%Y%m%d'))

        nc_coord_ids = np.vstack([nc_rows,nc_cols])

        lons, lats = grid.isin_convert(coord=nc_coord_ids)
        #print lon.shape,lat.shape,nc_vals.shape

        #print 'lon\n',np.amax(lon), np.amin(lon), lon.shape
        #print 'lat\n',np.amax(lat), np.amin(lat), lat.shape
        #print 'ncvals\n',np.amax(nc_vals), np.amin(nc_vals), np.size(nc_vals)
        #print file_date
        #print date_list
        #print np.swapaxes(np.vstack([lon,lat,nc_vals]),0,1)

        #nc_all = np.vstack([file_date,nc_coord_ids,nc_vals])
        #grid_coords = isin.isin_convert(nparray_coords)
        #grid_chla =

        # Write CSV
        #coordFile = open('./test-coords.csv', 'wb')