Beispiel #1
0
        var_is_3d = True

    if not var_is_3d:
        var = V
        vname = V
    else:
        var = V[3:-3]
        vname = V[3:]
        pressure = int(V[-3:]) * 100

    for n, date in enumerate(date_list):
        print date

        # Find the file and open it
        nc_path, nc_file = findClimoFile(grep + date + "*", directory)
        nc = camgoda(nc_path)

        # Read in the variable data
        if var == "PRECT_d18O":
            nc.PRECT_d18O(box)
        elif var == "PRECT_dD":
            nc.PRECT_dD(box)
        elif var == "PRECT_dxs":
            nc.PRECT_dxs(box)
        elif var == "QFLX_d18O":
            nc.QFLX_d18O(box)
        elif var == "QFLX_dD":
            nc.QFLX_dD(box)
        elif var == "fluxDelta":
            nc.fluxDelta(box)
        elif var == "Column_d18OV":
Beispiel #2
0
# Extract the dates
dates = camdates(start, end, months, days)

for n, date in enumerate(dates):
    # Find the file for this date
    cfull_path, cfname = findClimoFile(
        "*" + grep_pre + "*" + date + "*" + grep_post + "*", cdir)
    tfull_path, tfname = findClimoFile(
        "*" + grep_pre + "*" + date + "*" + grep_post + "*", tdir)
    if cfname != 0:
        print cfname
    if tfname != 0:
        print tfname
    # Open the file
    cnc = camgoda(cfull_path)
    tnc = camgoda(tfull_path)
    is3d, var, vname = cnc.ExtractData(variable, box)
    is3d, var, vname = tnc.ExtractData(variable, box)
    if n == 0:
        nlats, nlons = cnc.data.shape
        boxlat = cnc.boxlat
        boxlon = cnc.boxlon
        d = np.zeros(shape=(len(dates), nlats * nlons))
    d[n, :] = np.ndarray.flatten(tnc.data - cnc.data)

# Compute the amplitude timeseries and EOF spatial distributions of the data array
print "Computing the EOF..."
EOF = Eof(d, center=removeMeans)
eof = EOF.eofs(neofs=num_eofs)
pca = EOF.pcs(npcs=num_eofs, pcscaling=1)
Beispiel #3
0
    if not var_is_3d:
        var = V
        vname = V
    else:
        var = V[3:-3]
        vname = V[3:]
        pressure = int(V[-3:]) * 100

    for n, date in enumerate(date_list):
        print date
        c_nc_path, c_nc_file = findClimoFile(grep + date + "*",
                                             control_directory)
        t_nc_path, t_nc_file = findClimoFile(grep + date + "*", test_directory)
        #print c_nc_path
        #print t_nc_path
        c_nc = camgoda(c_nc_path)
        t_nc = camgoda(t_nc_path)

        # Extract the variable data
        # Special variables
        if var == "PRECT_d18O":
            t_nc.PRECT_d18O(box)
            c_nc.PRECT_d18O(box)

        elif var == "PRECT_dD":
            t_nc.PRECT_dD(box)
            c_nc.PRECT_dD(box)

        elif var == "PRECT_dxs":
            t_nc.PRECT_dxs(box)
            c_nc.PRECT_dxs(box)
	right_lon = 160

box = (southern_lat, northern_lat, left_lon, right_lon)

tloc_var_master = []
cloc_var_master = []

for n, d in enumerate(dates):
	# Find the file
	cpath, cfilename = findClimoFile('*' + grep + "*" + d + '*', directory = cdir)
	tpath, tfilename = findClimoFile('*' + grep + "*" + d + '*', directory = tdir)
	print tfilename
	print cfilename
	
	# Open the file
	cnc = camgoda(cpath)
	tnc = camgoda(tpath)
	
	if n == 0:
		cnc.ExtractData(v1, box) # This sets boxlat and boxlon
		lats = cnc.boxlat
		lons = cnc.boxlon
		hold = np.zeros(shape = (len(lats), len(lons), len(dates), 2, 2)) # lat, lon, dates, var, state

	hold[:,:,n,0,0] = cnc.ExtractData(v1, box, returnData = True)
	hold[:,:,n,0,1] = tnc.ExtractData(v1, box, returnData = True)
	hold[:,:,n,1,0] = cnc.ExtractData(v2, box, returnData = True)
	hold[:,:,n,1,1] = tnc.ExtractData(v2, box, returnData = True)
	

print "All data extracted, computing correlations..."
Beispiel #5
0
        print "Found file " + controlfn
    print "\nLooking for test " + grep + " files in " + tdir + "..."
    tfile, testfn = findClimoFile("*" + grep + "*", tdir)
    if not testdatafname:
        sys.exit()
    else:
        print "Found file " + testfn

else:
    controlfn = os.path.splitext(os.path.split(cfile)[1])[0]
    testfn = os.path.splitext(os.path.split(tfile)[1])[0]
    print "\nControl file is " + controlfn
    print "\nTest file is " + testfn

# Open the file
cnc = camgoda(cfile)
tnc = camgoda(tfile)

