def __init__(self, path=None, resolution='1min', xlim=None, ylim=None): # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/media/academia/data/raw/etopo') self.params['path'] = path self.params['fname'] = 'ETOPO1_Bed_g_gmt4.grd' # Reads file header f = self.open_file() lon = f.variables['x'].data lat = f.variables['y'].data f.close() if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) LON = lon_n(lon, xlim[0]) + 360 i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) selxx, selyy = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['offset_i'] = selx[0] self.params['tesffo_i'] = selx[-1] self.params['selxx'] = selxx self.params['ylim'] = ylim self.params['offset_j'] = sely[0] self.params['tesffo_j'] = sely[-1] self.params['selyy'] = selyy # Sets the grid attributes, dimensions, coordinates and variables. self.name = 'ocean_bathymetry' self.title = f.title self.description = """ ETOPO1 is a 1 arc-minute global relief model of Earth's surface that integrates land topography and ocean bathymetry. It was built from numerous global and regional data sets, and is available in "Ice Surface" (top of Antarctic and Greenland ice sheets) and "Bedrock" (base of the ice sheets) versions. Find out more about ETOPO at : http://www.ngdc.noaa.gov/mgg/global/global.html """ self.dimensions = dict(n=1, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time', k='height', j='latitude', i='longitude') self.variables = dict( time = atlantis.data.Variable( canonical_units='days since 0001-01-01 UTC', data=[0.], ), height = atlantis.data.get_standard_variable('height', data=[0.]), latitude = atlantis.data.get_standard_variable('latitude', data=lat), longitude = atlantis.data.get_standard_variable('longitude', data=lon), topo = atlantis.data.Variable( canonical_units='m', description='Topography of the Earth.' ) ) self.params['var_list'] = ['topo'] return
def __init__(self, path=None, mask_file=None, xlim=None, ylim=None): # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/home/sebastian/academia/data/ncdc.noaa/seawinds/stress/' 'daily') self.params['path'] = path self.params['mask_file'] = mask_file self.params['missing_value'] = -9999. # Generates list of files, tries to match them to the pattern and to # extract the time. file_pattern = 'tauxy([0-9]{8}).nc' flist = listdir(self.params['path']) flist, match = reglist(flist, file_pattern) self.params['file_list'] = flist if len(flist) == 0: return # Convert dates to matplotlib format, i.e. days since 0001-01-01 UTC. time_list = array([dates.datestr2num(item) for item in match]) # Reads first file in dataset to determine array geometry and # dimenstions (lon, lat) data = netcdf( '%s/%s' % (self.params['path'], self.params['file_list'][0]), 'r') for var in data.variables.keys(): if var in ['latitude', 'lat']: lat = data.variables[var].data elif var in ['longitude', 'lon']: lon = data.variables[var].data # If xlim and ylim are set, calculate how many indices have to be moved # in order for latitude array to start at xlim[0]. if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) # LON = lon_n(lon, xlim[1]) i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) ii, jj = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['ylim'] = ylim self.params['lon_i'] = ii self.params['lat_j'] = jj self.params['dlon'] = lon[1] - lon[0] self.params['dlat'] = lat[1] - lat[0] # Initializes the grid attributes, dimensions, coordinates and # variables. self.name = 'sea_surface_wind_stress' for attr, attr_value in vars(data).iteritems(): if attr in ['mode', 'filename']: continue if type(attr_value) == str: if attr in ['name']: self.name = attr_value elif attr in ['description', 'summary']: self.description = attr_value else: self.attributes[attr.lower()] = attr_value self.dimensions = dict(n=time_list.size, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time', k='height', j='latitude', i='longitude') # self.variables = dict( time=atlantis.data.variable( canonical_units='days since 0001-01-01 UTC', data=time_list, ), height=atlantis.data.get_standard_variable('height', data=[0.]), latitude=atlantis.data.get_standard_variable('latitude', data=lat), longitude=atlantis.data.get_standard_variable('longitude', data=lon), xm=atlantis.data.variable(canonical_units='km', description='Zonal distance.'), ym=atlantis.data.variable(canonical_units='km', description='Meridional distance.'), ) # self.variables['xm'].data, self.variables['ym'].data = (metergrid( self.variables['longitude'].data, self.variables['latitude'].data, unit='km')) # self.params['var_list'] = list() for var in data.variables.keys(): if var in ['tau', 'taux', 'tauy', 'tau_div', 'tau_curl']: attribs = dict() for attr, attr_value in vars(data.variables[var]).iteritems(): if attr == '_FillValue': attribs['missing_value'] = attr_value elif attr == 'data': continue elif attr == 'long_name': attribs['description'] = attr_value elif attr == 'units': if attr_value == 'N/m**2': a = 'N m-2' else: a = attr_value attribs['canonical_units'] = a else: attribs[attr] = attr_value self.variables[var] = atlantis.data.variable(**attribs) self.params['var_list'].append(var) if self.variables[var].missing_value == None: self.variables[var].missing_value = ( self.params['missing_value']) # data.close() return
def __init__(self, path=None, resolution='1min', xlim=None, ylim=None): # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/media/academia/data/raw/etopo') self.params['path'] = path self.params['fname'] = 'ETOPO1_Bed_g_gmt4.grd' # Reads file header f = self.open_file() lon = f.variables['x'].data lat = f.variables['y'].data f.close() if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) LON = lon_n(lon, xlim[0]) + 360 i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) selxx, selyy = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['offset_i'] = selx[0] self.params['tesffo_i'] = selx[-1] self.params['selxx'] = selxx self.params['ylim'] = ylim self.params['offset_j'] = sely[0] self.params['tesffo_j'] = sely[-1] self.params['selyy'] = selyy # Sets the grid attributes, dimensions, coordinates and variables. self.name = 'ocean_bathymetry' self.title = f.title self.description = """ ETOPO1 is a 1 arc-minute global relief model of Earth's surface that integrates land topography and ocean bathymetry. It was built from numerous global and regional data sets, and is available in "Ice Surface" (top of Antarctic and Greenland ice sheets) and "Bedrock" (base of the ice sheets) versions. Find out more about ETOPO at : http://www.ngdc.noaa.gov/mgg/global/global.html """ self.dimensions = dict(n=1, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time', k='height', j='latitude', i='longitude') self.variables = dict( time=atlantis.data.Variable( canonical_units='days since 0001-01-01 UTC', data=[0.], ), height=atlantis.data.get_standard_variable('height', data=[0.]), latitude=atlantis.data.get_standard_variable('latitude', data=lat), longitude=atlantis.data.get_standard_variable('longitude', data=lon), topo=atlantis.data.Variable( canonical_units='m', description='Topography of the Earth.')) self.params['var_list'] = ['topo'] return
def __init__(self, path=None, mask_file=None, xlim=None, ylim=None): # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/home/sebastian/academia/data/ncdc.noaa/seawinds/stress/' 'daily') self.params['path'] = path self.params['mask_file'] = mask_file self.params['missing_value'] = -9999. # Generates list of files, tries to match them to the pattern and to # extract the time. file_pattern = 'tauxy([0-9]{8}).nc' flist = listdir(self.params['path']) flist, match = reglist(flist, file_pattern) self.params['file_list'] = flist if len(flist) == 0: return # Convert dates to matplotlib format, i.e. days since 0001-01-01 UTC. time_list = array([dates.datestr2num(item) for item in match]) # Reads first file in dataset to determine array geometry and # dimenstions (lon, lat) data = netcdf('%s/%s' % (self.params['path'], self.params['file_list'][0]), 'r') for var in data.variables.keys(): if var in ['latitude', 'lat']: lat = data.variables[var].data elif var in ['longitude', 'lon']: lon = data.variables[var].data # If xlim and ylim are set, calculate how many indices have to be moved # in order for latitude array to start at xlim[0]. if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) # LON = lon_n(lon, xlim[1]) i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) ii, jj = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['ylim'] = ylim self.params['lon_i'] = ii self.params['lat_j'] = jj self.params['dlon'] = lon[1] - lon[0] self.params['dlat'] = lat[1] - lat[0] # Initializes the grid attributes, dimensions, coordinates and # variables. self.name = 'sea_surface_wind_stress' for attr, attr_value in vars(data).iteritems(): if attr in ['mode', 'filename']: continue if type(attr_value) == str: if attr in ['name']: self.name = attr_value elif attr in ['description', 'summary']: self.description = attr_value else: self.attributes[attr.lower()] = attr_value self.dimensions = dict(n=time_list.size, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time', k='height', j='latitude', i='longitude') # self.variables = dict( time = atlantis.data.variable( canonical_units='days since 0001-01-01 UTC', data=time_list, ), height = atlantis.data.get_standard_variable('height', data=[0.]), latitude = atlantis.data.get_standard_variable('latitude', data=lat), longitude = atlantis.data.get_standard_variable('longitude', data=lon), xm = atlantis.data.variable( canonical_units = 'km', description = 'Zonal distance.' ), ym = atlantis.data.variable( canonical_units = 'km', description = 'Meridional distance.' ), ) # self.variables['xm'].data, self.variables['ym'].data = ( metergrid(self.variables['longitude'].data, self.variables['latitude'].data, unit='km') ) # self.params['var_list'] = list() for var in data.variables.keys(): if var in ['tau', 'taux', 'tauy', 'tau_div', 'tau_curl']: attribs = dict() for attr, attr_value in vars(data.variables[var]).iteritems(): if attr == '_FillValue': attribs['missing_value'] = attr_value elif attr == 'data': continue elif attr == 'long_name': attribs['description'] = attr_value elif attr == 'units': if attr_value == 'N/m**2': a = 'N m-2' else: a = attr_value attribs['canonical_units'] = a else: attribs[attr] = attr_value self.variables[var] = atlantis.data.variable(**attribs) self.params['var_list'].append(var) if self.variables[var].missing_value == None: self.variables[var].missing_value = ( self.params['missing_value']) # data.close() return
def __init__(self, path=None, resolution='30sec', xlim=None, ylim=None): # NOTE: Within the netCDF files for the GEBCO_08 Grid and # GEBCO_08 SID Grid, the data are stored as one-dimensional arrays of # 2-byte signed integer values. # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/academia/data/raw/gebco') self.params['path'] = path if resolution == '30sec': #self.params['fname'] = 'gebco_08.nc' self.params['fname'] = 'GEBCO_2014_1D.nc' elif resolution == '1min': self.params['fname'] = 'gebco_1min.nc' raise Warning('Note: this dataset was not tested yet.') else: raise ValueError('Invalid resolution `{}`.'.format(resolution)) # Reads file header f = self.open_file() self.params['x_range'] = f.variables['x_range'].data self.params['y_range'] = f.variables['y_range'].data self.params['spacing'] = f.variables['spacing'].data f.close() # For the 30 arc-second file, data start at the northwest corner, # i.e. 89º59'45''N 179º59'45''W, and are arranged in latitudinal # bands. Data values are pixel centre registered, i.e. they refer to # data values at the centro of the grid cells. lon = arange(self.params['x_range'][0] + self.params['spacing'][0]/2., self.params['x_range'][1], self.params['spacing'][0]) lat = arange(self.params['y_range'][0] + self.params['spacing'][1]/2., self.params['y_range'][1], self.params['spacing'][1]) self.params['nlon'] = int((self.params['x_range'][1] - self.params['x_range'][0]) / self.params['spacing'][0]) self.params['nlat'] = int((self.params['y_range'][1] - self.params['y_range'][0]) / self.params['spacing'][1]) if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) LON = lon_n(lon, xlim[0]) + 360 i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) selxx, selyy = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['offset_i'] = selx[0] self.params['tesfoo_i'] = selx[-1] self.params['selxx'] = selxx self.params['ylim'] = ylim self.params['offset_j'] = sely[0] self.params['tesfoo_j'] = sely[-1] self.params['selyy'] = selyy # Sets the grid attributes, dimensions, coordinates and variables. self.name='ocean_bathymetry' self.title='General Bathymetric Chart of the Oceans (GEBCO)' self.description = """ The General Bathymetric Chart of the Oceans (GEBCO) consists of an international group of experts who work on the development of a range of bathymetric data sets and data products, with the aim of providing the most authoritative, publicly-available bathymetric grids for the world's oceans. GEBCO operates under the joint auspices of the International Hydrographic Organization (IHO) and the Intergovernmental Oceanographic Commission (IOC) of UNESCO. Find out more about GEBCO at the web site: www.gebco.net """ self.dimensions = dict(n=1, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time' , k='height', j='latitude', i='longitude') self.variables = dict( time = atlantis.data.Variable( canonical_units='days since 0001-01-01 UTC', data=[0.], ), height = atlantis.data.get_standard_variable('height', data=[0.]), latitude = atlantis.data.get_standard_variable('latitude', data=lat), longitude = atlantis.data.get_standard_variable('longitude', data=lon), topo = atlantis.data.Variable( canonical_units='m', description='Topography of the Earth.' ) ) self.params['var_list'] = ['topo'] return
def __init__(self, path=None, resolution='30sec', xlim=None, ylim=None): # NOTE: Within the netCDF files for the GEBCO_08 Grid and # GEBCO_08 SID Grid, the data are stored as one-dimensional arrays of # 2-byte signed integer values. # Initializes the variables to default values. The indices 'n', 'k', # 'j' and 'i' refer to the temporal, height, meridional and zonal # coordinates respectively. If one of these indexes is set to 'None', # then it is assumed infinite size, which is relevant for the 'time' # coordinate. self.attributes = dict() self.dimensions = dict(n=0, k=0, j=0, i=0) self.coordinates = dict(n=None, k=None, j=None, i=None) self.variables = dict() self.params = dict() self.stencil_coeffs = dict() self.stencil_params = dict() # Sets global parameters for grid. if path == None: path = ('/academia/data/raw/gebco') self.params['path'] = path if resolution == '30sec': #self.params['fname'] = 'gebco_08.nc' self.params['fname'] = 'GEBCO_2014_1D.nc' elif resolution == '1min': self.params['fname'] = 'gebco_1min.nc' raise Warning('Note: this dataset was not tested yet.') else: raise ValueError('Invalid resolution `{}`.'.format(resolution)) # Reads file header f = self.open_file() self.params['x_range'] = f.variables['x_range'].data self.params['y_range'] = f.variables['y_range'].data self.params['spacing'] = f.variables['spacing'].data f.close() # For the 30 arc-second file, data start at the northwest corner, # i.e. 89º59'45''N 179º59'45''W, and are arranged in latitudinal # bands. Data values are pixel centre registered, i.e. they refer to # data values at the centro of the grid cells. lon = arange( self.params['x_range'][0] + self.params['spacing'][0] / 2., self.params['x_range'][1], self.params['spacing'][0]) lat = arange( self.params['y_range'][0] + self.params['spacing'][1] / 2., self.params['y_range'][1], self.params['spacing'][1]) self.params['nlon'] = int( (self.params['x_range'][1] - self.params['x_range'][0]) / self.params['spacing'][0]) self.params['nlat'] = int( (self.params['y_range'][1] - self.params['y_range'][0]) / self.params['spacing'][1]) if (xlim != None) | (ylim != None): if xlim == None: xlim = (lon.min(), lon.max()) if ylim == None: ylim = (lat.min(), lat.max()) LON = lon_n(lon, xlim[0]) + 360 i = argsort(LON) selx = i[flatnonzero((LON[i] >= xlim[0]) & (LON[i] <= xlim[1]))] sely = flatnonzero((lat >= ylim[0]) & (lat <= ylim[1])) selxx, selyy = meshgrid(selx, sely) lon = LON[selx] lat = lat[sely] self.params['xlim'] = xlim self.params['offset_i'] = selx[0] self.params['tesfoo_i'] = selx[-1] self.params['selxx'] = selxx self.params['ylim'] = ylim self.params['offset_j'] = sely[0] self.params['tesfoo_j'] = sely[-1] self.params['selyy'] = selyy # Sets the grid attributes, dimensions, coordinates and variables. self.name = 'ocean_bathymetry' self.title = 'General Bathymetric Chart of the Oceans (GEBCO)' self.description = """ The General Bathymetric Chart of the Oceans (GEBCO) consists of an international group of experts who work on the development of a range of bathymetric data sets and data products, with the aim of providing the most authoritative, publicly-available bathymetric grids for the world's oceans. GEBCO operates under the joint auspices of the International Hydrographic Organization (IHO) and the Intergovernmental Oceanographic Commission (IOC) of UNESCO. Find out more about GEBCO at the web site: www.gebco.net """ self.dimensions = dict(n=1, k=1, j=lat.size, i=lon.size) self.coordinates = dict(n='time', k='height', j='latitude', i='longitude') self.variables = dict( time=atlantis.data.Variable( canonical_units='days since 0001-01-01 UTC', data=[0.], ), height=atlantis.data.get_standard_variable('height', data=[0.]), latitude=atlantis.data.get_standard_variable('latitude', data=lat), longitude=atlantis.data.get_standard_variable('longitude', data=lon), topo=atlantis.data.Variable( canonical_units='m', description='Topography of the Earth.')) self.params['var_list'] = ['topo'] return