Beispiel #1
0
def get_lc(year, tile, fips):
    '''
    Return LC mask for year,tile,fips
    '''
    kwargs = {
        'tile': tile,
        'product': 'MCD12Q1',
    }
    doy = 1
    # get the LC data
    modis = Modis(**kwargs)

    warp_args = {
        'dstNodata': 255,
        'format': 'MEM',
        'cropToCutline': True,
        'cutlineWhere': f"FIPS='{fips}'",
        'cutlineDSName': 'data/TM_WORLD_BORDERS-0.3.shp'
    }

    # specify day of year (DOY) and year
    lcfiles = modis.get_modis(year, doy, warp_args=warp_args)
    # get the item we want
    g = gdal.Open(lcfiles['LC_Type3'])
    # error checking
    if not g:
        print(f"cannot open LC file {lcfiles['LC_Type3']}")
        return None
    lc = g.ReadAsArray()
    del g

    # in your function, print out the unique values in the
    # landcover dataset to give some feedback to the user
    print(f"class codes: {np.unique(lc)}")
    return lc
Beispiel #2
0
def pull(year, tile=['h09v05'], doy="*", month=None, day=None, step=1):
    product = 'MYD10A1'
    kwargs = {'tile': list(tile), 'product': product, 'verbose': True}
    # get the data
    print(kwargs)
    modis = Modis(**kwargs)
    mfiles = modis.get_modis(year, doy, step=step)
    return mfiles
def modis_annual_dataset(year, tile, product, step=1, verbose=False):
    # load into kwargs
    kwargs = {
        'verbose': verbose,
        'tile': list(tile),
        'product': product,
    }
    # list of doys we want
    doys = "*"

    modis = Modis(**kwargs)
    ifiles = modis.get_modis(year, doys, step=step)
    return ifiles
Beispiel #4
0
def uk_lai(year=2019):
  kwargs = {
    'tile'      :    ['h17v03', 'h17v04', 'h18v03', 'h18v04'],
    'product'   :    'MCD15A3H',  
    'sds'       :    'Lai_500m',
    'log'       :    f'work/uk_lai_{year}_log.txt',
    'db_file'   :    ['data/database.db',f'work/uk_lai_{year}.db'],
    'local_dir' :    'work',
    'verbose'   :    True
  }
  modis = Modis(**kwargs)
  
  result = modis.get_year(year,step=4)
  return result
Beispiel #5
0
def main():
    '''example of use'''

    try:
        from geog0111.modis import Modis
    except:
        from modis import Modis
    # first get a MODIS hdf file
    modis = Modis(product='MCD15A3H', local_dir='work')
    hdf_files, sds = modis.stitch_date(2019, 1, get_files=True)
    filename = hdf_files[0]
    # generate output filename
    ofile = filename.split('.hdf')[0] + '_blank.hdf'
    create_blank_file(sds[0][0], ofile)
Beispiel #6
0
def pull(product, year, tile, doy=None, month=None, day=None, step=1):
    kwargs = {
        'tile': list(tile),
        'product': product,
        'log': f'{gwork}/{product}_{year}_{tidy(tile)}_log.txt',
        'db_file': [f'{gwork}/database.db', f'{gwork}/{product}_database.db'],
        'local_dir': f'{gwork}',
        'verbose': True
    }
    # get the data
    print(kwargs)
    modis = Modis(**kwargs)
    #modis.get_data(year,doy=doy,day=day,step=step,month=month)
    modis.stitch(year, doy=doy, day=day, step=step, month=month)
    return modis
at the command prompt.
'''

import gdal
try:
    from geog0111.modis import Modis
except:
    from modis import Modis
import matplotlib.pyplot as plt

kwargs = {
    'verbose': True,
    'tile': ['h17v03', 'h18v03', 'h17v04', 'h18v04'],
    'product': 'MCD15A3H',
}
year = 2018
# list of doys we want
doys = "*"

modis = Modis(**kwargs)

warp_args = {
    'dstNodata': 255,
    'format': 'MEM',
    'cropToCutline': True,
    'cutlineWhere': "FIPS='UK'",
    'cutlineDSName': 'data/TM_WORLD_BORDERS-0.3.shp'
}
mfiles = modis.get_modis(year, doys, warp_args=warp_args, step=4)
print(mfiles.keys())
Beispiel #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Example script to get all days of data for MCD64A1
for the tiles and year spewcified. 


To run this, simply type:

geog0111/get_lai.py

at the command prompt.
'''

from osgeo import gdal
try:
    from geog0111.modis import Modis
except:
    from modis import Modis
import matplotlib.pyplot as plt

kwargs = {
    'verbose': True,
    'tile': ['h17v03', 'h18v03', 'h17v04', 'h18v04'],
    'product': 'MCD64A1',
}
for year in [2017, 1018, 2019]:
    modis = Modis(**kwargs)
    modis.stitch(year, day=1, month="*")