Пример #1
0
def list_rows(wrs, path):
    """
    List the available rows for the given WRS and path.
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(wrs.upper())
            if not path.startswith('p'):
                path = 'p' + path
            ftp.cwd(path.lower())
            l = ftp.nlst()
            ftp.quit()
            l.sort()
            out = []
            for s in l:
                if '.' not in s:
                    out.append({'code': s, 'label': s})
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #2
0
def list_dates(wrs, path, row):
    """
    List the available dates for the given WRS, path and row.
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(wrs.upper())
            if not path.startswith('p'):
                path = 'p' + path
            if not row.startswith('r'):
                row = 'r' + row
            ftp.cwd(path.lower())
            ftp.cwd(row.lower())
            l = ftp.nlst()
            ftp.quit()
            l.sort()
            out = []
            for s in l:
                if 'EarthSat' in s:
                    lbl = s[11:15] + '-' + s[15:17] + '-' + s[17:19]
                    out.append({'code': s, 'label': lbl})
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #3
0
def list_days(year, month):
    """
    List all the available years.
    @param year: e.g. '2010'
    @param month: e.g. '02'
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(year)
            ftp.cwd(month)
            l = ftp.nlst()
            l.sort()
            out = []
            for s in l:
                out.append({'code': s, 'label': s})
            ftp.quit()
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #4
0
def list_years():
    """
    List all the available years.
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            l = ftp.nlst()
            l.sort(reverse=True)
            out = []
            for s in l:
                try:
                    int(s)
                    out.append({'code': s, 'label': s})
                except:
                    pass
            ftp.quit()
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except Exception, e:
        raise PGeoException(e.message, status_code=500)
Пример #5
0
def list_layers_subset(year, month, from_day, to_day):
    """
    List all the available layers for a given year and month.
    @param year: e.g. '2010'
    @param month: e.g. '02'
    @from_day: e.g. 01
    @to_day: e.g. 05
    @return: An array of code/label/extensions objects.
    """
    file_path_root = 'ftp://' + conf['source']['ftp']['base_url'] + conf[
        'source']['ftp']['data_dir']
    days = map(lambda x: str(x) if x > 9 else '0' + str(x),
               range(int(from_day), 1 + int(to_day)))
    out = []
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(year)
            ftp.cwd(month)
            for i in range(0, len(days)):
                if i > 0:
                    ftp.cwd('../')
                ftp.cwd(days[i])
                l = ftp.nlst()
                l.sort()
                fao_layers = filter(lambda x: '.tif' in x, l)
                for layer in fao_layers:
                    if '.7.' in layer or '.7A.' in layer:
                        code = layer
                        hour = layer[0:layer.index('.tif')].split('.')[2]
                        label = layer[0:layer.index('.tif')].split('.')[0]
                        label += ' ('
                        label += '-'.join([year, month, days[i]])
                        label += ', ' + hour + ')'
                        file_path = file_path_root + year + '/' + month + '/' + days[
                            i] + '/' + code
                        out.append({
                            'file_name': code,
                            'file_path': file_path,
                            'label': label,
                            'size': None
                        })
                        code = code.replace('.tif', '.tfw')
                        file_path = file_path_root + year + '/' + month + '/' + days[
                            i] + '/' + code
                        out.append({
                            'file_name': code,
                            'file_path': file_path,
                            'label': label,
                            'size': None
                        })
            ftp.quit()
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except Exception, e:
        log.error(e)
        raise PGeoException(errors[511], status_code=511)
Пример #6
0
def list_layers_month_subset_service(year, month):
    try:
        out = t.list_layers_month_subset(year, month)
        return Response(json.dumps(out),
                        content_type='application/json; charset=utf-8')
    except PGeoException, e:
        raise PGeoException(e.get_message(), e.get_status_code())
Пример #7
0
def list_layers(year, month, day):
    """
    List all the available layers for a given year and month.
    @param year: e.g. '2010'
    @param month: e.g. '02'
    @return: An array of code/label/extensions objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(year)
            ftp.cwd(month)
            ftp.cwd(day)
            l = ftp.nlst()
            l.sort()
            fao_layers = filter(lambda x: '.tif' in x, l)
            out = []
            for layer in fao_layers:
                if '.7.' in layer or '.7A.' in layer:
                    try:
                        code = layer
                        hour = layer[0:layer.index('.tif')].split('.')[2]
                        label = layer[0:layer.index('.tif')].split('.')[0]
                        label += ' ('
                        label += '-'.join([year, month, day])
                        label += ', ' + hour + ')'
                        out.append({
                            'code': code,
                            'label': label,
                            'extensions': ['.tif', '.tfw']
                        })
                    except:
                        pass
            ftp.quit()
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #8
0
def list_layers(wrs, path, row, date):
    """
    List the available dates for the given WRS, path and row.
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            ftp.cwd(wrs.upper())
            if not path.startswith('p'):
                path = 'p' + path
            if not row.startswith('r'):
                row = 'r' + row
            ftp.cwd(path.lower())
            ftp.cwd(row.lower())
            ftp.cwd(date)
            l = ftp.nlst()
            ftp.quit()
            l.sort()
            out = []
            for s in l:
                if '_nn' in s:
                    file_path = 'ftp://' + conf['source']['ftp'][
                        'base_url'] + conf['source']['ftp']['data_dir']
                    file_path += wrs.upper() + '/' + path.lower(
                    ) + '/' + row.lower() + '/' + date + '/'
                    file_path += s
                    out.append({
                        'file_name': s,
                        'file_path': file_path,
                        'label': s,
                        'size': None
                    })
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #9
0
def list_wrs():
    """
    List the available LANDSAT' World Reference Systems (WRS).
    @return: An array of code/label objects.
    """
    try:
        if conf['source']['type'] == 'FTP':
            ftp = FTP(conf['source']['ftp']['base_url'])
            ftp.login()
            ftp.cwd(conf['source']['ftp']['data_dir'])
            l = ftp.nlst()
            ftp.quit()
            l.sort()
            out = []
            for s in l:
                if 'WRS' in s:
                    out.append({'code': s, 'label': s})
            return out
        else:
            raise PGeoException(errors[512], status_code=512)
    except:
        raise PGeoException(errors[511], status_code=511)
Пример #10
0
def list_layers_service(wrs, path, row, date):
    try:
        out = m.list_layers(wrs, path, row, date)
        return Response(json.dumps(out), content_type='application/json; charset=utf-8')
    except PGeoException, e:
        raise PGeoException(e.get_message(), e.get_status_code())