-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added iceberg fluxes file and a few other small things
- Loading branch information
Kaitlin Alexander
committed
Aug 4, 2016
1 parent
a4b9cae
commit 6bf7dbb
Showing
9 changed files
with
324 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from netCDF4 import Dataset | ||
from numpy import * | ||
from scipy.interpolate import griddata | ||
|
||
# Read Martin and Adcroft's monthly climatology of freshwater fluxes | ||
# from iceberg melt, and add to the precipitation fields used by | ||
# ROMS and CICE. I suppose I should technically use a separate field | ||
# such as runoff, but this is easier and has the same effect! | ||
# Input: | ||
# file = path to ROMS FC forcing file, containing one year of monthly | ||
# averages for precipitation ("rain") in m/12h | ||
def add_iceberg_melt (file): | ||
|
||
# Naming conventions for iceberg files | ||
iceberg_head = '/short/m68/kaa561/ROMS-CICE-MCT/data/MartinAdcroft2010_iceberg_meltfluxes/icebergs.1861-1960.' | ||
iceberg_tail = '.melt.nc' | ||
# Iceberg grid file | ||
iceberg_grid = '/short/m68/kaa561/ROMS-CICE-MCT/data/MartinAdcroft2010_iceberg_meltfluxes/icebergs.static.nc' | ||
# ROMS grid file | ||
roms_grid ='/short/m68/kaa561/ROMS-CICE-MCT/apps/common/grid/circ30S_quarterdegree_10m.nc' | ||
# Density of freshwater | ||
rho_w = 1e3 | ||
# Seconds in 12 hours | ||
seconds_per_12h = 60.*60.*12. | ||
|
||
# Read ROMS grid | ||
id = Dataset(roms_grid, 'r') | ||
lon_roms = id.variables['lon_rho'][:,:] | ||
lat_roms = id.variables['lat_rho'][:,:] | ||
id.close() | ||
|
||
# Read the iceberg grid | ||
id = Dataset(iceberg_grid, 'r') | ||
lon_iceberg = id.variables['lon'][:,:] | ||
lat_iceberg = id.variables['lat'][:,:] | ||
id.close() | ||
|
||
# Make sure longitudes are between 0 and 360 | ||
index = lon_iceberg < 0 | ||
lon_iceberg[index] = lon_iceberg[index] + 360 | ||
|
||
# Loop over months | ||
for month in range(12): | ||
print 'Processing month ' + str(month+1) | ||
# Reconstruct the filename of this month's iceberg data | ||
if month+1 < 10: | ||
month_str = '0' + str(month+1) | ||
else: | ||
month_str = str(month+1) | ||
iceberg_file = iceberg_head + month_str + iceberg_tail | ||
# Read iceberg freshwater flux in kg/m^2/s | ||
id = Dataset(iceberg_file, 'r') | ||
melt_iceberg = id.variables['melt'][0,:,:] | ||
id.close() | ||
# Interpolate to ROMS grid | ||
melt_roms = interp_iceberg2roms(melt_iceberg, lon_iceberg, lat_iceberg, lon_roms, lat_roms) | ||
# Convert to m per 12 h | ||
melt_roms = melt_roms/rho_w*seconds_per_12h | ||
# Add to precipitation field for this month | ||
id = Dataset(file, 'a') | ||
id.variables['rain'][12*year+month,:,:] = id.variables['rain'][12*year+month,:,:] - melt_roms | ||
id.close() | ||
|
||
|
||
# Given a field A on the iceberg grid, linearly interpolate to the ROMS grid. | ||
# Input: | ||
# A = 2D array (m x n) containing data on the iceberg grid | ||
# lon_iceberg = 2D array (m x n) contaning longitude values on the | ||
# iceberg grid, from 0 to 360 | ||
# lat_iceberg = 2D array (m x n) containing latitude values on the | ||
# iceberg grid | ||
# lon_roms = 2D array (p x q) containing longitude values on the ROMS grid, | ||
# from 0 to 360 | ||
# lat_roms = 2D array (p x q) containing latitude values on the ROMS grid | ||
# Output: | ||
# A_interp = 2D array (p x q) containing A interpolated to the ROMS grid | ||
def interp_iceberg2roms (A, lon_iceberg, lat_iceberg, lon_roms, lat_roms): | ||
|
||
# Set up an nx2 array containing the coordinates of each point in the | ||
# iceberg grid | ||
points = empty([size(lon_iceberg), 2]) | ||
points[:,0] = ravel(lon_iceberg) | ||
points[:,1] = ravel(lat_iceberg) | ||
# Also flatten the data | ||
values = ravel(A) | ||
# Now set up an mx2 array containing the coordinates of each point | ||
# we want to interpolate to, in the ROMS grid | ||
xi = empty([size(lon_roms), 2]) | ||
xi[:,0] = ravel(lon_roms) | ||
xi[:,1] = ravel(lat_roms) | ||
# Now call griddata; fill out-of-bounds values (such as under ice shelves) | ||
# with zeros | ||
result = griddata(points, values, xi, method='linear', fill_value=0.0) | ||
# Un-flatten the result | ||
A_interp = reshape(result, shape(lon_roms)) | ||
|
||
return A_interp | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
file = raw_input('Path to ROMS input FC file containing one year of monthly data: ') | ||
add_iceberg_melt(file) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Name Mass loss Melt rate | ||
Amery 39 +/- 21 0.65 +/- 0.35 | ||
West 26 +/- 13 1.65 +/- 0.82 | ||
Shackleton 76 +/- 23 2.20 +/- 0.67 | ||
Totten 64 +/- 12 9.89 +/- 1.92 | ||
Moscow Uni 28 +/- 7 4.93 +/- 1.32 | ||
Mertz 5 +/- 4 0.87 +/- 0.79 | ||
Ross 34 +/- 25 0.07 +/- 0.05 | ||
Sulzberger 28 +/- 6 2.16 +/- 0.44 | ||
Getz 136 +/- 23 4.09 +/- 0.68 | ||
Thwaites 69 +/- 18 15.22 +/- 3.87 | ||
Pine Island 95 +/- 14 15.96 +/- 2.38 | ||
Abbot 86 +/- 22 2.72 +/- 0.7 | ||
George VI 144 +/- 42 2.88 +/- 0.83 | ||
Filchner-Ronne 50 +/- 40 0.12 +/- 0.09 | ||
Brunt-RL 26 +/- 16 0.33 +/- 0.20 | ||
Jelbart-Fimbul 24 +/- 13 0.52 +/- 0.27 | ||
Total 1454 +/- 174 0.94 +/- 0.11 | ||
|
||
Notes: | ||
Mertz a fair bit lower | ||
Ross a bit lower | ||
Sulzberger higher | ||
Thwaites lower | ||
Abbot higher | ||
R-F waaay lower | ||
Brunt-Riiser-Larsen much higher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from netCDF4 import Dataset | ||
from numpy import * | ||
|
||
# Convert a 1-year monthly dataset into an annually repeating dataset for | ||
# ROMS-CICE. The easiest way to do this is by making 4 identical files, altering | ||
# the time axis so data is always on the 15th of a month, and setting the cycle | ||
# length attribute to 1461 days (4 years where one is a leap year). | ||
# NB: This script assumes the first file has been copied three times to the | ||
# correct names of the next three files. | ||
# Sort of NB: This script uses the basic definition of leap year = year | ||
# divisible by 4. This does not hold for all years ending in 00, | ||
# e.g. 2000 was a leap year but 1900 wasn't. | ||
# Input: | ||
# directory = string containing path to the directory where the files exist | ||
# head = string containing the first part of each filename | ||
# tail = string containing the last part of each filename | ||
# NB: This script assumes the files differ only by the year, e.g. | ||
# AN_1995_unlim.nc through AN_1998_unlim.nc | ||
# year_start = integer containing the first year, which is also the year of | ||
# the original data | ||
|
||
def process (directory, head, tail, year_start): | ||
|
||
days_per_month = array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) | ||
|
||
# Loop through the four years | ||
for year in range(year_start,year_start+4): | ||
|
||
# Check if this is a leap year and update days in February | ||
if year % 4 == 0: | ||
days_per_month[1] = 29 | ||
else: | ||
days_per_month[1] = 28 | ||
|
||
# Make a time axis with data on the 15th of every month | ||
# First get the number of days between year_start and the current year | ||
start_day = 365*(year-year_start) | ||
if year > year_start: | ||
for year_tmp in range(year_start, year): | ||
if year_tmp % 4 == 0: | ||
# A leap year has occurred | ||
start_day += 1 | ||
# Start on Jan 15th at midnight | ||
time = [start_day + 14] | ||
# Loop over months | ||
for month in range(1,12): | ||
time.append(start_day + sum(days_per_month[0:month]) + 14) | ||
|
||
file = directory + head + str(year) + tail | ||
print 'Processing ' + file | ||
id = Dataset(file, 'a') | ||
id.variables['time'][:] = time | ||
# Set the cycle_length to 4 years | ||
id.variables['time'].cycle_length = 365.0*4 + 1 | ||
id.close() | ||
|
||
|
||
# Command-line interface | ||
if __name__ == '__main__': | ||
|
||
# User parameters to edit here | ||
|
||
# Data where files <an_head>yyyy<tail> and <fc_head>yyyy<tail> exist | ||
directory = '/short/m68/kaa561/ROMS-CICE-MCT/data/ERA_Interim/' | ||
# First part of filename for AN and FC files | ||
an_head = 'AN_' | ||
fc_head = 'FC_' | ||
# Last part of filename (common to both AN and FC) | ||
tail = '_monthly.nc' | ||
# Year to build data from | ||
year_start = 1995 | ||
|
||
# Run the actual script | ||
process(directory, an_head, tail, year_start) | ||
process(directory, fc_head, tail, year_start) | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.