anta-database 0.1__tar.gz → 0.1.2__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 (20) hide show
  1. {anta_database-0.1 → anta_database-0.1.2}/PKG-INFO +2 -2
  2. {anta_database-0.1 → anta_database-0.1.2}/anta_database/database/database.py +81 -10
  3. {anta_database-0.1 → anta_database-0.1.2}/anta_database.egg-info/PKG-INFO +2 -2
  4. {anta_database-0.1 → anta_database-0.1.2}/anta_database.egg-info/SOURCES.txt +0 -1
  5. {anta_database-0.1 → anta_database-0.1.2}/anta_database.egg-info/requires.txt +1 -1
  6. {anta_database-0.1 → anta_database-0.1.2}/setup.py +2 -2
  7. anta_database-0.1/README.md +0 -240
  8. {anta_database-0.1 → anta_database-0.1.2}/LICENSE +0 -0
  9. {anta_database-0.1 → anta_database-0.1.2}/anta_database/__init__.py +0 -0
  10. {anta_database-0.1 → anta_database-0.1.2}/anta_database/anta_database.py +0 -0
  11. {anta_database-0.1 → anta_database-0.1.2}/anta_database/compiling/__init__.py +0 -0
  12. {anta_database-0.1 → anta_database-0.1.2}/anta_database/compiling/compile.py +0 -0
  13. {anta_database-0.1 → anta_database-0.1.2}/anta_database/database/__init__.py +0 -0
  14. {anta_database-0.1 → anta_database-0.1.2}/anta_database/database/plotting/GL.pkl +0 -0
  15. {anta_database-0.1 → anta_database-0.1.2}/anta_database/database/plotting/__init__.py +0 -0
  16. {anta_database-0.1 → anta_database-0.1.2}/anta_database/indexing/__init__.py +0 -0
  17. {anta_database-0.1 → anta_database-0.1.2}/anta_database/indexing/index_database.py +0 -0
  18. {anta_database-0.1 → anta_database-0.1.2}/anta_database.egg-info/dependency_links.txt +0 -0
  19. {anta_database-0.1 → anta_database-0.1.2}/anta_database.egg-info/top_level.txt +0 -0
  20. {anta_database-0.1 → anta_database-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anta_database
3
- Version: 0.1
3
+ Version: 0.1.2
4
4
  Summary: SQLite database for the AntArchitecture Community Data
5
5
  Home-page: https://github.com/antoinehermant/anta_database
6
6
  Author: Antoine Hermant
@@ -10,7 +10,7 @@ License-File: LICENSE
10
10
  Requires-Dist: pandas
11
11
  Requires-Dist: pyproj
12
12
  Requires-Dist: matplotlib
13
- Requires-Dist: seaborn
13
+ Requires-Dist: colormaps
14
14
  Dynamic: author
15
15
  Dynamic: author-email
16
16
  Dynamic: home-page
@@ -4,7 +4,7 @@ import pandas as pd
4
4
  import numpy as np
5
5
  import matplotlib.pyplot as plt
6
6
  from matplotlib.colors import LinearSegmentedColormap
7
- import seaborn as sns
7
+ import colormaps as cmaps
8
8
  from typing import Union, List, Dict, Tuple
9
9
 
10
10
  class Database:
@@ -93,7 +93,42 @@ class Database:
93
93
  }
94
94
  return metadata
95
95
 
96
- def query(self, age: Union[None, str, List[str]]=None, var: Union[None, str, List[str]]=None,author: Union[None, str, List[str]]=None, trace_id: Union[None, str, List[str]]=None) -> Dict:
96
+ def __repr__(self):
97
+ """Return a pretty-printed string representation of the metadata."""
98
+ md = self.md
99
+ output = []
100
+ output.append("Metadata from query:")
101
+
102
+ output.append("\n - author:")
103
+ for author in md['author']:
104
+ output.append(f" {author}")
105
+
106
+ output.append("\n - age:")
107
+ ages = " ".join(md['age'])
108
+ output.append(f" {ages}")
109
+
110
+ output.append("\n - var:")
111
+ for var in md['var']:
112
+ output.append(f" {var}")
113
+
114
+ output.append("\n - trace_id:")
115
+ trace_ids = " ".join(md['trace_id'])
116
+ output.append(f" {trace_ids}")
117
+
118
+ output.append("\n - reference:")
119
+ for ref in md['reference']:
120
+ output.append(f" {ref}")
121
+
122
+ output.append("\n - DOIs:")
123
+ for doi in md['doi']:
124
+ output.append(f" {doi}")
125
+
126
+ output.append(f"\n - database: {md['database_path']}/{md['file_db']}")
127
+ output.append(f" - query params: {md['_query_params']}")
128
+
129
+ return "\n".join(output)
130
+
131
+ def query(self, age: Union[None, str, List[str]]=None, var: Union[None, str, List[str]]=None,author: Union[None, str, List[str]]=None, trace_id: Union[None, str, List[str]]=None) -> 'MetadataResult':
97
132
  select_clause = 'a.name, a.citation, a.doi, d.age, d.var, d.trace_id'
