wolfhece 2.1.84__py3-none-any.whl → 2.1.86__py3-none-any.whl

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.
wolfhece/irm_qdf.py CHANGED
@@ -10,13 +10,16 @@ copying or distribution of this file, via any medium, is strictly prohibited.
10
10
 
11
11
  #Code INS des communes belges
12
12
  import numpy as np
13
- from os import path,mkdir
13
+ from os import path, mkdir
14
+ from pathlib import Path
14
15
  from time import sleep
15
16
  import pandas as pd
16
17
  import matplotlib.pyplot as plt
17
18
  from scipy.optimize import minimize,curve_fit
18
19
  from scipy.stats import gumbel_r,genextreme
19
20
  from typing import Literal
21
+ from tqdm import tqdm
22
+ import logging
20
23
 
21
24
  from .ins import Localities
22
25
  from .PyTranslate import _
@@ -72,6 +75,7 @@ durationsd=np.array([1,2,3,4,5,7,10,15,20,25,30],np.float64)*24.*60.
72
75
  durations = np.concatenate([durations,durationsd])
73
76
 
74
77
  class MontanaIRM():
78
+ """ Classe pour la gestion des relations de Montana pour les précipitations """
75
79
 
76
80
  def __init__(self,coeff:pd.DataFrame,time_bounds=None) -> None:
77
81
 
@@ -82,7 +86,12 @@ class MontanaIRM():
82
86
 
83
87
  self.coeff=coeff
84
88
 
85
- def get_ab(self,dur,T):
89
+ def get_ab(self, dur, T):
90
+ """ Get the Montana coefficients for a given duration and return period
91
+
92
+ :param dur: the duration
93
+ :param T: the return period
94
+ """
86
95
 
87
96
  curcoeff = self.coeff.loc[float(T)]
88
97
  if dur<self.time_bounds[0]:
@@ -97,24 +106,48 @@ class MontanaIRM():
97
106
 
98
107
  return a,b
99
108
 
100
- def get_meanrain(self,dur,T,ab=None):
109
+ def get_meanrain(self, dur, T, ab= None):
110
+ """ Get the mean rain for a given duration and return period
111
+
112
+ :param dur: the duration
113
+ :param T: the return period
114
+ :param ab: the Montana coefficients
115
+ """
116
+
101
117
  if ab is None:
102
118
  ab = self.get_ab(dur,T)
103
119
  return ab[0]*dur**(-ab[1])
104
120
 
105
- def get_instantrain(self,dur,T,ab=None):
121
+ def get_instantrain(self, dur, T, ab= None):
122
+ """ Get the instantaneous rain for a given duration and return period
123
+
124
+ :param dur: the duration
125
+ :param T: the return period
126
+ :param ab: the Montana coefficients
127
+ """
106
128
  if ab is None:
107
129
  ab = self.get_ab(dur,T)
108
130
  meani=self.get_meanrain(dur,T,ab)
109
131
  return (1.-ab[1])*meani
110
132
 
111
- def get_Q(self,dur,T):
133
+ def get_Q(self, dur, T):
134
+ """ Get the quantity of rain for a given duration and return period
135
+
136
+ :param dur: the duration
137
+ :param T: the return period
138
+ """
139
+
112
140
  rain = self.get_meanrain(dur,T)
113
141
  return rain*dur/60. #to obtains [mm.h^-1] as dur is in [min]
114
142
 
