diff --git a/demo/land_cover_dataset_demo.ipynb b/demo/land_cover_dataset_demo.ipynb index 521266a..fc6533f 100644 --- a/demo/land_cover_dataset_demo.ipynb +++ b/demo/land_cover_dataset_demo.ipynb @@ -58,30 +58,17 @@ "name": "stderr", "output_type": "stream", "text": [ - " 50%|█████ | 1/2 [00:00<00:00, 1.84it/s]" + "100%|██████████| 2/2 [00:00<00:00, 3.90it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ + "File 'land-cover_LCCS_MAP_300m_2011.zip' already exists, skipping...\n", "File 'land-cover_LCCS_MAP_300m_2010.zip' already exists, skipping...\n" ] }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "100%|██████████| 2/2 [00:00<00:00, 2.30it/s]" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File 'land-cover_LCCS_MAP_300m_2011.zip' already exists, skipping...\n" - ] - }, { "name": "stderr", "output_type": "stream", @@ -554,14 +541,14 @@ " geospatial_lat_units: degrees_north\n", " geospatial_lat_resolution: 0.002778\n", " geospatial_lon_units: degrees_east\n", - " geospatial_lon_resolution: 0.002778
  • id :
    ESACCI-LC-L4-LCCS-Map-300m-P1Y-2010-v2.0.7cds
    title :
    Land Cover Map of ESA CCI brokered by CDS
    summary :
    This dataset characterizes the land cover of a particular year (see time_coverage). The land cover was derived from the analysis of satellite data time series of the full period.
    type :
    ESACCI-LC-L4-LCCS-Map-300m-P1Y
    project :
    Climate Change Initiative - European Space Agency
    references :
    http://www.esa-landcover-cci.org/
    institution :
    UCLouvain
    contact :
    https://www.ecmwf.int/en/about/contact-us/get-support
    comment :
    Conventions :
    CF-1.6
    standard_name_vocabulary :
    NetCDF Climate and Forecast (CF) Standard Names version 21
    keywords :
    land cover classification,satellite,observation
    keywords_vocabulary :
    NASA Global Change Master Directory (GCMD) Science Keywords
    license :
    ESA CCI Data Policy: free and open access
    naming_authority :
    org.esa-cci
    cdm_data_type :
    grid
    TileSize :
    2025:2025
    tracking_id :
    96ac9aca-1ca7-45c6-b4a5-ab448c692646
    product_version :
    2.0.7cds
    creation_date :
    20181130T095431Z
    creator_name :
    UCLouvain
    creator_url :
    http://www.uclouvain.be/
    creator_email :
    landcover-cci@uclouvain.be
    source :
    MERIS FR L1B version 5.05, MERIS RR L1B version 8.0, SPOT VGT P
    history :
    amorgos-4,0, lc-sdr-1.0, lc-sr-1.0, lc-classification-1.0,lc-user-tools-3.13,lc-user-tools-4.3
    time_coverage_start :
    20100101
    time_coverage_end :
    20101231
    time_coverage_duration :
    P1Y
    time_coverage_resolution :
    P1Y
    geospatial_lat_min :
    -90.0
    geospatial_lat_max :
    90.0
    geospatial_lon_min :
    -180
    geospatial_lon_max :
    180
    spatial_resolution :
    300m
    geospatial_lat_units :
    degrees_north
    geospatial_lat_resolution :
    0.002778
    geospatial_lon_units :
    degrees_east
    geospatial_lon_resolution :
    0.002778
  • " ], "text/plain": [ "\n", @@ -622,6 +609,494 @@ "source": [ "ds" ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "land_cover renamed to land_cover.\n", + "Conversion of dataset 'land-cover' following ALMA convention is complete!\n" + ] + } + ], + "source": [ + "from zampy.datasets import converter\n", + "\n", + "ds_convert = converter.convert(ds, land_cover_dataset, \"ALMA\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
    \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
    <xarray.Dataset>\n",
    +       "Dimensions:     (time: 2, latitude: 54, longitude: 54)\n",
    +       "Coordinates:\n",
    +       "  * time        (time) datetime64[ns] 2010-01-01 2011-01-01\n",
    +       "  * latitude    (latitude) float64 1.0 2.0 3.0 4.0 5.0 ... 51.0 52.0 53.0 54.0\n",
    +       "  * longitude   (longitude) float64 3.0 4.0 5.0 6.0 7.0 ... 53.0 54.0 55.0 56.0\n",
    +       "Data variables:\n",
    +       "    land_cover  (time, latitude, longitude) float32 210.0 210.0 ... 10.0 10.0\n",
    +       "Attributes: (12/38)\n",
    +       "    id:                         ESACCI-LC-L4-LCCS-Map-300m-P1Y-2010-v2.0.7cds\n",
    +       "    title:                      Land Cover Map of ESA CCI brokered by CDS\n",
    +       "    summary:                    This dataset characterizes the land cover of ...\n",
    +       "    type:                       ESACCI-LC-L4-LCCS-Map-300m-P1Y\n",
    +       "    project:                    Climate Change Initiative - European Space Ag...\n",
    +       "    references:                 http://www.esa-landcover-cci.org/\n",
    +       "    ...                         ...\n",
    +       "    geospatial_lon_max:         180\n",
    +       "    spatial_resolution:         300m\n",
    +       "    geospatial_lat_units:       degrees_north\n",
    +       "    geospatial_lat_resolution:  0.002778\n",
    +       "    geospatial_lon_units:       degrees_east\n",
    +       "    geospatial_lon_resolution:  0.002778
    " + ], + "text/plain": [ + "\n", + "Dimensions: (time: 2, latitude: 54, longitude: 54)\n", + "Coordinates:\n", + " * time (time) datetime64[ns] 2010-01-01 2011-01-01\n", + " * latitude (latitude) float64 1.0 2.0 3.0 4.0 5.0 ... 51.0 52.0 53.0 54.0\n", + " * longitude (longitude) float64 3.0 4.0 5.0 6.0 7.0 ... 53.0 54.0 55.0 56.0\n", + "Data variables:\n", + " land_cover (time, latitude, longitude) float32 210.0 210.0 ... 10.0 10.0\n", + "Attributes: (12/38)\n", + " id: ESACCI-LC-L4-LCCS-Map-300m-P1Y-2010-v2.0.7cds\n", + " title: Land Cover Map of ESA CCI brokered by CDS\n", + " summary: This dataset characterizes the land cover of ...\n", + " type: ESACCI-LC-L4-LCCS-Map-300m-P1Y\n", + " project: Climate Change Initiative - European Space Ag...\n", + " references: http://www.esa-landcover-cci.org/\n", + " ... ...\n", + " geospatial_lon_max: 180\n", + " spatial_resolution: 300m\n", + " geospatial_lat_units: degrees_north\n", + " geospatial_lat_resolution: 0.002778\n", + " geospatial_lon_units: degrees_east\n", + " geospatial_lon_resolution: 0.002778" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ds_convert" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/src/zampy/conventions/ALMA.json b/src/zampy/conventions/ALMA.json index 2971ee0..f5c04ea 100644 --- a/src/zampy/conventions/ALMA.json +++ b/src/zampy/conventions/ALMA.json @@ -76,5 +76,9 @@ "co2_concentration": { "variable": "CO2air", "units": "kilogram/kilogram" + }, + "land_cover": { + "variable": "land_cover", + "units": "" } } \ No newline at end of file diff --git a/src/zampy/datasets/land_cover.py b/src/zampy/datasets/land_cover.py index 2b964a8..22a7c6f 100644 --- a/src/zampy/datasets/land_cover.py +++ b/src/zampy/datasets/land_cover.py @@ -2,11 +2,13 @@ import os from pathlib import Path +from typing import Union from zipfile import ZipFile import numpy as np import xarray as xr import xarray_regrid from zampy.datasets import cds_utils +from zampy.datasets import converter from zampy.datasets import validation from zampy.datasets.dataset_protocol import SpatialBounds from zampy.datasets.dataset_protocol import TimeBounds @@ -150,6 +152,29 @@ def load( return ds_regrid + def convert( + self, + ingest_dir: Path, + convention: Union[str, Path], + ) -> bool: + converter.check_convention(convention) + ingest_folder = ingest_dir / self.name + + data_file_pattern = "land-cover_LCCS_MAP_*.nc" + + data_files = list(ingest_folder.glob(data_file_pattern)) + + for file in data_files: + # start conversion process + print(f"Start processing file `{file.name}`.") + ds = xr.open_dataset(file) + ds = converter.convert(ds, dataset=self, convention=convention) + # TODO: support derived variables + # TODO: other calculations + # call ds.compute() + + return True + def unzip_raw_to_netcdf( ingest_folder: Path,