def get_snodas_ds(dem_dt, code=<NUM_LIT>):
import tarfile<EOL>import gzip<EOL>snodas_ds = None<EOL>snodas_url_str = None<EOL>outdir = os.path.join(datadir, '<STR_LIT>')<EOL>if not os.path.exists(outdir):<EOL><INDENT>os.makedirs(outdir)<EOL><DEDENT>if dem_dt >= datetime(<NUM_LIT>,<NUM_LIT:9>,<NUM_LIT:30>) and dem_dt < datetime(<NUM_LIT>,<NUM_LIT:1>,<NUM_LIT:1>):<EOL><INDENT>snodas_url_str = '<STR_LIT>'<EOL>tar_subfn_str_fmt = '<STR_LIT>'<EOL><DEDENT>elif dem_dt >= datetime(<NUM_LIT>,<NUM_LIT:1>,<NUM_LIT:1>):<EOL><INDENT>snodas_url_str = '<STR_LIT>'<EOL>tar_subfn_str_fmt = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if snodas_url_str is not None:<EOL><INDENT>snodas_url = dem_dt.strftime(snodas_url_str)<EOL>snodas_tar_fn = iolib.getfile(snodas_url, outdir=outdir)<EOL>print("<STR_LIT>")<EOL>tar = tarfile.open(snodas_tar_fn)<EOL>for ext in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>tar_subfn_str = tar_subfn_str_fmt % (code, ext)<EOL>tar_subfn_gz = dem_dt.strftime(tar_subfn_str)<EOL>tar_subfn = os.path.splitext(tar_subfn_gz)[<NUM_LIT:0>]<EOL>print(tar_subfn)<EOL>if outdir is not None:<EOL><INDENT>tar_subfn = os.path.join(outdir, tar_subfn)<EOL><DEDENT>if not os.path.exists(tar_subfn):<EOL><INDENT>tar.extract(tar_subfn_gz)<EOL>with gzip.open(tar_subfn_gz, '<STR_LIT:rb>') as f:<EOL><INDENT>outf = open(tar_subfn, '<STR_LIT:wb>')<EOL>outf.write(f.read())<EOL>outf.close()<EOL><DEDENT>os.remove(tar_subfn_gz)<EOL><DEDENT><DEDENT>bad_str = '<STR_LIT>'<EOL>snodas_fn = tar_subfn<EOL>f = open(snodas_fn)<EOL>output = []<EOL>for line in f:<EOL><INDENT>if not bad_str in line:<EOL><INDENT>output.append(line)<EOL><DEDENT><DEDENT>f.close()<EOL>f = open(snodas_fn, '<STR_LIT:w>')<EOL>f.writelines(output)<EOL>f.close()<EOL>snodas_ds = gdal.Open(snodas_fn)<EOL><DEDENT>return snodas_ds<EOL>
Function to fetch and process SNODAS snow depth products for input datetime

    http://nsidc.org/data/docs/noaa/g02158_snodas_snow_cover_model/index.html

    Product codes:
    1036 is snow depth
    1034 is SWE

    filename format: us_ssmv11036tS__T0001TTNATS2015042205HP001.Hdr