For my project I want to extract data from a netCDF file, my file represent the Ocean Surface Temperature in function of latitude/longitude. I want to select on point with precise coordinate and then do a mean for each months for several years.
import netCDF4 as nc
import numpy as np
import cdo
import os
import pandas as pd
from scipy.io import netcdf
from netCDF4 import Dataset
from netCDF4 import num2date
import matplotlib as mpl
import matplotlib.pylab as plt
from cdo import Cdo
cdo = Cdo()
data = "/Users/bf/Desktop/Stage
tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
ds = nc.Dataset(data)
infile = "/Users/bf/Desktop/Stage/tos_Omon_EC-Earth3_historical_r5i1p1f1_gn_185001-201412.nc"
#to select years : 1979-2014
#new name for the file with the selected years : tos_1979-2014.nc
cdo.seldate('1979-01-01,2014-12-31', input=infile, output="tos_1979-2014.nc")
#to select longitute and latitute -> no important now
#new name for the file with the selected longitudes/latitudes : tos_1979-2014_2.nc
cdo.sellonlatbox('-26.45,65.03', input="tos_1979-2014.nc", output="tos_1979-2014_2.nc")
#ymonavg : multi-year monthly statistical values average
cdo.ymonavg(input="tos_1979-2014_2.nc", output="tos_1979-2014_mean_2.nc")
I thought of extract my temperature data (to do a mean of the temperature for each months since 1979 to 2014) and to put them in a data frame, to do graphics thereafter (with mathplolib).
But while using CDO
tool, I can't select just one point. Maybe I have to use another tool but I don't know how to do it.
Thanks for your help !