コード例 #1
0
def _make_racmo_wind_speed() -> Layer:
    return Layer(
        id='racmo_wind_speed',
        title='Annual mean wind speed 1958-2019 (5km)',
        description=
        ("""Averaged annual mean wind speed in meters per second from RACMO2.3p2
            for the period 1958-2019."""),
        tags=[],
        style='racmo_wind_speed',
        input=LayerInput(
            dataset=dataset,
            asset=dataset.assets['only'],
        ),
        steps=[
            decompress_step(
                input_file='{input_dir}/RACMO_QGreenland_Jan2021.zip',
                decompress_contents_mask='magnitudes.nc',
            ),
            *warp_and_cut(
                input_file='{input_dir}/magnitudes.nc',
                output_file='{output_dir}/racmo_wind_speed.tif',
                cut_file=project.boundaries['data'].filepath,
            ),
            *compress_and_add_overviews(
                input_file='{input_dir}/racmo_wind_speed.tif',
                output_file='{output_dir}/racmo_wind_speed.tif',
                dtype_is_float=True,
            ),
        ],
    )
コード例 #2
0
def _make_masked_racmo_layer(
        *,
        layer_id: str,
        title: str,
        description: str,
        style: str,
        input_filename: str,
        decompress_contents_mask: str,
        variable: str,
        nodata: int = -9999,
        gdal_edit_args=(),
) -> Layer:
    return Layer(
        id=layer_id,
        title=title,
        description=description,
        tags=[],
        style=style,
        input=LayerInput(
            dataset=dataset,
            asset=dataset.assets['only'],
        ),
        steps=[
            decompress_step(
                input_file='{input_dir}/RACMO_QGreenland_Jan2021.zip',
                decompress_contents_mask=decompress_contents_mask,
            ),
            # Apply the promice mask. The `Promicemask` values are 3 = Greenland ice
            # sheet; 2,1 = Greenland peripheral ice caps; 0 = Ocean. This step masks
            # out the ocean as 'nodata'.
            CommandStep(args=[
                'gdal_calc.py',
                f'--calc="numpy.where((B != 0), A, {nodata})"',
                f'--NoDataValue={nodata}',
                '--outfile={output_dir}/' + f'{variable}.tif',
                '-A',
                'NETCDF:{input_dir}/' + f'{input_filename}:{variable}',
                '-B',
                ('NETCDF:{input_dir}/'
                 'Icemask_Topo_Iceclasses_lon_lat_average_1km_GrIS.nc:Promicemask'
                 ),
            ], ),
            *gdal_edit(
                input_file='{input_dir}/' + f'{variable}.tif',
                output_file='{output_dir}/edited.tif',
                gdal_edit_args=[
                    '-a_srs',
                    project.crs,
                    *gdal_edit_args,
                ],
            ),
            *compress_and_add_overviews(
                input_file='{input_dir}/edited.tif',
                output_file='{output_dir}/' + f'racmo_{variable}.tif',
                dtype_is_float=True,
            ),
        ],
    )
コード例 #3
0
def _make_layer(
    *,
    layer_id: str,
    title: str,
    description: str,
    style: str,
    filename: str,
    dataset: Dataset,
) -> Layer:
    return Layer(
        id=layer_id,
        title=title,
        description=description,
        tags=[],
        style=style,
        input=LayerInput(
            dataset=dataset,
            asset=dataset.assets['only'],
        ),
        steps=[
            decompress_step(
                input_file='{input_dir}/archive.zip',
                decompress_contents_mask=filename,
            ),
            *warp_and_cut(
                input_file='{input_dir}/' + filename,
                output_file='{output_dir}/' + filename,
                reproject_args=[
                    # Source data is 0.02x-0.02 degrees resolution. Rene noted in
                    # his email to QGreenland on 2021-01-22 that the geoid and
                    # gravity anomaly grids are 2km resolution.
                    '-tr',
                    '2000',
                    '2000',
                ],
                cut_file=project.boundaries['data'].filepath,
            ),
            *compress_and_add_overviews(
                input_file='{input_dir}/' + filename,
                output_file='{output_dir}/' + filename,
                dtype_is_float=True,
            ),
        ],
    )
