コード例 #1
0
def run_main(fname_shis='simulated.cdf', fmt={'tau': '10.5f'}, **kwargs):
    '''
	atmospheric profile is arbitrary from gdas/lblrtm, rest is garbage
	'''
    from hs3_utils import write_collocated
    from libtools import combination as combo
    from libtools import dtg2epoch as d2e

    #_temporarily pull out for size since profile has to come first
    vars, ranges = kwargs.get('vars'), kwargs.get('ranges')
    combos = combo([ranges[v] for v in vars])
    size = len(combos)

    #_create name of file to store real values
    fname_txt = fname_shis.replace('.hdf',
                                   '.txt').replace('COLLOC', 'GDAS.COLLOC')
    fname_txt = os.path.join(kwargs.get('dir_hs3'), fname_txt)

    #_write combos in order to output
    fmts = ['{{{0:d}:{1:s}}}'.format(i, key) for i, key in enumerate(fmt)]
    fmt = ''.join(fmts)
    with open(fname_txt, 'w') as f:
        fmt0 = ''.join(['{{{0:d}:>8s}}'.format(i) for i, v in enumerate(vars)])
        fmt1 = ''.join(
            ['{{{0:d}:8.5f}}'.format(i) for i, v in enumerate(vars)])
        f.write(fmt0.format(*vars) + '\n')
        [f.write(fmt1.format(*a) + '\n') for a in combos]
        print fname_txt, 'written...'

    #_use single profile
    prof = fake_prof(size, **kwargs)

    #_make fake epochs to to maintain order
    epoch_start = d2e('2014010100')

    #_generate fake S-HIS data
    shis, notes = fake_shis_sge(latitude=prof.latitude[0],
                                longitude=prof.longitude[0],
                                **kwargs)

    #_add individual seconds to fake time data
    epoch = arange(shis.size) + epoch_start
    shis.epoch[:] = epoch

    #_read in fov profile from GDAS (PUT IN METADATA)
    cpl = fake_cpl(size, lat=prof.latitude[0], lon=prof.longitude, **kwargs)

    #_write to file
    write_collocated(shis, cpl, prof, fname_shis, notes=notes, **kwargs)
コード例 #2
0
def get_surf_temp(
        fov,
        surf_temp_src='GDAS',
        varname='skt',  #_sst || skt
        ecmwf_file='/data/wsessions/era-interim/hs3_2013.nc',
        **kwargs):
    '''
	return surf temperature depending on source

	The default behavior of the code is to use GDAS
	or LBL-ATM based surface temperatures.  If the
	surf_temp_src str is passed as ECMWF, this method
	returns a reaaalllly poorly done nearest neighbor
	interp from the ERA Interim data.
	'''
    from netCDF4 import Dataset
    from libtools import ecmwf_day2dtg as d2d
    from libtools import dtg2epoch as d2e
    from libtools import epoch2dtg as e2d
    from numpy import array

    #_only do this if ECMWF
    if surf_temp_src == 'GDAS':
        return fov.GDAS_sfc_temperature
    elif surf_temp_src == 'LBL-ATM':
        return -1
    else:
        pass

    #_open netcdf file
    ncdf = Dataset(ecmwf_file, 'r')

    #_get indices
    yidx = abs(fov.SHIS_latitude - ncdf.variables['latitude']).argmin()
    xidx = abs(fov.SHIS_longitude - ncdf.variables['longitude']).argmin()
    epoch = array([d2e(d2d(t)) for t in ncdf.variables['time']])
    tidx = abs(fov.SHIS_epoch - epoch).argmin()

    print d2d(ncdf.variables['time'][tidx]), ncdf.variables['latitude'][yidx], \
     ncdf.variables['longitude'][xidx]
    print e2d(fov.SHIS_epoch), fov.SHIS_latitude, fov.SHIS_longitude

    surf_temp = ncdf.variables[varname][tidx, yidx, xidx]
    ncdf.close()

    return surf_temp
コード例 #3
0
def run_main(fname_shis='simulated.cdf', fmt={'tau': '10.5f'}, **kwargs):
    '''
	atmospheric profile is arbitrary from gdas/lblrtm, rest is garbage
	'''
    from hs3_utils import write_collocated
    from libtools import combination as combo
    from libtools import dtg2epoch as d2e

    #_temporarily pull out for size since profile has to come first
    vars, ranges = kwargs.get('vars'), kwargs.get('ranges')
    combos = combo([ranges[v] for v in vars])
    size = len(combos)

    #_write combos in order to output
    fmts = ['{{{0:d}:{1:s}}}'.format(i, key) for i, key in enumerate(fmt)]
    fmt = ','.join(fmts)
    ##	fmt = '{0:10.5f}, {1:10.5f}, {2:10.5f}\n'
    with open('simulation.txt', 'w') as f:
        fmt0 = '_'.join(
            ['{{{0:d}:10s}},'.format(i) for i, v in enumerate(vars)])
        fmt1 = ' '.join(
            ['{{{0:d}:8.5f}},'.format(i) for i, v in enumerate(vars)])
        f.write(fmt0.format(*vars) + '\n')
        [f.write(fmt1.format(*a) + '\n') for a in combos]

    #_use single profile
    prof = fake_prof(size, **kwargs)

    #_make fake epochs to to maintain order
    epoch_start = d2e('2014010100')

    #_generate fake S-HIS data
    shis, notes = fake_shis(latitude=prof.latitude[0],
                            longitude=prof.longitude[0],
                            **kwargs)

    epoch = arange(shis.size) + epoch_start
    shis.epoch[:] = epoch

    #_read in fov profile from GDAS (PUT IN METADATA)
    cpl = fake_cpl(size, lat=prof.latitude[0], lon=prof.longitude, **kwargs)

    #_write to file
    write_collocated(shis, cpl, prof, fname_shis, notes=notes, **kwargs)
コード例 #4
0
	def convert(n):
		from numpy import floor
		from libtools import dtg2epoch as d2e
		dtg = '20{0:6.0f}00'.format(floor(n))
		sec = (n - floor(n)) * 86400.
		return d2e(dtg) + sec