for v in variables:
    # Extract the variable
    cnc.ExtractData(v, box)
    tnc.ExtractData(v, box)

    # Save the data
    cvar = cnc.data
    tvar = tnc.data
    long_name = cnc.long_name
    units = cnc.units
    lon = cnc.boxlon

    # Zonally average the data
Beispiel #6
0
    if not controldatafname:
        sys.exit()
    print "Found control file: " + controlfn
    print "\nLooking for test " + grep + " files in " + testdir
    testdatafname, testfn = findClimoFile("*" + grep + "*", testdir)
    if not testdatafname:
        sys.exit()
    print "Found test file: " + testfn
else:
    print "\nControl file is " + controldatafname
    print "\nTest file is " + testdatafname
    controlfn = os.path.splitext(os.path.split(controldatafname)[1])[0]
    testfn = os.path.splitext(os.path.split(testdatafname)[1])[0]

# Read the data
controldata = camgoda(controldatafname)
testdata = camgoda(testdatafname)

# Set the boxlat and boxlon
box = (southern_lat, northern_lat, left_lon, right_lon)
controldata.variable(controldata.vars[0], box,
                     setData=False)  # this sets self.boxlon and self.boxlat

# Create bm coords from region bounds
# bm lonitude coords need to be 0 < coord < 360
bmlon, bmlat = np.meshgrid(controldata.boxlon, controldata.boxlat)

# Reset the lat and lon bounds so that maps don't show grey areas
southern_lat, northern_lat = np.array(controldata.boxlat)[[0, -1]]
# Change lons to be negative is 180 < lon < 360 because that's how bm works for 'cea' projection
left_lon, right_lon = np.array(controldata.boxlon)[[0, -1]]
Beispiel #7
0
##################
# Main algorithm #
##################

# Creates the master array of the correct shape
var_master = np.zeros(shape=(len(dates), len(variables)))
long_name = []
units = []
for n, d in enumerate(dates):
    # Find the file for this date
    full_path, fname = findClimoFile("*" + grep + "*" + d + "*",
                                     directory=ARGS.directory)
    if fname != 0:
        print fname
    # Open the file
    nc = camgoda(full_path)
    for m, v in enumerate(variables):
        # Read the data
        var_is_3d, var, pressure = nc.ExtractData(v, box)
        data = nc.data
        # Average the data
        data_avg = np.nanmean(data)
        var_master[n, m] = data_avg
        if n == 0:
            long_name.append(nc.long_name)
            units.append(nc.units)

ntime, nvar = var_master.shape
add = 0
if nvar > 1:
    add = 1
Beispiel #8
0
region = [bottom, top, left, right]
box = [int(l) for l in ARGS.box]

# These are mapping variable
southern_lat, northern_lat, left_lon, right_lon = box
if left_lon > right_lon:
    left_lon -= 360

for date_idx, date in enumerate(dates):
    # Find the file
    path, filename = findClimoFile(grep_pre + '*' + date + '*' + grep_post,
                                   directory)
    print filename
    # Open the file
    nc = camgoda(path)
    if date_idx == 0:
        data = np.zeros(shape=(len(dates), len(nc.lat), len(nc.lon), 2))
    data[date_idx, ...] = nc.ExtractData(lv + "," + fv, returnData=True)
#
# Extract the lv timeseries
lv_ts = np.nanmean(boxOut(data[..., 0], region), axis=(-2, -1))

# Box out the fv
fv_boxed_ts, lats, lons = boxOut(data[..., 1], box, returnGrid=True)

corr_array = corr_2d(np.expand_dims(np.expand_dims(lv_ts, -1), -1),
                     fv_boxed_ts,
                     axis=0)

# Make the map of the corr array
Beispiel #9
0
    # Create Map directory is it doesn't exist
    if not os.path.exists("Map"):
        os.mkdir("Map")
        if verbose:
            print "Created directory " + "Map"

    # Create the region directory if it doesn't already exist
    if not os.path.exists("Map/" + region_name):
        os.mkdir("Map/" + region_name)
        if verbose:
            print "Created directory " + "Map/" + region_name

for filein in files:
    print "Current files is : " + filein + '\n'
    # Read the data
    ncdata = camgoda(filein)

    # Set the boxlat and boxlon
    box = (southern_lat, northern_lat, left_lon, right_lon)
    ncdata.variable(ncdata.vars[0], box,
                    setData=False)  # this sets self.boxlon and self.boxlat

    # Create bm coords from region bounds
    # bm lonitude coords need to be 0 < coord < 360
    bmlon, bmlat = np.meshgrid(ncdata.boxlon, ncdata.boxlat)

    # Reset the lat and lon bounds so that Map don't show grey areas
    # southern_lat, northern_lat = np.array(ncdata.boxlat)[[0,-1]]
    # Change lons to be negative is 180 < lon < 360 because that's how bm works for 'cea' projection
    # left_lon, right_lon = np.array(ncdata.boxlon)[[0,-1]]
    if 0 in ncdata.boxlon[1:-2]:  # if we cross the gml