mean of neighbor points in a netcdf-file

36 views
Skip to first unread message

Phil13

unread,
Sep 28, 2015, 11:04:51 AM9/28/15
to Iris
Hello,
I'm a newby and I've a problem calculating the mean and variance of a specific area over time.
I've a csv-file including lon & lat coordinates and a specific date which I want to match with a netcdf-file which contains daily precipitation of a year and lons& lats. My problem is to aggregate all precip-values per month and for an area around my points, coming from the csv-file. Acctually, I know how to aggregate the daily precipitation to monthly precipitation and match this with the csv-file points as shown below. BUT I've no clue how to get the mean or variance of the neighbor data around the points. Let's say the next 4 raster-values around each point coming from the csv-file.


for line in csv_data:
    try:
# defining x&y coordinates in the csv-file
        (x ,y) = (line[2], line[1])
# splitting time coords and match the date with the netcdf date
        time = parse(line[3])
        pd = iris.time.PartialDateTime(year=time.year, month=time.month, day=time.day)
        t_constraint = iris.Constraint(time=lambda cell: cell.point==pd)
# grid size: 1km x 1km; x &y constraints do only match with one netcdf value
        x_constraint = iris.Constraint(grid_longitude=lambda cell: x-500 < cell.point < x+500)
        y_constraint = iris.Constraint(grid_latitude=lambda cell: y-500 < cell.point < y+500)
#extract in a new cube
        with iris.FUTURE.context(cell_datetime_objects=True):
            precip_cube = cube.extract(t_constraint & x_constraint & y_constraint)
# print the matched data
        if precip_cube:
            print line[0], precip_cube[0].data
            output.append((line[0], line[1], line[2], line[3], float(precip_cube[0].data)))
    except:
        pass

I'm thankful for every hint.

marqh

unread,
Oct 16, 2015, 10:34:37 AM10/16/15
to Iris
Reply all
Reply to author
Forward
0 new messages