コード例 #1
0
def generate_dataset_report(folder):
    '''
    Generate a descriptive report on the data included in the use case.
    
    :param folder: Path to the folder containing the NARCCAP example data.
    :type folder: str
    :returns: Path to the report file.
    :rtype: str
    '''

    ocgis.env.DIR_DATA = folder
    rds = parse_narccap_filenames(folder)
    rdc = ocgis.RequestDatasetCollection(rds)
    headers = ['DID', 'Filenames', 'Variable', 'Time Start', 'Time End']
    (fd, name) = tempfile.mkstemp(suffix='.csv')
    f = open(name, 'w')
    writer = csv.writer(f)
    writer.writerow(headers)
    for rd in rdc:
        logging.info(rd)
        ds = NcDataset(rd)
        to_write = [
            rd.did, [os.path.split(uri)[1] for uri in rd.uri], rd.variable,
            ds.temporal.value[0], ds.temporal.value[-1]
        ]
        writer.writerow(to_write)
    f.close()
    return (name)
コード例 #2
0
## subset data by the boundaries of the USA ####################################

ops = ocgis.OcgOperations(dataset=rd1, geom='state_boundaries', agg_selection=True)
ret = ops.execute()
## access the subsetted values. returned data is stored as a dictionary with the
## key the geometry identifier and the value an OcgCollection.
values = ret[1].variables['tasmax'].value
## to get to the geometries
geoms = ret[1].variables['tasmax'].spatial.value
## time points
times = ret[1].variables['tasmax'].temporal.value

## return two variables ########################################################

rdc = ocgis.RequestDatasetCollection([rd1, rd2])
ops = ocgis.OcgOperations(rdc, snippet=True)
ret = ops.execute()

## aggregate the data by state boundary ########################################

ops = ocgis.OcgOperations(dataset=rd1, geom='state_boundaries', aggregate=True,
                          snippet=True, spatial_operation='clip')
ret = ops.execute()
## returned data has 51 keys. access the selection geometry for a particular 
## collection.
ugeom = ret[1].ugeom

## load a selection geometry from disk #########################################

sc = ocgis.ShpCabinet()
コード例 #3
0
## directory holding data files. this directory and it subdirectories will be
## searched for data.
DIR_DATA = '/home/local/WX/ben.koziol/Dropbox/nesii/project/ocg/bin/climate_data/CanCM4'
## where output data files are written.
DIR_OUTPUT = '/home/local/WX/ben.koziol/Dropbox/nesii/project/ocg/presentation/20130225_caspar_demo/output/01'
## state identifiers in the state shapefile that together comprise the
## southwestern united states.
SW_IDS = [25, 23, 24, 37, 42]
## set to true until final execution
SNIPPET = False

## update environmental variables.
ocgis.env.DIR_DATA = DIR_DATA
ocgis.env.DIR_OUTPUT = DIR_OUTPUT
## pull data files together into a single collections of request datasets.
rdc = ocgis.RequestDatasetCollection()
for ii, filename in enumerate(os.listdir(ocgis.env.DIR_DATA)):
    variable = filename.split('_')[0]
    alias = variable + '_' + str(ii)
    rd = ocgis.RequestDataset(filename, variable, alias=alias)
    rdc.update(rd)

## SUBSETTING ##################################################################

ops = ocgis.OcgOperations(rdc,
                          snippet=SNIPPET,
                          geom='state_boundaries',
                          select_ugid=SW_IDS,
                          output_format='shp',
                          agg_selection=False,
                          spatial_operation='clip',