예제 #1
0
def read_igra_metadata(filename=None):
    # TODO: read routine for IGRA metadata
    # use default filename
    from raso.config import get_data

    file = get_data('igra-metadata.txt')
    contents = pd.read_csv(file)
    return
예제 #2
0
def radiosondelist(minimal=True):
    """ Read Radiosonde List Predefined

    Returns
    -------
    DataFrame
    """
    table = pd.read_csv(get_data("radiosondeslist.csv"), sep=";", index_col=0)
    if minimal:
        return table[["lon", "lat", "alt", "name", "source", "total"]]
    return table
예제 #3
0
def notebook(ident, directory=None):
    """Make a default Notebook for that radiosonde"""
    from raso.config import wkdir, get_data
    import nbformat
    import json

    with open(get_data('notebook_template.ipynb'), 'r') as f:
        template = json.load(f)

    for icell in template[u'cells']:
        if isinstance(icell[u'source'], list):
            tmp=[]
            for isource in icell[u'source']:
                if 'RASOID' in isource:
                    isource = isource.replace('RASOID', ident)
                tmp.append(isource)
            icell[u'source'] = tmp
        else:
            if 'RASOID' in icell[u'source']:
                icell[u'source'] = icell[u'source'].replace('RASOID', ident)

    if directory is None:
        filename = wkdir + '/notebooks/stations/%s.ipynb' % ident
    else:
        filename = directory + '/%s.ipynb' % ident

    if not os.path.isdir(os.path.dirname(filename)):
        os.makedirs(os.path.dirname(filename))

    if not os.path.isdir(os.path.dirname(filename)+'/figures/'):
        os.makedirs(os.path.dirname(filename)+'/figures/')

    template = nbformat.notebooknode.from_dict(template)  # Make a Class Object
    with open(filename, 'wt') as f:
        nbformat.write(template, f)

    print "Notebook: ", filename
예제 #4
0
def us_standard(filename=None, profile=None, levels=None, interpolate=False):
    """Standard Atmospheres

    Profile Types:
          TROPICAL                        0
          MIDLATITUDE SUMMER              1
          MIDLATITUDE WINTER              2
          SUBARCTIC SUMMER                3
          SUBARCTIC WINTER                4
          U. S. STANDARD,  1976           5

    from RTTOV v11
    
    Options:    filename
                profile          Profile Number
                interpolation    Interpolated to ERA-Interim Levels?

    Output:   profile , info
              as Pandas DataFrames
    """
    from raso.config import era_plevels, get_data

    if filename is None:
        filename = get_data('us_standard_76.H5')

    f = h5py.File(filename, 'r')
    
    info = pd.DataFrame()

    if profile is not None and isinstance(profile,str):
        profile = profile.upper()
        profs_infile = [  f['PROFILES'][i]['ID'].value for i in f['PROFILES'].keys()]
        if profile in profs_infile:
            profile = profs_infile.index(profile)+1
        else:
            raise ValueError("Could not find Profile: %s"%profile)
    
    if levels is None:
        levels = era_plevels

    if profile is not None:
        out = pd.DataFrame()
        if 0 < profile and profile < 7:
            iobj = f['PROFILES']['%04d' % profile]
            info = pd.concat([info, pd.DataFrame({'lon': iobj['LONGITUDE'][0], 'lat': iobj['LATITUDE'][0],
                                                  'time': datetime.datetime(
                                                      *np.concatenate([iobj['DATE'][:], iobj['TIME'][:]])),
                                                  'id': iobj['ID'].value}, index=[int(profile)])])
            if interpolate:
                tnew = interp_mod(iobj['T'][:], np.log(levels), np.log(iobj['P'][:] * 100.), False)
                qnew = interp_mod(iobj['Q'][:], np.log(levels), np.log(iobj['P'][:] * 100.), False)
                out = pd.DataFrame({'p': levels, 't': tnew, 'q': qnew})

            else:
                out = pd.DataFrame({'p': iobj['P'][:] * 100., 't': iobj['T'][:], 'q': iobj['Q'][:]})
    else:
        out = {}
        for ikey, iobj in f['PROFILES'].iteritems():
            info = pd.concat([info, pd.DataFrame({'lon': iobj['LONGITUDE'][0], 'lat': iobj['LATITUDE'][0],
                                                  'time': datetime.datetime(
                                                      *np.concatenate([iobj['DATE'][:], iobj['TIME'][:]])),
                                                  'id': iobj['ID'].value}, index=[int(ikey)])])
            if interpolate:
                tnew = interp_mod(iobj['T'][:], np.log(levels), np.log(iobj['P'][:] * 100.), False)
                qnew = interp_mod(iobj['Q'][:], np.log(levels), np.log(iobj['P'][:] * 100.), False)
                out[iobj['ID'].value] =  pd.DataFrame({'p': levels, 't': tnew, 'q': qnew})
            else:
                out[iobj['ID'].value] = pd.DataFrame({'p': iobj['P'][:] * 100., 't': iobj['T'][:], 'q': iobj['Q'][:]})
        try:
            out = pd.Panel(out)
        except:
            pass

    print "Units: p: %s t: %s q: %s " % ('Pa', iobj['T'].attrs['UNITS'], iobj['Q'].attrs['UNITS'])
    f.close()
    return out, info