Ejemplo n.º 1
0
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# 10 sea level pressure observations, 3 hours after model is run. Accuracy is
# approx 0.01 in mercury, 33.8 Pa, rounded to 34
#Ketchikan
ob1 = Observation(
    value=101320,
    time=datetime(2017, 9, 6, 6),
    lat=55.356,
    lon=228.286,  #101210
    obtype='MSLP',
    localize_radius=2000,
    assimilate_this=True,
    error=34)
#Seatac
ob2 = Observation(
    value=101420,
    time=datetime(2017, 9, 6, 6),
    lat=47.445,
    lon=237.686,  #101280
    obtype='MSLP',
    localize_radius=2000,
    assimilate_this=True,
    error=34)
#Spokane
Ejemplo n.º 2
0
                ob_lon = float(ob_split[2])
                #get longitude positive-definite- ie -130 lon is 230 E
                #    if ob_lon < 0:
                #        ob_lon = ob_lon + 360
                ob_elev = float(ob_split[3])
                ob_time = mt.timestamp2utc(float(ob_split[4]))
                ob_value = float(ob_split[5])

                #call function to check elevation to see whether or not to assimilate ob
                TorF = efa.check_elevation(lats, lons, elevs, ob, ob_lat,
                                           ob_lon, ob_elev)

                obser = Observation(value=ob_value,
                                    time=ob_time,
                                    lat=ob_lat,
                                    lon=ob_lon,
                                    obtype=ob_type,
                                    localize_radius=1000,
                                    assimilate_this=TorF,
                                    error=1)

                if TorF == True and ob_id != 'SHIP':

                    #create dictionary for station ID if it doesn't exist
                    ob_dict[ob_type][sfh][hour][ob_id] = ob_dict[ob_type][sfh][
                        hour].get(ob_id, {})
                    #create empty lists for the station ID if they don't exist yet
                    ob_dict[ob_type][sfh][hour][ob_id]['hx'] = ob_dict[
                        ob_type][sfh][hour][ob_id].get('hx', [])
                    ob_dict[ob_type][sfh][hour][ob_id]['ob_all'] = ob_dict[
                        ob_type][sfh][hour][ob_id].get('ob_all', [])
                    ob_dict[ob_type][sfh][hour][ob_id]['obs'] = ob_dict[
Ejemplo n.º 3
0
# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# Creating 2 dummy obs to test EFA- if exact coordinates in the lat/lon,
# interpolate will fail.
#key west
ob1 = Observation(value=5900,
                  time=datetime(2017, 9, 6, 12),
                  lat=24.55,
                  lon=278.21,
                  obtype='Z500',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=10)
#Miami
ob2 = Observation(value=5900,
                  time=datetime(2017, 9, 6, 12),
                  lat=25.75,
                  lon=279.62,
                  obtype='Z500',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=10)
#Tampa Bay
ob3 = Observation(value=5870,
                  time=datetime(2017, 9, 6, 12),
Ejemplo n.º 4
0
# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# 10 sea level pressure observations, 3 hours after model is run. Accuracy is
# approx 0.01 in mercury, 33.8 Pa, rounded to 34
#key west
ob1 = Observation(value=101440,
                  time=datetime(2017, 9, 6, 3),
                  lat=24.555,
                  lon=278.248,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=34)
#Miami
ob2 = Observation(value=101470,
                  time=datetime(2017, 9, 6, 3),
                  lat=25.791,
                  lon=279.684,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=34)
#Tampa Bay
ob3 = Observation(value=101510,
                  time=datetime(2017, 9, 6, 3),
Ejemplo n.º 5
0
# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# 10 sea level pressure observations, 3 hours after model is run. Accuracy is
# approx 0.01 in mercury, 33.8 Pa, rounded to 34
#key west
ob1 = Observation(value=101440,
                  time=datetime(2017, 9, 6, 3),
                  lat=24.555,
                  lon=278.248,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=34)
#Miami
ob2 = Observation(value=101470,
                  time=datetime(2017, 9, 6, 3),
                  lat=25.791,
                  lon=279.684,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=34)
#Tampa Bay
ob3 = Observation(value=101510,
                  time=datetime(2017, 9, 6, 3),
Ejemplo n.º 6
0
def get_gdas_obs(atime,
                 vrbls=['Z500'],
                 sampling_interval=5,
                 cutofflat=None,
                 loc='GC2000',
                 err=100.,
                 errvar_file=None):
    """
    Gets a list of 'observations' from the CFSv2 f00 forecast (i.e., GDAS
    analysis) grid.
    
    Requires:
    atime ------------> A datetime object indicating the time of the desired
                        observations.
    vrbls ------------> A list of variables to get observations of.
                        Default: 500 mb heights.
    sampling_interval-> An integer specifying the interval at which to sample
                        the gridded analysis for observations.
                        Default: Sample every 5 degrees lat/lon. (1 deg grid)
    cutofflat --------> Grid points poleward of this latitude are ignored.
                        
    Returns:
    observations -----> A list of Observation objects.
    """
    # Set the localization radius
    if loc[:2] == 'GC':
        locrad = int(loc[2:])
    else:
        locrad = 2000.0  # kilometers

    # Corresponding parameters in the analysis file
    apars = {'Z500': 'HGT_500mb', 'CHI200': 'VPOT_200mb'}
    # Set I/O variable(s)
    anl_file = '/home/disk/vader2/njweber2/research/subseasonal/efa/' + \
               'verification/analyses_01Dec2015-01Mar2016.nc'

    # Load the data
    vardata = {}
    with Dataset(anl_file, 'r') as ncdata:
        # Load dimensions
        timenums = ncdata.variables['time']
        times = num2date(timenums[:], timenums.units)
        lats = ncdata.variables['latitude'][:]
        lons = ncdata.variables['longitude'][:]
        # Cut off polar grid points:
        if cutofflat is not None:
            yi = ut.nearest_ind(lats, -cutofflat)
            yf = ut.nearest_ind(lats, cutofflat) + 1
        else:
            yi = 0
            yf = len(lats)
        lats = lats[yi:yf]
        # Get a lat/lon value for every location
        lonarr, latarr = np.meshgrid(lons, lats)
        # Sample only a fraction of the points in the analysis
        lonarr = lonarr[::sampling_interval, ::sampling_interval].flatten()
        latarr = latarr[::sampling_interval, ::sampling_interval].flatten()
        # Find the desired time
        t_ind = np.where(times == atime)[0][0]
        # Load the variable
        for var in vrbls:
            vardata[var] = ncdata.variables[apars[var]][t_ind, yi:yf, :]
            # Sample only a fraction of the points in the analysis
            vardata[var] = vardata[
                var][::sampling_interval, ::sampling_interval].flatten()
            if var == 'CHI200': vardata[var] /= 10**6  # to 10^6 m^2 s^-1

    # Load the ob error variance file, if necessary
    if errvar_file is not None:
        with Dataset(errvar_file, 'r') as ncdata:
            errvar_la = ncdata.variables['lat'][:]
            errvar_lo = ncdata.variables['lon'][:]
            errvar_xy = ncdata.variables['errvar'][:]

    # Create Observation objects for each of the sampled locations
    observations = []
    for x in range(len(lonarr)):
        # Assign the ob error variance
        if errvar_file is None:
            oberr = err
        else:
            la_i = ut.nearest_ind(errvar_la, latarr[x])
            lo_i = ut.nearest_ind(errvar_lo, lonarr[x])
            oberr = errvar_xy[la_i, lo_i]
        # Create an Observation object for each variable
        for var in vrbls:
            obsject = Observation(value=vardata[var][x],
                                  obtype=var,
                                  time=atime,
                                  error=oberr,
                                  lat=latarr[x],
                                  lon=lonarr[x],
                                  localize_radius=locrad,
                                  description='GDAS')
            obsject.assimilate_this = True
            observations.append(obsject)
    return observations
Ejemplo n.º 7
0
                        ncdata.variables[var][:])
lonarr, latarr = np.meshgrid(lons, lats)

# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(allvars,
                                      {'validtime' : ftimes,
                                       'lat' : (['y','x'], latarr),
                                       'lon' : (['y','x'], lonarr),
                                       'mem' : mems,
                                       })

# Creating 2 dummy obs to test EFA- if exact coordinates in the lat/lon,
# interpolate will fail.   
#Annette Island, AK  
ob1 = Observation(value=5820, time=datetime(2017,9,6,0),lat=55.05,lon=228.41,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Prince George, BC
ob2 = Observation(value=5890, time=datetime(2017,9,6,0),lat=53.9,lon=237.21,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Edmonton Stony Plain, AB
ob3 = Observation(value=5870, time=datetime(2017,9,6,0),lat=53.53,lon=245.9,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Port Hardy, BC
ob4 = Observation(value=5870, time=datetime(2017,9,6,0),lat=50.68,lon=232.64,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Quillayute
ob5 = Observation(value=5910, time=datetime(2017,9,6,0),lat=47.95,lon=235.45,
Ejemplo n.º 8
0
        #get the lat/lon of the station
        ob_lat = float(ob_split[1])
        ob_lon = float(ob_split[2])
        #get longitude positive-definite- ie -130 lon is 230 E
        if ob_lon < 0:
            ob_lon = ob_lon + 360
        ob_elev = float(ob_split[3])
        ob_time = float(ob_split[4])
        time2 = datetime.utcfromtimestamp(ob_time)
        ob_value = float(ob_split[5])
        
        #call function to check elevation to see whether or not to assimilate ob
        TorF = efa.check_elevation(lats,lons,elevs,ob,ob_lat,ob_lon,ob_elev)
        
        obser = Observation(value=ob_value, time=time2,
                        lat=ob_lat,lon=ob_lon, obtype=o_type, localize_radius=1000,
                        assimilate_this=TorF, error=1)
        observations.append(obser)

# Put the state class object and observation objects into EnSRF object
assimilator = EnSRF(statecls, observations, loc='GC')

# Update the prior with EFA- post_state is an EnsembleState object
post_state, post_obs = assimilator.update()

state=post_state
outdir = '/home/disk/hot/stangen/Documents/atms544/posterior/'+ensemble_type+'/'+m_dict[month]+year+'/'

#Create output directories if they don't yet exit
if (os.path.isdir(outdir)):
    pass
Ejemplo n.º 9
0
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# 10 sea level pressure observations, 3 hours after model is run. Accuracy is
# approx 0.01 in mercury, 33.8 Pa, rounded to 34
#Ketchikan
ob1 = Observation(
    value=290.95,
    time=datetime(2017, 9, 6, 6),
    lat=55.356,
    lon=228.286,  #101210
    obtype='T2M',
    localize_radius=2000,
    assimilate_this=True,
    error=0.3)
#Seatac
ob2 = Observation(
    value=294.85,
    time=datetime(2017, 9, 6, 6),
    lat=47.445,
    lon=237.686,  #101280
    obtype='T2M',
    localize_radius=2000,
    assimilate_this=True,
    error=0.3)
#Spokane
Ejemplo n.º 10
0
# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# 10 sea level pressure observations, 3 hours after model is run. Accuracy is
# approx 0.01 in mercury, 33.8 Pa, rounded to 34
#key west
ob1 = Observation(value=101440,
                  time=datetime(2017, 9, 6, 3),
                  lat=24.555,
                  lon=278.248,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=100000)
#Miami
ob2 = Observation(value=101470,
                  time=datetime(2017, 9, 6, 3),
                  lat=25.791,
                  lon=279.684,
                  obtype='MSLP',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=100000)
#Tampa Bay
ob3 = Observation(value=101510,
                  time=datetime(2017, 9, 6, 3),
Ejemplo n.º 11
0
# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(
    allvars, {
        'validtime': ftimes,
        'lat': (['y', 'x'], latarr),
        'lon': (['y', 'x'], lonarr),
        'mem': mems,
    })

# Creating 2 dummy obs to test EFA- if exact coordinates in the lat/lon,
# interpolate will fail.
#key west
ob1 = Observation(value=5900,
                  time=datetime(2017, 9, 6, 0),
                  lat=24.55,
                  lon=278.21,
                  obtype='Z500',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=10)
#Miami
ob2 = Observation(value=5890,
                  time=datetime(2017, 9, 6, 0),
                  lat=25.75,
                  lon=279.62,
                  obtype='Z500',
                  localize_radius=2000,
                  assimilate_this=True,
                  error=10)
#Tampa Bay
ob3 = Observation(value=5880,
                  time=datetime(2017, 9, 6, 0),
Ejemplo n.º 12
0
                        ncdata.variables[var][:])
lonarr, latarr = np.meshgrid(lons, lats)

# Package into an EnsembleState object knowing the state and metadata
statecls = EnsembleState.from_vardict(allvars,
                                      {'validtime' : ftimes,
                                       'lat' : (['y','x'], latarr),
                                       'lon' : (['y','x'], lonarr),
                                       'mem' : mems,
                                       })

# Creating 2 dummy obs to test EFA- if exact coordinates in the lat/lon,
# interpolate will fail.   
#key west  
ob1 = Observation(value=5900, time=datetime(2017,9,6,0),lat=24.55,lon=278.21,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Miami
ob2 = Observation(value=5890, time=datetime(2017,9,6,0),lat=25.75,lon=279.62,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Tampa Bay
ob3 = Observation(value=5880, time=datetime(2017,9,6,0),lat=27.70,lon=277.6,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Tallahassee
ob4 = Observation(value=5870, time=datetime(2017,9,6,0),lat=30.45,lon=275.7,
                  obtype = 'Z500', localize_radius=2000, assimilate_this=True,
                  error=10)
#Jacksonville
ob5 = Observation(value=5870, time=datetime(2017,9,6,0),lat=30.50,lon=278.3,