anta-database 0.3.2__tar.gz → 0.3.4__tar.gz

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 (51) hide show
  1. {anta_database-0.3.2 → anta_database-0.3.4}/PKG-INFO +7 -7
  2. {anta_database-0.3.2 → anta_database-0.3.4}/README.md +6 -6
  3. anta_database-0.3.4/ROADMAP.md +12 -0
  4. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/compiling/compile.py +28 -6
  5. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/compiling/reconnect.py +1 -1
  6. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/database/database.py +36 -123
  7. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/indexing/index_database.py +24 -11
  8. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/plotting/plotting.py +133 -93
  9. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database.egg-info/PKG-INFO +7 -7
  10. {anta_database-0.3.2 → anta_database-0.3.4}/book/_config.yml +1 -0
  11. {anta_database-0.3.2 → anta_database-0.3.4}/book/contribute.md +2 -0
  12. anta_database-0.3.4/book/figures/Overview_all.png +0 -0
  13. {anta_database-0.3.2 → anta_database-0.3.4}/book/intro.md +18 -12
  14. {anta_database-0.3.2 → anta_database-0.3.4}/book/quick_start.ipynb +201 -78
  15. anta_database-0.3.2/ROADMAP.md +0 -12
  16. anta_database-0.3.2/book/figures/Overview_all.png +0 -0
  17. {anta_database-0.3.2 → anta_database-0.3.4}/.github/workflows/deploy.yml +0 -0
  18. {anta_database-0.3.2 → anta_database-0.3.4}/.github/workflows/release.yml +0 -0
  19. {anta_database-0.3.2 → anta_database-0.3.4}/.gitignore +0 -0
  20. {anta_database-0.3.2 → anta_database-0.3.4}/LICENSE +0 -0
  21. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/__init__.py +0 -0
  22. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/anta_database.py +0 -0
  23. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/compiling/__init__.py +0 -0
  24. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/ANT_Basins_IMBIE2_v1.6.cpg +0 -0
  25. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/ANT_Basins_IMBIE2_v1.6.dbf +0 -0
  26. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/ANT_Basins_IMBIE2_v1.6.prj +0 -0
  27. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/ANT_Basins_IMBIE2_v1.6.shp +0 -0
  28. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/ANT_Basins_IMBIE2_v1.6.shx +0 -0
  29. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/GL.pkl +0 -0
  30. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/centeroid_coords_basins.cpg +0 -0
  31. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/centeroid_coords_basins.dbf +0 -0
  32. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/centeroid_coords_basins.prj +0 -0
  33. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/centeroid_coords_basins.shp +0 -0
  34. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/centeroid_coords_basins.shx +0 -0
  35. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/data/site-coords.pkl +0 -0
  36. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/database/__init__.py +0 -0
  37. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/figures/AntA_38ka.png +0 -0
  38. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/indexing/__init__.py +0 -0
  39. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database/plotting/__init__.py +0 -0
  40. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database.egg-info/SOURCES.txt +0 -0
  41. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database.egg-info/dependency_links.txt +0 -0
  42. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database.egg-info/requires.txt +0 -0
  43. {anta_database-0.3.2 → anta_database-0.3.4}/anta_database.egg-info/top_level.txt +0 -0
  44. {anta_database-0.3.2 → anta_database-0.3.4}/book/_toc.yml +0 -0
  45. {anta_database-0.3.2 → anta_database-0.3.4}/book/advanced.md +0 -0
  46. {anta_database-0.3.2 → anta_database-0.3.4}/book/contact.md +0 -0
  47. {anta_database-0.3.2 → anta_database-0.3.4}/book/logo.png +0 -0
  48. {anta_database-0.3.2 → anta_database-0.3.4}/book/references.bib +0 -0
  49. {anta_database-0.3.2 → anta_database-0.3.4}/book/requirements.txt +0 -0
  50. {anta_database-0.3.2 → anta_database-0.3.4}/pyproject.toml +0 -0
  51. {anta_database-0.3.2 → anta_database-0.3.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anta_database
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: SQLite database for the AntArchitecture Community Data
5
5
  Author: Antoine Hermant
6
6
  Author-email: antoine.hermant@etik.com
@@ -48,12 +48,12 @@ Visit the [Home Page](https://antoinehermant.github.io/anta_database/intro) for
48
48
 
49
49
  The AntADatabase contains all traced and dated Internal Reflective Horizons (isochrones) that have been published at that date. All the data is organized by flight transect for each dataset. The data is encoded in HDF5 (Hierarchical Data Format) which provides convenient data structure and performant read speeds.
50
50
  Variables per file (when exist):
51
- - x(point)
52
- - y(point)
53
- - distance(point)
51
+ - PSX(point)
52
+ - PSY(point)
53
+ - Distance(point)
54
54
  - IRH_DEPTH(point, age)
55
- - IRH_DENS(point, age)
56
- - ICE_THCK(point, age)
55
+ - IRH_NUM(point, age)
56
+ - ICE_THK(point)
57
57
  - SURF_ELEV(point, age)
58
58
  - BED_ELEV(point, age)
59
59
 
@@ -66,7 +66,7 @@ This Python module provides SQL indexing for the AntADatabase, as well as quick
66
66
  - age
67
67
  - acquisition_year (year of radar acquisition)
68
68
  - region
69
- - basin
69
+ - IMBIE_basin
70
70
  - var (variable)
71
71
  - flight id
72
72
 
@@ -16,12 +16,12 @@ Visit the [Home Page](https://antoinehermant.github.io/anta_database/intro) for
16
16
 
17
17
  The AntADatabase contains all traced and dated Internal Reflective Horizons (isochrones) that have been published at that date. All the data is organized by flight transect for each dataset. The data is encoded in HDF5 (Hierarchical Data Format) which provides convenient data structure and performant read speeds.
18
18
  Variables per file (when exist):
19
- - x(point)
20
- - y(point)
21
- - distance(point)
19
+ - PSX(point)
20
+ - PSY(point)
21
+ - Distance(point)
22
22
  - IRH_DEPTH(point, age)
23
- - IRH_DENS(point, age)
24
- - ICE_THCK(point, age)
23
+ - IRH_NUM(point, age)
24
+ - ICE_THK(point)
25
25
  - SURF_ELEV(point, age)
26
26
  - BED_ELEV(point, age)
27
27
 
@@ -34,7 +34,7 @@ This Python module provides SQL indexing for the AntADatabase, as well as quick
34
34
  - age
35
35
  - acquisition_year (year of radar acquisition)
36
36
  - region
37
- - basin
37
+ - IMBIE_basin
38
38
  - var (variable)
39
39
  - flight id
40
40
 
@@ -0,0 +1,12 @@
1
+ # Roadmap
2
+
3
+ Here is a todo list of features that we want to include in the AntADatabase.
4
+
5
+ ## Important
6
+ - [x] Implement HDF5 format (In process, for next release)
7
+ - [x] Filter by radar system
8
+ - [x] Create shapefiles, e.g. for QAntarctica (In process)
9
+
10
+ ## To discuss
11
+ - [ ] A netCDF version
12
+
@@ -294,7 +294,7 @@ class CompileDatabase:
294
294
  header=0,
295
295
  sep=sep,
296
296
  # usecols=original_new_columns.columns,
297
- na_values=['-9999', '-9999.0', 'NaN', 'nan', ''],
297
+ # na_values=['-9999', '-9999.0', 'NaN', 'nan', ''],
298
298
  dtype=str
299
299
  )
300
300
 
@@ -304,6 +304,26 @@ class CompileDatabase:
304
304
  ds = ds[ds.columns.intersection(original_new_columns.columns)]
305
305
  ds.columns = original_new_columns[ds.columns].iloc[0].values # renaming the columns
306
306
 
307
+ values_to_replace = ['-9999', '-9999.0', 'NaN', 'nan', '']
308
+
309
+ if 'PSX' in ds.columns and 'PSY' in ds.columns:
310
+ # Create a mask for rows where both PSX and PSY are in values_to_replace
311
+ mask = (
312
+ ds['PSX'].isin(values_to_replace) &
313
+ ds['PSY'].isin(values_to_replace)
314
+ )
315
+ if mask.any():
316
+ problematic_indices = ds.index[mask].tolist()
317
+ warnings.warn(
318
+ f"Found {len(problematic_indices)} rows where both PSX and PSY are in {values_to_replace}. "
319
+ f"Indices: {problematic_indices}. Dropping these rows."
320
+ )
321
+
322
+ ds = ds[~mask].copy()
323
+
324
+ cols_to_replace = [col for col in ds.columns if col not in ['PSX', 'PSY']]
325
+ ds[cols_to_replace] = ds[cols_to_replace].replace(values_to_replace, pd.NA)
326
+
307
327
  pattern_values = original_new_columns[1:]
308
328
  pattern_header = original_new_columns.iloc[0]
309
329
  pattern_values.columns = pattern_header
@@ -863,6 +883,8 @@ class CompileDatabase:
863
883
  max_depth[i] = depth_slice[max_idx]
864
884
  age_max_depth[i] = ds.IRH_AGE.values[max_idx]
865
885
 
886
+ age_max_depth = np.abs(age_max_depth)
887
+ max_depth = np.abs(max_depth)
866
888
  flight_id = ds.attrs["flight ID"]
867
889
  acq_year = ds.attrs["acquisition year"]
868
890
  project = ds.attrs["project"]
@@ -871,11 +893,11 @@ class CompileDatabase:
871
893
 
872
894
  df = gpd.GeoDataFrame({
873
895
  "geometry": [Point(x, y) for x, y in zip(ds.PSX.values, ds.PSY.values)],
874
- "irh_num": N.astype('int16'),
875
- "max_age": age_max_depth.astype('int16'),
876
- "max_depth": max_depth.astype('int16'),
877
- "flight_id": [flight_id] * len(N),
878
- "doi_data": [doi_data] * len(N),
896
+ "irh_num": N.astype('int8'),
897
+ "max_age": age_max_depth.astype('int32'),
898
+ "max_depth": np.rint(max_depth).astype('int16'),
899
+ # "flight_id": [flight_id] * len(N),
900
+ # "doi_data": [doi_data] * len(N),
879
901
  }, crs="EPSG:3031")
880
902
 
881
903
  all_dfs.append(df)
@@ -43,7 +43,7 @@ class Reconnect:
43
43
 
44
44
 
45
45
  def process(self, df_connect: pd.DataFrame, tree, file_path: str):
46
- data_dir = self._db.db_dir
46
+ data_dir = self._db._db_dir
47
47
  full_path = os.path.join(data_dir, file_path)
48
48
  with h5py.File(full_path, 'a') as f:
49
49
  with xr.open_dataset(f, engine='h5netcdf') as ds:
@@ -92,11 +92,13 @@ class Database:
92
92
  LEFT JOIN
93
93
  variables v ON dv.variable_id = v.id
94
94
  LEFT JOIN
95
- dataset_ages da ON d.id = da.dataset_id
95
+ dataset_ages da ON d.id = da.dataset_id AND v.name = 'IRH_DEPTH'
96
96
  LEFT JOIN
97
97
  ages a ON da.age_id = a.id
98
98
  LEFT JOIN
99
- regions r ON da.region_id = r.id
99
+ dataset_regions dr ON d.id = dr.dataset_id
100
+ LEFT JOIN
101
+ regions r ON dr.region_id = r.id
100
102
  '''
101
103
  conditions = []
102
104
  params = []
@@ -415,21 +417,21 @@ class Database:
415
417
  Helper method to build the SQL query and parameters for filtering.
416
418
  Returns the query string and parameters list.
417
419
  """
418
- select_clause = 's.name AS dataset, \
420
+ select_clause = "s.name AS dataset, \
419
421
  s.citation, \
420
422
  s.DOI_dataset, \
421
423
  s.DOI_publication, \
422
424
  institutes_list.institutes, \
423
425
  projects_list.projects, \
424
426
  d.acq_year, \
425
- a.age, \
426
- a.age_unc, \
427
+ CASE WHEN v.name = 'IRH_DEPTH' THEN a.age ELSE NULL END AS age, \
428
+ CASE WHEN v.name = 'IRH_DEPTH' THEN a.age_unc ELSE NULL END AS age_unc, \
427
429
  v.name AS var, \
428
430
  d.flight_id, \
429
431
  r.region, \
430
432
  r.IMBIE_basin, \
431
433
  radar_instruments_list.radar_instruments \
432
- '
434
+ "
433
435
  query = f'''
434
436
  SELECT {select_clause}
435
437
  FROM
@@ -474,11 +476,13 @@ class Database:
474
476
  LEFT JOIN
475
477
  variables v ON dv.variable_id = v.id
476
478
  LEFT JOIN
477
- dataset_ages da ON d.id = da.dataset_id
479
+ dataset_ages da ON d.id = da.dataset_id AND v.name = 'IRH_DEPTH'
478
480
  LEFT JOIN
479
481
  ages a ON da.age_id = a.id
480
482
  LEFT JOIN
481
- regions r ON da.region_id = r.id
483
+ dataset_regions dr ON d.id = dr.dataset_id
484
+ LEFT JOIN
485
+ regions r ON dr.region_id = r.id
482
486
  '''
483
487
  conditions = []
484
488
  params = []
@@ -536,21 +540,21 @@ class Database:
536
540
  retain_query: Optional[bool] = True,
537
541
  ) -> 'MetadataResult':
538
542
 
539
- select_clause = 's.name AS dataset, \
543
+ select_clause = "s.name AS dataset, \
540
544
  s.citation, \
541
545
  s.DOI_dataset, \
542
546
  s.DOI_publication, \
543
547
  institutes_list.institutes, \
544
548
  projects_list.projects, \
545
549
  d.acq_year, \
546
- a.age, \
547
- a.age_unc, \
550
+ CASE WHEN v.name = 'IRH_DEPTH' THEN a.age ELSE NULL END AS age, \
551
+ CASE WHEN v.name = 'IRH_DEPTH' THEN a.age_unc ELSE NULL END AS age_unc, \
548
552
  v.name AS var, \
549
553
  d.flight_id, \
550
554
  r.region, \
551
555
  r.IMBIE_basin, \
552
556
  radar_instruments_list.radar_instruments \
553
- '
557
+ "
554
558
  query, params = self._build_query_and_params(age, var, dataset, institute, project, acquisition_year, flight_id, region, IMBIE_basin, radar_instrument, select_clause)
555
559
 
556
560
  conn = sqlite3.connect(self._file_db_path)
@@ -686,18 +690,18 @@ class Database:
686
690
 
687
691
  def get_files(
688
692
  self,
689
- metadata: Union[None, Dict, 'MetadataResult'] = None,
690
- data_dir: Union[None, str] = None,
693
+ metadata: Optional[Union[None, Dict, 'MetadataResult']] = None,
694
+ data_dir: Optional[Union[None, str]] = None,
691
695
  ):
692
696
 
693
697
  md = metadata or self._md
694
698
  if not md:
695
- print('Please provide metadata of the files you want to generate the data from. Exiting...')
699
+ print('Please provide metadata of the files you want to generate the data from.')
696
700
  return
697
701
 
698
702
  data_dir = data_dir or self._db_dir
699
703
  if not data_dir:
700
- print('No data directory provided. Exiting...')
704
+ print('No data directory provided.')
701
705
  return
702
706
 
703
707
  file_paths = self._get_file_paths_from_metadata(metadata=md)
@@ -711,7 +715,7 @@ class Database:
711
715
  self,
712
716
  metadata: Union[None, Dict, 'MetadataResult'] = None,
713
717
  data_dir: Optional[str] = None,
714
- downscale_factor: Optional[str] = None,
718
+ downsampling_factor: Optional[str] = None,
715
719
  disable_tqdm: bool = False,
716
720
  ) -> Generator[Tuple[pd.DataFrame, Dict]]:
717
721
  """
@@ -740,35 +744,43 @@ class Database:
740
744
  file_paths = self._get_file_paths_from_metadata(metadata=md)
741
745
  file_paths = np.unique(file_paths) # Be carefull as many pointers point to the same file
742
746
 
747
+ if disable_tqdm or self._disable_tqdm:
748
+ disable_tqdm = True
749
+
743
750
  for file_path in tqdm(file_paths, desc='Generating dataframes', total=len(file_paths), unit='file', disable=disable_tqdm):
744
751
  full_path = os.path.join(data_dir, file_path)
745
752
  file_md = self._get_file_metadata(file_path)
746
753
  ds = h5py.File(full_path, 'r')
747
- df = pd.DataFrame({'PSX': ds['PSX'][::downscale_factor],
748
- 'PSY': ds['PSY'][::downscale_factor]})
754
+ df = pd.DataFrame({'PSX': ds['PSX'][::downsampling_factor],
755
+ 'PSY': ds['PSY'][::downsampling_factor]})
749
756
 
750
757
  if 'Distance' in ds.keys():
751
- df['Distance'] = ds['Distance'][::downscale_factor]
758
+ df['Distance'] = ds['Distance'][::downsampling_factor]
752
759
 
760
+ var_impl = []
761
+ age_impl = []
753
762
  for var in md['var']:
754
763
  if var == 'IRH_DEPTH':
764
+ var_impl.append(var)
755
765
  for age in md['age']:
756
766
  irh_values = ds['IRH_AGE'][:]
757
767
  irh_index = np.where(irh_values == int(age))[0]
758
768
  if len(irh_index) == 0:
759
769
  continue
760
770
  irh_index = irh_index[0]
771
+ age_impl.append(age)
761
772
 
762
- df[int(age)] = ds[var][::downscale_factor, irh_index]
773
+ df[int(age)] = ds[var][::downsampling_factor, irh_index]
763
774
 
764
775
  else:
765
776
  if var in ds.keys():
766
- df[var] = ds[var][::downscale_factor]
777
+ var_impl.append(var)
778
+ df[var] = ds[var][::downsampling_factor]
767
779
 
768
780
  metadata = {
769
781
  'dataset': file_md['dataset'],
770
- 'var': md['var'],
771
- 'age': md['age'],
782
+ 'var': var_impl,
783
+ 'age': age_impl,
772
784
  'flight_id': file_md['flight_id'],
773
785
  'institute': file_md['institute'],
774
786
  'project': file_md['project'],
@@ -785,105 +797,6 @@ class Database:
785
797
 
786
798
  yield df, metadata
787
799
 
788
- # def return_dataset(
789
- # self,
790
- # metadata: Union[None, Dict, 'MetadataResult'] = None,
791
- # data_dir: Optional[str] = None,
792
- # downscale_factor: Optional[str] = None,
793
- # ) -> Generator[Tuple[pd.DataFrame, Dict]]:
794
- # """
795
- # Generates xarray Datasets from HDF5 files, one at a time, with lazy loading.
796
-
797
- # Args:
798
- # metadata: Metadata for filtering files.
799
- # data_dir: Directory containing the data files.
800
- # vars_to_load: List of variables to load from each file.
801
-
802
- # Yields:
803
- # Tuple[xr.Dataset, Dict]: A lazy-loaded xarray Dataset and its metadata.
804
- # """
805
- # # Resolve metadata
806
- # md = metadata or self._md
807
- # if not md:
808
- # print('Please provide metadata of the files you want to generate the data from. Exiting...')
809
- # return
810
-
811
- # # Resolve data directory
812
- # data_dir = data_dir or self._db_dir
813
- # if not data_dir:
814
- # print('No data directory provided. Exiting...')
815
- # return
816
-
817
- # if len(md['var']) > 1:
818
- # print(f'WARNING: you requested multiple variables ({md['var']}), this will return individual dataframes for each variable in each transect.')
819
-
820
- # file_paths = self._get_file_paths_from_metadata(metadata=md)
821
- # file_paths = np.unique(file_paths) # Be carefull as many pointers point to the same file
822
-
823
- # for file_path in file_paths:
824
- # full_path = os.path.join(data_dir, file_path)
825
- # file_md = self._get_file_metadata(file_path)
826
- # for var in md['var']:
827
- # if var == 'IRH_DEPTH':
828
- # for age in md['age']:
829
- # with h5py.File(full_path, 'r') as ds:
830
- # irh_values = ds['age'][:]
831
- # irh_index = np.where(irh_values == int(age))[0]
832
- # if len(irh_index) == 0:
833
- # continue
834
- # irh_index = irh_index[0]
835
- # df = pd.DataFrame({'x': ds['x'][::downscale_factor],
836
- # 'y': ds['y'][::downscale_factor],
837
- # 'distance': ds['distance'][::downscale_factor],
838
- # var: ds[var][::downscale_factor, irh_index]})
839
-
840
- # metadata = {
841
- # 'dataset': file_md['dataset'],
842
- # 'var': var,
843
- # 'age': age,
844
- # 'flight_id': file_md['flight_id'],
845
- # 'institute': file_md['institute'],
846
- # 'project': file_md['project'],
847
- # 'acquisition_year': file_md['acquisition_year'],
848
- # 'age_unc': file_md['age'],
849
- # 'reference': file_md['reference'],
850
- # 'DOI_dataset': file_md['DOI_dataset'],
851
- # 'DOI_publication': file_md['DOI_publication'],
852
- # 'flight_id': file_md['flight_id'],
853
- # 'region': file_md['region'],
854
- # 'IMBIE_basin': file_md['IMBIE_basin'],
855
- # 'radar_instrument': file_md['radar_instrument'],
856
- # }
857
-
858
- # yield df, metadata
859
-
860
- # else:
861
- # ds = h5py.File(full_path, 'r')
862
- # df = pd.DataFrame({'PSX': ds['PSX'][::downscale_factor],
863
- # 'PSY': ds['PSY'][::downscale_factor],
864
- # 'Distance': ds['Distance'][::downscale_factor],
865
- # var: ds[var][::downscale_factor]})
866
-
867
- # metadata = {
868
- # 'dataset': file_md['dataset'],
869
- # 'var': var,
870
- # 'age': None,
871
- # 'flight_id': file_md['flight_id'],
872
- # 'institute': file_md['institute'],
873
- # 'project': file_md['project'],
874
- # 'acquisition_year': file_md['acquisition_year'],
875
- # 'age_unc': file_md['age'],
876
- # 'reference': file_md['reference'],
877
- # 'DOI_dataset': file_md['DOI_dataset'],
878
- # 'DOI_publication': file_md['DOI_publication'],
879
- # 'flight_id': file_md['flight_id'],
880
- # 'region': file_md['region'],
881
- # 'IMBIE_basin': file_md['IMBIE_basin'],
882
- # 'radar_instrument': file_md['radar_instrument'],
883
- # }
884
-
885
- # yield df, metadata
886
-
887
800
  @property
888
801
  def plot(self):
889
802
  if self._plotting is None:
@@ -126,11 +126,9 @@ class IndexDatabase:
126
126
  CREATE TABLE IF NOT EXISTS dataset_ages (
127
127
  dataset_id INTEGER,
128
128
  age_id INTEGER,
129
- region_id INTEGER,
130
129
  FOREIGN KEY (dataset_id) REFERENCES datasets (id),
131
130
  FOREIGN KEY (age_id) REFERENCES ages (id),
132
- FOREIGN KEY (region_id) REFERENCES regions (id),
133
- PRIMARY KEY (dataset_id, age_id, region_id)
131
+ PRIMARY KEY (dataset_id, age_id)
134
132
  )
135
133
  ''')
136
134
 
@@ -164,6 +162,16 @@ class IndexDatabase:
164
162
  )