98
133
  query, params = self._build_query_and_params(age, var, author, trace_id, select_clause)
99
134
 
@@ -134,7 +169,7 @@ class Database:
134
169
  metadata['trace_id'] = list(set(metadata['trace_id']))
135
170
 
136
171
  self.md = metadata
137
- return metadata
172
+ return MetadataResult(metadata)
138
173
 
139
174
  def _get_file_paths_from_metadata(self, metadata) -> List:
140
175
  query_params = metadata.get('_query_params', {})
@@ -172,7 +207,7 @@ class Database:
172
207
  print('Please provide metadata of the files you want to generate the data from. Exiting ...')
173
208
  sys.exit()
174
209
 
175
- query_params = md.get('_query_params', {})
210
+ query_params = md['_query_params']
176
211
  age = query_params.get('age')
177
212
  var = query_params.get('var')
178
213
  author = query_params.get('author')
@@ -208,14 +243,14 @@ class Database:
208
243
 
209
244
  def custom_cmap(self):
210
245
 
211
- flare = plt.colormaps['magma_r'] # Sequential (yellow/orange/red)
212
- crest = plt.colormaps['mako'] # Diverging (blue/white/red)
246
+ cm1 = cmaps.torch_r
247
+ cm2 = cmaps.deep_r
213
248
 
214
- flare_colors = flare(np.linspace(0, 0.8, 256)) # Shape: (256, 4) RGBA
215
- crest_colors = crest(np.linspace(0.2, 1, 256)) # Shape: (256, 4) RGBA
216
- combined_colors = np.vstack((flare_colors, crest_colors))
249
+ cm1_colors = cm1(np.linspace(0.05, 0.8, 256)) # Shape: (256, 4) RGBA
250
+ cm2_colors = cm2(np.linspace(0.1, 1, 256)) # Shape: (256, 4) RGBA
251
+ combined_colors = np.vstack((cm1_colors, cm2_colors))
217
252
  custom_cmap = LinearSegmentedColormap.from_list(
218
- 'flare_crest', # Name your colormap
253
+ 'custom_cmap', # Name your colormap
219
254
  combined_colors,
220
255
  N=512 # Double the resolution (256 + 256)
221
256
  )
@@ -286,3 +321,39 @@ class Database:
286
321
  else:
287
322
  plt.show()
288
323
  plt.close()
324
+
325
+ class MetadataResult:
326
+ def __init__(self, metadata):
327
+ self._metadata = metadata
328
+
329
+ def __getitem__(self, key):
330
+ return self._metadata[key]
331
+
332
+ def __repr__(self):
333
+ """Pretty-print the metadata."""
334
+ md = self._metadata
335
+ output = []
336
+ output.append("Metadata from query:")
337
+ output.append(f"\n - author:")
338
+ for author in md['author']:
339
+ output.append(f" {author}")
340
+ output.append(f"\n - age:")
341
+ output.append(f" {' '.join(md['age'])}")
342
+ output.append(f"\n - var:")
343
+ for var in md['var']:
344
+ output.append(f" {var}")
345
+ output.append(f"\n - trace_id:")
346
+ output.append(f" {' '.join(md['trace_id'])}")
347
+ output.append(f"\n - reference:")
348
+ for ref in md['reference']:
349
+ output.append(f" {ref}")
350
+ output.append(f"\n - DOIs:")
351
+ for doi in md['doi']:
352
+ output.append(f" {doi}")
353
+ output.append(f"\n - database: {md['database_path']}/{md['file_db']}")
354
+ output.append(f" - query params: {md['_query_params']}")
355
+ return "\n".join(output)
356
+
357
+ def to_dict(self):
358
+ """Return the raw metadata dictionary."""
359
+ return self._metadata
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anta_database
3
- Version: 0.1
3
+ Version: 0.1.2
4
4
  Summary: SQLite database for the AntArchitecture Community Data