115
- def get_hyeto(self,durmax,T,r=0.5):
116
- """ :param r: Decentration coefficient
143
+ def get_hyeto(self, durmax, T, r= 0.5):
144
+ """ Get the hyetogram for a given return period
145
+
146
+ :param durmax: the maximum duration of the hyetogram
147
+ :param T: the return period
148
+ :param r: Decentration coefficient
117
149
  """
150
+
118
151
  x = np.arange(10,durmax,1,dtype=np.float64)
119
152
  # y = [self.get_instantrain(curx,T) for curx in x]
120
153
 
@@ -148,7 +181,13 @@ class MontanaIRM():
148
181
 
149
182
  return x_hyeto,y_hyeto
150
183
 
151
- def plot_hyeto(self,durmax,T,r=0.5):
184
+ def plot_hyeto(self, durmax, T, r= 0.5):
185
+ """ Plot the hyetogram for a given return period
186
+
187
+ :param durmax: the maximum duration of the hyetogram
188
+ :param T: the return period
189
+ :param r: Decentration coefficient
190
+ """
152
191
  x,y = self.get_hyeto(durmax,T,r)
153
192
 
154
193
  fig,ax = plt.subplots(1,1,figsize=[15,10])
@@ -160,7 +199,13 @@ class MontanaIRM():
160
199
 
161
200
  return fig,ax
162
201
 
163
- def plot_hyetos(self,durmax,r=0.5):
202
+ def plot_hyetos(self, durmax, r= 0.5):
203
+ """ Plot the hyetograms for all return periods
204
+
205
+ :param durmax: the maximum duration of the hyetograms
206
+ :param r: Decentration coefficient
207
+ """
208
+
164
209
  fig,ax = plt.subplots(1,1,figsize=[15,10])
165
210
 
166
211
  for curT in RT:
@@ -183,6 +228,7 @@ class Qdf_IRM():
183
228
  Pour importer les fichiers depuis le site web de l'IRM meteo.be
184
229
  from wolfhece.irm_qdf import Qdf_IRM
185
230
  qdf = Qdf_IRM(force_import=True)
231
+ qdf =
186
232
 
187
233
  Il est possible de spécifier le répertoire de stockage des fichiers Excel
188
234
  Par défaut, il s'agit d'un sous-répertoire 'irm' du répertoire courant qui sera créé s'il n'exsiste pas
@@ -209,25 +255,58 @@ class Qdf_IRM():
209
255
 
210
256
  """
211
257
 
212
- def __init__(self, store_path= 'irm', code:int= 0, name= '', force_import= False, ins:Literal['2018', '2019', '2025', 2018, 2019, 2025] = 2019) -> None:
258
+ def __init__(self, store_path= 'irm',
259
+ code:int= 0, name= '',
260
+ force_import= False,
261
+ ins:Literal['2018', '2019', '2025', 2018, 2019, 2025] = 2018,
262
+ localities:Localities = None) -> None:
263
+
264
+ if localities is None:
265
+
266
+ assert int(ins) in [2018, 2019, 2025], _('Bad INS - Retry !')
267
+
268
+ self.myloc = Localities(ins)
269
+ else:
270
+ self.myloc = localities
213
271
 
214
- self.myloc = Localities()
215
272
  self.store = store_path
216
273
 
217
274
  if force_import:
218
- self.importfromwebsite(store_path)
275
+ self.importfromwebsite(store_path, ins=ins)
219
276
 
220
277
  if code !=0:
221
- self.ins_read_excel(code=str(code))
222
- self.fit_all()
278
+ if self.ins_read_excel(code=str(code)):
279
+ self.fit_all()
280
+ self._code = code
281
+ self._name = self.myloc.get_namefromINS(code)
282
+ else:
283
+ logging.debug(f"INS code {code} not found in the store")
223
284
  elif name!='':
224
- self.ins_read_excel(name=name)
225
- self.fit_all()
285
+ if self.ins_read_excel(name=name):
286
+ self.fit_all()
287
+ self._name = name
288
+ self._code = self.myloc.get_INSfromname(name)
289
+ else:
290
+ logging.debug(f"Name {name} not found in the store")
291
+
292
+ @property
293
+ def name(self):
294
+ return self._name
295
+
296
+ @property
297
+ def code(self):
298
+ return self._code
226
299
 
227
- self.montanacoeff=None
228
- pass
300
+ @property
301
+ def code_name(self):
302
+ return str(self._code) + '-' + self._name
303
+
304
+ @property
305
+ def name_code(self):
306
+ return self._name + '-' + str(self._code)
229
307
 
230
308
  def export_allmontana2xls(self):
309
+ """ Export all Montana coefficients to an Excel file """
231
310
 
232
311
  newdf = []
233
312
 
@@ -246,24 +325,29 @@ class Qdf_IRM():
246
325
  newdf.to_excel("allmontana.xlsx")
247
326
 
248
327
 
