@radiantearth/stac-migrate 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +24 -5
  2. package/migrate.js +104 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -57,6 +57,10 @@ The commands follow the different methods above and has the same "restrictions"
57
57
 
58
58
  _A non-standalone Collection (with `child`/`item` links) migrated on its own drops its shared `properties`; pass the Items via `Migrate.item(item, collection)` to keep them._
59
59
 
60
+ - Contacts 1.0.1
61
+
62
+ _Migrates from 0.1.0 onwards. The structure of 0.0.1 is not converted._
63
+
60
64
  - Data Cube 2.3.0
61
65
 
62
66
  _A `cube:dimensions` `reference_system` given as a PROJ4 or WKT string is not converted to the 2.0.0 representation._
@@ -70,7 +74,7 @@ The commands follow the different methods above and has the same "restrictions"
70
74
 
71
75
  _`file:nodata` maps to the single-valued `nodata` (first value kept); extra values are copied to a non-standard `nodata:values`._
72
76
 
73
- - Instruments 0.1.0
77
+ - Instruments 0.2.0
74
78
  - Item Asset Definition 1.0.0 (legacy)
75
79
  - Label 1.0.1
76
80
  - Order 1.1.0
@@ -78,15 +82,30 @@ The commands follow the different methods above and has the same "restrictions"
78
82
 
79
83
  _`pc:encoding` is not rewritten and left in place._
80
84
 
81
- - Processing 1.2.0
82
- - Product 1.0.0
83
- - Projection 2.0.0
85
+ - Processing 1.3.0
86
+ - Product 1.1.0
87
+
88
+ _The deprecated `product:status` value `qualitydegraded` becomes `accepted` with `product:quality_status` set to `degraded`._
89
+
90
+ - Projection 2.1.0
84
91
  - Raster 2.0.0
85
92
  - SAR 1.3.2
86
93
  - Satellite 1.2.0
87
94
  - Scientific Citation 1.0.0
95
+ - Sentinel-1 0.2.0
96
+
97
+ _`s1:resolution`, `s1:product_identifier` and `s1:product_timeliness` are not migrated, as they have no 1:1 replacement._
98
+
99
+ - Sentinel-3 0.2.0
100
+
101
+ _`s3:product_name`, `s3:processing_timeliness`, `s3:lrm_mode`, `s3:sar_mode` and the `s3:gsd` objects are not migrated, as they have no 1:1 replacement._
102
+
103
+ - Sentinel-5P 0.2.0
104
+
105
+ _`s5p:product_name`, `s5p:spatial_resolution` and the product-specific objects are not migrated, as they have no 1:1 replacement._
106
+
88
107
  - Single Item
89
- - Table 1.2.0
108
+ - Table 1.3.0
90
109
  - Timestamps 1.1.0
91
110
  - Versioning Indicators 1.2.0
92
111
  - View Geometry 1.1.0
package/migrate.js CHANGED
@@ -9,26 +9,47 @@ const DONE = true; // This is used to verify in code coverage whether something
9
9
  const SCHEMAS = {
10
10
  cf: 'https://stac-extensions.github.io/cf/v1.0.0/schema.json',
11
11
  classification: 'https://stac-extensions.github.io/classification/v2.0.0/schema.json',
12
+ contacts: 'https://stac-extensions.github.io/contacts/v1.0.1/schema.json',
12
13
  datacube: 'https://stac-extensions.github.io/datacube/v2.3.0/schema.json',
13
14
  eo: 'https://stac-extensions.github.io/eo/v2.0.0/schema.json',
14
15
  file: 'https://stac-extensions.github.io/file/v2.1.0/schema.json',
15
- instruments: 'https://stac-extensions.github.io/instruments/v0.1.0/schema.json',
16
+ instruments: 'https://stac-extensions.github.io/instruments/v0.2.0/schema.json',
16
17
  'item-assets': 'https://stac-extensions.github.io/item-assets/v1.0.0/schema.json',
17
18
  label: 'https://stac-extensions.github.io/label/v1.0.1/schema.json',
18
19
  order: 'https://stac-extensions.github.io/order/v1.1.0/schema.json',
19
20
  pointcloud: 'https://stac-extensions.github.io/pointcloud/v2.0.0/schema.json',
20
- processing: 'https://stac-extensions.github.io/processing/v1.2.0/schema.json',
21
- product: 'https://stac-extensions.github.io/product/v1.0.0/schema.json',
22
- projection: 'https://stac-extensions.github.io/projection/v2.0.0/schema.json',
21
+ processing: 'https://stac-extensions.github.io/processing/v1.3.0/schema.json',
22
+ product: 'https://stac-extensions.github.io/product/v1.1.0/schema.json',
23
+ projection: 'https://stac-extensions.github.io/projection/v2.1.0/schema.json',
23
24
  raster: 'https://stac-extensions.github.io/raster/v2.0.0/schema.json',
24
25
  sar: 'https://stac-extensions.github.io/sar/v1.3.2/schema.json',
25
26
  sat: 'https://stac-extensions.github.io/sat/v1.2.0/schema.json',
26
27
  scientific: 'https://stac-extensions.github.io/scientific/v1.0.0/schema.json',
27
- table: 'https://stac-extensions.github.io/table/v1.2.0/schema.json',
28
+ 'sentinel-1': 'https://stac-extensions.github.io/sentinel-1/v0.2.0/schema.json',
29
+ 'sentinel-3': 'https://stac-extensions.github.io/sentinel-3/v0.2.0/schema.json',
30
+ 'sentinel-5p': 'https://stac-extensions.github.io/sentinel-5p/v0.2.0/schema.json',
31
+ table: 'https://stac-extensions.github.io/table/v1.3.0/schema.json',
28
32
  timestamps: 'https://stac-extensions.github.io/timestamps/v1.1.0/schema.json',
29
33
  version: 'https://stac-extensions.github.io/version/v1.2.0/schema.json',
30
34
  view: 'https://stac-extensions.github.io/view/v1.1.0/schema.json',
31
35
  };
