Esempio n. 1
0
def set_bounds(info):
    atm_file = info.atmdir + info.atmfile
    print(atm_file)
    cmip_file= atm_file.replace("_Y_",str(info.start_year))        \
                    .replace("_VAR_","hus")                        \
                    .replace("_ENS_",info.ensemble)                \
                    .replace("_EXP_",info.experiment)              \
                    .replace("_GCM_",info.gcm_name)
    print(cmip_file)
    cmip_file = glob.glob(cmip_file)[0]
    print(cmip_file)
    varlist = ["lat", "lon"]

    lat = io.read_nc(cmip_file, varlist[0]).data
    lon = io.read_nc(cmip_file, varlist[1]).data
    if lon.max() > 180:
        lon[lon > 180] = lon[lon > 180] - 360
    if len(lat.shape) > 1 or len(lon.shape) > 1:
        print(lat.shape, len(lat.shape))
        print(lon.shape, len(lon.shape))
        raise ValueError("config.py requires lat,lon to be 1D arrays")
    lonbounds = np.where((lon >= info.lon[0]) & (lon <= info.lon[1]))[0]
    info.xmin = max(lonbounds[0] - 1, 0)
    info.xmax = min(lonbounds[-1] + 1, len(lon))
    info.ymin = max(np.where(lat >= info.lat[0])[0][0] - 1, 0)
    info.ymax = min(np.where(lat <= info.lat[1])[0][-1] + 1, len(lat))

    lon, lat = np.meshgrid(lon[info.xmin:info.xmax], lat[info.ymin:info.ymax])
    info.lat_data = lat
    info.lon_data = lon
Esempio n. 2
0
File: config.py Progetto: NCAR/icar
def set_bounds(info):
    atm_file = info.atmdir + info.atmfile
    cesm_file = (
        atm_file.replace("_Y_", str(info.start_year))
        .replace("_VAR_", "Q")
        .replace("_ENS_", info.ensemble)
        .replace("_EXP_", info.experiment)
    )
    try:
        cesm_file = glob.glob(cesm_file)[0]
    except:
        print("ERROR searching for: " + cesm_file)
        sys.exit(1)
    varlist = ["lat", "lon"]

    lat = io.read_nc(cesm_file, varlist[0]).data
    lon = io.read_nc(cesm_file, varlist[1]).data  # -360

    try:
        info.xmin = np.where(lon >= info.lon[0])[0][0]
        info.xmax = np.where(lon <= info.lon[1])[0][-1] + 1
        info.ymin = np.where(lat >= info.lat[0])[0][0]
        info.ymax = np.where(lat <= info.lat[1])[0][-1] + 1
    except:
        print("ERROR searching for lat/lon bounds:")
        print(info.lat, info.lon)
        print(lat.min(), lat.max())
        print(lon.min(), lon.max())
        sys.exit(1)

    lon, lat = np.meshgrid(lon[info.xmin : info.xmax], lat[info.ymin : info.ymax])
    info.lat_data = lat
    info.lon_data = lon
Esempio n. 3
0
def set_bounds(info):
    atm_file=info.atmdir+info.atmfile
    print(atm_file)
    cmip_file= atm_file.replace("_Y_",str(info.start_year))        \
                    .replace("_VAR_","hus")                        \
                    .replace("_ENS_",info.ensemble)                \
                    .replace("_EXP_",info.experiment)              \
                    .replace("_GCM_",info.gcm_name)
    print(cmip_file)
    cmip_file=glob.glob(cmip_file)[0]
    print(cmip_file)
    varlist=["lat","lon"]
    
    lat=io.read_nc(cmip_file,varlist[0]).data
    lon=io.read_nc(cmip_file,varlist[1]).data
    if lon.max()>180:
        lon[lon>180]=lon[lon>180]-360
    if len(lat.shape)>1 or len(lon.shape)>1:
        print(lat.shape,len(lat.shape))
        print(lon.shape,len(lon.shape))
        raise ValueError("config.py requires lat,lon to be 1D arrays")
    lonbounds=np.where((lon>=info.lon[0])&(lon<=info.lon[1]))[0]
    info.xmin=max(lonbounds[0]-1,0)
    info.xmax=min(lonbounds[-1]+1,len(lon))
    info.ymin=max(np.where(lat>=info.lat[0])[0][0]-1,0)
    info.ymax=min(np.where(lat<=info.lat[1])[0][-1]+1,len(lat))
    
    lon,lat=np.meshgrid(lon[info.xmin:info.xmax],lat[info.ymin:info.ymax])
    info.lat_data=lat
    info.lon_data=lon