コード例 #4
0
def make_layers() -> list[Layer]:
    return [
        Layer(
            id=f'continental_shelf_{key}',
            title=params['title'],
            description=params['description'],
            tags=[],
            input=LayerInput(
                dataset=dataset,
                asset=dataset.assets[key],
            ),
            steps=[
                decompress_step(input_file='{input_dir}/*.zip', ),
                CommandStep(args=[
                    'ogr2ogr',
                    *STANDARD_OGR2OGR_ARGS,
                    '-makevalid',
                    '{output_dir}/final.gpkg',
                    '{input_dir}/*.shp',
                ], ),
            ],
        ) for key, params in LAYER_PARAMS.items()
    ]
コード例 #5
0
def compressed_vector(
    *,
    input_file: str,
    output_file: str,
    vector_filename: str = '*.shp',
    decompress_step_kwargs=default_decompress_step_kwargs,
    ogr2ogr_args: StepArgs = (),
    boundary_filepath: EvalFilePath = project.boundaries['background'].
    filepath,
) -> list[CommandStep]:
    """Unzip a vector data file and reproject."""
    return [
        decompress_step(
            input_file=input_file,
            **decompress_step_kwargs,
        ),
        *ogr2ogr(
            input_file='{input_dir}/' + vector_filename,
            output_file=output_file,
            boundary_filepath=boundary_filepath,
            ogr2ogr_args=ogr2ogr_args,
        ),
    ]
コード例 #6
0
def make_racmo_supplemental_layers() -> list[Layer]:
    layers = []

    _racmo_mask_layer_params = {
        'racmo_promicemask': {
            'title':
            'PROMICE mask (1km)',
            'description':
            ("""Mask of categorized Greenland ice. 3 = Greenland ice sheet; 2,1 = Greenland
                peripheral ice caps; 0 = Ocean."""),
            'extract_filename':
            'Icemask_Topo_Iceclasses_lon_lat_average_1km_GrIS.nc',
            'variable':
            'Promicemask',
        },
        'racmo_grounded_ice': {
            'title': 'Grounded ice mask (1km)',
            'description': 'Mask of grounded ice. 1 = grounded.',
            'extract_filename':
            'Icemask_Topo_Iceclasses_lon_lat_average_1km_Aug2020.nc',
            'variable': 'grounded_ice',
        },
    }

    for layer_id, params in _racmo_mask_layer_params.items():
        layers.append(
            Layer(
                id=layer_id,
                title=params['title'],
                description=params['description'],
                tags=[],
                style='racmo_promicemask',
                input=LayerInput(
                    dataset=dataset,
                    asset=dataset.assets['only'],
                ),
                steps=[
                    decompress_step(
                        input_file='{input_dir}/RACMO_QGreenland_Jan2021.zip',
                        decompress_contents_mask=params['extract_filename'],
                    ),
                    CommandStep(
                        args=[
                            'gdal_translate',
                            '-a_srs',
                            project.crs,
                            '-a_ullr',
                            RACMO_ULLR,
                            # Data is stored as Float32 but uses integers for mask values.
                            '-ot',
                            'Byte',
                            '-a_nodata',
                            'none',
                            ('NETCDF:{input_dir}/' +
                             f"{params['extract_filename']}:{params['variable']}"
                             ),
                            '{output_dir}/' + f"{params['variable']}.tif",
                        ], ),
                    *compress_and_add_overviews(
                        input_file='{input_dir}/' +
                        f"{params['variable']}.tif",
                        output_file='{output_dir}/' + f'{layer_id}.tif',
                        dtype_is_float=False,
                    ),
                ],
            ), )

    racmo_topography = _make_masked_racmo_layer(
        layer_id='racmo_topography',
        title='Ice surface topography (1km)',
        description=
        ("""Ice sheet surface elevation in meters upscaled from the Greenland Mapping
            Project (GIMP) Digital Elevation Model."""),
        style='racmo_topography',
        decompress_contents_mask=
        'Icemask_Topo_Iceclasses_lon_lat_average_1km_GrIS.nc',
        input_filename='Icemask_Topo_Iceclasses_lon_lat_average_1km_GrIS.nc',
        variable='Topography',
        gdal_edit_args=[
            '-a_ullr',
            RACMO_ULLR,
        ],
    )

    layers.append(racmo_topography)

    return layers