165
163
  ''')
166
164
 
165
+ cursor.execute('''
166
+ CREATE TABLE IF NOT EXISTS dataset_regions (
167
+ dataset_id INTEGER,
168
+ region_id INTEGER,
169
+ FOREIGN KEY (dataset_id) REFERENCES datasets (id),
170
+ FOREIGN KEY (region_id) REFERENCES regions (id),
171
+ PRIMARY KEY (dataset_id, region_id)
172
+ )
173
+ ''')
174
+
167
175
  for f in tqdm(h5_files, desc="Indexing files"):
168
176
  _, file_name = os.path.split(f)
169
177
 
@@ -281,7 +289,7 @@ class IndexDatabase:
281
289
  # Insert variables
282
290
  var_list = ['ICE_THK', 'SURF_ELEV', 'BED_ELEV', 'BASAL_UNIT', 'IRH_NUM', 'IRH_DEPTH']
283
291
  for var in var_list:
284
- if var in ds_vars or var == 'IRH_DEPTH':
292
+ if var in ds_vars:
285
293
  cursor.execute('INSERT OR IGNORE INTO variables (name) VALUES (?)', (var,))
286
294
  var_id = cursor.execute('SELECT id FROM variables WHERE name = ?', (var,)).fetchone()[0]
287
295
  cursor.execute('''