5
5
  Home-page: https://github.com/antoinehermant/anta_database
6
6
  Author: Antoine Hermant
@@ -10,7 +10,7 @@ License-File: LICENSE
10
10
  Requires-Dist: pandas
11
11
  Requires-Dist: pyproj
12
12
  Requires-Dist: matplotlib
13
- Requires-Dist: seaborn
13
+ Requires-Dist: colormaps
14
14
  Dynamic: author
15
15
  Dynamic: author-email
16
16
  Dynamic: home-page
@@ -1,5 +1,4 @@
1
1
  LICENSE
2
- README.md
3
2
  setup.py
4
3
  anta_database/__init__.py
5
4
  anta_database/anta_database.py
@@ -1,4 +1,4 @@
1
1
  pandas
2
2
  pyproj
3
3
  matplotlib
4
- seaborn
4
+ colormaps
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='anta_database',
5
- version="0.1",
5
+ version="0.1.2",
6
6
  author="Antoine Hermant",
7
7
  author_email= "antoine.hermant@etik.com",
8
8
  url="https://github.com/antoinehermant/anta_database",
@@ -17,6 +17,6 @@ setup(
17
17
  'pandas',
18
18
  'pyproj',
19
19
  'matplotlib',
20
- 'seaborn',
20
+ 'colormaps',
21
21
  ]
22
22
  )