249
- def importfromwebsite(self,store_path='irm',verbose=False,waitingtime=.01):
328
+ @classmethod
329
+ def importfromwebsite(cls, store_path= 'irm', verbose:bool= False, waitingtime:float= .01, ins:Literal['2018', '2019', '2025', 2018, 2019, 2025] = 2018):
250
330
  """ Import Excel files for all municipalities from the IRM website
251
331
 
252
- :param store_path: Where to store the downloaded data. Directory
253
- will be created if it doesn't exists.
254
- :param verbose: If `True`, will print some progress information. If
255
- `False`, will do nothing. If a callable, then will call it with a
256
- float in [0, 1]. 0 means nothing downloaded, 1 means everything
257
- downloaded.
258
- :param waitingtime: How long to wait (in seconds) betwenn the download
259
- of each station (will make sure we don't overwhelm IRM's website).
332
+ :param store_path: Where to store the downloaded data. Directory will be created if it doesn't exists.
333
+ :param verbose: If `True`, will print some progress information.
334
+ If `False`, will do nothing.
335
+ If a callable, then will call it with a float in [0, 1].
336
+ 0 means nothing downloaded, 1 means everything downloaded.
337
+
338
+ :param waitingtime: How long to wait (in seconds) betwenn the download
339
+ of each station (will make sure we don't overwhelm IRM's website).
340
+
341
+ :param ins: The year of the INS codes to use.
260
342
  """
261
343
  import requests
262
344
 
345
+ myloc = Localities(ins)
346
+
263
347
  if not path.exists(store_path):
264
348
  mkdir(store_path)
265
349
 
266
- for key,myins in enumerate(self.myloc.inscode2name):
350
+ for key,myins in enumerate(myloc.inscode2name):
267
351
  #chaîne URL du fichier Excel
268
352
  url="https://www.meteo.be//resources//climatology//climateCity//xls//IDF_table_INS"+str(myins)+".xlsx"
269
353
  #Obtention du fichiers depuis le site web de l'IRM
@@ -275,7 +359,7 @@ class Qdf_IRM():
275
359
  file.close()
276
360
  if verbose:
277
361
  if callable(verbose):
278
- verbose(key/len(self.myloc.inscode2name))
362
+ verbose(key/len(myloc.inscode2name))
279
363
  else:
280
364
  print(myins)
281
365
 
@@ -293,22 +377,73 @@ class Qdf_IRM():
293
377
  return _('Bad name ! - Retry')
294
378
  loccode=str(self.myloc.insname2code[name.lower()])
295
379
 
296
- self.code = loccode
297
- self.name = name
380
+ self._code = loccode
381
+ self._name = name
298
382
 
