diff --git a/catalog/ssebopeta_monthly/collection.json b/catalog/ssebopeta_monthly/collection.json index 340f8031f020619a566e1a2f7e8f9891f1918c49..0d27ceb9c40253e0bb5541b7df85a4d0f0a8493c 100644 --- a/catalog/ssebopeta_monthly/collection.json +++ b/catalog/ssebopeta_monthly/collection.json @@ -37,7 +37,7 @@ -66.49649999999997 ], "step": 0.009, - "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"Conversion\",\"name\":\"PROJ-based coordinate operation\",\"method\":{\"name\":\"PROJ-based operation method: +proj=longlat +datum=WGS84 +no_defs\"},\"parameters\":[]}" + "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"GeographicCRS\",\"name\":\"WGS 84\",\"datum\":{\"type\":\"GeodeticReferenceFrame\",\"name\":\"World Geodetic System 1984\",\"ellipsoid\":{\"name\":\"WGS 84\",\"semi_major_axis\":6378137,\"inverse_flattening\":298.257223563}},\"coordinate_system\":{\"subtype\":\"ellipsoidal\",\"axis\":[{\"name\":\"Geodetic latitude\",\"abbreviation\":\"Lat\",\"direction\":\"north\",\"unit\":\"degree\"},{\"name\":\"Geodetic longitude\",\"abbreviation\":\"Lon\",\"direction\":\"east\",\"unit\":\"degree\"}]},\"id\":{\"authority\":\"EPSG\",\"code\":4326}}" }, "lat": { "type": "spatial", @@ -48,7 +48,7 @@ 49.495499999999986 ], "step": 0.009, - "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"Conversion\",\"name\":\"PROJ-based coordinate operation\",\"method\":{\"name\":\"PROJ-based operation method: +proj=longlat +datum=WGS84 +no_defs\"},\"parameters\":[]}" + "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"GeographicCRS\",\"name\":\"WGS 84\",\"datum\":{\"type\":\"GeodeticReferenceFrame\",\"name\":\"World Geodetic System 1984\",\"ellipsoid\":{\"name\":\"WGS 84\",\"semi_major_axis\":6378137,\"inverse_flattening\":298.257223563}},\"coordinate_system\":{\"subtype\":\"ellipsoidal\",\"axis\":[{\"name\":\"Geodetic latitude\",\"abbreviation\":\"Lat\",\"direction\":\"north\",\"unit\":\"degree\"},{\"name\":\"Geodetic longitude\",\"abbreviation\":\"Lon\",\"direction\":\"east\",\"unit\":\"degree\"}]},\"id\":{\"authority\":\"EPSG\",\"code\":4326}}" } }, "cube:variables": { @@ -56,7 +56,7 @@ "dimensions": [ "time" ], - "type": "data", + "type": "auxiliary", "description": "CRS definition", "unit": null }, diff --git a/catalog/ssebopeta_yearly/collection.json b/catalog/ssebopeta_yearly/collection.json index d33656ec9a51a510d9ec7a8ef6746128ccf515d0..b153aaae408e119cdcab38e973ba2eb9e8b2536b 100644 --- a/catalog/ssebopeta_yearly/collection.json +++ b/catalog/ssebopeta_yearly/collection.json @@ -37,7 +37,7 @@ -66.4965 ], "step": 0.009, - "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"Conversion\",\"name\":\"PROJ-based coordinate operation\",\"method\":{\"name\":\"PROJ-based operation method: +proj=longlat +datum=WGS84 +no_defs\"},\"parameters\":[]}" + "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"GeographicCRS\",\"name\":\"WGS 84\",\"datum\":{\"type\":\"GeodeticReferenceFrame\",\"name\":\"World Geodetic System 1984\",\"ellipsoid\":{\"name\":\"WGS 84\",\"semi_major_axis\":6378137,\"inverse_flattening\":298.257223563}},\"coordinate_system\":{\"subtype\":\"ellipsoidal\",\"axis\":[{\"name\":\"Geodetic latitude\",\"abbreviation\":\"Lat\",\"direction\":\"north\",\"unit\":\"degree\"},{\"name\":\"Geodetic longitude\",\"abbreviation\":\"Lon\",\"direction\":\"east\",\"unit\":\"degree\"}]},\"id\":{\"authority\":\"EPSG\",\"code\":4326}}" }, "lat": { "type": "spatial", @@ -48,7 +48,7 @@ 49.4955 ], "step": 0.009, - "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"Conversion\",\"name\":\"PROJ-based coordinate operation\",\"method\":{\"name\":\"PROJ-based operation method: +proj=longlat +datum=WGS84 +no_defs\"},\"parameters\":[]}" + "reference_system": "{\"$schema\":\"https://proj.org/schemas/v0.5/projjson.schema.json\",\"type\":\"GeographicCRS\",\"name\":\"WGS 84\",\"datum\":{\"type\":\"GeodeticReferenceFrame\",\"name\":\"World Geodetic System 1984\",\"ellipsoid\":{\"name\":\"WGS 84\",\"semi_major_axis\":6378137,\"inverse_flattening\":298.257223563}},\"coordinate_system\":{\"subtype\":\"ellipsoidal\",\"axis\":[{\"name\":\"Geodetic latitude\",\"abbreviation\":\"Lat\",\"direction\":\"north\",\"unit\":\"degree\"},{\"name\":\"Geodetic longitude\",\"abbreviation\":\"Lon\",\"direction\":\"east\",\"unit\":\"degree\"}]},\"id\":{\"authority\":\"EPSG\",\"code\":4326}}" } }, "cube:variables": { @@ -56,7 +56,7 @@ "dimensions": [ "time" ], - "type": "data", + "type": "auxiliary", "description": "CRS definition", "unit": null }, diff --git a/workflows/archive/maca_vic_future_create_collection_from_zarr.ipynb b/workflows/archive/maca_vic_future_create_collection_from_zarr.ipynb index 3fc0ed330fb0407076596bf8de986901dcd49627..f877bf95edcac5a96a9227f19620f3e0e2cc64a9 100644 --- a/workflows/archive/maca_vic_future_create_collection_from_zarr.ipynb +++ b/workflows/archive/maca_vic_future_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "4cadb3f9-aeb8-4eeb-97ac-9c3229d113f2", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -727,7 +737,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/maca_vic_past_create_collection_from_zarr.ipynb b/workflows/archive/maca_vic_past_create_collection_from_zarr.ipynb index 0e85e7cc28bdd89b68bad66d515de01054f4bdea..f289292c494424b4a26226898886e6a3b76e57f9 100644 --- a/workflows/archive/maca_vic_past_create_collection_from_zarr.ipynb +++ b/workflows/archive/maca_vic_past_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "39497901-2d08-4926-8eaf-1d447cf27210", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -727,7 +737,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/macav2_future_daily_create_collection_from_zarr.ipynb b/workflows/archive/macav2_future_daily_create_collection_from_zarr.ipynb index b2b2dd102a7d048b434c85be276befcaba3a0a42..c665f9b469056a46ebb7a068b114bc017b34f3ec 100644 --- a/workflows/archive/macav2_future_daily_create_collection_from_zarr.ipynb +++ b/workflows/archive/macav2_future_daily_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "4c1e0914-684e-4843-9ba0-86f7132097f8", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -232,7 +242,7 @@ }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { @@ -756,7 +766,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/macav2_future_monthly_create_collection_from_zarr.ipynb b/workflows/archive/macav2_future_monthly_create_collection_from_zarr.ipynb index f77d5d8195bf076329b43476fcb4d6397bd0a3bd..61932b97964a02deb53dd9472a3ca874e106fe9d 100644 --- a/workflows/archive/macav2_future_monthly_create_collection_from_zarr.ipynb +++ b/workflows/archive/macav2_future_monthly_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "09bdcd33-4ec0-4d72-ba59-d4edae59640a", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -232,7 +242,7 @@ }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { @@ -762,7 +772,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/macav2_historical_daily_create_collection_from_zarr.ipynb b/workflows/archive/macav2_historical_daily_create_collection_from_zarr.ipynb index 3c4d80827f797004adfa0346de4302f99119272c..7ea2c6a268145b5154cb967f994a18e19cd42810 100644 --- a/workflows/archive/macav2_historical_daily_create_collection_from_zarr.ipynb +++ b/workflows/archive/macav2_historical_daily_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "bee579bf-bc09-40c4-9301-077f94a361cc", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -232,7 +242,7 @@ }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { @@ -756,7 +766,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/macav2_historical_monthly_create_collection_from_zarr.ipynb b/workflows/archive/macav2_historical_monthly_create_collection_from_zarr.ipynb index 7447432604abc7e52269ec3595446a80f95115c7..94a27c9462b58c0474bfe4ac83c0b61c94009a6d 100644 --- a/workflows/archive/macav2_historical_monthly_create_collection_from_zarr.ipynb +++ b/workflows/archive/macav2_historical_monthly_create_collection_from_zarr.ipynb @@ -207,6 +207,16 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "165c5ea8-af4a-4bfa-b217-216ef053bc04", + "metadata": {}, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -215,7 +225,7 @@ "outputs": [], "source": [ "# use pyproj to automatically extract crs info\n", - "crs = pyproj.CRS.from_cf(ds.crs.attrs)\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", "\n", "# alternatively, create the appropriate cartopy projection\n", "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", @@ -232,7 +242,7 @@ }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { @@ -762,7 +772,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/ssebopeta_monthly_create_collection_from_zarr.ipynb b/workflows/archive/ssebopeta_monthly_create_collection_from_zarr.ipynb index 8b1d8765a73ed289a57b4a78c84bbd5119a7a3a0..71711f70fa28273ddf103f39d5052b78bf6044e7 100644 --- a/workflows/archive/ssebopeta_monthly_create_collection_from_zarr.ipynb +++ b/workflows/archive/ssebopeta_monthly_create_collection_from_zarr.ipynb @@ -35,12 +35,12 @@ "import pandas as pd\n", "import json\n", "import numpy as np\n", - "import metpy\n", + "import pyproj\n", + "from pyproj import Transformer\n", "import cartopy.crs as ccrs\n", "import cfunits\n", "import json\n", "import sys\n", - "from pyproj import Transformer\n", "sys.path.insert(1, '..')\n", "import stac_helpers" ] @@ -215,6 +215,18 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "edf9f3c1-9cf1-4d00-be91-c0474ee90cad", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -224,8 +236,13 @@ }, "outputs": [], "source": [ - "ds = ds.metpy.parse_cf()\n", - "crs = ds[list(ds.keys())[0]].metpy.pyproj_proj" + "# use pyproj to automatically extract crs info\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", + "\n", + "# alternatively, create the appropriate cartopy projection\n", + "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", + "# central_latitude=crs_info.latitude_of_projection_origin,\n", + "# standard_parallels=crs_info.standard_parallel)" ] }, { @@ -240,17 +257,21 @@ "cell_type": "code", "execution_count": null, "id": "2cab5f28-79e5-4a47-bdc6-54cf4e6fb2f5", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { "cell_type": "code", "execution_count": null, "id": "4d3822b9-e2a6-4b6a-8fc0-447cf4a69226", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "crs.to_proj4()" @@ -293,7 +314,9 @@ "cell_type": "code", "execution_count": null, "id": "57367074-cbe7-43c3-9311-a3eac72f2544", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "X = np.linspace(spatial_bounds[0], spatial_bounds[2], 2)\n", @@ -305,10 +328,12 @@ "cell_type": "code", "execution_count": null, "id": "71d7b52c-3fac-4c57-9b89-f79caf7b8efa", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "transformer = Transformer.from_crs(crs.crs, \"EPSG:4326\", always_xy=True)\n", + "transformer = Transformer.from_crs(crs, \"EPSG:4326\", always_xy=True)\n", "lon, lat = transformer.transform(XX.ravel(), YY.ravel())" ] }, @@ -316,7 +341,9 @@ "cell_type": "code", "execution_count": null, "id": "e2189ce1-dc7f-408b-a4e7-72bf012f36f0", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "print(f'lower left coordinates (WGS84): {min(lon)}, {min(lat)}')\n", @@ -327,7 +354,9 @@ "cell_type": "code", "execution_count": null, "id": "01b2eec4-b907-46ac-a6c3-6d0b78aa5f4e", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# create a spatial extent object \n", @@ -508,20 +537,6 @@ "print(dims)" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "00a18a29-fb9a-4b56-8009-493122997b16", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# get x, y bounds for extent of those dimensions (required)\n", - "xy_bounds = [ds[dim_names_dict['X']].data.min().astype(float).item(), ds[dim_names_dict['Y']].data.min().astype(float).item(), ds[dim_names_dict['X']].data.max().astype(float).item(), ds[dim_names_dict['Y']].data.max().astype(float).item()]\n", - "print(xy_bounds)" - ] - }, { "cell_type": "markdown", "id": "e7dc357c-91ec-49ae-83e5-400f791f9792", @@ -531,19 +546,6 @@ "reference list of cartopy projections: https://scitools.org.uk/cartopy/docs/latest/reference/projections.html" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "ea452f62-5644-49b6-8a4e-7dc4f649fd1a", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# print ot crs information in dataset\n", - "print(crs)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -650,7 +652,9 @@ "cell_type": "code", "execution_count": null, "id": "9005e2f6-2c6d-4207-9e8a-bd83d6568a6f", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps: get all step values and locations\n", @@ -663,7 +667,9 @@ "cell_type": "code", "execution_count": null, "id": "0380a900-5efa-4df7-8d7a-9a989d52c2f8", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps, cont:\n", @@ -700,7 +706,9 @@ "cell_type": "code", "execution_count": null, "id": "b4c6d46e-51ee-4ad4-90b6-cfc957d089d7", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps: get all step values and locations\n", @@ -713,7 +721,9 @@ "cell_type": "code", "execution_count": null, "id": "de5189d4-3388-450b-8adb-d4f55bfb96b6", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps, cont:\n", @@ -757,8 +767,8 @@ "# we do not recommend including redundant dimensions (do not include x,y if you have lon,lat)\n", "# note that the extent of each dimension should be pulled from the dataset\n", "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': stac_helpers.get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step':time_step}),\n", - " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': stac_helpers.get_long_name(ds, dim_names_dict['X']), 'extent': [xy_bounds[0], xy_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", - " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': stac_helpers.get_long_name(ds, dim_names_dict['Y']), 'extent': [xy_bounds[1], xy_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", + " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': stac_helpers.get_long_name(ds, dim_names_dict['X']), 'extent': [spatial_bounds[0], spatial_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", + " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': stac_helpers.get_long_name(ds, dim_names_dict['Y']), 'extent': [spatial_bounds[1], spatial_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", " }" ] }, @@ -799,7 +809,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ] diff --git a/workflows/archive/ssebopeta_yearly_create_collection_from_zarr.ipynb b/workflows/archive/ssebopeta_yearly_create_collection_from_zarr.ipynb index 1aaa0e649449087a1fb2a06afc142a47ab0cab3b..25b08505abb0f66f68b3c878ffceb1da3491ff24 100644 --- a/workflows/archive/ssebopeta_yearly_create_collection_from_zarr.ipynb +++ b/workflows/archive/ssebopeta_yearly_create_collection_from_zarr.ipynb @@ -35,12 +35,12 @@ "import pandas as pd\n", "import json\n", "import numpy as np\n", - "import metpy\n", + "import pyproj\n", + "from pyproj import Transformer\n", "import cartopy.crs as ccrs\n", "import cfunits\n", "import json\n", "import sys\n", - "from pyproj import Transformer\n", "sys.path.insert(1, '..')\n", "import stac_helpers" ] @@ -215,6 +215,18 @@ "## Get crs info" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d4a474e-a3ce-41cd-92fb-e398269f7a96", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "crs_var = 'crs'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -224,8 +236,13 @@ }, "outputs": [], "source": [ - "ds = ds.metpy.parse_cf()\n", - "crs = ds[list(ds.keys())[0]].metpy.pyproj_proj" + "# use pyproj to automatically extract crs info\n", + "crs = pyproj.CRS.from_cf(ds[crs_var].attrs)\n", + "\n", + "# alternatively, create the appropriate cartopy projection\n", + "# crs = ccrs.LambertConformal(central_longitude=crs_info.longitude_of_central_meridian, \n", + "# central_latitude=crs_info.latitude_of_projection_origin,\n", + "# standard_parallels=crs_info.standard_parallel)" ] }, { @@ -240,17 +257,21 @@ "cell_type": "code", "execution_count": null, "id": "2cab5f28-79e5-4a47-bdc6-54cf4e6fb2f5", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "ds.crs" + "ds[crs_var]" ] }, { "cell_type": "code", "execution_count": null, "id": "4d3822b9-e2a6-4b6a-8fc0-447cf4a69226", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "crs.to_proj4()" @@ -293,7 +314,9 @@ "cell_type": "code", "execution_count": null, "id": "57367074-cbe7-43c3-9311-a3eac72f2544", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "X = np.linspace(spatial_bounds[0], spatial_bounds[2], 2)\n", @@ -305,10 +328,12 @@ "cell_type": "code", "execution_count": null, "id": "71d7b52c-3fac-4c57-9b89-f79caf7b8efa", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "transformer = Transformer.from_crs(crs.crs, \"EPSG:4326\", always_xy=True)\n", + "transformer = Transformer.from_crs(crs, \"EPSG:4326\", always_xy=True)\n", "lon, lat = transformer.transform(XX.ravel(), YY.ravel())" ] }, @@ -316,7 +341,9 @@ "cell_type": "code", "execution_count": null, "id": "e2189ce1-dc7f-408b-a4e7-72bf012f36f0", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "print(f'lower left coordinates (WGS84): {min(lon)}, {min(lat)}')\n", @@ -327,7 +354,9 @@ "cell_type": "code", "execution_count": null, "id": "01b2eec4-b907-46ac-a6c3-6d0b78aa5f4e", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# create a spatial extent object \n", @@ -508,20 +537,6 @@ "print(dims)" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "00a18a29-fb9a-4b56-8009-493122997b16", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# get x, y bounds for extent of those dimensions (required)\n", - "xy_bounds = [ds[dim_names_dict['X']].data.min().astype(float).item(), ds[dim_names_dict['Y']].data.min().astype(float).item(), ds[dim_names_dict['X']].data.max().astype(float).item(), ds[dim_names_dict['Y']].data.max().astype(float).item()]\n", - "print(xy_bounds)" - ] - }, { "cell_type": "markdown", "id": "e7dc357c-91ec-49ae-83e5-400f791f9792", @@ -531,19 +546,6 @@ "reference list of cartopy projections: https://scitools.org.uk/cartopy/docs/latest/reference/projections.html" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "ea452f62-5644-49b6-8a4e-7dc4f649fd1a", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# print ot crs information in dataset\n", - "print(crs)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -650,7 +652,9 @@ "cell_type": "code", "execution_count": null, "id": "9005e2f6-2c6d-4207-9e8a-bd83d6568a6f", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps: get all step values and locations\n", @@ -663,7 +667,9 @@ "cell_type": "code", "execution_count": null, "id": "0380a900-5efa-4df7-8d7a-9a989d52c2f8", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps, cont:\n", @@ -700,7 +706,9 @@ "cell_type": "code", "execution_count": null, "id": "b4c6d46e-51ee-4ad4-90b6-cfc957d089d7", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps: get all step values and locations\n", @@ -713,7 +721,9 @@ "cell_type": "code", "execution_count": null, "id": "de5189d4-3388-450b-8adb-d4f55bfb96b6", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# # debugging for spatial steps, cont:\n", @@ -757,8 +767,8 @@ "# we do not recommend including redundant dimensions (do not include x,y if you have lon,lat)\n", "# note that the extent of each dimension should be pulled from the dataset\n", "dims_dict = {dim_names_dict['T']: pystac.extensions.datacube.Dimension({'type': 'temporal', 'description': stac_helpers.get_long_name(ds, dim_names_dict['T']), 'extent': [temporal_extent_lower.strftime('%Y-%m-%dT%XZ'), temporal_extent_upper.strftime('%Y-%m-%dT%XZ')], 'step':time_step}),\n", - " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': stac_helpers.get_long_name(ds, dim_names_dict['X']), 'extent': [xy_bounds[0], xy_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", - " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': stac_helpers.get_long_name(ds, dim_names_dict['Y']), 'extent': [xy_bounds[1], xy_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", + " dim_names_dict['X']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'x', 'description': stac_helpers.get_long_name(ds, dim_names_dict['X']), 'extent': [spatial_bounds[0], spatial_bounds[2]], 'step': x_step, 'reference_system': projjson}),\n", + " dim_names_dict['Y']: pystac.extensions.datacube.Dimension({'type': 'spatial', 'axis': 'y', 'description': stac_helpers.get_long_name(ds, dim_names_dict['Y']), 'extent': [spatial_bounds[1], spatial_bounds[3]], 'step': y_step, 'reference_system': projjson}),\n", " }" ] }, @@ -799,7 +809,7 @@ "vars_dict={}\n", "for v in vars:\n", " unit = stac_helpers.get_unit(ds, v)\n", - " var_type = stac_helpers.get_var_type(ds, v)\n", + " var_type = stac_helpers.get_var_type(ds, v, crs_var)\n", " long_name = stac_helpers.get_long_name(ds, v)\n", " vars_dict[v] = pystac.extensions.datacube.Variable({'dimensions':list(ds[v].dims), 'type': var_type, 'description': long_name, 'unit': unit})" ]