@@ -1,240 +0,0 @@
1
-
2
- # Table of Contents
3
-
4
- 1. [SQLite Database](#org7c02cbe)
5
- 1. [Datasets currently included:](#orge88c16b)
6
- 2. [Key Features](#orgda9a069)
7
- 3. [Installation](#org0ae2129)
8
- 4. [How to use with examples](#org94cd2fd)
9
- 1. [Browsing Metadata](#org89a166a)
10
- 2. [Visualization](#orgf9cf6be)
11
- 3. [Generate Data](#org6e8f9a4)
12
- 5. [Advanced: Managing the database](#org213a1d3)
13
- 1. [Reindexing](#orge03e052)
14
- 2. [(Re)compile the database](#org841514e)
15
- 6. [Support and contact](#org87c7675)
16
- 7. [Contribution](#org2896907)
17
- 8. [Acknowledgments](#org7ea1cbb)
18
-
19
- This Python module provides an efficient SQLite database for browsing, visualizing and processing Internal Reflecting Horizons (isochrones) across Antarctica, curated by the AntArchitecture action group. It is specifically designed for ice dynamic modelers who need a fast, memory-efficient data structure to constrain their models.
20
-
21
-
22
- <a id="org7c02cbe"></a>
23
-
24
- # SQLite Database
25
-
26
- The database uses SQLite for efficient indexing. Data is sourced from the associated DOIs and stored as binary DataFrame files for each layer (IRH) and trace ID. This structure enables:
27
-
28
- - Browsing by author (region), layer age, or trace ID.
29
- - Memory efficiency: Only relevant data is read when needed.
30
- - Fast read performance: Lightweight and optimized for speed.
31
-
32
-
33
- <a id="orge88c16b"></a>
34
-
35
- ## Datasets currently included:
36
-
37
- - Winter et al. 2018, (<https://doi.org/10.1594/PANGAEA.895528>)
38
- - Cavitte et al. 2020, (<https://doi.org/10.15784/601411>)
39
- - Beem et al. 2021, (<https://doi.org/10.15784/601437>)
40
- - Wang et al. 2023, (<https://doi.org/10.1594/PANGAEA.958462>)
41
- - Sanderson et al. 2024, (<https://doi.org/10.5285/cfafb639-991a-422f-9caa-7793c195d316>)
42
- - Franke et al. 2025, (<https://doi.org/10.1594/PANGAEA.973266>)
43
-
44
-
45
- <a id="orgda9a069"></a>
46
-
47
- # Key Features
48
-
49
- - Efficient SQLite indexing
50
- - Quick visualization on Antarctica map
51
- - Generate lazy data for later use
52
-
53
-
54
- <a id="org0ae2129"></a>
55
-
56
- # Installation
57
-
58
- 1- Clone this repository:
59
-
60
- git clone git@github:antoinehermant/anta_database.git
61
- cd anta_database
62
-
63
- 2- Create a specific python environment (optional but recommended):
64
-
65
- '''Using conda'''
66
- conda create -n anta_database
67
- conda activate anta_database
68
- conda install pip
69
-
70
- '''Using venv'''
71
- python -m venv /path/to/environment/anta_database # Replace the path with your desired environment path
72
- source /path/to/environment/anta_database
73
-
74
- 3- Install the Python module:
75
-
76
- pip install .
77
-
78
- Note: The database is not included in this repository. Contact me for access.
79
-
80
-
81
- <a id="org94cd2fd"></a>
82
-
83
- # How to use with examples
84
-
85
- Also see the Jupyter Notebook &rsquo;example.ipynb&rsquo; for a more integrated tutorial.
86
-
87
-
88
- <a id="org89a166a"></a>
89
-
90
- ## Browsing Metadata
91
-
92
- - First, initialize the Database class:
93
-
94
- from anta_database import Database
95
- database = Database('/path/to/AntADatabase/') # insert the path of the downloaded database, absolute path is recommanded
96
-
97
- Then use the query() function to browse the database. query() without argument will return all metadata from the database:
98
-
99
- database.query()
100
-
101
- By default, a dictionary with all available trace IDs is included in the query results. This can seem a lot, but it is actually useful for grepping traces with descriptive names such as &rsquo;DC<sub>LDC</sub><sub>DIVIDE</sub>&rsquo;.
102
-
103
- - Refine your search either by author, age, or trace<sub>id</sub>, or by combining arguments. Lists are also allowed:
104
-
105
- database.query(author='Cavitte_2020') # all data from Cavitte et al. 2020
106
- database.query(age='38100') # all datasets with the 38.1ka isochrone
107
- database.query(var='IceThk') # all datasets with IceThk variable
108
- database.query(trace_id='DC_LDC_DIVIDE') # all layers with the trace ID DC_LDC_DIVIDE
109
- database.query(author=['Franke_2025', 'Winter_2018'], age='38100') # example of multiple criteria
110
-
111
- Note: &rsquo;IceThk&rsquo;, &rsquo;SurfElev&rsquo; and &rsquo;BedElev&rsquo; are possible extra variables included in the database when the datasets contain the relevant data.
112
-
113
-
114
- <a id="orgf9cf6be"></a>
115
-
116
- ## Visualization
117
-
118
- Use the results of the query in the plotting functions:
119
-
120
- results = database.query(age='38100')
121
- database.plotXY(results,
122
- downscale_factor=1000, # downscale the datasets n times, which makes no visual difference but it is much lighter
123
- title='AntArchitecture 38.1ka layer',
124
- xlim=(-500, 2400), ylim=(-2200, 2200), # set the plot extent in km
125
- scale_factor=0.5, # adjust the size of the plot
126
- latex=True, # use latex compilers for plotting if you have them installed on your system
127
- # save='AntA_38ka.pdf', # Uncomment to save the figure, otherwise it we visualize with pyplot
128
- )
129
-
130
- ![img](./anta_database/figures/AntA_38ka.png "Example figure")
131
-
132
-
133
- <a id="org6e8f9a4"></a>
134
-
135
- ## Generate Data
136
-
137
- Note: This part could be developed further in the future if there is the need. But for now, I am designing a separate Python module for constraining my ice sheet model of use, which is tailored to this database and other parallel processing libraries.
138
-
139
- The data<sub>generator</sub>() function reads the query and &rsquo;yield&rsquo; the dataframes for later use.
140
- Here is a quick example of how this can be used for computing the mean layer depth:
141
-
142
- results = database.query(age='38100')
143
- lazy_dfs = database.data_generator(results)
144
-
145
- mean_depth_trs = []
146
- for df, md in lazy_dfs:
147
- mean_depth_trs.append(np.mean(df['38100']))
148
-
149
- mean_depth = np.mean(mean_depth_trs)
150
- print('The mean depth of the 38ka isochrone across East Antarctica is', mean_depth, 'm')
151
-
152
- The downscale<sub>factor</sub> argument in the data<sub>generator</sub> reduces the size of the generated data by n times. This is useful when dealing with large data where the downscaling has a neglectable influence on the results:
153
-
154
- lazy_dfs = database.data_generator(results, downscale_factor=10)
155
-
156
- Note: In the database, the file paths are relative to the database path. When initiating the database, you provide the absolute path to the database. So the data<sub>generator</sub> function uses the relative path given in the results from the query and the absolute path to the database to read the files. The second argument returned by data<sub>generator</sub> (&rsquo;md&rsquo; in the example above) is the unique metadata for the current df.
157
-
158
-
159
- <a id="org213a1d3"></a>
160
-
161
- # Advanced: Managing the database
162
-
163
-
164
- <a id="orge03e052"></a>
165
-
166
- ## Reindexing
167
-
168
- You may want for example to update the age of the layers in a particular dataset.
169
- For this, you just need to modify the ages in the file called &rsquo;IRH<sub>ages.tab</sub>&rsquo; located under a dataset directory. Then, reindex with the IndexDatabase class:
170
-
171
- from anta_database import IndexDatabase
172
-
173
- db_path = '/path/to/root/of/the/database/' # path to 'AntADatabase/'
174
- indexing = IndexDatabase(db_path)
175
- indexing.index_database()
176
-
177
-
178
- <a id="org841514e"></a>
179
-
180
- ## (Re)compile the database
181
-
182
- You can (re)compile the database, if for example you modify some data in the raw directories or if you add a dataset.
183
- For this, make sure to follow the structure:
184
-
185
- AntADatabase/
186
- ├── AntADatabase.db
187
- ├── database_index.csv #List of directories to index: Author_YYYY,Author et al. YYYY,doi
188
- ├── Author_YYYY
189
- ├── IRH_ages.tab #IRH file names without .ext followed by there respective age in years
190
- ├── original_new_column_names.csv #first row: names of columns to keep from raw files, second row: how the columns should be renamed
191
- ├── raw/
192
- └── pkl/
193
-
194
- Then use the CompileDatabase class to compile the database.
195
-
196
- from anta_database import CompileDatabase
197
-
198
- dir_path_list = [ # list of the dataset subdirectories to compile
199
- './Winter_2018',
200
- './Sanderson_2024',
201
- './Franke_2025',
202
- './Cavitte_2020',
203
- './Beem_2021',
204
- ]
205
-
206
- compiler = CompileDatabase(dir_path_list)
207
- compiler.compile()
208
-
209
- Then reindex (see above).
210
- By default, it assumes that the files in raw/ are sorted by IRH (one file = one layer and multiple traces). If the files are sorted the other way around (one file = one trace and multiple layers), you can set file<sub>type</sub>=&rsquo;trace&rsquo; in CompileDatabase(). Furthermore, if the depth is not given in meters but TWT, you should set the wave<sub>speed</sub> (units should match values in the file) for conversion and firn<sub>correction</sub> (meters):
211
-
212
- dir_path = './Wang_2023'
213
- compiler = CompileDatabase(dir_path, file_type='trace', wave_speed=0.1685, firn_correction=15.5)
214
- compiler.compile()
215
-
216
-
217
- <a id="org87c7675"></a>
218
-
219
- # Support and contact
220
-
221
- You can email me for downloading the database: antoine.hermant@unibe.ch
222
-
223
- Feel free to raise an issue on the GitHub if you find any bug or if you would like a feature added.
224
-
225
-
226
- <a id="org2896907"></a>
227
-
228
- # Contribution
229
-
230
- If you like this database and wish to help me develop this module, do not hesitate to contact me. You should then fork the repo, build feature branches and pull request. That would be much appreciated!
231
-
232
-
233
- <a id="org7ea1cbb"></a>
234
-
235
- # Acknowledgments
236
-
237
- I am developing this tool as part of my PhD project, which is funded by the Swiss National Science Foundation (grant no. 211542, Project CHARIBDIS)
238
- Any data used through this database should be cited at source. For this, use the DOI provided in the metadata.
239
- If you used this tool for your work and this was useful, please cite this repo, so other people get to know that it exists.
240
-
File without changes
File without changes