コード例 #7
0
ice_thickness_change = Layer(
    id='ice_thickness_change',
    title='Ice column thickness rate of change 2003-2019 (5km)',
    description=(
        """Ice column thickness-change-rate estimates in meters per year based
        on data from NASA's ICESat and ICESat-2 satellites."""
    ),
    tags=[],
    style='ice_thickness_change',
    input=LayerInput(
        dataset=dataset,
        asset=dataset.assets['only'],
    ),
    steps=[
        decompress_step(
            input_file='{input_dir}/ICESat1_ICESat2_mass_change.zip',
            decompress_contents_mask=SOURCE_FP,
        ),
        *warp(
            input_file='{input_dir}/' + SOURCE_FP,
            output_file='{output_dir}/warped.tif',
            cut_file=project.boundaries['data'].filepath,
        ),
        *compress_and_add_overviews(
            input_file='{input_dir}/warped.tif',
            output_file='{output_dir}/final.tif',
            dtype_is_float=True,
        ),
    ],
)
コード例 #8
0
ファイル: soil_types.py プロジェクト: nsidc/qgreenland
soil_types = Layer(
    id='soil_types',
    title='Soil characteristics',
    description=(
        """Polygons representing dominant soil characteristics with percentage
        polygon area for each soil type. Data coverage limited to Greenland."""
    ),
    tags=[],
    style='soil_types',
    input=LayerInput(
        dataset=dataset,
        asset=dataset.assets['only'],
    ),
    steps=[
        decompress_step(
            decompress_type='gzip',
            input_file='{input_dir}/*.gz',
        ),
        *ogr2ogr(
            input_file='{input_dir}/ggd602_soils_greenland.shp',
            output_file='{output_dir}/soil_types.gpkg',
            boundary_filepath=project.boundaries['data'].filepath,
            ogr2ogr_args=(
                '-s_srs',
                '"+proj=laea +a=6370997.00 +b=6370997.00 +lat_0=90 +lon_0=180 +x_0=0 +y_0=0"',
            ),
        ),
    ],
)
コード例 #9
0
ファイル: layers.py プロジェクト: nsidc/qgreenland
layers = [
    Layer(
        id=layer_id,
        title=params['title'],
        description=params['description'],
        tags=[],
        style=params['style'],
        input=LayerInput(
            dataset=dataset,
            asset=dataset.assets['only'],
        ),
        steps=[
            decompress_step(
                input_file=
                '{input_dir}/greenland_iv_250m_s1_20191214_20200131_v1_3.zip',
                decompress_contents_mask=(
                    'greenland_iv_250m_s1_20191214_20200131_v1_3'
                    '/greenland_iv_250m_s1_20191214_20200131_v1_3.nc'),
            ),
            *warp_and_cut(
                input_file=
                ('NETCDF:{input_dir}/greenland_iv_250m_s1_20191214_20200131_v1_3/'
                 'greenland_iv_250m_s1_20191214_20200131_v1_3.nc'
                 f":{params['variable']}"),
                output_file='{output_dir}/' + f'{layer_id}.tif',
                cut_file=project.boundaries['data'].filepath,
            ),
            *compress_and_add_overviews(
                input_file='{input_dir}/' + f'{layer_id}.tif',
                output_file='{output_dir}/' + f'{layer_id}.tif',
                dtype_is_float=True,
コード例 #10
0
    ]


background = Layer(
    id='background',
    title='Background (500m)',
    description='Stylized shaded-relief map for providing a general sense of geography.',
    tags=['background', 'shaded-relief'],
    show=True,
    input=LayerInput(
        dataset=background_dataset,
        asset=background_dataset.assets['high_res'],
    ),
    steps=[
        decompress_step(
            input_file='{input_dir}/*.zip',
        ),
        *warp_and_cut(
            input_file='{input_dir}/NE2_HR_LC_SR_W.tif',
            output_file='{output_dir}/warped_and_cut.tif',
            reproject_args=[
                '-tr', '500', '500',
                # TODO import project config and access correct boundary.
                '-te', '-5774572.727595 -5774572.727595 5774572.727595 5774572.727595',
                '-dstnodata', '0',
                '-wo', 'SOURCE_EXTRA=100',
                '-wo', 'SAMPLE_GRID=YES',
            ],
            cut_file='{assets_dir}/latitude_shape_40_degrees.geojson',
        ),
        # Because the background image is large, we use JPEG compression