@@ -294,13 +302,18 @@ class IndexDatabase:
294
302
  for age, age_unc in age_uncs.iterrows():
295
303
  cursor.execute('INSERT OR IGNORE INTO ages (age, age_unc) VALUES (?, ?)', (str(age), str(age_unc['age_unc'])))
296
304
  age_id = cursor.execute('SELECT id FROM ages WHERE age = ? AND age_unc = ?', (str(age), str(age_unc['age_unc']))).fetchone()[0]
297
- for basin, region in basin_mapping.items():
298
- cursor.execute('INSERT OR IGNORE INTO regions (region, IMBIE_basin) VALUES (?, ?)', (region, basin))
299
- region_id = cursor.execute('SELECT id FROM regions WHERE region = ? AND IMBIE_basin = ?', (region, basin)).fetchone()[0]
300
- cursor.execute('''
301
- INSERT OR IGNORE INTO dataset_ages (dataset_id, age_id, region_id)
302
- VALUES (?, ?, ?)
303
- ''', (dataset_row_id, age_id, region_id))
305
+ cursor.execute('''
306
+ INSERT OR IGNORE INTO dataset_ages (dataset_id, age_id)
307
+ VALUES (?, ?)
308
+ ''', (dataset_row_id, age_id))
309
+
310
+ for basin, region in basin_mapping.items():
311
+ cursor.execute('INSERT OR IGNORE INTO regions (region, IMBIE_basin) VALUES (?, ?)', (region, basin))
312
+ region_id = cursor.execute('SELECT id FROM regions WHERE region = ? AND IMBIE_basin = ?', (region, basin)).fetchone()[0]
313
+ cursor.execute('''
314
+ INSERT OR IGNORE INTO dataset_regions (dataset_id, region_id)
315
+ VALUES (?, ?)
316
+ ''', (dataset_row_id, region_id))
304
317
 
305
318
  conn.commit()
306
319
  conn.close()