Esempio n. 4
0
def set_bounds(info):
    atm_file=info.atmdir+info.atmfile
    cesm_file=atm_file.replace("_Y_",str(info.start_year)).replace("_VAR_","Q").replace("_ENS_",info.ensemble).replace("_EXP_",info.experiment)
    try:
        cesm_file=glob.glob(cesm_file)[0]
    except:
        print("ERROR searching for: "+cesm_file)
        sys.exit(1)
    varlist=["lat","lon"]
    
    lat=io.read_nc(cesm_file,varlist[0]).data
    lon=io.read_nc(cesm_file,varlist[1]).data#-360
    
    try:
        info.xmin=np.where(lon>=info.lon[0])[0][0]
        info.xmax=np.where(lon<=info.lon[1])[0][-1]+1
        info.ymin=np.where(lat>=info.lat[0])[0][0]
        info.ymax=np.where(lat<=info.lat[1])[0][-1]+1
    except:
        print("ERROR searching for lat/lon bounds:")
        print(info.lat, info.lon)
        print(lat.min(), lat.max())
        print(lon.min(), lon.max())
        sys.exit(1)
    
    lon,lat=np.meshgrid(lon[info.xmin:info.xmax],lat[info.ymin:info.ymax])
    info.lat_data=lat
    info.lon_data=lon
Esempio n. 5
0
def set_bounds(info):
    atm_file=info.atmdir+info.atmfile
    cesm_file=atm_file.replace("_Y_",str(info.start_year)).replace("_VAR_","Q").replace("_ENS_",info.ensemble).replace("_EXP_",info.experiment)
    cesm_file=glob.glob(cesm_file)[0]
    varlist=["lat","lon"]
    
    lat=io.read_nc(cesm_file,varlist[0]).data
    lon=io.read_nc(cesm_file,varlist[1]).data-360
    
    info.xmin=np.where(lon>=info.lon[0])[0][0]
    info.xmax=np.where(lon<=info.lon[1])[0][-1]+1
    info.ymin=np.where(lat>=info.lat[0])[0][0]
    info.ymax=np.where(lat<=info.lat[1])[0][-1]+1
    
    lon,lat=np.meshgrid(lon[info.xmin:info.xmax],lat[info.ymin:info.ymax])
    info.lat_data=lat
    info.lon_data=lon
Esempio n. 6
0
def set_bounds(info):
    atm_file=info.atmdir+info.atmfile
    ccsm_file=atm_file.replace("_Y_","2006").replace("_M_","01").replace("_D_","01").replace("_VAR_","hus")
    ccsm_file=glob.glob(ccsm_file)[0]
    varlist=["lat","lon"]
    
    lat=io.read_nc(ccsm_file,varlist[0]).data
    lon=io.read_nc(ccsm_file,varlist[1]).data-360
    
    info.xmin=np.where(lon>=info.lon[0])[0][0]
    info.xmax=np.where(lon<=info.lon[1])[0][-1]+1
    info.ymin=np.where(lat>=info.lat[0])[0][0]
    info.ymax=np.where(lat<=info.lat[1])[0][-1]+1
    
    lon,lat=np.meshgrid(lon[info.xmin:info.xmax],lat[info.ymin:info.ymax])
    info.lat_data=lat
    info.lon_data=lon