def process_woa(config, decades): ''' Download WOA 18 temperature and salinity, and remap them to the ISMIP6 grid ''' try: os.makedirs('woa') except OSError: pass print('Processing World Ocean Atlas...') woaDecades = ['95A4', 'A5B7'] woaWeights = [10., 13.] for decade in woaDecades: for fieldName, shortName in [('temperature', 't'), ('salinity', 's')]: baseURL = 'https://data.nodc.noaa.gov/thredds/fileServer/ncei/' \ 'woa/{}/{}/0.25/'.format(fieldName, decade) fileNames = ['woa18_{}_{}00_04.nc'.format(decade, shortName)] download_files(fileNames, baseURL, 'woa') remap.remap_woa(config, woaDecades, woaWeights, decades) print('Done.')
def process_meop(config): ''' Download MEOP temperature and salinity, and bin them on the ISMIP6 grid ''' try: os.makedirs('meop') except OSError: pass print('Processing Marine Mammals Exploring the Oceans Pole to Pole ' '(MEOP)...') if not os.path.exists('meop/MEOP-CTD_2018-04-10'): baseURL = 'https://www.seanoe.org/data/00343/45461/data' fileNames = ['58202.zip'] download_files(fileNames, baseURL, 'meop') print(' Decompressing MEOP data...') args = ['unzip', 'meop/58202.zip', '-d', 'meop/'] returncode = subprocess.call(args) if returncode not in [0, 1, 2]: raise subprocess.CalledProcessError(returncode, args) print(' Done.') _bin_meop(config, 'TEMP', 'temperature') _bin_meop(config, 'PSAL', 'salinity') print('Done.')
def process_en4(config, startYear, endYear): ''' Download EN4 temperature and salinity, and bin them on the ISMIP6 grid ''' try: os.makedirs('en4/zips') except OSError: pass print('Processing UK Met Office EN4...') if not os.path.exists('en4/profiles'): baseURL = 'https://www.metoffice.gov.uk/hadobs/en4/data/en4-2-1/' fileNames = [ 'EN.4.2.1.profiles.g10.{}.zip'.format(year) for year in range(startYear, endYear + 1) ] download_files(fileNames, baseURL, 'en4/zips') try: os.makedirs('en4/profiles') except OSError: pass print(' Decompressing EN4 data...') widgets = [ ' ', progressbar.Percentage(), ' ', progressbar.Bar(), ' ', progressbar.ETA() ] bar = progressbar.ProgressBar(widgets=widgets, maxval=len(fileNames)).start() for index, fileName in enumerate(fileNames): with zipfile.ZipFile('en4/zips/{}'.format(fileName), 'r') as f: f.extractall('en4/profiles') bar.update(index + 1) bar.finish() res = get_res(config) tempFileName = 'en4/en4_temperature_{}-{}_{}.nc'.format( startYear, endYear, res) salinFileName = 'en4/en4_salinity_{}-{}_{}.nc'.format( startYear, endYear, res) if not os.path.exists(salinFileName): dsSalinity = _bin_en4(config, 'PSAL', 'salinity', startYear, endYear) dsSalinity.to_netcdf(salinFileName) dsSalinity.close() if not os.path.exists(tempFileName): dsSalinity = xarray.open_dataset(salinFileName) dsPotTemp = _bin_en4(config, 'POTM', 'temperature', startYear, endYear) dsTemp = potential_to_in_situ_temperature(dsPotTemp, dsSalinity) dsTemp.to_netcdf(tempFileName) print('Done.')
def _download_imbie(): ''' Download the geojson files that define the IMBIE basins ''' if not os.path.exists( 'imbie/ANT_Basins_IMBIE2_v1.6/ANT_Basins_IMBIE2_v1.6.shp'): # download geojsonURL = 'http://imbie.org/wp-content/uploads/2016/09/' fileNames = ['ANT_Basins_IMBIE2_v1.6.zip'] download_files(fileNames, geojsonURL, 'imbie') print('Decompressing IMBIE2 data...') # unzip with zipfile.ZipFile('imbie/ANT_Basins_IMBIE2_v1.6.zip', 'r') as f: f.extractall('imbie/ANT_Basins_IMBIE2_v1.6/') print(' Done.')
def _bedmap2_bin_to_netcdf(outFileName): if os.path.exists(outFileName): return fields = ['bed', 'surface', 'thickness', 'coverage', 'rockmask', 'grounded_bed_uncertainty', 'icemask_grounded_and_shelves'] allExist = True for field in fields: fileName = 'bedmap2/bedmap2_bin/bedmap2_{}.flt'.format(field) if not os.path.exists(fileName): allExist = False break if not allExist: # download baseURL = 'https://secure.antarctica.ac.uk/data/bedmap2' fileNames = ['bedmap2_bin.zip'] download_files(fileNames, baseURL, 'bedmap2') print('Decompressing Bedmap2 data...') # unzip with zipfile.ZipFile('bedmap2/bedmap2_bin.zip', 'r') as f: f.extractall('bedmap2/') print(' Done.') print('Converting Bedmap2 to NetCDF...') ds = xarray.Dataset() x = numpy.linspace(-3333000., 3333000., 6667) y = x ds['x'] = ('x', x) ds.x.attrs['units'] = 'meters' ds['y'] = ('y', y) ds.y.attrs['units'] = 'meters' ds.attrs['Grid'] = "Datum = WGS84, earth_radius = 6378137., " \ "earth_eccentricity = 0.081819190842621, " \ "falseeasting = -3333000., " \ "falsenorthing = -3333000., " \ "standard_parallel = -71., central_meridien = 0, " \ "EPSG=3031" ds.attrs['proj'] = "+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 " \ "+x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs" ds.attrs['proj4'] = "+init=epsg:3031" # add Bedmap2 data for fieldName in fields: fileName = 'bedmap2/bedmap2_bin/bedmap2_{}.flt'.format(fieldName) with open(fileName, 'r') as f: field = numpy.fromfile(f, dtype=numpy.float32).reshape(6667, 6667) # flip the y axis field = field[::-1, :] # switch invalid values to be NaN (as expected by xarray) field[field == -9999.] = numpy.nan if fieldName == 'rockmask': # rock mask is zero where rock and -9999 (now NaN) elsewhere field = numpy.array(numpy.isfinite(field), numpy.float32) if fieldName == 'icemask_grounded_and_shelves': # split into separate grounded and floating masks ds['icemask_grounded'] = \ (('y', 'x'), numpy.array(field == 0, numpy.float32)) ds['icemask_shelves'] = \ (('y', 'x'), numpy.array(field == 1, numpy.float32)) ds['open_ocean_mask'] = \ (('y', 'x'), numpy.array(numpy.isnan(field), numpy.float32)) else: ds[fieldName] = (('y', 'x'), field) ds.to_netcdf(outFileName) print(' Done.')