299
- pathname = path.join(self.store,loccode+".xlsx")
383
+ store = Path(self.store)
384
+
385
+ pathname_xls = store / (loccode+".xlsx")
386
+ pathname_csv = store / 'csv' / loccode
387
+
388
+ if pathname_csv.exists():
389
+ self.qdf = pd.read_csv(pathname_csv / 'qdf.csv', index_col=0)
390
+ self.standarddev = pd.read_csv(pathname_csv / 'standarddev.csv', index_col=0)
391
+ self.confintlow = pd.read_csv(pathname_csv / 'confintlow.csv', index_col=0)
392
+ self.confintup = pd.read_csv(pathname_csv / 'confintup.csv', index_col=0)
393
+ self.montanacoeff = pd.read_csv(pathname_csv / 'montanacoeff.csv', index_col=0)
394
+ self.montana = MontanaIRM(self.montanacoeff)
395
+ return True
396
+ else:
397
+ with warnings.catch_warnings(record=True):
398
+ warnings.simplefilter("always")
399
+ if path.exists(pathname_xls):
400
+ self.qdf=pd.read_excel(pathname_xls,"Return level",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
401
+ self.standarddev=pd.read_excel(pathname_xls,"Standard deviation",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
402
+ self.confintlow=pd.read_excel(pathname_xls,"Conf. interval, lower bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
403
+ self.confintup=pd.read_excel(pathname_xls,"Conf. interval, upper bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
404
+ self.montanacoeff=pd.read_excel(pathname_xls,"Montana coefficients",index_col=0,skiprows=range(11),nrows=12,usecols="A:G",engine='openpyxl', engine_kwargs={'read_only': True})
405
+ self.montana = MontanaIRM(self.montanacoeff)
406
+ return True
407
+ else:
408
+ self.qdf=None
409
+ self.standarddev=None
410
+ self.confintlow=None
411
+ self.confintup=None
412
+ self.montanacoeff=None
413
+ self.montana=None
414
+ return False
415
+
416
+ @classmethod
417
+ def convert_xls2csv(cls, store_path= 'irm', ins:Literal['2018', '2019', '2025', 2018, 2019, 2025] = 2018):
418
+ """ Convert all Excel files to JSON files
419
+
420
+ :param store_path: Where to store the downloaded data. Directory will be created if it doesn't exists.
421
+ :param ins: The year of the INS codes to use.
422
+ """
423
+
424
+ myloc = Localities(ins)
425
+
426
+ store_path = Path(store_path)
427
+
428
+ for key,myins in enumerate(myloc.get_allcodes()):
429
+ pathname = store_path / (str(myins)+".xlsx")
430
+ if pathname.exists():
431
+
432
+ qdf=pd.read_excel(pathname,"Return level",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
433
+ standarddev=pd.read_excel(pathname,"Standard deviation",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
434
+ confintlow=pd.read_excel(pathname,"Conf. interval, lower bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
435
+ confintup=pd.read_excel(pathname,"Conf. interval, upper bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl', engine_kwargs={'read_only': True})
436
+ montanacoeff=pd.read_excel(pathname,"Montana coefficients",index_col=0,skiprows=range(11),nrows=12,usecols="A:G",engine='openpyxl', engine_kwargs={'read_only': True})
437
+
438
+ store_csv = store_path / 'csv' / str(myins)
439
+ store_csv.mkdir(exist_ok=True)
440
+
441
+ qdf.to_csv(store_csv / 'qdf.csv')
442
+ standarddev.to_csv(store_csv / 'standarddev.csv')
443
+ confintlow.to_csv(store_csv / 'confintlow.csv')
444
+ confintup.to_csv(store_csv / 'confintup.csv')
445
+ montanacoeff.to_csv(store_csv / 'montanacoeff.csv')
300
446
 
301
- with warnings.catch_warnings(record=True):
302
- warnings.simplefilter("always")
303
- if path.exists(pathname):
304
- self.qdf=pd.read_excel(pathname,"Return level",index_col=0,skiprows=range(7),nrows=19,usecols="A:M")
305
- self.standarddev=pd.read_excel(pathname,"Standard deviation",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl')
306
- self.confintlow=pd.read_excel(pathname,"Conf. interval, lower bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl')
307
- self.confintup=pd.read_excel(pathname,"Conf. interval, upper bound",index_col=0,skiprows=range(7),nrows=19,usecols="A:M",engine='openpyxl')
308
- self.montanacoeff=pd.read_excel(pathname,"Montana coefficients",index_col=0,skiprows=range(11),nrows=12,usecols="A:G",engine='openpyxl')
309
- self.montana = MontanaIRM(self.montanacoeff)
310
- else:
311
- return 'File not present'
312
447
 
313
448
  def plot_idf(self,T=None,which='All',color=[27./255.,136./255.,245./255.]):
314
449
  """
@@ -347,7 +482,7 @@ class Qdf_IRM():
347
482
  ax.set_ylabel(_('Intensity [mm/h]'))
348
483
  ax.set_xticks(durations)
349
484
  ax.set_xticklabels(durationstext,rotation=45)
350
- ax.set_title(self.name + ' - code : ' + str(self.code))
485
+ ax.set_title(self._name + ' - code : ' + str(self._code))
351
486
 
352
487
  return fig,ax
353
488
 
@@ -386,11 +521,12 @@ class Qdf_IRM():
386
521
  ax.set_ylabel(_('Quantity [mm]'))
387
522
  ax.set_xticks(durations)
388
523
  ax.set_xticklabels(durationstext,rotation=45)
389
- ax.set_title(self.name + ' - code : ' + str(self.code))
524
+ ax.set_title(self._name + ' - code : ' + str(self._code))
390
525
 
391
526
  return fig,ax
392
527
 
393
528
  def plot_cdf(self,dur=None):
529
+ """ Plot the cdf of the QDF data for a given duration """
394
530
 
395
531
  fig,ax = plt.subplots(1,1,figsize=(10,10))
396
532
  if dur is None:
@@ -404,37 +540,85 @@ class Qdf_IRM():
404
540
  ax.legend().set_draggable(True)
405
541
  ax.set_ylabel(_('Cumulative distribution function (cdf)'))
406
542
  ax.set_xlabel(_('Quantity [mm]'))
407
- ax.set_title(self.name + ' - code : ' + str(self.code))
543
+ ax.set_title(self._name + ' - code : ' + str(self._code))
408
544
 
409
545
  return fig,ax
410
546
 
411
547
  def fit_all(self):
548
+ """ Fit all durations with a Generalized Extreme Value distribution """
549
+
550
+ self.load_fits_json()
551
+
552
+ if self.popt_all == {}:
553
+ for curdur in durationstext:
554
+ fig,ax,popt,pcov = self.fit_cdf(curdur)
555
+ self.popt_all[curdur]=popt
556
+ # self.pcov_all[curdur]=pcov
557
+
558
+ self.save_fits_json()
559
+
560
+ def save_fits_json(self):
561
+ """ Save the fits in a csv file """
412
562
 
413
- self.popt_all={}
414
- self.pcov_all={}
563
+ with open(path.join(self.store, str(self._code) + '_fits.json'), 'w') as f:
564
+ df = pd.DataFrame(self.popt_all)
565
+ df.to_json(f)
415
566
 
416
- for curdur in durationstext:
417
- fig,ax,popt,pcov = self.fit_cdf(curdur)
418
- self.popt_all[curdur]=popt
419
- self.pcov_all[curdur]=pcov
567
+ # with open(path.join(self.store, str(self.code) + '_fits_cov.json'), 'w') as f:
568
+ # df = pd.DataFrame(self.pcov_all)
569
+ # df.to_json(f)
420
570
 
421
- def fit_cdf(self,dur=None,plot=False):
571
+ def load_fits_json(self):
572
+ """ Load the fits from a json file """
573
+
574
+ import json
575
+
576
+ filename = path.join(self.store, str(self._code) + '_fits.json')
577
+
578
+ if path.exists(filename):
579
+ with open(filename, 'r') as f:
580
+ self.popt_all = json.load(f)
581
+
582
+ for key in self.popt_all.keys():
583
+ self.popt_all[key] = np.array([val for val in self.popt_all[key].values()])
584
+ else:
585
+ self.popt_all = {}
422
586
 
423
- x=np.asarray(self.qdf.loc[dur],dtype=np.float64)
587
+ # filename = path.join(self.store, str(self.code) + '_fits_cov.json')
588
+
589
+ # if path.exists(filename):
590
+ # with open(filename, 'r') as f:
591
+ # self.pcov_all = json.load(f)
592
+ # else:
593
+ # self.pcov_all = {}
594
+
595
+ def fit_cdf(self, dur=None, plot=False):
596
+ """ Fit the cdf of the QDF data with a Generalized Extreme Value distribution
597
+
598
+ :param dur: the duration to fit
599
+ :param plot: if True, will plot the cdf with the fit
600
+ """
601
+
602
+ if dur is None:
603
+ return _('Bad duration - Retry !')
604
+ if dur not in durationstext:
605
+ return _('Bad duration - Retry !')
606
+
607
+ x=np.asarray(self.qdf.loc[dur], dtype=np.float64)
424
608
 
425
609
  def locextreme(x,a,b,c):
426
- return genextreme.cdf(x,a,loc=b,scale=c)
610
+ return genextreme.cdf(x, a, loc=b, scale=c)
427
611
 
428
612
  def locextreme2(a):
429
613
  LL = -np.sum(genextreme.logpdf(x,a[0],loc=a[1],scale=a[2]))
430
614
  return LL
431
615
 
432
616
  popt = genextreme.fit(x)
433
- popt,pcov=curve_fit(locextreme,x,freqndep,p0=popt)
617
+ popt, pcov = curve_fit(locextreme, x, freqndep, p0=popt)
434
618
 
435
619
  #ptest = minimize(locextreme2,popt,bounds=[[-10.,0.],[0.,100.],[0.,100.]])
436
620
 
437
- perr = np.sqrt(np.diag(pcov))
621
+ # perr = np.sqrt(np.diag(pcov))
438
622
 
439
623
  fig=ax=None
440
624
  if plot:
@@ -447,27 +631,92 @@ class Qdf_IRM():
447
631
 
448
632
  return fig,ax,popt,pcov
449
633
 
450
- def get_Tfromrain(self,Q,dur=dur1h):
451
- return 1./self.stat.sf(Q,self.popt_all[dur][0],loc=self.popt_all[dur][1],scale=self.popt_all[dur][2])
634
+ def get_Tfromrain(self, Q, dur=dur1h):
635
+ """ Get the return period for a given quantity of rain
636
+
637
+ :param Q: the quantity of rain
638
+ :param dur: the duration
639
+ """
640
+
641
+ return 1./self.stat.sf(Q, self.popt_all[dur][0], loc=self.popt_all[dur][1], scale=self.popt_all[dur][2])
642
+
643
+ def get_rainfromT(self, T, dur= dur1h):
644
+ """ Get the quantity of rain for a given return period and duration
645
+
646
+ :param T: the return period
647
+ :param dur: the duration
648
+ """
452
649
 
453
- def get_rainfromT(self,T,dur=dur1h):
454
650
  return self.stat.isf(1./T,self.popt_all[dur][0],loc=self.popt_all[dur][1],scale=self.popt_all[dur][2])
455
651
 
456
- def get_MontanacoeffforT(self,return_period):
652
+ def get_MontanacoeffforT(self, return_period):
653
+ """ Get the Montana coefficients for a given return period
654
+
655
+ :param return_period: the return period
656
+ """
457
657
 
458
658
  if return_period in RT:
459
659
  return self.montanacoeff.loc[float(return_period)]
460
660
  else:
461
661
  return _('Bad RT - Retry !')
462
662
 
463
- def plot_hyeto(self,durmax,T,r=.5):
663
+ def plot_hyeto(self, durmax, T, r=.5):
664
+ """ Plot the hyetogram for a given return period
665
+
666
+ :param durmax: the maximum duration of the hyetogram
667
+ :param T: the return period
668
+ :param r: the decentration coefficient
669
+ """
464
670
 
465
671
  fig,ax = self.montana.plot_hyeto(durmax,T,r)
466
- ax.set_title(self.name + ' - code : ' + str(self.code))
672
+ ax.set_title(self._name + ' - code : ' + str(self._code))
467
673
 
468
674
  return fig
469
675
 
470
- def plot_hyetos(self,durmax,r=.5):
676
+ def plot_hyetos(self, durmax, r=.5):
677
+ """ Plot the hyetograms for all return periods
678
+
679
+ :param durmax: the maximum duration of the hyetograms
680
+ :param r: the decentration coefficient
681
+ """
471
682
 
472
683
  fig,ax = self.montana.plot_hyetos(durmax,r)
473
- ax.set_title(self.name + ' - code : ' + str(self.code))
684
+ ax.set_title(self._name + ' - code : ' + str(self._code))
685
+
686
+ def __str__(self) -> str:
687
+ """ Return the QDF data as a string """
688
+ return self.qdf.__str__()
689
+
690
+ class QDF_Belgium():
691
+
692
+ def __init__(self, store_path= 'irm', ins:Literal['2018', '2019', '2025', 2018, 2019, 2025] = 2018) -> None:
693
+
694
+ self.localities = Localities(ins)
695
+ self.store_path = Path(store_path)
696
+
697
+ self.all = {}
698
+ for loc_ins in tqdm(self.localities.get_allcodes()):
699
+ loc = Qdf_IRM(store_path=str(self.store_path), code=loc_ins, localities=self.localities)
700
+ if loc.qdf is not None:
701
+ self.all[loc_ins] = loc
702
+
703
+ def __getitem__(self, key) -> Qdf_IRM:
704
+
705
+ if isinstance(key, int):
706
+ if key in self.all:
707
+ return self.all[key]
708
+ else:
709
+ logging.error(f"INS code {key} not found in the data")
710
+ return None
711
+
712
+ elif isinstance(key, str):
713
+ key = self.localities.get_INSfromname(key)
714
+ if key is not None:
715
+ if key in self.all:
716
+ return self.all[key]
717
+ else:
718
+ logging.error(f"INS code {key} not found in the data")
719
+ return None
720
+ else:
721
+ logging.error(f"Name {key} not found in the data")
722
+ return None