36
+ const S3_STATISTICS = [
37
+ 'bright',
38
+ 'closed_sea',
39
+ 'coastal',
40
+ 'continental_ice',
41
+ 'cosmetic',
42
+ 'dubious_samples',
43
+ 'duplicated',
44
+ 'fresh_inland_water',
45
+ 'invalid',
46
+ 'land',
47
+ 'open_ocean',
48
+ 'out_of_range',
49
+ 'saline_water',
50
+ 'saturated',
51
+ 'tidal_region',
52
+ ];
32
53
  const EXTENSIONS = {
33
54
  // Add a : at the end to indicate it has a prefix, otherwise list all fields separately (see version extension for example).
34
55
  itemAndCollection: {
@@ -37,6 +58,7 @@ const EXTENSIONS = {
37
58
  'cube:': SCHEMAS.datacube,
38
59
  'eo:': SCHEMAS.eo,
39
60
  'file:': SCHEMAS.file,
61
+ 'instrument:': SCHEMAS.instruments,
40
62
  'label:': SCHEMAS.label,
41
63
  'pc:': SCHEMAS.pointcloud,
42
64
  'processing:': SCHEMAS.processing,
@@ -806,7 +828,10 @@ var Band = {
806
828
  }
807
829
  }
808
830
 
809
- if (V.before('1.1.0-beta.1') && (Array.isArray(obj['raster:bands']) || Array.isArray(obj['eo:bands']))) {
831
+ if (
832
+ (Array.isArray(obj['raster:bands']) || Array.isArray(obj['eo:bands'])) &&
833
+ (V.before('1.1.0-beta.1') || V.before('2.0.0-beta.1', 'raster') || V.before('2.0.0-beta.1', 'eo'))
834
+ ) {
810
835
  _.ensure(obj, 'bands', []);
811
836
 
812
837
  const raster = obj['raster:bands'] || [];
@@ -928,6 +953,12 @@ var Fields = {
928
953
  _.upgradeExtension(context, SCHEMAS.cf);
929
954
  },
930
955
 
956
+ contacts(obj, context) {
957
+ _.forAll(obj, 'contacts', (c) => _.isObject(c) && _.rename(c, 'positionName', 'position')) && DONE;
958
+
959
+ _.upgradeExtension(context, SCHEMAS.contacts);
960
+ },
961
+
931
962
  cube(obj, context) {
932
963
  // We'd need to convert proj strings to something else for v1.0 -> v2.0, but that's unfeasible here.
933
964
  // Nothing else to do here.
@@ -975,6 +1006,12 @@ var Fields = {
975
1006
  _.upgradeExtension(context, SCHEMAS.file);
976
1007
  },
977
1008
 
1009
+ instruments(obj, context) {
1010
+ _.rename(obj, 'instrument_modes', 'instrument:modes') && _.addExtension(context, SCHEMAS.instruments) && DONE;
1011
+
1012
+ _.upgradeExtension(context, SCHEMAS.instruments);
1013
+ },
1014
+
978
1015
  label(obj, context) {
979
1016
  // Migrate 0.8.0-rc1 non-pluralized forms
980
1017
  if (V.before('0.8.0')) {
@@ -1012,8 +1049,18 @@ var Fields = {
1012
1049
  _.upgradeExtension(context, SCHEMAS.processing);
1013
1050
  },
1014
1051
 
1015
- product(obj, context) {
1016
- // Nothing to do
1052
+ product(obj, context, summaries) {
1053
+ const status = obj['product:status'];
1054
+ if (status === 'qualitydegraded' && !_.isDefined(obj['product:quality_status'])) {
1055
+ obj['product:status'] = 'accepted';
1056
+ obj['product:quality_status'] = 'degraded';
1057
+ DONE;
1058
+ } else if (summaries && Array.isArray(status) && status.includes('qualitydegraded')) {
1059
+ obj['product:status'] = [...new Set(status.map((s) => (s === 'qualitydegraded' ? 'accepted' : s)))];
1060
+ _.ensure(obj, 'product:quality_status', []);
1061
+ !obj['product:quality_status'].includes('degraded') && obj['product:quality_status'].push('degraded');
1062
+ DONE;
1063
+ }
1017
1064
 
1018
1065
  _.upgradeExtension(context, SCHEMAS.product);
1019
1066
  },
@@ -1067,8 +1114,8 @@ var Fields = {
1067
1114
 
1068
1115
  _.rename(obj, 'sar:product_type', 'product:type') && _.addExtension(context, SCHEMAS.product) && DONE;
1069
1116
 
1070
- if (_.rename(obj, 'sar:instrument_mode', 'instrument_modes')) {
1071
- !summary && _.toArray(obj, 'instrument_modes');
1117
+ if (_.rename(obj, 'sar:instrument_mode', 'instrument:modes')) {
1118
+ !summary && _.toArray(obj, 'instrument:modes');
1072
1119
  _.addExtension(context, SCHEMAS.instruments) && DONE;
1073
1120
  }
1074
1121
 
@@ -1087,6 +1134,53 @@ var Fields = {
1087
1134
  _.upgradeExtension(context, SCHEMAS.sat);
1088
1135
  },
1089
1136
 
1137
+ s1(obj, context) {
1138
+ _.rename(obj, 's1:processing_datetime', 'processing:datetime') &&
1139
+ _.addExtension(context, SCHEMAS.processing) &&
1140
+ DONE;
1141
+ _.rename(obj, 's1:processing_level', 'processing:level') &&
1142
+ _.mapValues(obj, 'processing:level', ['0', '1', '2'], ['L0', 'L1', 'L2']) &&
1143
+ _.addExtension(context, SCHEMAS.processing) &&
1144
+ DONE;
1145
+ _.rename(obj, 's1:shape', 'proj:shape') && _.addExtension(context, SCHEMAS.projection) && DONE;
1146
+
1147
+ _.upgradeExtension(context, SCHEMAS['sentinel-1']);
1148
+ },
1149
+
1150
+ s3(obj, context, summaries) {
1151
+ _.rename(obj, 's3:product_type', 'product:type') && _.addExtension(context, SCHEMAS.product) && DONE;
1152
+ _.rename(obj, 's3:snow_or_ice', 'eo:snow_cover') && _.addExtension(context, SCHEMAS.eo) && DONE;
1153
+
1154
+ // Only the numeric GSD maps to gsd, the GSD objects of the other products are ambiguous
1155
+ const gsd = obj['s3:gsd'];
1156
+ if (_.is(gsd, 'number') || (summaries && Array.isArray(gsd) && gsd.every((v) => _.is(v, 'number')))) {
1157
+ _.rename(obj, 's3:gsd', 'gsd') && DONE;
1158
+ }
1159
+
1160
+ if (!summaries) {
1161
+ for (let key of S3_STATISTICS) {
1162
+ let oldKey = 's3:' + key;
1163
+ if (_.is(obj[oldKey], 'number')) {
1164
+ _.ensure(obj, 'statistics', {});
1165
+ if (!_.isDefined(obj.statistics[key])) {
1166
+ obj.statistics[key] = obj[oldKey];
1167
+ delete obj[oldKey];
1168
+ DONE;
1169
+ }
1170
+ }
1171
+ }
1172
+ }
1173
+
1174
+ _.upgradeExtension(context, SCHEMAS['sentinel-3']);
1175
+ },
1176
+
1177
+ s5p(obj, context) {
1178
+ _.rename(obj, 's5p:product_type', 'product:type') && _.addExtension(context, SCHEMAS.product) && DONE;
1179
+ _.rename(obj, 's5p:shape', 'proj:shape') && _.addExtension(context, SCHEMAS.projection) && DONE;
1180
+
1181
+ _.upgradeExtension(context, SCHEMAS['sentinel-5p']);
1182
+ },
1183
+
1090
1184
  sci(obj, context) {
1091
1185
  // Nothing to do
1092
1186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "A library to update STAC files to the latest version.",
5
5
  "main": "migrate.js",
6
6
  "bin": {