Skip to content

Product processors

Product processors

Era5

A class to process ERA5 hourly to hidrocl variables. Where:

total precipitation: tp -> pp (10000 * m) sum

air temperature: t2m -> temp (10 * ºC) mean

dewpoint temperature: d2m -> dew (10 * ºC) mean

surface pressure: sp -> pres (10 * Pa) mean

u wind component: u10 -> u (10 * m/s) mean

v wind component: v10 -> v (10 * m/s) mean

pp, dew, pres, u, v: HidroCLVariable object with ERA5 data

Attributes:

Name Type Description
pp HidroCLVariable

HidroCLVariable object with ERA5 precipitation data

temp HidroCLVariable

HidroCLVariable object with ERA5 air temperature data

tempmin HidroCLVariable

HidroCLVariable object with ERA5 minimum air temperature data

tempmax HidroCLVariable

HidroCLVariable object with ERA5 maximum air temperature data

dew HidroCLVariable

HidroCLVariable object with ERA5 dewpoint temperature data

pres HidroCLVariable

HidroCLVariable object with ERA5 surface pressure data

u HidroCLVariable

HidroCLVariable object with ERA5 u wind component data

v HidroCLVariable

HidroCLVariable object with ERA5 v wind component data

pp_log str

Log file path for precipitation data

temp_log str

Log file path for air temperature data

tempmin_log str

Log file path for minimum air temperature data

tempmax_log str

Log file path for maximum air temperature data

dew_log str

Log file path for dewpoint temperature data

pres_log str

Log file path for surface pressure data

u_log str

Log file path for u wind component data

v_log str

Log file path for v wind component data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the pp, dew, pres, u and v databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scenes for era5)

complete_scenes list

List of complete scenes (1 scenes for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scenes for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
class Era5:
    """
    A class to process ERA5 hourly to hidrocl variables. Where:

    total precipitation: tp -> pp (10000 * m) sum \n
    air temperature: t2m -> temp (10 * ºC) mean \n
    dewpoint temperature: d2m -> dew (10 * ºC) mean \n
    surface pressure: sp -> pres (10 * Pa) mean \n
    u wind component: u10 -> u (10 * m/s) mean \n
    v wind component: v10 -> v (10 * m/s) mean \n

    pp, dew, pres, u, v: HidroCLVariable object with ERA5 data \n

    Attributes:
        pp (HidroCLVariable): HidroCLVariable object with ERA5 precipitation data \n
        temp (HidroCLVariable): HidroCLVariable object with ERA5 air temperature data \n
        tempmin (HidroCLVariable): HidroCLVariable object with ERA5 minimum air temperature data \n
        tempmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum air temperature data \n
        dew (HidroCLVariable): HidroCLVariable object with ERA5 dewpoint temperature data \n
        pres (HidroCLVariable): HidroCLVariable object with ERA5 surface pressure data \n
        u (HidroCLVariable): HidroCLVariable object with ERA5 u wind component data \n
        v (HidroCLVariable): HidroCLVariable object with ERA5 v wind component data \n
        pp_log (str): Log file path for precipitation data \n
        temp_log (str): Log file path for air temperature data \n
        tempmin_log (str): Log file path for minimum air temperature data \n
        tempmax_log (str): Log file path for maximum air temperature data \n
        dew_log (str): Log file path for dewpoint temperature data \n
        pres_log (str): Log file path for surface pressure data \n
        u_log (str): Log file path for u wind component data \n
        v_log (str): Log file path for v wind component data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the pp, dew, pres, u and v databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scenes for era5) \n
        complete_scenes (list): List of complete scenes (1 scenes for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scenes for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pp, temp, tempmin, tempmax,
                 dew, pres, u, v, product_path, vector_path,
                 pp_log, temp_log, tempmin_log, tempmax_log,
                 dew_log, pres_log, u_log, v_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5
            >>> pp = HidroCLVariable('pp', pp.db, pppc.db)
            >>> temp = HidroCLVariable('temp', temp.db, temppc.db)
            >>> tempmin = HidroCLVariable('tempmin', tempmin.db, tempminpc.db)
            >>> tempmax = HidroCLVariable('tempmax', tempmax.db, tempmaxpc.db)
            >>> dew = HidroCLVariable('dew', dew.db, dewpc.db)
            >>> pres = HidroCLVariable('pres', pres.db, prespc.db)
            >>> u = HidroCLVariable('u', u.db, upc.db)
            >>> v = HidroCLVariable('v', v.db, vpc.db)
            >>> product_path = '/home/user/era5'
            >>> vector_path = '/home/user/shapefiles'
            >>> pp_log = '/home/user/pp.log'
            >>> dew_log = '/home/user/dew.log'
            >>> pres_log = '/home/user/pres.log'
            >>> u_log = '/home/user/u.log'
            >>> v_log = '/home/user/v.log'
            >>> era5 = Era5(pp, temp, tempmin, tempmax,
                            dew, pres, u, v,
                            product_path, vector_path,
                            pp_log, temp_log,
                            tempmin_log, tempmax_log,
                            pp_log, dew_log, pres_log, u_log, v_log)
            >>> era5
            "Class to extract ERA5 Hourly 0.25 degree"
            >>> era5.run_extraction()


        Args:
            pp (HidroCLVariable): HidroCLVariable object with ERA5 precipitation data \n
            temp (HidroCLVariable): HidroCLVariable object with ERA5 air temperature data \n
            tempmin (HidroCLVariable): HidroCLVariable object with ERA5 minimum air temperature data \n
            tempmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum air temperature data \n
            dew (HidroCLVariable): HidroCLVariable object with ERA5 dewpoint temperature data \n
            pres (HidroCLVariable): HidroCLVariable object with ERA5 surface pressure data \n
            u (HidroCLVariable): HidroCLVariable object with ERA5 u wind component data \n
            v (HidroCLVariable): HidroCLVariable object with ERA5 v wind component data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            pp_log (str): Log file path for precipitation data \n
            temp_log (str): Log file path for air temperature data \n
            tempmin_log (str): Log file path for minimum air temperature data \n
            tempmax_log (str): Log file path for maximum air temperature data \n
            dew_log (str): Log file path for dewpoint temperature data \n
            pres_log (str): Log file path for surface pressure data \n
            u_log (str): Log file path for u wind component data \n
            v_log (str): Log file path for v wind component data \n

        Raises:
            TypeError: If pp, temp, tempmin, tempmax, dew, pres, u or v are not HidroCLVariable objects \n
        """
        if t.check_instance(pp, temp, tempmin, tempmax, dew, pres, u, v):
            self.pp = pp
            self.temp = temp
            self.tempmin = tempmin
            self.tempmax = tempmax
            self.dew = dew
            self.pres = pres
            self.u = u
            self.v = v
            self.pp_log = pp_log
            self.temp_log = temp_log
            self.tempmin_log = tempmin_log
            self.tempmax_log = tempmax_log
            self.dew_log = dew_log
            self.pres_log = pres_log
            self.u_log = u_log
            self.v_log = v_log
            self.productname = "ERA5 Hourly 0.25 degree on single levels"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                        self.temp.indatabase,
                                                        self.tempmin.indatabase,
                                                        self.tempmax.indatabase,
                                                        self.dew.indatabase,
                                                        self.pres.indatabase,
                                                        self.u.indatabase,
                                                        self.v.indatabase)
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('pp, temp, tempmin, tempmax, dew, pres, u and v must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Precipitation records: {len(self.pp.indatabase)}.
Precipitation path: {self.pp.database}

Air temperature records: {len(self.temp.indatabase)}.
Air temperature path: {self.temp.database}

Minimum air temperature records: {len(self.tempmin.indatabase)}.
Minimum air temperature path: {self.tempmin.database}

Maximum air temperature records: {len(self.tempmax.indatabase)}.
Maximum air temperature path: {self.tempmax.database}

Dewpoint temperature records: {len(self.dew.indatabase)}.
Dewpoint temperature path: {self.dew.database}

Surface pressure records: {len(self.pres.indatabase)}.
Surface pressure path: {self.pres.database}

U wind component records: {len(self.u.indatabase)}.
U wind component path: {self.u.database}

V wind component records: {len(self.v.indatabase)}.
V wind component path: {self.v.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()
            self.temp.checkdatabase()
            self.tempmin.checkdatabase()
            self.tempmax.checkdatabase()
            self.dew.checkdatabase()
            self.pres.checkdatabase()
            self.u.checkdatabase()
            self.v.checkdatabase()

        self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                    self.temp.indatabase,
                                                    self.tempmin.indatabase,
                                                    self.tempmax.indatabase,
                                                    self.dew.indatabase,
                                                    self.pres.indatabase,
                                                    self.u.indatabase,
                                                    self.v.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'pp_era5',
                                  self.pp.catchment_names, self.pp_log,
                                  database=self.pp.database,
                                  pcdatabase=self.pp.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='sum',
                                  layer="tp")

                if scene not in self.temp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'temp_era5',
                                  self.temp.catchment_names, self.temp_log,
                                  database=self.temp.database,
                                  pcdatabase=self.temp.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='mean',
                                  layer="t2m")

                if scene not in self.tempmin.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'tempmin_era5',
                                  self.tempmin.catchment_names, self.tempmin_log,
                                  database=self.tempmin.database,
                                  pcdatabase=self.tempmin.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='min',
                                  layer="t2m")

                if scene not in self.tempmax.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'tempmax_era5',
                                  self.tempmax.catchment_names, self.tempmax_log,
                                  database=self.tempmax.database,
                                  pcdatabase=self.tempmax.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='max',
                                  layer="t2m")

                if scene not in self.dew.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'dew_era5',
                                  self.dew.catchment_names, self.dew_log,
                                  database=self.dew.database,
                                  pcdatabase=self.dew.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="d2m")

                if scene not in self.pres.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'pres_era5',
                                  self.pres.catchment_names, self.pres_log,
                                  database=self.pres.database,
                                  pcdatabase=self.pres.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="sp")

                if scene not in self.u.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'u10_era5',
                                  self.u.catchment_names, self.u_log,
                                  database=self.u.database,
                                  pcdatabase=self.u.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="u10")

                if scene not in self.v.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'v10_era5',
                                  self.v.catchment_names, self.v_log,
                                  database=self.v.database,
                                  pcdatabase=self.v.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="v10")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()
            self.temp.checkdatabase()
            self.tempmin.checkdatabase()
            self.tempmax.checkdatabase()
            self.dew.checkdatabase()
            self.pres.checkdatabase()
            self.u.checkdatabase()
            self.v.checkdatabase()

        self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                    self.temp.indatabase,
                                                    self.tempmin.indatabase,
                                                    self.tempmax.indatabase,
                                                    self.dew.indatabase,
                                                    self.pres.indatabase,
                                                    self.u.indatabase,
                                                    self.v.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(pp, temp, tempmin, tempmax, dew, pres, u, v, product_path, vector_path, pp_log, temp_log, tempmin_log, tempmax_log, dew_log, pres_log, u_log, v_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5
>>> pp = HidroCLVariable('pp', pp.db, pppc.db)
>>> temp = HidroCLVariable('temp', temp.db, temppc.db)
>>> tempmin = HidroCLVariable('tempmin', tempmin.db, tempminpc.db)
>>> tempmax = HidroCLVariable('tempmax', tempmax.db, tempmaxpc.db)
>>> dew = HidroCLVariable('dew', dew.db, dewpc.db)
>>> pres = HidroCLVariable('pres', pres.db, prespc.db)
>>> u = HidroCLVariable('u', u.db, upc.db)
>>> v = HidroCLVariable('v', v.db, vpc.db)
>>> product_path = '/home/user/era5'
>>> vector_path = '/home/user/shapefiles'
>>> pp_log = '/home/user/pp.log'
>>> dew_log = '/home/user/dew.log'
>>> pres_log = '/home/user/pres.log'
>>> u_log = '/home/user/u.log'
>>> v_log = '/home/user/v.log'
>>> era5 = Era5(pp, temp, tempmin, tempmax,
                dew, pres, u, v,
                product_path, vector_path,
                pp_log, temp_log,
                tempmin_log, tempmax_log,
                pp_log, dew_log, pres_log, u_log, v_log)
>>> era5
"Class to extract ERA5 Hourly 0.25 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
pp HidroCLVariable

HidroCLVariable object with ERA5 precipitation data

required
temp HidroCLVariable

HidroCLVariable object with ERA5 air temperature data

required
tempmin HidroCLVariable

HidroCLVariable object with ERA5 minimum air temperature data

required
tempmax HidroCLVariable

HidroCLVariable object with ERA5 maximum air temperature data

required
dew HidroCLVariable

HidroCLVariable object with ERA5 dewpoint temperature data

required
pres HidroCLVariable

HidroCLVariable object with ERA5 surface pressure data

required
u HidroCLVariable

HidroCLVariable object with ERA5 u wind component data

required
v HidroCLVariable

HidroCLVariable object with ERA5 v wind component data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
pp_log str

Log file path for precipitation data

required
temp_log str

Log file path for air temperature data

required
tempmin_log str

Log file path for minimum air temperature data

required
tempmax_log str

Log file path for maximum air temperature data

required
dew_log str

Log file path for dewpoint temperature data

required
pres_log str

Log file path for surface pressure data

required
u_log str

Log file path for u wind component data

required
v_log str

Log file path for v wind component data

required

Raises:

Type Description
TypeError

If pp, temp, tempmin, tempmax, dew, pres, u or v are not HidroCLVariable objects

Source code in hidrocl/products/__init__.py
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
def __init__(self, pp, temp, tempmin, tempmax,
             dew, pres, u, v, product_path, vector_path,
             pp_log, temp_log, tempmin_log, tempmax_log,
             dew_log, pres_log, u_log, v_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5
        >>> pp = HidroCLVariable('pp', pp.db, pppc.db)
        >>> temp = HidroCLVariable('temp', temp.db, temppc.db)
        >>> tempmin = HidroCLVariable('tempmin', tempmin.db, tempminpc.db)
        >>> tempmax = HidroCLVariable('tempmax', tempmax.db, tempmaxpc.db)
        >>> dew = HidroCLVariable('dew', dew.db, dewpc.db)
        >>> pres = HidroCLVariable('pres', pres.db, prespc.db)
        >>> u = HidroCLVariable('u', u.db, upc.db)
        >>> v = HidroCLVariable('v', v.db, vpc.db)
        >>> product_path = '/home/user/era5'
        >>> vector_path = '/home/user/shapefiles'
        >>> pp_log = '/home/user/pp.log'
        >>> dew_log = '/home/user/dew.log'
        >>> pres_log = '/home/user/pres.log'
        >>> u_log = '/home/user/u.log'
        >>> v_log = '/home/user/v.log'
        >>> era5 = Era5(pp, temp, tempmin, tempmax,
                        dew, pres, u, v,
                        product_path, vector_path,
                        pp_log, temp_log,
                        tempmin_log, tempmax_log,
                        pp_log, dew_log, pres_log, u_log, v_log)
        >>> era5
        "Class to extract ERA5 Hourly 0.25 degree"
        >>> era5.run_extraction()


    Args:
        pp (HidroCLVariable): HidroCLVariable object with ERA5 precipitation data \n
        temp (HidroCLVariable): HidroCLVariable object with ERA5 air temperature data \n
        tempmin (HidroCLVariable): HidroCLVariable object with ERA5 minimum air temperature data \n
        tempmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum air temperature data \n
        dew (HidroCLVariable): HidroCLVariable object with ERA5 dewpoint temperature data \n
        pres (HidroCLVariable): HidroCLVariable object with ERA5 surface pressure data \n
        u (HidroCLVariable): HidroCLVariable object with ERA5 u wind component data \n
        v (HidroCLVariable): HidroCLVariable object with ERA5 v wind component data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        pp_log (str): Log file path for precipitation data \n
        temp_log (str): Log file path for air temperature data \n
        tempmin_log (str): Log file path for minimum air temperature data \n
        tempmax_log (str): Log file path for maximum air temperature data \n
        dew_log (str): Log file path for dewpoint temperature data \n
        pres_log (str): Log file path for surface pressure data \n
        u_log (str): Log file path for u wind component data \n
        v_log (str): Log file path for v wind component data \n

    Raises:
        TypeError: If pp, temp, tempmin, tempmax, dew, pres, u or v are not HidroCLVariable objects \n
    """
    if t.check_instance(pp, temp, tempmin, tempmax, dew, pres, u, v):
        self.pp = pp
        self.temp = temp
        self.tempmin = tempmin
        self.tempmax = tempmax
        self.dew = dew
        self.pres = pres
        self.u = u
        self.v = v
        self.pp_log = pp_log
        self.temp_log = temp_log
        self.tempmin_log = tempmin_log
        self.tempmax_log = tempmax_log
        self.dew_log = dew_log
        self.pres_log = pres_log
        self.u_log = u_log
        self.v_log = v_log
        self.productname = "ERA5 Hourly 0.25 degree on single levels"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                    self.temp.indatabase,
                                                    self.tempmin.indatabase,
                                                    self.tempmax.indatabase,
                                                    self.dew.indatabase,
                                                    self.pres.indatabase,
                                                    self.u.indatabase,
                                                    self.v.indatabase)
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('pp, temp, tempmin, tempmax, dew, pres, u and v must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2461
2462
2463
2464
2465
2466
2467
2468
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Precipitation records: {len(self.pp.indatabase)}.
Precipitation path: {self.pp.database}

Air temperature records: {len(self.temp.indatabase)}.
Air temperature path: {self.temp.database}

Minimum air temperature records: {len(self.tempmin.indatabase)}.
Minimum air temperature path: {self.tempmin.database}

Maximum air temperature records: {len(self.tempmax.indatabase)}.
Maximum air temperature path: {self.tempmax.database}

Dewpoint temperature records: {len(self.dew.indatabase)}.
Dewpoint temperature path: {self.dew.database}

Surface pressure records: {len(self.pres.indatabase)}.
Surface pressure path: {self.pres.database}

U wind component records: {len(self.u.indatabase)}.
U wind component path: {self.u.database}

V wind component records: {len(self.v.indatabase)}.
V wind component path: {self.v.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()
        self.temp.checkdatabase()
        self.tempmin.checkdatabase()
        self.tempmax.checkdatabase()
        self.dew.checkdatabase()
        self.pres.checkdatabase()
        self.u.checkdatabase()
        self.v.checkdatabase()

    self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                self.temp.indatabase,
                                                self.tempmin.indatabase,
                                                self.tempmax.indatabase,
                                                self.dew.indatabase,
                                                self.pres.indatabase,
                                                self.u.indatabase,
                                                self.v.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'pp_era5',
                              self.pp.catchment_names, self.pp_log,
                              database=self.pp.database,
                              pcdatabase=self.pp.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='sum',
                              layer="tp")

            if scene not in self.temp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'temp_era5',
                              self.temp.catchment_names, self.temp_log,
                              database=self.temp.database,
                              pcdatabase=self.temp.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='mean',
                              layer="t2m")

            if scene not in self.tempmin.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'tempmin_era5',
                              self.tempmin.catchment_names, self.tempmin_log,
                              database=self.tempmin.database,
                              pcdatabase=self.tempmin.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='min',
                              layer="t2m")

            if scene not in self.tempmax.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'tempmax_era5',
                              self.tempmax.catchment_names, self.tempmax_log,
                              database=self.tempmax.database,
                              pcdatabase=self.tempmax.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='max',
                              layer="t2m")

            if scene not in self.dew.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'dew_era5',
                              self.dew.catchment_names, self.dew_log,
                              database=self.dew.database,
                              pcdatabase=self.dew.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="d2m")

            if scene not in self.pres.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'pres_era5',
                              self.pres.catchment_names, self.pres_log,
                              database=self.pres.database,
                              pcdatabase=self.pres.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="sp")

            if scene not in self.u.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'u10_era5',
                              self.u.catchment_names, self.u_log,
                              database=self.u.database,
                              pcdatabase=self.u.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="u10")

            if scene not in self.v.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'v10_era5',
                              self.v.catchment_names, self.v_log,
                              database=self.v.database,
                              pcdatabase=self.v.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="v10")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()
        self.temp.checkdatabase()
        self.tempmin.checkdatabase()
        self.tempmax.checkdatabase()
        self.dew.checkdatabase()
        self.pres.checkdatabase()
        self.u.checkdatabase()
        self.v.checkdatabase()

    self.common_elements = t.compare_indatabase(self.pp.indatabase,
                                                self.temp.indatabase,
                                                self.tempmin.indatabase,
                                                self.tempmax.indatabase,
                                                self.dew.indatabase,
                                                self.pres.indatabase,
                                                self.u.indatabase,
                                                self.v.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Era5_land

A class to process ERA5-Land hourly to hidrocl variables. Where:

potential evapotranspiration: pev -> pet (10000 * m) sum

snow albedo: asn -> snwa (10 * frac) mean

snow cover: snowc -> snw (10 * frac) mean

snow density: rsn -> snwdn (10 * kg/m3) mean

snow depth: sd -> snwdt (10 * m) mean

evapotranspiration: e -> et (10000 * m) sum

out now: total precipitation: tp -> pp (10000 * m) sum

volumetric soil water: swvl1+swvl2+swvl3+swvl4 -> soilm (1000 * m3/m3) mean

et, pet, snow, snowa, snowdn, snowdt, soilm

Attributes:

Name Type Description
et HidroCLVariable

HidroCLVariable object with ERA5 evapotranspiration data

pet HidroCLVariable

HidroCLVariable object with ERA5 potential evapotranspiration data

snw HidroCLVariable

HidroCLVariable object with ERA5 snow cover data

snwa HidroCLVariable

HidroCLVariable object with ERA5 snow albedo data

snwdn HidroCLVariable

HidroCLVariable object with ERA5 snow density data

snwdt HidroCLVariable

HidroCLVariable object with ERA5 snow depth data

soilm HidroCLVariable

HidroCLVariable object with ERA5 volumetric soil water data

et_log str

Log file path for evapotranspiration data

pet_log str

Log file path for potential evapotranspiration data

snw_log str

Log file path for snow cover data

snwa_log str

Log file path for snow albedo data

snwdn_log str

Log file path for snow density data

snwdt_log str

Log file path for snow depth data

soilm_log str

Log file path for volumetric soil water data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the snow, temp, et and soilm databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scenes for era5)

complete_scenes list

List of complete scenes (1 scenes for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scenes for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
class Era5_land:
    """
    A class to process ERA5-Land hourly to hidrocl variables. Where:

    potential evapotranspiration: pev -> pet (10000 * m) sum \n
    snow albedo: asn -> snwa (10 * frac) mean \n
    snow cover: snowc -> snw (10 * frac) mean \n
    snow density: rsn -> snwdn (10 * kg/m3) mean \n
    snow depth: sd -> snwdt (10 * m) mean \n
    evapotranspiration: e -> et (10000 * m) sum \n
    # out now: total precipitation: tp -> pp (10000 * m) sum \n
    volumetric soil water: swvl1+swvl2+swvl3+swvl4 -> soilm (1000 * m3/m3) mean \n

    et, pet, snow, snowa, snowdn, snowdt, soilm \n

    Attributes:
        et (HidroCLVariable): HidroCLVariable object with ERA5 evapotranspiration data \n
        pet (HidroCLVariable): HidroCLVariable object with ERA5 potential evapotranspiration data \n
        snw (HidroCLVariable): HidroCLVariable object with ERA5 snow cover data \n
        snwa (HidroCLVariable): HidroCLVariable object with ERA5 snow albedo data \n
        snwdn (HidroCLVariable): HidroCLVariable object with ERA5 snow density data \n
        snwdt (HidroCLVariable): HidroCLVariable object with ERA5 snow depth data \n
        soilm (HidroCLVariable): HidroCLVariable object with ERA5 volumetric soil water data \n
        et_log (str): Log file path for evapotranspiration data \n
        pet_log (str): Log file path for potential evapotranspiration data \n
        snw_log (str): Log file path for snow cover data \n
        snwa_log (str): Log file path for snow albedo data \n
        snwdn_log (str): Log file path for snow density data \n
        snwdt_log (str): Log file path for snow depth data \n
        soilm_log (str): Log file path for volumetric soil water data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the snow, temp, et and soilm databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scenes for era5) \n
        complete_scenes (list): List of complete scenes (1 scenes for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scenes for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, et, pet, snw, snwa, snwdn, snwdt,
                 soilm, product_path, vector_path,
                 et_log, pet_log, snw_log, snwa_log, snwdn_log,
                 snwdt_log, soilm_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5_land
            >>> et = HidroCLVariable('et', et.db, etpc.db)
            >>> pet = HidroCLVariable('pet', pet.db, petpc.db)
            >>> snw = HidroCLVariable('snw', snw.db, snwpc.db)
            >>> snwa = HidroCLVariable('snwa', snwa.db, snwapc.db)
            >>> snwdn = HidroCLVariable('snwdn', snwdn.db, snwdnpc.db)
            >>> snwdt = HidroCLVariable('snwdt', snwdt.db, snwdtpc.db)
            >>> soilm = HidroCLVariable('soilm', soilm.db, soilmdb.db)
            >>> product_path = '/home/user/era5-land'
            >>> vector_path = '/home/user/shapefiles'
            >>> et_log = '/home/user/et.log'
            >>> pet_log = '/home/user/pet.log'
            >>> snw_log = '/home/user/snw.log'
            >>> snwa_log = '/home/user/snwa.log'
            >>> snwdn_log = '/home/user/snwdn.log'
            >>> snwdt_log = '/home/user/snwdt.log'
            >>> soilm_log = '/home/user/soilm.log'
            >>> era5 = Era5_land(et, pet, snw, snwa, snwdn, snwdt,
                                 soilm, product_path, vector_path,
                                 et_log, pet_log, snw_log, snwa_log,
                                 snwdn_log, snwdt_log, soilm_log)
            >>> era5
            "Class to extract ERA5-Land Hourly 0.1 degree"
            >>> era5.run_extraction()


        Args:
            et (HidroCLVariable): HidroCLVariable object with ERA5 evapotranspiration data \n
            pet (HidroCLVariable): HidroCLVariable object with ERA5 potential evapotranspiration data \n
            snw (HidroCLVariable): HidroCLVariable object with ERA5 snow cover data \n
            snwa (HidroCLVariable): HidroCLVariable object with ERA5 snow albedo data \n
            snwdn (HidroCLVariable): HidroCLVariable object with ERA5 snow density data \n
            snwdt (HidroCLVariable): HidroCLVariable object with ERA5 snow depth data \n
            soilm (HidroCLVariable): HidroCLVariable object with ERA5 volumetric soil water data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            et_log (str): Log file path for evapotranspiration data \n
            pet_log (str): Log file path for potential evapotranspiration data \n
            snw_log (str): Log file path for snow cover data \n
            snwa_log (str): Log file path for snow albedo data \n
            snwdn_log (str): Log file path for snow density data \n
            snwdt_log (str): Log file path for snow depth data \n
            soilm_log (str): Log file path for volumetric soil water data \n

        Raises:
            TypeError: If pp, et, pet, snow, snowa, snowdn, snowdt or soilm is not HidroCLVariable objects \n
        """
        if t.check_instance(et, pet, snw, snwa, snwdn, snwdt, soilm):
            self.et = et
            self.pet = pet
            self.snw = snw
            self.snwa = snwa
            self.snwdn = snwdn
            self.snwdt = snwdt
            self.soilm = soilm
            self.et_log = et_log
            self.pet_log = pet_log
            self.snw_log = snw_log
            self.snwa_log = snwa_log
            self.snwdn_log = snwdn_log
            self.snwdt_log = snwdt_log
            self.soilm_log = soilm_log
            self.productname = "ERA5-Land Hourly 0.1 degree"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                        self.pet.indatabase,
                                                        self.snw.indatabase,
                                                        self.snwa.indatabase,
                                                        self.snwdn.indatabase,
                                                        self.snwdt.indatabase,
                                                        self.soilm.indatabase)
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('et, pet, snw, snwa, snwdn, snwdt ' +
                            'and soilm must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Evapotranspiration records: {len(self.et.indatabase)}.
Evapotranspiration path: {self.et.database}

Potential evapotranspiration records: {len(self.pet.indatabase)}.
Potential evapotranspiration path: {self.pet.database}

Snow cover records: {len(self.snw.indatabase)}.
Snow cover path: {self.snw.database}

Snow albedo records: {len(self.snwa.indatabase)}.
Snow albedo path: {self.snwa.database}

Snow density records: {len(self.snwdn.indatabase)}.
Snow density path: {self.snwdn.database}

Snow depth records: {len(self.snwdt.indatabase)}.
Snow depth path: {self.snwdt.database}

Volumetric soil water records: {len(self.soilm.indatabase)}.
Volumetric soil water path: {self.soilm.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.et.checkdatabase()
            self.pet.checkdatabase()
            self.snw.checkdatabase()
            self.snwa.checkdatabase()
            self.snwdn.checkdatabase()
            self.snwdt.checkdatabase()
            self.soilm.checkdatabase()

        self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                    self.pet.indatabase,
                                                    self.snw.indatabase,
                                                    self.snwa.indatabase,
                                                    self.snwdn.indatabase,
                                                    self.snwdt.indatabase,
                                                    self.soilm.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.et.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'et_era5',
                                  self.et.catchment_names, self.et_log,
                                  database=self.et.database,
                                  pcdatabase=self.et.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='sum',
                                  layer="e")

                if scene not in self.pet.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'pet_era5',
                                  self.pet.catchment_names, self.pet_log,
                                  database=self.pet.database,
                                  pcdatabase=self.pet.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='sum',
                                  layer="pev")

                if scene not in self.snw.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snw_era5',
                                  self.snw.catchment_names, self.snw_log,
                                  database=self.snw.database,
                                  pcdatabase=self.snw.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="snowc")

                if scene not in self.snwa.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snwa_era5',
                                  self.snwa.catchment_names, self.snwa_log,
                                  database=self.snwa.database,
                                  pcdatabase=self.snwa.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="asn")

                if scene not in self.snwdn.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snwdn_era5',
                                  self.snwdn.catchment_names, self.snwdn_log,
                                  database=self.snwdn.database,
                                  pcdatabase=self.snwdn.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="rsn")

                if scene not in self.snwdt.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snwdt_era5',
                                  self.snwdt.catchment_names, self.snwdt_log,
                                  database=self.snwdt.database,
                                  pcdatabase=self.snwdt.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="sd")

                if scene not in self.soilm.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'soilm_era5',
                                  self.soilm.catchment_names, self.soilm_log,
                                  database=self.soilm.database,
                                  pcdatabase=self.soilm.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer=["swvl1", "swvl2", "swvl3", "swvl4"])

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.et.checkdatabase()
            self.pet.checkdatabase()
            self.snw.checkdatabase()
            self.snwa.checkdatabase()
            self.snwdn.checkdatabase()
            self.snwdt.checkdatabase()
            self.soilm.checkdatabase()

        self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                    self.pet.indatabase,
                                                    self.snw.indatabase,
                                                    self.snwa.indatabase,
                                                    self.snwdn.indatabase,
                                                    self.snwdt.indatabase,
                                                    self.soilm.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(et, pet, snw, snwa, snwdn, snwdt, soilm, product_path, vector_path, et_log, pet_log, snw_log, snwa_log, snwdn_log, snwdt_log, soilm_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5_land
>>> et = HidroCLVariable('et', et.db, etpc.db)
>>> pet = HidroCLVariable('pet', pet.db, petpc.db)
>>> snw = HidroCLVariable('snw', snw.db, snwpc.db)
>>> snwa = HidroCLVariable('snwa', snwa.db, snwapc.db)
>>> snwdn = HidroCLVariable('snwdn', snwdn.db, snwdnpc.db)
>>> snwdt = HidroCLVariable('snwdt', snwdt.db, snwdtpc.db)
>>> soilm = HidroCLVariable('soilm', soilm.db, soilmdb.db)
>>> product_path = '/home/user/era5-land'
>>> vector_path = '/home/user/shapefiles'
>>> et_log = '/home/user/et.log'
>>> pet_log = '/home/user/pet.log'
>>> snw_log = '/home/user/snw.log'
>>> snwa_log = '/home/user/snwa.log'
>>> snwdn_log = '/home/user/snwdn.log'
>>> snwdt_log = '/home/user/snwdt.log'
>>> soilm_log = '/home/user/soilm.log'
>>> era5 = Era5_land(et, pet, snw, snwa, snwdn, snwdt,
                     soilm, product_path, vector_path,
                     et_log, pet_log, snw_log, snwa_log,
                     snwdn_log, snwdt_log, soilm_log)
>>> era5
"Class to extract ERA5-Land Hourly 0.1 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
et HidroCLVariable

HidroCLVariable object with ERA5 evapotranspiration data

required
pet HidroCLVariable

HidroCLVariable object with ERA5 potential evapotranspiration data

required
snw HidroCLVariable

HidroCLVariable object with ERA5 snow cover data

required
snwa HidroCLVariable

HidroCLVariable object with ERA5 snow albedo data

required
snwdn HidroCLVariable

HidroCLVariable object with ERA5 snow density data

required
snwdt HidroCLVariable

HidroCLVariable object with ERA5 snow depth data

required
soilm HidroCLVariable

HidroCLVariable object with ERA5 volumetric soil water data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
et_log str

Log file path for evapotranspiration data

required
pet_log str

Log file path for potential evapotranspiration data

required
snw_log str

Log file path for snow cover data

required
snwa_log str

Log file path for snow albedo data

required
snwdn_log str

Log file path for snow density data

required
snwdt_log str

Log file path for snow depth data

required
soilm_log str

Log file path for volumetric soil water data

required

Raises:

Type Description
TypeError

If pp, et, pet, snow, snowa, snowdn, snowdt or soilm is not HidroCLVariable objects

Source code in hidrocl/products/__init__.py
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
def __init__(self, et, pet, snw, snwa, snwdn, snwdt,
             soilm, product_path, vector_path,
             et_log, pet_log, snw_log, snwa_log, snwdn_log,
             snwdt_log, soilm_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5_land
        >>> et = HidroCLVariable('et', et.db, etpc.db)
        >>> pet = HidroCLVariable('pet', pet.db, petpc.db)
        >>> snw = HidroCLVariable('snw', snw.db, snwpc.db)
        >>> snwa = HidroCLVariable('snwa', snwa.db, snwapc.db)
        >>> snwdn = HidroCLVariable('snwdn', snwdn.db, snwdnpc.db)
        >>> snwdt = HidroCLVariable('snwdt', snwdt.db, snwdtpc.db)
        >>> soilm = HidroCLVariable('soilm', soilm.db, soilmdb.db)
        >>> product_path = '/home/user/era5-land'
        >>> vector_path = '/home/user/shapefiles'
        >>> et_log = '/home/user/et.log'
        >>> pet_log = '/home/user/pet.log'
        >>> snw_log = '/home/user/snw.log'
        >>> snwa_log = '/home/user/snwa.log'
        >>> snwdn_log = '/home/user/snwdn.log'
        >>> snwdt_log = '/home/user/snwdt.log'
        >>> soilm_log = '/home/user/soilm.log'
        >>> era5 = Era5_land(et, pet, snw, snwa, snwdn, snwdt,
                             soilm, product_path, vector_path,
                             et_log, pet_log, snw_log, snwa_log,
                             snwdn_log, snwdt_log, soilm_log)
        >>> era5
        "Class to extract ERA5-Land Hourly 0.1 degree"
        >>> era5.run_extraction()


    Args:
        et (HidroCLVariable): HidroCLVariable object with ERA5 evapotranspiration data \n
        pet (HidroCLVariable): HidroCLVariable object with ERA5 potential evapotranspiration data \n
        snw (HidroCLVariable): HidroCLVariable object with ERA5 snow cover data \n
        snwa (HidroCLVariable): HidroCLVariable object with ERA5 snow albedo data \n
        snwdn (HidroCLVariable): HidroCLVariable object with ERA5 snow density data \n
        snwdt (HidroCLVariable): HidroCLVariable object with ERA5 snow depth data \n
        soilm (HidroCLVariable): HidroCLVariable object with ERA5 volumetric soil water data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        et_log (str): Log file path for evapotranspiration data \n
        pet_log (str): Log file path for potential evapotranspiration data \n
        snw_log (str): Log file path for snow cover data \n
        snwa_log (str): Log file path for snow albedo data \n
        snwdn_log (str): Log file path for snow density data \n
        snwdt_log (str): Log file path for snow depth data \n
        soilm_log (str): Log file path for volumetric soil water data \n

    Raises:
        TypeError: If pp, et, pet, snow, snowa, snowdn, snowdt or soilm is not HidroCLVariable objects \n
    """
    if t.check_instance(et, pet, snw, snwa, snwdn, snwdt, soilm):
        self.et = et
        self.pet = pet
        self.snw = snw
        self.snwa = snwa
        self.snwdn = snwdn
        self.snwdt = snwdt
        self.soilm = soilm
        self.et_log = et_log
        self.pet_log = pet_log
        self.snw_log = snw_log
        self.snwa_log = snwa_log
        self.snwdn_log = snwdn_log
        self.snwdt_log = snwdt_log
        self.soilm_log = soilm_log
        self.productname = "ERA5-Land Hourly 0.1 degree"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                    self.pet.indatabase,
                                                    self.snw.indatabase,
                                                    self.snwa.indatabase,
                                                    self.snwdn.indatabase,
                                                    self.snwdt.indatabase,
                                                    self.soilm.indatabase)
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('et, pet, snw, snwa, snwdn, snwdt ' +
                        'and soilm must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2121
2122
2123
2124
2125
2126
2127
2128
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Evapotranspiration records: {len(self.et.indatabase)}.
Evapotranspiration path: {self.et.database}

Potential evapotranspiration records: {len(self.pet.indatabase)}.
Potential evapotranspiration path: {self.pet.database}

Snow cover records: {len(self.snw.indatabase)}.
Snow cover path: {self.snw.database}

Snow albedo records: {len(self.snwa.indatabase)}.
Snow albedo path: {self.snwa.database}

Snow density records: {len(self.snwdn.indatabase)}.
Snow density path: {self.snwdn.database}

Snow depth records: {len(self.snwdt.indatabase)}.
Snow depth path: {self.snwdt.database}

Volumetric soil water records: {len(self.soilm.indatabase)}.
Volumetric soil water path: {self.soilm.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.et.checkdatabase()
        self.pet.checkdatabase()
        self.snw.checkdatabase()
        self.snwa.checkdatabase()
        self.snwdn.checkdatabase()
        self.snwdt.checkdatabase()
        self.soilm.checkdatabase()

    self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                self.pet.indatabase,
                                                self.snw.indatabase,
                                                self.snwa.indatabase,
                                                self.snwdn.indatabase,
                                                self.snwdt.indatabase,
                                                self.soilm.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.et.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'et_era5',
                              self.et.catchment_names, self.et_log,
                              database=self.et.database,
                              pcdatabase=self.et.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='sum',
                              layer="e")

            if scene not in self.pet.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'pet_era5',
                              self.pet.catchment_names, self.pet_log,
                              database=self.pet.database,
                              pcdatabase=self.pet.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='sum',
                              layer="pev")

            if scene not in self.snw.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snw_era5',
                              self.snw.catchment_names, self.snw_log,
                              database=self.snw.database,
                              pcdatabase=self.snw.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="snowc")

            if scene not in self.snwa.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snwa_era5',
                              self.snwa.catchment_names, self.snwa_log,
                              database=self.snwa.database,
                              pcdatabase=self.snwa.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="asn")

            if scene not in self.snwdn.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snwdn_era5',
                              self.snwdn.catchment_names, self.snwdn_log,
                              database=self.snwdn.database,
                              pcdatabase=self.snwdn.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="rsn")

            if scene not in self.snwdt.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snwdt_era5',
                              self.snwdt.catchment_names, self.snwdt_log,
                              database=self.snwdt.database,
                              pcdatabase=self.snwdt.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="sd")

            if scene not in self.soilm.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'soilm_era5',
                              self.soilm.catchment_names, self.soilm_log,
                              database=self.soilm.database,
                              pcdatabase=self.soilm.pcdatabase,
                              vector_path=self.vectorpath,
                              layer=["swvl1", "swvl2", "swvl3", "swvl4"])

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.et.checkdatabase()
        self.pet.checkdatabase()
        self.snw.checkdatabase()
        self.snwa.checkdatabase()
        self.snwdn.checkdatabase()
        self.snwdt.checkdatabase()
        self.soilm.checkdatabase()

    self.common_elements = t.compare_indatabase(self.et.indatabase,
                                                self.pet.indatabase,
                                                self.snw.indatabase,
                                                self.snwa.indatabase,
                                                self.snwdn.indatabase,
                                                self.snwdt.indatabase,
                                                self.soilm.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Era5_pressure

A class to process ERA5 pressure levels hourly to hidrocl variables. Where:

geopotential height 500 hPa: z -> z (10 * m) mean

z: HidroCLVariable object with ERA5 data

Attributes:

Name Type Description
z HidroCLVariable

HidroCLVariable object with ERA5 geopotential height 500 hPa data

z_log str

Log file path for geopotential height data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements / this case the same elements

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for era5)

complete_scenes list

List of complete scenes (1 scene for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
class Era5_pressure:
    """
    A class to process ERA5 pressure levels hourly to hidrocl variables. Where:

    geopotential height 500 hPa: z -> z (10 * m) mean \n

    z: HidroCLVariable object with ERA5 data \n

    Attributes:
        z (HidroCLVariable): HidroCLVariable object with ERA5 geopotential height 500 hPa data \n
        z_log (str): Log file path for geopotential height data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements / this case the same elements \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for era5) \n
        complete_scenes (list): List of complete scenes (1 scene for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, z, product_path, vector_path, z_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5_pressure
            >>> z = HidroCLVariable('z', z.db, zpc.db)
            >>> product_path = '/home/user/era5-pressure-levels'
            >>> vector_path = '/home/user/shapefiles'
            >>> z_log = '/home/user/z.log'
            >>> era5 = Era5_pressure(z, product_path, vector_path, z_log)
            >>> era5
            "Class to extract ERA5 Pressure Levels Hourly 0.25 degree"
            >>> era5.run_extraction()


        Args:
            z (HidroCLVariable): HidroCLVariable object with ERA5 geopotential height data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            z_log (str): Log file path for geopotential height data \n

        Raises:
            TypeError: If z is not HidroCLVariable object \n
        """
        if t.check_instance(z):
            self.z = z
            self.z_log = z_log
            self.productname = "ERA5 Pressure Levels Hourly 0.25 degree"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = self.z.indatabase
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('z must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Geo potential height records: {len(self.z.indatabase)}.
Geo potential height path: {self.z.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.z.checkdatabase()

        self.common_elements = self.z.indatabase

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.z.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'z_era5',
                                  self.z.catchment_names, self.z_log,
                                  database=self.z.database,
                                  pcdatabase=self.z.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="z")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.z.checkdatabase()

        self.common_elements = self.z.indatabase

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(z, product_path, vector_path, z_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5_pressure
>>> z = HidroCLVariable('z', z.db, zpc.db)
>>> product_path = '/home/user/era5-pressure-levels'
>>> vector_path = '/home/user/shapefiles'
>>> z_log = '/home/user/z.log'
>>> era5 = Era5_pressure(z, product_path, vector_path, z_log)
>>> era5
"Class to extract ERA5 Pressure Levels Hourly 0.25 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
z HidroCLVariable

HidroCLVariable object with ERA5 geopotential height data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
z_log str

Log file path for geopotential height data

required

Raises:

Type Description
TypeError

If z is not HidroCLVariable object

Source code in hidrocl/products/__init__.py
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
def __init__(self, z, product_path, vector_path, z_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5_pressure
        >>> z = HidroCLVariable('z', z.db, zpc.db)
        >>> product_path = '/home/user/era5-pressure-levels'
        >>> vector_path = '/home/user/shapefiles'
        >>> z_log = '/home/user/z.log'
        >>> era5 = Era5_pressure(z, product_path, vector_path, z_log)
        >>> era5
        "Class to extract ERA5 Pressure Levels Hourly 0.25 degree"
        >>> era5.run_extraction()


    Args:
        z (HidroCLVariable): HidroCLVariable object with ERA5 geopotential height data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        z_log (str): Log file path for geopotential height data \n

    Raises:
        TypeError: If z is not HidroCLVariable object \n
    """
    if t.check_instance(z):
        self.z = z
        self.z_log = z_log
        self.productname = "ERA5 Pressure Levels Hourly 0.25 degree"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = self.z.indatabase
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('z must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3089
3090
3091
3092
3093
3094
3095
3096
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Geo potential height records: {len(self.z.indatabase)}.
Geo potential height path: {self.z.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.z.checkdatabase()

    self.common_elements = self.z.indatabase

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.z.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'z_era5',
                              self.z.catchment_names, self.z_log,
                              database=self.z.database,
                              pcdatabase=self.z.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="z")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.z.checkdatabase()

    self.common_elements = self.z.indatabase

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Era5_rh

A class to process ERA5 relative humidity hourly to hidrocl variables. Where:

relative humidity (%): rh -> rh (10 * %) mean

rh: HidroCLVariable object with ERA5 data

Attributes:

Name Type Description
rh HidroCLVariable

HidroCLVariable object with ERA5 relative humidity data

rh_log str

Log file path for relative humidity data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements / this case the same elements

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for era5)

complete_scenes list

List of complete scenes (1 scene for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
class Era5_rh:
    """
    A class to process ERA5 relative humidity hourly to hidrocl variables. Where:

    relative humidity (%): rh -> rh (10 * %) mean \n

    rh: HidroCLVariable object with ERA5 data \n

    Attributes:
        rh (HidroCLVariable): HidroCLVariable object with ERA5 relative humidity data \n
        rh_log (str): Log file path for relative humidity data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements / this case the same elements \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for era5) \n
        complete_scenes (list): List of complete scenes (1 scene for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, rh, product_path, vector_path, rh_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5_rh
            >>> rh = HidroCLVariable('rh', rh.db, rhpc.db)
            >>> product_path = '/home/user/era5-rh'
            >>> vector_path = '/home/user/shapefiles'
            >>> rh_log = '/home/user/rh.log'
            >>> era5 = Era5_rh(rh, product_path, vector_path, rh_log)
            >>> era5
            "Class to extract ERA5 Relative humidity Hourly 0.25 degree"
            >>> era5.run_extraction()


        Args:
            rh (HidroCLVariable): HidroCLVariable object with ERA5 relative humidity data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            rh_log (str): Log file path for relative humidity data \n

        Raises:
            TypeError: If rh is not HidroCLVariable object \n
        """
        if t.check_instance(rh):
            self.rh = rh
            self.rh_log = rh_log
            self.productname = "ERA5 Relative humidity Hourly 0.25 degree"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = self.rh.indatabase
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('rh must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Relative humidity records: {len(self.rh.indatabase)}.
Relative humidity path: {self.rh.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.rh.checkdatabase()

        self.common_elements = self.rh.indatabase

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.rh.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'rh_era5',
                                  self.rh.catchment_names, self.rh_log,
                                  database=self.rh.database,
                                  pcdatabase=self.rh.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="rh")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.rh.checkdatabase()

        self.common_elements = self.rh.indatabase

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(rh, product_path, vector_path, rh_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5_rh
>>> rh = HidroCLVariable('rh', rh.db, rhpc.db)
>>> product_path = '/home/user/era5-rh'
>>> vector_path = '/home/user/shapefiles'
>>> rh_log = '/home/user/rh.log'
>>> era5 = Era5_rh(rh, product_path, vector_path, rh_log)
>>> era5
"Class to extract ERA5 Relative humidity Hourly 0.25 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
rh HidroCLVariable

HidroCLVariable object with ERA5 relative humidity data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
rh_log str

Log file path for relative humidity data

required

Raises:

Type Description
TypeError

If rh is not HidroCLVariable object

Source code in hidrocl/products/__init__.py
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
def __init__(self, rh, product_path, vector_path, rh_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5_rh
        >>> rh = HidroCLVariable('rh', rh.db, rhpc.db)
        >>> product_path = '/home/user/era5-rh'
        >>> vector_path = '/home/user/shapefiles'
        >>> rh_log = '/home/user/rh.log'
        >>> era5 = Era5_rh(rh, product_path, vector_path, rh_log)
        >>> era5
        "Class to extract ERA5 Relative humidity Hourly 0.25 degree"
        >>> era5.run_extraction()


    Args:
        rh (HidroCLVariable): HidroCLVariable object with ERA5 relative humidity data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        rh_log (str): Log file path for relative humidity data \n

    Raises:
        TypeError: If rh is not HidroCLVariable object \n
    """
    if t.check_instance(rh):
        self.rh = rh
        self.rh_log = rh_log
        self.productname = "ERA5 Relative humidity Hourly 0.25 degree"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = self.rh.indatabase
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('rh must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3258
3259
3260
3261
3262
3263
3264
3265
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Relative humidity records: {len(self.rh.indatabase)}.
Relative humidity path: {self.rh.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.rh.checkdatabase()

    self.common_elements = self.rh.indatabase

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.rh.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'rh_era5',
                              self.rh.catchment_names, self.rh_log,
                              database=self.rh.database,
                              pcdatabase=self.rh.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="rh")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.rh.checkdatabase()

    self.common_elements = self.rh.indatabase

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Era5pplen

A class to process ERA5 hourly to hidrocl variables. Where:

total precipitation: tp -> pp (10000 * m) sum

ppmax: HidroCLVariable object with ERA5 data

Attributes:

Name Type Description
pplen HidroCLVariable

HidroCLVariable object with ERA5 precipitation length data

pplen_log str

Log file path for precipitation length data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between pp database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for era5)

complete_scenes list

List of complete scenes (1 scene for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
class Era5pplen:
    """
    A class to process ERA5 hourly to hidrocl variables. Where:

    total precipitation: tp -> pp (10000 * m) sum \n

    ppmax: HidroCLVariable object with ERA5 data \n

    Attributes:
        pplen (HidroCLVariable): HidroCLVariable object with ERA5 precipitation length data \n
        pplen_log (str): Log file path for precipitation length data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between pp database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for era5) \n
        complete_scenes (list): List of complete scenes (1 scene for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pplen, product_path, vector_path, pplen_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5pplen
            >>> pplen = HidroCLVariable('pplen', pplen.db, pplenpc.db)
            >>> product_path = '/home/user/era5'
            >>> vector_path = '/home/user/shapefiles'
            >>> pplen_log = '/home/user/pp.log'
            >>> era5 = Era5(pplen, product_path, vector_path,
                            pplen_log)
            >>> era5
            "Class to extract ERA5 precipitation 3-Hour length 0.25 degree"
            >>> era5.run_extraction()


        Args:
            ppmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum precipitation data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            ppmax_log (str): Log file path for maximum precipitation data \n

        Raises:
            TypeError: If pplen is not HidroCLVariable objects \n
        """
        if t.check_instance(pplen):
            self.pplen = pplen
            self.pplen_log = pplen_log
            self.productname = "ERA5 precipitation 3-Hour length 0.25 degree"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.pplen.indatabase)
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('pplen must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Precipitation length records: {len(self.pplen.indatabase)}.
Precipitation length path: {self.pplen.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pplen.checkdatabase()

        self.common_elements = t.compare_indatabase(self.pplen.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pplen.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'pp_era5',
                                  self.pplen.catchment_names, self.pplen_log,
                                  database=self.pplen.database,
                                  pcdatabase=self.pplen.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='len',
                                  layer="tp",
                                  prec_threshold=1)

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pplen.checkdatabase()

        self.common_elements = t.compare_indatabase(self.pplen.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(pplen, product_path, vector_path, pplen_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5pplen
>>> pplen = HidroCLVariable('pplen', pplen.db, pplenpc.db)
>>> product_path = '/home/user/era5'
>>> vector_path = '/home/user/shapefiles'
>>> pplen_log = '/home/user/pp.log'
>>> era5 = Era5(pplen, product_path, vector_path,
                pplen_log)
>>> era5
"Class to extract ERA5 precipitation 3-Hour length 0.25 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
ppmax HidroCLVariable

HidroCLVariable object with ERA5 maximum precipitation data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
ppmax_log str

Log file path for maximum precipitation data

required

Raises:

Type Description
TypeError

If pplen is not HidroCLVariable objects

Source code in hidrocl/products/__init__.py
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
def __init__(self, pplen, product_path, vector_path, pplen_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5pplen
        >>> pplen = HidroCLVariable('pplen', pplen.db, pplenpc.db)
        >>> product_path = '/home/user/era5'
        >>> vector_path = '/home/user/shapefiles'
        >>> pplen_log = '/home/user/pp.log'
        >>> era5 = Era5(pplen, product_path, vector_path,
                        pplen_log)
        >>> era5
        "Class to extract ERA5 precipitation 3-Hour length 0.25 degree"
        >>> era5.run_extraction()


    Args:
        ppmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum precipitation data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        ppmax_log (str): Log file path for maximum precipitation data \n

    Raises:
        TypeError: If pplen is not HidroCLVariable objects \n
    """
    if t.check_instance(pplen):
        self.pplen = pplen
        self.pplen_log = pplen_log
        self.productname = "ERA5 precipitation 3-Hour length 0.25 degree"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.pplen.indatabase)
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('pplen must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2918
2919
2920
2921
2922
2923
2924
2925
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Precipitation length records: {len(self.pplen.indatabase)}.
Precipitation length path: {self.pplen.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pplen.checkdatabase()

    self.common_elements = t.compare_indatabase(self.pplen.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pplen.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'pp_era5',
                              self.pplen.catchment_names, self.pplen_log,
                              database=self.pplen.database,
                              pcdatabase=self.pplen.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='len',
                              layer="tp",
                              prec_threshold=1)

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pplen.checkdatabase()

    self.common_elements = t.compare_indatabase(self.pplen.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Era5ppmax

A class to process ERA5 hourly to hidrocl variables. Where:

total precipitation: tp -> pp (10000 * m) sum

ppmax: HidroCLVariable object with ERA5 data

Attributes:

Name Type Description
ppmax HidroCLVariable

HidroCLVariable object with ERA5 maximum precipitation data

ppmax_log str

Log file path for maximum precipitation data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between pp database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for era5)

complete_scenes list

List of complete scenes (1 scene for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
class Era5ppmax:
    """
    A class to process ERA5 hourly to hidrocl variables. Where:

    total precipitation: tp -> pp (10000 * m) sum \n

    ppmax: HidroCLVariable object with ERA5 data \n

    Attributes:
        ppmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum precipitation data \n
        ppmax_log (str): Log file path for maximum precipitation data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between pp database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for era5) \n
        complete_scenes (list): List of complete scenes (1 scene for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, ppmax, product_path, vector_path, ppmax_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Era5ppmax
            >>> ppmax = HidroCLVariable('ppmax', ppmax.db, ppmaxpc.db)
            >>> product_path = '/home/user/era5'
            >>> vector_path = '/home/user/shapefiles'
            >>> ppmax_log = '/home/user/pp.log'
            >>> era5 = Era5(ppmax, product_path, vector_path,
                            ppmax_log)
            >>> era5
            "Class to extract ERA5 max precipitation 3-Hour 0.25 degree"
            >>> era5.run_extraction()


        Args:
            ppmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum precipitation data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            ppmax_log (str): Log file path for maximum precipitation data \n

        Raises:
            TypeError: If ppmax is not HidroCLVariable objects \n
        """
        if t.check_instance(ppmax):
            self.ppmax = ppmax
            self.ppmax_log = ppmax_log
            self.productname = "ERA5 max precipitation 3-Hour 0.25 degree"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.ppmax.indatabase)
            self.product_files = t.read_product_files(self.productpath, "era5")
            self.product_ids = t.get_product_ids(self.product_files, "era5")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="era5")
        else:
            raise TypeError('ppmax must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Maximum precipitation records: {len(self.ppmax.indatabase)}.
Maximum precipitation path: {self.ppmax.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ppmax.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ppmax.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.ppmax.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'maxpp_eraacc',
                                  self.ppmax.catchment_names, self.ppmax_log,
                                  database=self.ppmax.database,
                                  pcdatabase=self.ppmax.pcdatabase,
                                  vector_path=self.vectorpath,
                                  aggregation='max',
                                  layer="tp")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ppmax.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ppmax.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='era5',
                              log_file=log_file)

__init__(ppmax, product_path, vector_path, ppmax_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Era5ppmax
>>> ppmax = HidroCLVariable('ppmax', ppmax.db, ppmaxpc.db)
>>> product_path = '/home/user/era5'
>>> vector_path = '/home/user/shapefiles'
>>> ppmax_log = '/home/user/pp.log'
>>> era5 = Era5(ppmax, product_path, vector_path,
                ppmax_log)
>>> era5
"Class to extract ERA5 max precipitation 3-Hour 0.25 degree"
>>> era5.run_extraction()

Parameters:

Name Type Description Default
ppmax HidroCLVariable

HidroCLVariable object with ERA5 maximum precipitation data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
ppmax_log str

Log file path for maximum precipitation data

required

Raises:

Type Description
TypeError

If ppmax is not HidroCLVariable objects

Source code in hidrocl/products/__init__.py
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
def __init__(self, ppmax, product_path, vector_path, ppmax_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Era5ppmax
        >>> ppmax = HidroCLVariable('ppmax', ppmax.db, ppmaxpc.db)
        >>> product_path = '/home/user/era5'
        >>> vector_path = '/home/user/shapefiles'
        >>> ppmax_log = '/home/user/pp.log'
        >>> era5 = Era5(ppmax, product_path, vector_path,
                        ppmax_log)
        >>> era5
        "Class to extract ERA5 max precipitation 3-Hour 0.25 degree"
        >>> era5.run_extraction()


    Args:
        ppmax (HidroCLVariable): HidroCLVariable object with ERA5 maximum precipitation data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        ppmax_log (str): Log file path for maximum precipitation data \n

    Raises:
        TypeError: If ppmax is not HidroCLVariable objects \n
    """
    if t.check_instance(ppmax):
        self.ppmax = ppmax
        self.ppmax_log = ppmax_log
        self.productname = "ERA5 max precipitation 3-Hour 0.25 degree"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.ppmax.indatabase)
        self.product_files = t.read_product_files(self.productpath, "era5")
        self.product_ids = t.get_product_ids(self.product_files, "era5")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "era5")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="era5")
    else:
        raise TypeError('ppmax must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2747
2748
2749
2750
2751
2752
2753
2754
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Maximum precipitation records: {len(self.ppmax.indatabase)}.
Maximum precipitation path: {self.ppmax.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ppmax.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ppmax.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.ppmax.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'maxpp_eraacc',
                              self.ppmax.catchment_names, self.ppmax_log,
                              database=self.ppmax.database,
                              pcdatabase=self.ppmax.pcdatabase,
                              vector_path=self.vectorpath,
                              aggregation='max',
                              layer="tp")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ppmax.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ppmax.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "era5")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='era5',
                          log_file=log_file)

Gfs

A class to process GFS to hidrocl variables. The used variables are: - gh: Geopotential height - prate: Precipitation rate - r2: 2m relative humidity - t2m: 2m temperature - u10: 10m U wind component - v10: 10m V wind component

Attributes:

Name Type Description
db0 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe) of day 0

db1 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe) of day 1

db2 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe) of day 2

db3 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe) of day 3

db4 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe) of day 4

db_log str

Log file path for variable data

variable str

Variable name

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for era5)

complete_scenes list

List of complete scenes (1 scene for era5)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for era5)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
class Gfs:
    """
    A class to process GFS to hidrocl variables. The used variables are:
    - gh: Geopotential height
    - prate: Precipitation rate
    - r2: 2m relative humidity
    - t2m: 2m temperature
    - u10: 10m U wind component
    - v10: 10m V wind component

    Attributes:
        db0 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) of day 0 \n
        db1 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) of day 1 \n
        db2 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) of day 2 \n
        db3 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) of day 3 \n
        db4 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) of day 4 \n
        db_log (str): Log file path for variable data \n
        variable (str): Variable name \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for era5) \n
        complete_scenes (list): List of complete scenes (1 scene for era5) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for era5) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, db0, db1, db2, db3, db4,
                 db_log, variable, aggregation,
                 product_path, vectorpath,
                 prec_threshold=1):
        """
        Examples:

        Args:
            db0 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
            db1 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
            db2 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
            db3 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
            db4 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
            db_log (str): Log file path for extracted data \n
            variable (str): Variable name \n
            aggregation (str): Aggregation type \n
            product_path (str): Path to the product folder where the product files are located \n
            vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n

        Raises:
            TypeError: If db is not HidroCLVariable objects \n
        """
        if t.check_instance(db0, db1, db2, db3, db4):
            self.db0 = db0
            self.db1 = db1
            self.db2 = db2
            self.db3 = db3
            self.db4 = db4
            self.db_log = db_log
            self.variable = variable
            self.aggregation = aggregation
            self.productname = "GFS 0.5º"
            self.productpath = product_path
            self.vectorpath = vectorpath
            self.prec_threshold = prec_threshold
            self.common_elements = t.compare_indatabase(self.db0.indatabase, self.db1.indatabase,
                                                        self.db2.indatabase, self.db3.indatabase, self.db4.indatabase)
            self.product_files = t.read_product_files(self.productpath, "gfs", variable=self.variable)
            self.product_ids = t.get_product_ids(self.product_files, "gfs")

            self.all_scenes = t.check_product_files(self.product_ids)

            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "gfs")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what="gfs")
        else:
            raise TypeError('db0, db1, db2, db3, db4 must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Database records day0: {len(self.db0.indatabase)}.
Database path day 0: {self.db0.database}

Database records day1: {len(self.db1.indatabase)}.
Database path day 1: {self.db1.database}

Database records day2: {len(self.db2.indatabase)}.
Database path day 2: {self.db2.database}

Database records day3: {len(self.db3.indatabase)}.
Database path day 3: {self.db3.database}

Database records day4: {len(self.db4.indatabase)}.
Database path day 4: {self.db4.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.db0.checkdatabase()
            self.db1.checkdatabase()
            self.db2.checkdatabase()
            self.db3.checkdatabase()
            self.db4.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, what="gfs")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                days = []
                if scene not in self.db0.indatabase:
                    days.append(0)
                if scene not in self.db1.indatabase:
                    days.append(1)
                if scene not in self.db2.indatabase:
                    days.append(2)
                if scene not in self.db3.indatabase:
                    days.append(3)
                if scene not in self.db4.indatabase:
                    days.append(4)

                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'gfs',
                              self.db0.catchment_names, self.db_log,
                              database=None,
                              databases=[self.db0.database,
                                         self.db1.database,
                                         self.db2.database,
                                         self.db3.database,
                                         self.db4.database],
                              pcdatabase=None,
                              pcdatabases=[self.db0.pcdatabase,
                                           self.db1.pcdatabase,
                                           self.db2.pcdatabase,
                                           self.db3.pcdatabase,
                                           self.db4.pcdatabase],
                              vector_path=self.vectorpath,
                              layer=self.variable,
                              aggregation=self.aggregation,
                              days=days,
                              prec_threshold=self.prec_threshold)

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.db0.checkdatabase()
            self.db1.checkdatabase()
            self.db2.checkdatabase()
            self.db3.checkdatabase()
            self.db4.checkdatabase()

        self.common_elements = t.compare_indatabase(self.db0.database,
                                                    self.db1.database,
                                                    self.db2.database,
                                                    self.db3.database,
                                                    self.db4.database)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gfs")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='gfs',
                              log_file=log_file)

__init__(db0, db1, db2, db3, db4, db_log, variable, aggregation, product_path, vectorpath, prec_threshold=1)

Examples:

Parameters:

Name Type Description Default
db0 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe)

required
db1 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe)

required
db2 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe)

required
db3 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe)

required
db4 HidroCLVariable

HidroCLVariable object with GFS variable (see avobe)

required
db_log str

Log file path for extracted data

required
variable str

Variable name

required
aggregation str

Aggregation type

required
product_path str

Path to the product folder where the product files are located

required
vectorpath str

Path to the vector folder with Shapefile with areas to be processed

required

Raises:

Type Description
TypeError

If db is not HidroCLVariable objects

Source code in hidrocl/products/__init__.py
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
def __init__(self, db0, db1, db2, db3, db4,
             db_log, variable, aggregation,
             product_path, vectorpath,
             prec_threshold=1):
    """
    Examples:

    Args:
        db0 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
        db1 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
        db2 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
        db3 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
        db4 (HidroCLVariable): HidroCLVariable object with GFS variable (see avobe) \n
        db_log (str): Log file path for extracted data \n
        variable (str): Variable name \n
        aggregation (str): Aggregation type \n
        product_path (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n

    Raises:
        TypeError: If db is not HidroCLVariable objects \n
    """
    if t.check_instance(db0, db1, db2, db3, db4):
        self.db0 = db0
        self.db1 = db1
        self.db2 = db2
        self.db3 = db3
        self.db4 = db4
        self.db_log = db_log
        self.variable = variable
        self.aggregation = aggregation
        self.productname = "GFS 0.5º"
        self.productpath = product_path
        self.vectorpath = vectorpath
        self.prec_threshold = prec_threshold
        self.common_elements = t.compare_indatabase(self.db0.indatabase, self.db1.indatabase,
                                                    self.db2.indatabase, self.db3.indatabase, self.db4.indatabase)
        self.product_files = t.read_product_files(self.productpath, "gfs", variable=self.variable)
        self.product_ids = t.get_product_ids(self.product_files, "gfs")

        self.all_scenes = t.check_product_files(self.product_ids)

        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "gfs")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what="gfs")
    else:
        raise TypeError('db0, db1, db2, db3, db4 must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3441
3442
3443
3444
3445
3446
3447
3448
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Database records day0: {len(self.db0.indatabase)}.
Database path day 0: {self.db0.database}

Database records day1: {len(self.db1.indatabase)}.
Database path day 1: {self.db1.database}

Database records day2: {len(self.db2.indatabase)}.
Database path day 2: {self.db2.database}

Database records day3: {len(self.db3.indatabase)}.
Database path day 3: {self.db3.database}

Database records day4: {len(self.db4.indatabase)}.
Database path day 4: {self.db4.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.db0.checkdatabase()
        self.db1.checkdatabase()
        self.db2.checkdatabase()
        self.db3.checkdatabase()
        self.db4.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, what="gfs")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            days = []
            if scene not in self.db0.indatabase:
                days.append(0)
            if scene not in self.db1.indatabase:
                days.append(1)
            if scene not in self.db2.indatabase:
                days.append(2)
            if scene not in self.db3.indatabase:
                days.append(3)
            if scene not in self.db4.indatabase:
                days.append(4)

            e.zonal_stats(scene, scenes_path,
                          temp_dir, 'gfs',
                          self.db0.catchment_names, self.db_log,
                          database=None,
                          databases=[self.db0.database,
                                     self.db1.database,
                                     self.db2.database,
                                     self.db3.database,
                                     self.db4.database],
                          pcdatabase=None,
                          pcdatabases=[self.db0.pcdatabase,
                                       self.db1.pcdatabase,
                                       self.db2.pcdatabase,
                                       self.db3.pcdatabase,
                                       self.db4.pcdatabase],
                          vector_path=self.vectorpath,
                          layer=self.variable,
                          aggregation=self.aggregation,
                          days=days,
                          prec_threshold=self.prec_threshold)

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.db0.checkdatabase()
        self.db1.checkdatabase()
        self.db2.checkdatabase()
        self.db3.checkdatabase()
        self.db4.checkdatabase()

    self.common_elements = t.compare_indatabase(self.db0.database,
                                                self.db1.database,
                                                self.db2.database,
                                                self.db3.database,
                                                self.db4.database)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gfs")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='gfs',
                          log_file=log_file)

Gldas_noah

A class to process GLDAS_NOAH025_3H to hidrocl variables

Attributes:

Name Type Description
snow HidroCLVariable

HidroCLVariable with the GLDAS snow data

temp HidroCLVariable

HidroCLVariable with the GLDAS temperature data

et HidroCLVariable

HidroCLVariable with the GLDAS evapotranspiration data

soilm HidroCLVariable

HidroCLVariable with the GLDAS soil moisture data

snow_log str

Path to the log file for the snow extraction

temp_log str

Path to the log file for the temperature extraction

et_log str

Path to the log file for the evapotranspiration extraction

soilm_log str

Path to the log file for the soil moisture extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the snow, temp, et and soilm databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 8 scenes for gldas)

complete_scenes list

List of complete scenes (8 scenes for gldas)

incomplete_scenes list

List of incomplete scenes (less than 8 scenes for gldas)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
class Gldas_noah:
    """
    A class to process GLDAS_NOAH025_3H to hidrocl variables

    Attributes:
        snow (HidroCLVariable): HidroCLVariable with the GLDAS snow data \n
        temp (HidroCLVariable): HidroCLVariable with the GLDAS temperature data \n
        et (HidroCLVariable): HidroCLVariable with the GLDAS evapotranspiration data \n
        soilm (HidroCLVariable): HidroCLVariable with the GLDAS soil moisture data \n
        snow_log (str): Path to the log file for the snow extraction \n
        temp_log (str): Path to the log file for the temperature extraction \n
        et_log (str): Path to the log file for the evapotranspiration extraction \n
        soilm_log (str): Path to the log file for the soil moisture extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the snow, temp, et and soilm databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 8 scenes for gldas) \n
        complete_scenes (list): List of complete scenes (8 scenes for gldas) \n
        incomplete_scenes (list): List of incomplete scenes (less than 8 scenes for gldas) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, snow, temp, et, soilm, product_path,
                 vector_path, snow_log, temp_log, et_log, soilm_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Gldas_noah
            >>> snow = HidroCLVariable('snow', 'snow.db', 'snow_pc.db')
            >>> temp = HidroCLVariable('temp', 'temp.db', 'temp_pc.db')
            >>> et = HidroCLVariable('et', 'et.db', 'et.db')
            >>> soilm = HidroCLVariable('soilm', 'soilm.db', 'soilm_pc.db')
            >>> product_path = '/home/user/data/GLDAS_NOAH025_3H'
            >>> vector_path = '/home/user/data/vector.shp'
            >>> snow_log = '/home/user/data/logs/snow.log'
            >>> temp_log = '/home/user/data/logs/temp.log'
            >>> et_log = '/home/user/data/logs/et.log'
            >>> soilm_log = '/home/user/data/logs/soilm.log'
            >>> gldas = Gldas_noah(snow, temp, et, soilm, product_path,
            ...                    vector_path, snow_log, temp_log, et_log, soilm_log)
            >>> gldas
            "Class to extract GLDAS Noah Land Surface Model L4 3 hourly 0.25 degree Version 2.1"

        Args:
            snow (HidroCLVariable): HidroCLVariable with the GLDAS snow data \n
            temp (HidroCLVariable): HidroCLVariable with the GLDAS temperature data \n
            et (HidroCLVariable): HidroCLVariable with the GLDAS evapotranspiration data \n
            soilm (HidroCLVariable): HidroCLVariable with the GLDAS soil moisture data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            snow_log (str): Path to the log file for the snow extraction \n
            temp_log (str): Path to the log file for the temperature extraction \n
            et_log (str): Path to the log file for the evapotranspiration extraction \n
            soilm_log (str): Path to the log file for the soil moisture extraction \n

        Raises:
            TypeError: If snow, temp, et or soilm is not a HidroCLVariable
        """
        if t.check_instance(snow, temp, et, soilm):
            self.snow = snow
            self.temp = temp
            self.et = et
            self.soilm = soilm
            self.snow_log = snow_log
            self.temp_log = temp_log
            self.et_log = et_log
            self.soilm_log = soilm_log
            self.productname = "GLDAS Noah Land Surface Model L4 3 hourly 0.25 degree Version 2.1"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                        self.temp.indatabase,
                                                        self.et.indatabase,
                                                        self.soilm.indatabase)
            self.product_files = t.read_product_files(self.productpath, "gldas")
            self.product_ids = t.get_product_ids(self.product_files, "gldas")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "gldas")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='gldas')
        else:
            raise TypeError('snow, temp, et and soilm must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Snow records: {len(self.snow.indatabase)}.
Snow path: {self.snow.database}

Temperature records: {len(self.temp.indatabase)}.
Temperature path: {self.temp.database}

Evapotranspiration records: {len(self.et.indatabase)}.
Evapotranspiration path: {self.et.database}

Soil moisture records: {len(self.soilm.indatabase)}.
Soil moisture path: {self.soilm.database}
                '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.snow.checkdatabase()
            self.temp.checkdatabase()
            self.et.checkdatabase()
            self.soilm.checkdatabase()

        self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                    self.temp.indatabase,
                                                    self.et.indatabase,
                                                    self.soilm.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gldas")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.snow.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snow_gldas',
                                  self.snow.catchment_names, self.snow_log,
                                  database=self.snow.database,
                                  pcdatabase=self.snow.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="SWE_inst")

                if scene not in self.temp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'temp_gldas',
                                  self.temp.catchment_names, self.temp_log,
                                  database=self.temp.database,
                                  pcdatabase=self.temp.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="Tair_f_inst")

                if scene not in self.et.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'et_gldas',
                                  self.et.catchment_names, self.et_log,
                                  database=self.et.database,
                                  pcdatabase=self.et.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="ECanop_tavg")

                if scene not in self.soilm.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'soilm_gldas',
                                  self.soilm.catchment_names, self.soilm_log,
                                  database=self.soilm.database,
                                  pcdatabase=self.soilm.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer=["SoilMoi0_10cm_inst",
                                         "SoilMoi10_40cm_inst",
                                         "SoilMoi40_100cm_inst",
                                         "SoilMoi100_200cm_inst"])

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.snow.checkdatabase()
            self.temp.checkdatabase()
            self.et.checkdatabase()
            self.soilm.checkdatabase()

        self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                    self.temp.indatabase,
                                                    self.et.indatabase,
                                                    self.soilm.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gldas")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='gldas',
                              log_file=log_file)

__init__(snow, temp, et, soilm, product_path, vector_path, snow_log, temp_log, et_log, soilm_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Gldas_noah
>>> snow = HidroCLVariable('snow', 'snow.db', 'snow_pc.db')
>>> temp = HidroCLVariable('temp', 'temp.db', 'temp_pc.db')
>>> et = HidroCLVariable('et', 'et.db', 'et.db')
>>> soilm = HidroCLVariable('soilm', 'soilm.db', 'soilm_pc.db')
>>> product_path = '/home/user/data/GLDAS_NOAH025_3H'
>>> vector_path = '/home/user/data/vector.shp'
>>> snow_log = '/home/user/data/logs/snow.log'
>>> temp_log = '/home/user/data/logs/temp.log'
>>> et_log = '/home/user/data/logs/et.log'
>>> soilm_log = '/home/user/data/logs/soilm.log'
>>> gldas = Gldas_noah(snow, temp, et, soilm, product_path,
...                    vector_path, snow_log, temp_log, et_log, soilm_log)
>>> gldas
"Class to extract GLDAS Noah Land Surface Model L4 3 hourly 0.25 degree Version 2.1"

Parameters:

Name Type Description Default
snow HidroCLVariable

HidroCLVariable with the GLDAS snow data

required
temp HidroCLVariable

HidroCLVariable with the GLDAS temperature data

required
et HidroCLVariable

HidroCLVariable with the GLDAS evapotranspiration data

required
soilm HidroCLVariable

HidroCLVariable with the GLDAS soil moisture data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
snow_log str

Path to the log file for the snow extraction

required
temp_log str

Path to the log file for the temperature extraction

required
et_log str

Path to the log file for the evapotranspiration extraction

required
soilm_log str

Path to the log file for the soil moisture extraction

required

Raises:

Type Description
TypeError

If snow, temp, et or soilm is not a HidroCLVariable

Source code in hidrocl/products/__init__.py
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
def __init__(self, snow, temp, et, soilm, product_path,
             vector_path, snow_log, temp_log, et_log, soilm_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Gldas_noah
        >>> snow = HidroCLVariable('snow', 'snow.db', 'snow_pc.db')
        >>> temp = HidroCLVariable('temp', 'temp.db', 'temp_pc.db')
        >>> et = HidroCLVariable('et', 'et.db', 'et.db')
        >>> soilm = HidroCLVariable('soilm', 'soilm.db', 'soilm_pc.db')
        >>> product_path = '/home/user/data/GLDAS_NOAH025_3H'
        >>> vector_path = '/home/user/data/vector.shp'
        >>> snow_log = '/home/user/data/logs/snow.log'
        >>> temp_log = '/home/user/data/logs/temp.log'
        >>> et_log = '/home/user/data/logs/et.log'
        >>> soilm_log = '/home/user/data/logs/soilm.log'
        >>> gldas = Gldas_noah(snow, temp, et, soilm, product_path,
        ...                    vector_path, snow_log, temp_log, et_log, soilm_log)
        >>> gldas
        "Class to extract GLDAS Noah Land Surface Model L4 3 hourly 0.25 degree Version 2.1"

    Args:
        snow (HidroCLVariable): HidroCLVariable with the GLDAS snow data \n
        temp (HidroCLVariable): HidroCLVariable with the GLDAS temperature data \n
        et (HidroCLVariable): HidroCLVariable with the GLDAS evapotranspiration data \n
        soilm (HidroCLVariable): HidroCLVariable with the GLDAS soil moisture data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        snow_log (str): Path to the log file for the snow extraction \n
        temp_log (str): Path to the log file for the temperature extraction \n
        et_log (str): Path to the log file for the evapotranspiration extraction \n
        soilm_log (str): Path to the log file for the soil moisture extraction \n

    Raises:
        TypeError: If snow, temp, et or soilm is not a HidroCLVariable
    """
    if t.check_instance(snow, temp, et, soilm):
        self.snow = snow
        self.temp = temp
        self.et = et
        self.soilm = soilm
        self.snow_log = snow_log
        self.temp_log = temp_log
        self.et_log = et_log
        self.soilm_log = soilm_log
        self.productname = "GLDAS Noah Land Surface Model L4 3 hourly 0.25 degree Version 2.1"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                    self.temp.indatabase,
                                                    self.et.indatabase,
                                                    self.soilm.indatabase)
        self.product_files = t.read_product_files(self.productpath, "gldas")
        self.product_ids = t.get_product_ids(self.product_files, "gldas")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "gldas")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='gldas')
    else:
        raise TypeError('snow, temp, et and soilm must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1359
1360
1361
1362
1363
1364
1365
1366
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

Snow records: {len(self.snow.indatabase)}.
Snow path: {self.snow.database}

Temperature records: {len(self.temp.indatabase)}.
Temperature path: {self.temp.database}

Evapotranspiration records: {len(self.et.indatabase)}.
Evapotranspiration path: {self.et.database}

Soil moisture records: {len(self.soilm.indatabase)}.
Soil moisture path: {self.soilm.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.snow.checkdatabase()
        self.temp.checkdatabase()
        self.et.checkdatabase()
        self.soilm.checkdatabase()

    self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                self.temp.indatabase,
                                                self.et.indatabase,
                                                self.soilm.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gldas")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.snow.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snow_gldas',
                              self.snow.catchment_names, self.snow_log,
                              database=self.snow.database,
                              pcdatabase=self.snow.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="SWE_inst")

            if scene not in self.temp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'temp_gldas',
                              self.temp.catchment_names, self.temp_log,
                              database=self.temp.database,
                              pcdatabase=self.temp.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="Tair_f_inst")

            if scene not in self.et.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'et_gldas',
                              self.et.catchment_names, self.et_log,
                              database=self.et.database,
                              pcdatabase=self.et.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="ECanop_tavg")

            if scene not in self.soilm.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'soilm_gldas',
                              self.soilm.catchment_names, self.soilm_log,
                              database=self.soilm.database,
                              pcdatabase=self.soilm.pcdatabase,
                              vector_path=self.vectorpath,
                              layer=["SoilMoi0_10cm_inst",
                                     "SoilMoi10_40cm_inst",
                                     "SoilMoi40_100cm_inst",
                                     "SoilMoi100_200cm_inst"])

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.snow.checkdatabase()
        self.temp.checkdatabase()
        self.et.checkdatabase()
        self.soilm.checkdatabase()

    self.common_elements = t.compare_indatabase(self.snow.indatabase,
                                                self.temp.indatabase,
                                                self.et.indatabase,
                                                self.soilm.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements, "gldas")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='gldas',
                          log_file=log_file)

Gpm_3imrghhl

A class to process GPM_3IMRGHHL to hidrocl variables

Attributes:

Name Type Description
pp HidroCLVariable

HidroCLVariable object with IMERG precipitation data

pp_log str

Path to the log file for IMERG precipitation data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

common_elements (list): Elements in precipitation database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 48 scenes for imerg)

complete_scenes list

List of complete scenes (48 scenes for imerg)

incomplete_scenes list

List of incomplete scenes (less than 48 scenes for imerg)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
class Gpm_3imrghhl:
    """
    A class to process GPM_3IMRGHHL to hidrocl variables

    Attributes:
        pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
        pp_log (str): Path to the log file for IMERG precipitation data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): common_elements (list): Elements in precipitation database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 48 scenes for imerg) \n
        complete_scenes (list): List of complete scenes (48 scenes for imerg) \n
        incomplete_scenes (list): List of incomplete scenes (less than 48 scenes for imerg) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pp, product_path, vector_path, pp_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Gpm_3imrghhl
            >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
            >>> gpm = Gpm_3imrghhl(pp, product_path, vector_path, pp_log)
            >>> gpm
            "Class to extract GPM IMERG Late Precipitation L3 Half Hourly 0.1 degree Version 0.6"

        Args:
            pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            pp_log (str): Path to the log file for IMERG precipitation data \n

        Raises:
            TypeError: If pp is not a HidroCLVariable object
        """
        if t.check_instance(pp):
            self.pp = pp
            self.pp_log = pp_log
            self.productname = "GPM IMERG Late Precipitation L3 Half Hourly 0.1 degree Version 0.6"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = self.pp.indatabase
            self.product_files = t.read_product_files(self.productpath, "imerg")
            self.product_ids = t.get_product_ids(self.product_files, "imerg")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "imerg")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='imerg')
        else:
            raise TypeError('pp must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

IMERG precipitation records: {len(self.pp.indatabase)}.
IMERG precipitation database path: {self.pp.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imerg")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'imerg',
                                  self.pp.catchment_names, self.pp_log,
                                  database=self.pp.database,
                                  pcdatabase=self.pp.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="Grid_precipitationCal")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imerg")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='imerg',
                              log_file=log_file)

__init__(pp, product_path, vector_path, pp_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Gpm_3imrghhl
>>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
>>> gpm = Gpm_3imrghhl(pp, product_path, vector_path, pp_log)
>>> gpm
"Class to extract GPM IMERG Late Precipitation L3 Half Hourly 0.1 degree Version 0.6"

Parameters:

Name Type Description Default
pp HidroCLVariable

HidroCLVariable object with IMERG precipitation data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
pp_log str

Path to the log file for IMERG precipitation data

required

Raises:

Type Description
TypeError

If pp is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
def __init__(self, pp, product_path, vector_path, pp_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Gpm_3imrghhl
        >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
        >>> gpm = Gpm_3imrghhl(pp, product_path, vector_path, pp_log)
        >>> gpm
        "Class to extract GPM IMERG Late Precipitation L3 Half Hourly 0.1 degree Version 0.6"

    Args:
        pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        pp_log (str): Path to the log file for IMERG precipitation data \n

    Raises:
        TypeError: If pp is not a HidroCLVariable object
    """
    if t.check_instance(pp):
        self.pp = pp
        self.pp_log = pp_log
        self.productname = "GPM IMERG Late Precipitation L3 Half Hourly 0.1 degree Version 0.6"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = self.pp.indatabase
        self.product_files = t.read_product_files(self.productpath, "imerg")
        self.product_ids = t.get_product_ids(self.product_files, "imerg")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "imerg")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='imerg')
    else:
        raise TypeError('pp must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1014
1015
1016
1017
1018
1019
1020
1021
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

IMERG precipitation records: {len(self.pp.indatabase)}.
IMERG precipitation database path: {self.pp.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imerg")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'imerg',
                              self.pp.catchment_names, self.pp_log,
                              database=self.pp.database,
                              pcdatabase=self.pp.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="Grid_precipitationCal")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imerg")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='imerg',
                          log_file=log_file)

ImergGIS

A class to process GPM_3IMRGHHL GIS to hidrocl variables.

The extracted variable is precipitatation [mm] with a scale factor of 10.

Attributes:

Name Type Description
pp HidroCLVariable

HidroCLVariable object with IMERG precipitation data

pp_log str

Path to the log file for IMERG precipitation data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

common_elements (list): Elements in precipitation database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 48 scenes for imerg)

complete_scenes list

List of complete scenes (48 scenes for imerg)

incomplete_scenes list

List of incomplete scenes (less than 48 scenes for imerg)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
class ImergGIS:
    """
    A class to process GPM_3IMRGHHL GIS  to hidrocl variables.

    The extracted variable is precipitatation [mm] with a scale factor of 10.

    Attributes:
        pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
        pp_log (str): Path to the log file for IMERG precipitation data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): common_elements (list): Elements in precipitation database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 48 scenes for imerg) \n
        complete_scenes (list): List of complete scenes (48 scenes for imerg) \n
        incomplete_scenes (list): List of incomplete scenes (less than 48 scenes for imerg) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pp, product_path, vector_path, pp_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import ImergGIS
            >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
            >>> gpm = ImergGIS(pp, product_path, vector_path, pp_log)
            >>> gpm
            "Class to extract GPM IMERG GIS Late Run Precipitation Half Hourly 0.1 degree Version 6"

        Args:
            pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            pp_log (str): Path to the log file for IMERG precipitation data \n

        Raises:
            TypeError: If pp is not a HidroCLVariable object
        """
        if t.check_instance(pp):
            self.pp = pp
            self.pp_log = pp_log
            self.productname = "GPM IMERG GIS Late Run Precipitation Half Hourly 0.1 degree Version 6"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = self.pp.indatabase
            self.product_files = t.read_product_files(self.productpath, "imgis")
            self.product_ids = t.get_product_ids(self.product_files, "imgis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "imgis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='imgis')
        else:
            raise TypeError('pp must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

IMERG GIS precipitation records: {len(self.pp.indatabase)}.
IMERG GIS precipitation database path: {self.pp.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imgis")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'imgis',
                                  self.pp.catchment_names, self.pp_log,
                                  database=self.pp.database,
                                  pcdatabase=self.pp.pcdatabase,
                                  vector_path=self.vectorpath)

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imgis")

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='imgis',
                              log_file=log_file)

__init__(pp, product_path, vector_path, pp_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import ImergGIS
>>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
>>> gpm = ImergGIS(pp, product_path, vector_path, pp_log)
>>> gpm
"Class to extract GPM IMERG GIS Late Run Precipitation Half Hourly 0.1 degree Version 6"

Parameters:

Name Type Description Default
pp HidroCLVariable

HidroCLVariable object with IMERG precipitation data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
pp_log str

Path to the log file for IMERG precipitation data

required

Raises:

Type Description
TypeError

If pp is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
def __init__(self, pp, product_path, vector_path, pp_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import ImergGIS
        >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
        >>> gpm = ImergGIS(pp, product_path, vector_path, pp_log)
        >>> gpm
        "Class to extract GPM IMERG GIS Late Run Precipitation Half Hourly 0.1 degree Version 6"

    Args:
        pp (HidroCLVariable): HidroCLVariable object with IMERG precipitation data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        pp_log (str): Path to the log file for IMERG precipitation data \n

    Raises:
        TypeError: If pp is not a HidroCLVariable object
    """
    if t.check_instance(pp):
        self.pp = pp
        self.pp_log = pp_log
        self.productname = "GPM IMERG GIS Late Run Precipitation Half Hourly 0.1 degree Version 6"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = self.pp.indatabase
        self.product_files = t.read_product_files(self.productpath, "imgis")
        self.product_ids = t.get_product_ids(self.product_files, "imgis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "imgis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='imgis')
    else:
        raise TypeError('pp must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1172
1173
1174
1175
1176
1177
1178
1179
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

IMERG GIS precipitation records: {len(self.pp.indatabase)}.
IMERG GIS precipitation database path: {self.pp.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imgis")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'imgis',
                              self.pp.catchment_names, self.pp_log,
                              database=self.pp.database,
                              pcdatabase=self.pp.pcdatabase,
                              vector_path=self.vectorpath)

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, "imgis")

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='imgis',
                          log_file=log_file)

Mcd15a2h

A class to process MCD15A2H to hidrocl variables

Attributes:

Name Type Description
lai HidroCLVariable

HidroCLVariable object with the LAI data

fpar HidroCLVariable

HidroCLVariable object with the FPAR data

lai_log str

Path to the log file for the LAI extraction

fpar_log str

Path to the log file for the FPAR extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the FPAR and LAI databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 9 scenes for modis)

complete_scenes list

List of complete scenes (9 scenes for modis)

incomplete_scenes list

List of incomplete scenes (less than 9 scenes for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
class Mcd15a2h:
    """
    A class to process MCD15A2H to hidrocl variables

    Attributes:
        lai (HidroCLVariable): HidroCLVariable object with the LAI data \n
        fpar (HidroCLVariable): HidroCLVariable object with the FPAR data \n
        lai_log (str): Path to the log file for the LAI extraction \n
        fpar_log (str): Path to the log file for the FPAR extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the FPAR and LAI databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 9 scenes for modis) \n
        complete_scenes (list): List of complete scenes (9 scenes for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 9 scenes for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, lai, fpar, product_path, vector_path,
                 lai_log, fpar_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Mcd15a2h
            >>> lai = HidroCLVariable('lai', 'lai.db', 'lai_pc.db')
            >>> fpar = HidroCLVariable('fpar', 'fpar.db', 'fpar_pc.db')
            >>> product_path = '/home/user/mod15a2h'
            >>> vector_path = '/home/user/vector'
            >>> lai_log = '/home/user/lai.log'
            >>> fpar_log = '/home/user/fpar.log'
            >>> mcd15a2h = Mcd15a2h(lai, fpar, product_path, vector_path,
            ...                     lai_log, fpar_log)
            >>> mcd15a2h
            "Class to extract MODIS MCD15A2H Version 6.0"

        Args:
            lai (HidroCLVariable): HidroCLVariable object with the LAI data
            fpar (HidroCLVariable): HidroCLVariable object with the FPAR data
            product_path (str): Path to the product folder
            vector_path (str): Path to the vector folder
            lai_log (str): Path to the log file for the LAI extraction
            fpar_log (str): Path to the log file for the FPAR extraction

        Raises:
            TypeError: If lai or fpar is not HidroCLVariable object
        """
        if t.check_instance(lai, fpar):
            self.lai = lai
            self.fpar = fpar
            self.lai_log = lai_log
            self.fpar_log = fpar_log
            self.productname = "MODIS MCD15A2H Version 6.0"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                        self.fpar.indatabase)
            self.product_files = t.read_product_files(self.productpath, "modis")
            self.product_ids = t.get_product_ids(self.product_files, "modis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='modis')
        else:
            raise TypeError('lai and fpar must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

LAI records: {len(self.lai.indatabase)}.
LAI database path: {self.lai.database}

FPAR records: {len(self.fpar.indatabase)}.
FPAR database path: {self.fpar.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.lai.checkdatabase()
            self.fpar.checkdatabase()

        self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                    self.fpar.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.lai.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'lai',
                                  self.lai.catchment_names, self.lai_log,
                                  database=self.lai.database,
                                  pcdatabase=self.lai.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="Lai_500m", )

                if scene not in self.fpar.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'fpar',
                                  self.fpar.catchment_names, self.fpar_log,
                                  database=self.fpar.database,
                                  pcdatabase=self.fpar.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="Fpar_500m")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.lai.checkdatabase()
            self.fpar.checkdatabase()

        self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                    self.fpar.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='modis',
                              log_file=log_file)

__init__(lai, fpar, product_path, vector_path, lai_log, fpar_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Mcd15a2h
>>> lai = HidroCLVariable('lai', 'lai.db', 'lai_pc.db')
>>> fpar = HidroCLVariable('fpar', 'fpar.db', 'fpar_pc.db')
>>> product_path = '/home/user/mod15a2h'
>>> vector_path = '/home/user/vector'
>>> lai_log = '/home/user/lai.log'
>>> fpar_log = '/home/user/fpar.log'
>>> mcd15a2h = Mcd15a2h(lai, fpar, product_path, vector_path,
...                     lai_log, fpar_log)
>>> mcd15a2h
"Class to extract MODIS MCD15A2H Version 6.0"

Parameters:

Name Type Description Default
lai HidroCLVariable

HidroCLVariable object with the LAI data

required
fpar HidroCLVariable

HidroCLVariable object with the FPAR data

required
product_path str

Path to the product folder

required
vector_path str

Path to the vector folder

required
lai_log str

Path to the log file for the LAI extraction

required
fpar_log str

Path to the log file for the FPAR extraction

required

Raises:

Type Description
TypeError

If lai or fpar is not HidroCLVariable object

Source code in hidrocl/products/__init__.py
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
def __init__(self, lai, fpar, product_path, vector_path,
             lai_log, fpar_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Mcd15a2h
        >>> lai = HidroCLVariable('lai', 'lai.db', 'lai_pc.db')
        >>> fpar = HidroCLVariable('fpar', 'fpar.db', 'fpar_pc.db')
        >>> product_path = '/home/user/mod15a2h'
        >>> vector_path = '/home/user/vector'
        >>> lai_log = '/home/user/lai.log'
        >>> fpar_log = '/home/user/fpar.log'
        >>> mcd15a2h = Mcd15a2h(lai, fpar, product_path, vector_path,
        ...                     lai_log, fpar_log)
        >>> mcd15a2h
        "Class to extract MODIS MCD15A2H Version 6.0"

    Args:
        lai (HidroCLVariable): HidroCLVariable object with the LAI data
        fpar (HidroCLVariable): HidroCLVariable object with the FPAR data
        product_path (str): Path to the product folder
        vector_path (str): Path to the vector folder
        lai_log (str): Path to the log file for the LAI extraction
        fpar_log (str): Path to the log file for the FPAR extraction

    Raises:
        TypeError: If lai or fpar is not HidroCLVariable object
    """
    if t.check_instance(lai, fpar):
        self.lai = lai
        self.fpar = fpar
        self.lai_log = lai_log
        self.fpar_log = fpar_log
        self.productname = "MODIS MCD15A2H Version 6.0"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                    self.fpar.indatabase)
        self.product_files = t.read_product_files(self.productpath, "modis")
        self.product_ids = t.get_product_ids(self.product_files, "modis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='modis')
    else:
        raise TypeError('lai and fpar must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
838
839
840
841
842
843
844
845
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

LAI records: {len(self.lai.indatabase)}.
LAI database path: {self.lai.database}

FPAR records: {len(self.fpar.indatabase)}.
FPAR database path: {self.fpar.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.lai.checkdatabase()
        self.fpar.checkdatabase()

    self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                self.fpar.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.lai.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'lai',
                              self.lai.catchment_names, self.lai_log,
                              database=self.lai.database,
                              pcdatabase=self.lai.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="Lai_500m", )

            if scene not in self.fpar.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'fpar',
                              self.fpar.catchment_names, self.fpar_log,
                              database=self.fpar.database,
                              pcdatabase=self.fpar.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="Fpar_500m")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.lai.checkdatabase()
        self.fpar.checkdatabase()

    self.common_elements = t.compare_indatabase(self.lai.indatabase,
                                                self.fpar.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='modis',
                          log_file=log_file)

Mod10a2

A class to process MOD10A2 to hidrocl variables

Attributes:

Name Type Description
nsnow HidroCLVariable

HidroCLVariable object with north face snow data

ssnow HidroCLVariable

HidroCLVariable object with south face snow data

snow_log str

Path to the log file for the snow extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

northvectorpath str

Path to the vector folder with the north Shapefile with areas to be processed

southvectorpath str

Path to the vector folder with the south Shapefile with areas to be processed

common_elements list

List of common elements between the nsnow and ssnow databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 9 scenes for modis)

complete_scenes list

List of complete scenes (9 scenes for modis)

incomplete_scenes list

List of incomplete scenes (less than 9 scenes for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
class Mod10a2:
    """
    A class to process MOD10A2 to hidrocl variables

    Attributes:
        nsnow (HidroCLVariable): HidroCLVariable object with north face snow data \n
        ssnow (HidroCLVariable): HidroCLVariable object with south face snow data \n
        snow_log (str): Path to the log file for the snow extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        northvectorpath (str): Path to the vector folder with the north Shapefile with areas to be processed \n
        southvectorpath (str): Path to the vector folder with the south Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the nsnow and ssnow databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 9 scenes for modis) \n
        complete_scenes (list): List of complete scenes (9 scenes for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 9 scenes for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, nsnow, ssnow, product_path,
                 north_vector_path, south_vector_path, snow_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Mod10a2
            >>> nsnow = HidroCLVariable('nsnow', 'modis', 'mod10a2', 'north')
            >>> ssnow = HidroCLVariable('ssnow', 'modis', 'mod10a2', 'south')
            >>> product_path = '/home/user/mod10a2'
            >>> north_vector_path = '/home/user/north_vector.shp'
            >>> south_vector_path = '/home/user/south_vector.shp'
            >>> snow_log = '/home/user/snow.log'
            >>> mod10a2 = Mod10a2(nsnow, ssnow, product_path,
            ...                   north_vector_path, south_vector_path, snow_log)
            >>> mod10a2
            "Class to extract MODIS MOD10A2 Version 6.1"


        Args:
            nsnow (HidroCLVariable): HidroCLVariable object with north face snow data \n
            ssnow (HidroCLVariable): HidroCLVariable object with south face snow data \n
            product_path (str): Path to the product folder where the product files are located \n
            north_vector_path (str): Path to the vector folder with the north Shapefile with areas to be processed \n
            south_vector_path (str): Path to the vector folder with the south Shapefile with areas to be processed \n
            snow_log (str): Path to the log file for the snow extraction \n

        Raises:
              TypeError: If nsnow or ssnow is not a HidroCLVariable object \n
        """
        if t.check_instance(nsnow, ssnow):
            self.nsnow = nsnow
            self.ssnow = ssnow
            self.snow_log = snow_log
            self.productname = "MODIS MOD10A2 Version 6.1"
            self.productpath = product_path
            self.northvectorpath = north_vector_path
            self.southvectorpath = south_vector_path
            self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                        self.ssnow.indatabase)
            self.product_files = t.read_product_files(self.productpath, "modis")
            self.product_ids = t.get_product_ids(self.product_files, "modis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='modis')
        else:
            raise TypeError('nsnow and ssnow must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

North face snow records: {len(self.nsnow.indatabase)}.
North face snow path: {self.nsnow.database}

South face snow records: {len(self.ssnow.indatabase)}.
South face snow database path: {self.ssnow.database}
                '''

    def run_extraction(self, limit=None):
        """Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.nsnow.checkdatabase()
            self.ssnow.checkdatabase()

        self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                    self.ssnow.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.nsnow.indatabase:  # so what about the south one?
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'snow',
                                  self.nsnow.catchment_names, self.snow_log,
                                  north_database=self.nsnow.database,
                                  north_pcdatabase=self.nsnow.pcdatabase,
                                  south_database=self.ssnow.database,
                                  south_pcdatabase=self.ssnow.pcdatabase,
                                  north_vector_path=self.northvectorpath,
                                  south_vector_path=self.southvectorpath,
                                  layer="Maximum_Snow_Extent")

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.nsnow.checkdatabase()
            self.ssnow.checkdatabase()

        self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                    self.ssnow.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='modis',
                              log_file=log_file)

__init__(nsnow, ssnow, product_path, north_vector_path, south_vector_path, snow_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Mod10a2
>>> nsnow = HidroCLVariable('nsnow', 'modis', 'mod10a2', 'north')
>>> ssnow = HidroCLVariable('ssnow', 'modis', 'mod10a2', 'south')
>>> product_path = '/home/user/mod10a2'
>>> north_vector_path = '/home/user/north_vector.shp'
>>> south_vector_path = '/home/user/south_vector.shp'
>>> snow_log = '/home/user/snow.log'
>>> mod10a2 = Mod10a2(nsnow, ssnow, product_path,
...                   north_vector_path, south_vector_path, snow_log)
>>> mod10a2
"Class to extract MODIS MOD10A2 Version 6.1"

Parameters:

Name Type Description Default
nsnow HidroCLVariable

HidroCLVariable object with north face snow data

required
ssnow HidroCLVariable

HidroCLVariable object with south face snow data

required
product_path str

Path to the product folder where the product files are located

required
north_vector_path str

Path to the vector folder with the north Shapefile with areas to be processed

required
south_vector_path str

Path to the vector folder with the south Shapefile with areas to be processed

required
snow_log str

Path to the log file for the snow extraction

required

Raises:

Type Description
TypeError

If nsnow or ssnow is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
def __init__(self, nsnow, ssnow, product_path,
             north_vector_path, south_vector_path, snow_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Mod10a2
        >>> nsnow = HidroCLVariable('nsnow', 'modis', 'mod10a2', 'north')
        >>> ssnow = HidroCLVariable('ssnow', 'modis', 'mod10a2', 'south')
        >>> product_path = '/home/user/mod10a2'
        >>> north_vector_path = '/home/user/north_vector.shp'
        >>> south_vector_path = '/home/user/south_vector.shp'
        >>> snow_log = '/home/user/snow.log'
        >>> mod10a2 = Mod10a2(nsnow, ssnow, product_path,
        ...                   north_vector_path, south_vector_path, snow_log)
        >>> mod10a2
        "Class to extract MODIS MOD10A2 Version 6.1"


    Args:
        nsnow (HidroCLVariable): HidroCLVariable object with north face snow data \n
        ssnow (HidroCLVariable): HidroCLVariable object with south face snow data \n
        product_path (str): Path to the product folder where the product files are located \n
        north_vector_path (str): Path to the vector folder with the north Shapefile with areas to be processed \n
        south_vector_path (str): Path to the vector folder with the south Shapefile with areas to be processed \n
        snow_log (str): Path to the log file for the snow extraction \n

    Raises:
          TypeError: If nsnow or ssnow is not a HidroCLVariable object \n
    """
    if t.check_instance(nsnow, ssnow):
        self.nsnow = nsnow
        self.ssnow = ssnow
        self.snow_log = snow_log
        self.productname = "MODIS MOD10A2 Version 6.1"
        self.productpath = product_path
        self.northvectorpath = north_vector_path
        self.southvectorpath = south_vector_path
        self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                    self.ssnow.indatabase)
        self.product_files = t.read_product_files(self.productpath, "modis")
        self.product_ids = t.get_product_ids(self.product_files, "modis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='modis')
    else:
        raise TypeError('nsnow and ssnow must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
471
472
473
474
475
476
477
478
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

North face snow records: {len(self.nsnow.indatabase)}.
North face snow path: {self.nsnow.database}

South face snow records: {len(self.ssnow.indatabase)}.
South face snow database path: {self.ssnow.database}
                '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
def run_extraction(self, limit=None):
    """Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.nsnow.checkdatabase()
        self.ssnow.checkdatabase()

    self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                self.ssnow.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.nsnow.indatabase:  # so what about the south one?
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'snow',
                              self.nsnow.catchment_names, self.snow_log,
                              north_database=self.nsnow.database,
                              north_pcdatabase=self.nsnow.pcdatabase,
                              south_database=self.ssnow.database,
                              south_pcdatabase=self.ssnow.pcdatabase,
                              north_vector_path=self.northvectorpath,
                              south_vector_path=self.southvectorpath,
                              layer="Maximum_Snow_Extent")

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.nsnow.checkdatabase()
        self.ssnow.checkdatabase()

    self.common_elements = t.compare_indatabase(self.nsnow.indatabase,
                                                self.ssnow.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='modis',
                          log_file=log_file)

Mod13q1

A class to process MOD13Q1 to hidrocl variables

Attributes:

Name Type Description
ndvi HidroCLVariable

HidroCLVariable object with the NDVI data

evi HidroCLVariable

HidroCLVariable object with the EVI data

nbr HidroCLVariable

HidroCLVariable object with the NBR data

ndvi_log str

Path to the log file for the NDVI extraction

evi_log str

Path to the log file for the EVI extraction

nbr_log str

Path to the log file for the NBR extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the NDVI, EVI and NBR databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 9 scenes for modis)

complete_scenes list

List of complete scenes (9 scenes for modis)

incomplete_scenes list

List of incomplete scenes (less than 9 scenes for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
class Mod13q1:
    """
    A class to process MOD13Q1 to hidrocl variables

    Attributes:
        ndvi (HidroCLVariable): HidroCLVariable object with the NDVI data \n
        evi (HidroCLVariable): HidroCLVariable object with the EVI data \n
        nbr (HidroCLVariable): HidroCLVariable object with the NBR data \n
        ndvi_log (str): Path to the log file for the NDVI extraction \n
        evi_log (str): Path to the log file for the EVI extraction \n
        nbr_log (str): Path to the log file for the NBR extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the NDVI, EVI and NBR databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 9 scenes for modis) \n
        complete_scenes (list): List of complete scenes (9 scenes for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 9 scenes for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, ndvi, evi, nbr, product_path, vector_path,
                 ndvi_log, evi_log, nbr_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl.products import Mod13q1
            >>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
            >>> evi = HidroCLVariable('evi', 'evi.db', 'evi_pc.db')
            >>> nbr = HidroCLVariable('nbr', 'nbr.db', 'nbr_pc.db')
            >>> product_path = '/home/user/mod13q1'
            >>> vector_path = '/home/user/vector.shp'
            >>> ndvi_log = '/home/user/ndvi.log'
            >>> evi_log = '/home/user/evi.log'
            >>> nbr_log = '/home/user/nbr.log'
            >>> mod13q1 = Mod13q1(ndvi, evi, nbr, product_path, vector_path,
            ...                   ndvi_log, evi_log, nbr_log)
            >>> mod13q1
            "Class to extract MODIS MOD13Q1 Version 6.1"

        Args:
            ndvi (HidroCLVariable): Object with the NDVI data
            evi (HidroCLVariable): Object with the EVI data
            nbr (HidroCLVariable): Object with the NBR data
            product_path (str): Path to the product folder
            vector_path (str): Path to the vector folder
            ndvi_log (str): Path to the log file for the NDVI extraction
            evi_log (str): Path to the log file for the EVI extraction
            nbr_log (str): Path to the log file for the NBR extraction

        Raises:
              TypeError: If the input is not a HidroCLVariable object
        """
        if t.check_instance(ndvi, evi, nbr):
            self.ndvi = ndvi
            self.evi = evi
            self.nbr = nbr
            self.ndvi_log = ndvi_log
            self.evi_log = evi_log
            self.nbr_log = nbr_log
            self.productname = "MODIS MOD13Q1 Version 6.1"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                        self.evi.indatabase,
                                                        self.nbr.indatabase)
            self.product_files = t.read_product_files(self.productpath, "modis")
            self.product_ids = t.get_product_ids(self.product_files, "modis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='modis')
        else:
            raise TypeError('ndvi, evi and nbr must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

NDVI records: {len(self.ndvi.indatabase)}.
NDVI database path: {self.ndvi.database}

EVI records: {len(self.evi.indatabase)}.
EVI database path: {self.evi.database}

NBR records: {len(self.nbr.indatabase)}.
NBR database path: {self.nbr.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ndvi.checkdatabase()
            self.evi.checkdatabase()
            self.nbr.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                    self.evi.indatabase,
                                                    self.nbr.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.ndvi.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'ndvi',
                                  self.ndvi.catchment_names, self.ndvi_log,
                                  database=self.ndvi.database,
                                  pcdatabase=self.ndvi.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="250m 16 days NDVI", )

                if scene not in self.evi.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'evi',
                                  self.evi.catchment_names, self.evi_log,
                                  database=self.evi.database,
                                  pcdatabase=self.evi.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="250m 16 days EVI", )

                if scene not in self.evi.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'nbr',
                                  self.nbr.catchment_names, self.nbr_log,
                                  database=self.nbr.database,
                                  pcdatabase=self.nbr.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer=["250m 16 days NIR reflectance",
                                         "250m 16 days MIR reflectance"])

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ndvi.checkdatabase()
            self.evi.checkdatabase()
            self.nbr.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                    self.evi.indatabase,
                                                    self.nbr.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='modis',
                              log_file=log_file)

__init__(ndvi, evi, nbr, product_path, vector_path, ndvi_log, evi_log, nbr_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl.products import Mod13q1
>>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
>>> evi = HidroCLVariable('evi', 'evi.db', 'evi_pc.db')
>>> nbr = HidroCLVariable('nbr', 'nbr.db', 'nbr_pc.db')
>>> product_path = '/home/user/mod13q1'
>>> vector_path = '/home/user/vector.shp'
>>> ndvi_log = '/home/user/ndvi.log'
>>> evi_log = '/home/user/evi.log'
>>> nbr_log = '/home/user/nbr.log'
>>> mod13q1 = Mod13q1(ndvi, evi, nbr, product_path, vector_path,
...                   ndvi_log, evi_log, nbr_log)
>>> mod13q1
"Class to extract MODIS MOD13Q1 Version 6.1"

Parameters:

Name Type Description Default
ndvi HidroCLVariable

Object with the NDVI data

required
evi HidroCLVariable

Object with the EVI data

required
nbr HidroCLVariable

Object with the NBR data

required
product_path str

Path to the product folder

required
vector_path str

Path to the vector folder

required
ndvi_log str

Path to the log file for the NDVI extraction

required
evi_log str

Path to the log file for the EVI extraction

required
nbr_log str

Path to the log file for the NBR extraction

required

Raises:

Type Description
TypeError

If the input is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def __init__(self, ndvi, evi, nbr, product_path, vector_path,
             ndvi_log, evi_log, nbr_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl.products import Mod13q1
        >>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
        >>> evi = HidroCLVariable('evi', 'evi.db', 'evi_pc.db')
        >>> nbr = HidroCLVariable('nbr', 'nbr.db', 'nbr_pc.db')
        >>> product_path = '/home/user/mod13q1'
        >>> vector_path = '/home/user/vector.shp'
        >>> ndvi_log = '/home/user/ndvi.log'
        >>> evi_log = '/home/user/evi.log'
        >>> nbr_log = '/home/user/nbr.log'
        >>> mod13q1 = Mod13q1(ndvi, evi, nbr, product_path, vector_path,
        ...                   ndvi_log, evi_log, nbr_log)
        >>> mod13q1
        "Class to extract MODIS MOD13Q1 Version 6.1"

    Args:
        ndvi (HidroCLVariable): Object with the NDVI data
        evi (HidroCLVariable): Object with the EVI data
        nbr (HidroCLVariable): Object with the NBR data
        product_path (str): Path to the product folder
        vector_path (str): Path to the vector folder
        ndvi_log (str): Path to the log file for the NDVI extraction
        evi_log (str): Path to the log file for the EVI extraction
        nbr_log (str): Path to the log file for the NBR extraction

    Raises:
          TypeError: If the input is not a HidroCLVariable object
    """
    if t.check_instance(ndvi, evi, nbr):
        self.ndvi = ndvi
        self.evi = evi
        self.nbr = nbr
        self.ndvi_log = ndvi_log
        self.evi_log = evi_log
        self.nbr_log = nbr_log
        self.productname = "MODIS MOD13Q1 Version 6.1"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                    self.evi.indatabase,
                                                    self.nbr.indatabase)
        self.product_files = t.read_product_files(self.productpath, "modis")
        self.product_ids = t.get_product_ids(self.product_files, "modis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='modis')
    else:
        raise TypeError('ndvi, evi and nbr must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
 97
 98
 99
100
101
102
103
104
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

NDVI records: {len(self.ndvi.indatabase)}.
NDVI database path: {self.ndvi.database}

EVI records: {len(self.evi.indatabase)}.
EVI database path: {self.evi.database}

NBR records: {len(self.nbr.indatabase)}.
NBR database path: {self.nbr.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ndvi.checkdatabase()
        self.evi.checkdatabase()
        self.nbr.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                self.evi.indatabase,
                                                self.nbr.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.ndvi.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'ndvi',
                              self.ndvi.catchment_names, self.ndvi_log,
                              database=self.ndvi.database,
                              pcdatabase=self.ndvi.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="250m 16 days NDVI", )

            if scene not in self.evi.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'evi',
                              self.evi.catchment_names, self.evi_log,
                              database=self.evi.database,
                              pcdatabase=self.evi.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="250m 16 days EVI", )

            if scene not in self.evi.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'nbr',
                              self.nbr.catchment_names, self.nbr_log,
                              database=self.nbr.database,
                              pcdatabase=self.nbr.pcdatabase,
                              vector_path=self.vectorpath,
                              layer=["250m 16 days NIR reflectance",
                                     "250m 16 days MIR reflectance"])

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ndvi.checkdatabase()
        self.evi.checkdatabase()
        self.nbr.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ndvi.indatabase,
                                                self.evi.indatabase,
                                                self.nbr.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='modis',
                          log_file=log_file)

Mod13q1agr

A class to process MOD13Q1 to hidrocl variables

Attributes:

Name Type Description
ndvi HidroCLVariable

HidroCLVariable object with the NDVI data

ndvi_log str

Path to the log file for the NDVI extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

List of common elements between the NDVI, EVI and NBR databases

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 9 scenes for modis)

complete_scenes list

List of complete scenes (9 scenes for modis)

incomplete_scenes list

List of incomplete scenes (less than 9 scenes for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
class Mod13q1agr:
    """
    A class to process MOD13Q1 to hidrocl variables

    Attributes:
        ndvi (HidroCLVariable): HidroCLVariable object with the NDVI data \n
        ndvi_log (str): Path to the log file for the NDVI extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): List of common elements between the NDVI, EVI and NBR databases \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 9 scenes for modis) \n
        complete_scenes (list): List of complete scenes (9 scenes for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 9 scenes for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, ndvi, product_path, vector_path, ndvi_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl.products import Mod13q1agr
            >>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
            >>> product_path = '/home/user/mod13q1'
            >>> vector_path = '/home/user/vector.shp'
            >>> ndvi_log = '/home/user/ndvi.log'
            >>> mod13q1agr = Mod13q1agr(ndvi, product_path, vector_path, ndvi_log)
            >>> mod13q1agr
            "Class to extract agricultural NDVI from MODIS MOD13Q1 Version 6.1"

        Args:
            ndvi (HidroCLVariable): Object with the NDVI data
            evi (HidroCLVariable): Object with the EVI data
            nbr (HidroCLVariable): Object with the NBR data
            product_path (str): Path to the product folder
            vector_path (str): Path to the vector folder
            ndvi_log (str): Path to the log file for the NDVI extraction
            evi_log (str): Path to the log file for the EVI extraction
            nbr_log (str): Path to the log file for the NBR extraction

        Raises:
              TypeError: If the input is not a HidroCLVariable object
        """
        if t.check_instance(ndvi):
            self.ndvi = ndvi
            self.ndvi_log = ndvi_log
            self.productname = "agricultural NDVI from MODIS MOD13Q1 Version 6.1"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.ndvi.indatabase)
            self.product_files = t.read_product_files(self.productpath, "modis")
            self.product_ids = t.get_product_ids(self.product_files, "modis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='modis')
        else:
            raise TypeError('ndvi, evi and nbr must be HidroCLVariable objects')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

NDVI records: {len(self.ndvi.indatabase)}.
NDVI database path: {self.ndvi.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ndvi.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ndvi.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'ndvi',
                              self.ndvi.catchment_names, self.ndvi_log,
                              database=self.ndvi.database,
                              pcdatabase=self.ndvi.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="250m 16 days NDVI", )

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.ndvi.checkdatabase()

        self.common_elements = t.compare_indatabase(self.ndvi.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='modis',
                              log_file=log_file)

__init__(ndvi, product_path, vector_path, ndvi_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl.products import Mod13q1agr
>>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
>>> product_path = '/home/user/mod13q1'
>>> vector_path = '/home/user/vector.shp'
>>> ndvi_log = '/home/user/ndvi.log'
>>> mod13q1agr = Mod13q1agr(ndvi, product_path, vector_path, ndvi_log)
>>> mod13q1agr
"Class to extract agricultural NDVI from MODIS MOD13Q1 Version 6.1"

Parameters:

Name Type Description Default
ndvi HidroCLVariable

Object with the NDVI data

required
evi HidroCLVariable

Object with the EVI data

required
nbr HidroCLVariable

Object with the NBR data

required
product_path str

Path to the product folder

required
vector_path str

Path to the vector folder

required
ndvi_log str

Path to the log file for the NDVI extraction

required
evi_log str

Path to the log file for the EVI extraction

required
nbr_log str

Path to the log file for the NBR extraction

required

Raises:

Type Description
TypeError

If the input is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
def __init__(self, ndvi, product_path, vector_path, ndvi_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl.products import Mod13q1agr
        >>> ndvi = HidroCLVariable('ndvi', 'ndvi.db', 'ndvi_pc.db')
        >>> product_path = '/home/user/mod13q1'
        >>> vector_path = '/home/user/vector.shp'
        >>> ndvi_log = '/home/user/ndvi.log'
        >>> mod13q1agr = Mod13q1agr(ndvi, product_path, vector_path, ndvi_log)
        >>> mod13q1agr
        "Class to extract agricultural NDVI from MODIS MOD13Q1 Version 6.1"

    Args:
        ndvi (HidroCLVariable): Object with the NDVI data
        evi (HidroCLVariable): Object with the EVI data
        nbr (HidroCLVariable): Object with the NBR data
        product_path (str): Path to the product folder
        vector_path (str): Path to the vector folder
        ndvi_log (str): Path to the log file for the NDVI extraction
        evi_log (str): Path to the log file for the EVI extraction
        nbr_log (str): Path to the log file for the NBR extraction

    Raises:
          TypeError: If the input is not a HidroCLVariable object
    """
    if t.check_instance(ndvi):
        self.ndvi = ndvi
        self.ndvi_log = ndvi_log
        self.productname = "agricultural NDVI from MODIS MOD13Q1 Version 6.1"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.ndvi.indatabase)
        self.product_files = t.read_product_files(self.productpath, "modis")
        self.product_ids = t.get_product_ids(self.product_files, "modis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='modis')
    else:
        raise TypeError('ndvi, evi and nbr must be HidroCLVariable objects')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
297
298
299
300
301
302
303
304
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
306
307
308
309
310
311
312
313
314
315
316
317
318
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

NDVI records: {len(self.ndvi.indatabase)}.
NDVI database path: {self.ndvi.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ndvi.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ndvi.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            e.zonal_stats(scene, scenes_path,
                          temp_dir, 'ndvi',
                          self.ndvi.catchment_names, self.ndvi_log,
                          database=self.ndvi.database,
                          pcdatabase=self.ndvi.pcdatabase,
                          vector_path=self.vectorpath,
                          layer="250m 16 days NDVI", )

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.ndvi.checkdatabase()

    self.common_elements = t.compare_indatabase(self.ndvi.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='modis',
                          log_file=log_file)

Mod16a2

A class to process MOD16A2 to hidrocl variables

Attributes:

Name Type Description
pet HidroCLVariable

HidroCLVariable object with the potential evapotranspiration

et HidroCLVariable

HidroCLVariable object with the actual evapotranspiration

pet_log str

Path to the log file for the pet extraction

et_log str

Path to the log file for the et extraction

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

Elements in pet database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 9 scenes for modis)

complete_scenes list

List of complete scenes (9 scenes for modis)

incomplete_scenes list

List of incomplete scenes (less than 9 scenes for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
class Mod16a2:
    """
    A class to process MOD16A2 to hidrocl variables

    Attributes:
        pet (HidroCLVariable): HidroCLVariable object with the potential evapotranspiration \n
        et (HidroCLVariable): HidroCLVariable object with the actual evapotranspiration \n
        pet_log (str): Path to the log file for the pet extraction \n
        et_log (str): Path to the log file for the et extraction \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): Elements in pet database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 9 scenes for modis) \n
        complete_scenes (list): List of complete scenes (9 scenes for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 9 scenes for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pet, et, product_path, vector_path, pet_log, et_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Mod16a2
            >>> pet = HidroCLVariable('pet', 'pet.db', 'pet_pc.db')
            >>> et = HidroCLVariable('et', 'et.db', 'et_pc.db')
            >>> product_path = '/home/user/modis/mod16a2'
            >>> vector_path = '/home/user/vector.shp'
            >>> pet_log = '/home/user/log/pet.log'
            >>> et_log = '/home/user/log/et.log'
            >>> mod16a2 = Mod16a2(pet, et, product_path, vector_path, pet_log, et_log)
            >>> mod16a2
            "Class to extract MODIS MOD16A2 Version 6.1"

        Args:
            pet (HidroCLVariable): Object with the potential evapotranspiration data
            et (HidroCLVariable): Object with the actual evapotranspiration data
            product_path (str): Path to the product folder
            vector_path (str): Path to the vector folder
            pet_log (str): Path to the log file for the pet extraction
            et_log (str): Path to the log file for the et extraction

        Raises:
            TypeError: If pet is not a HidroCLVariable object
        """
        if t.check_instance(pet):
            self.pet = pet
            self.et = et
            self.pet_log = pet_log
            self.et_log = et_log
            self.productname = "MODIS MOD16A2 Version 6.1"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = t.compare_indatabase(self.pet.indatabase,
                                                        self.et.indatabase)
            self.product_files = t.read_product_files(self.productpath, "modis")
            self.product_ids = t.get_product_ids(self.product_files, "modis")
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='modis')
        else:
            raise TypeError('pet must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

PET records: {len(self.pet.indatabase)}.
PET database path: {self.pet.database}

ET records: {len(self.et.indatabase)}.
ET database path: {self.et.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pet.checkdatabase()
            self.et.checkdatabase()

        self.common_elements = t.compare_indatabase(self.pet.indatabase,
                                                    self.et.indatabase)

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pet.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'pet',
                                  self.pet.catchment_names, self.pet_log,
                                  database=self.pet.database,
                                  pcdatabase=self.pet.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="PET_500m", )

                if scene not in self.pet.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, 'et',
                                  self.et.catchment_names, self.et_log,
                                  database=self.et.database,
                                  pcdatabase=self.et.pcdatabase,
                                  vector_path=self.vectorpath,
                                  layer="ET_500m", )

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pet.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pet.indatabase)

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='modis',
                              log_file=log_file)

__init__(pet, et, product_path, vector_path, pet_log, et_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Mod16a2
>>> pet = HidroCLVariable('pet', 'pet.db', 'pet_pc.db')
>>> et = HidroCLVariable('et', 'et.db', 'et_pc.db')
>>> product_path = '/home/user/modis/mod16a2'
>>> vector_path = '/home/user/vector.shp'
>>> pet_log = '/home/user/log/pet.log'
>>> et_log = '/home/user/log/et.log'
>>> mod16a2 = Mod16a2(pet, et, product_path, vector_path, pet_log, et_log)
>>> mod16a2
"Class to extract MODIS MOD16A2 Version 6.1"

Parameters:

Name Type Description Default
pet HidroCLVariable

Object with the potential evapotranspiration data

required
et HidroCLVariable

Object with the actual evapotranspiration data

required
product_path str

Path to the product folder

required
vector_path str

Path to the vector folder

required
pet_log str

Path to the log file for the pet extraction

required
et_log str

Path to the log file for the et extraction

required

Raises:

Type Description
TypeError

If pet is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
def __init__(self, pet, et, product_path, vector_path, pet_log, et_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Mod16a2
        >>> pet = HidroCLVariable('pet', 'pet.db', 'pet_pc.db')
        >>> et = HidroCLVariable('et', 'et.db', 'et_pc.db')
        >>> product_path = '/home/user/modis/mod16a2'
        >>> vector_path = '/home/user/vector.shp'
        >>> pet_log = '/home/user/log/pet.log'
        >>> et_log = '/home/user/log/et.log'
        >>> mod16a2 = Mod16a2(pet, et, product_path, vector_path, pet_log, et_log)
        >>> mod16a2
        "Class to extract MODIS MOD16A2 Version 6.1"

    Args:
        pet (HidroCLVariable): Object with the potential evapotranspiration data
        et (HidroCLVariable): Object with the actual evapotranspiration data
        product_path (str): Path to the product folder
        vector_path (str): Path to the vector folder
        pet_log (str): Path to the log file for the pet extraction
        et_log (str): Path to the log file for the et extraction

    Raises:
        TypeError: If pet is not a HidroCLVariable object
    """
    if t.check_instance(pet):
        self.pet = pet
        self.et = et
        self.pet_log = pet_log
        self.et_log = et_log
        self.productname = "MODIS MOD16A2 Version 6.1"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = t.compare_indatabase(self.pet.indatabase,
                                                    self.et.indatabase)
        self.product_files = t.read_product_files(self.productpath, "modis")
        self.product_ids = t.get_product_ids(self.product_files, "modis")
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, "modis")
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='modis')
    else:
        raise TypeError('pet must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
652
653
654
655
656
657
658
659
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

PET records: {len(self.pet.indatabase)}.
PET database path: {self.pet.database}

ET records: {len(self.et.indatabase)}.
ET database path: {self.et.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pet.checkdatabase()
        self.et.checkdatabase()

    self.common_elements = t.compare_indatabase(self.pet.indatabase,
                                                self.et.indatabase)

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.common_elements)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pet.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'pet',
                              self.pet.catchment_names, self.pet_log,
                              database=self.pet.database,
                              pcdatabase=self.pet.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="PET_500m", )

            if scene not in self.pet.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, 'et',
                              self.et.catchment_names, self.et_log,
                              database=self.et.database,
                              pcdatabase=self.et.pcdatabase,
                              vector_path=self.vectorpath,
                              layer="ET_500m", )

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pet.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pet.indatabase)

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='modis',
                          log_file=log_file)

Pdirnow

A class to process PDIR-Now to hidrocl variables

Attributes:

Name Type Description
pp HidroCLVariable

HidroCLVariable object with PDIR-Now precipitation data

pp_log str

Path to the log file for PDIR-Now precipitation data

productname str

Name of the remote sensing product to be processed

productpath str

Path to the product folder where the product files are located

vectorpath str

Path to the vector folder with Shapefile with areas to be processed

common_elements list

common_elements (list): Elements in precipitation database

product_files list

List of product files in the product folder

product_ids list

List of product ids. Each product id is str with common tag by date

all_scenes list

List of all scenes (no matter the product id here)

scenes_occurrences list

List of scenes occurrences for each product id

overpopulated_scenes list

List of overpopulated scenes (more than 1 scene for modis)

complete_scenes list

List of complete scenes (1 scene for modis)

incomplete_scenes list

List of incomplete scenes (less than 1 scene for modis)

scenes_to_process list

List of scenes to process (complete scenes no processed)

Source code in hidrocl/products/__init__.py
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
class Pdirnow:
    """
    A class to process PDIR-Now to hidrocl variables

    Attributes:
        pp (HidroCLVariable): HidroCLVariable object with PDIR-Now precipitation data \n
        pp_log (str): Path to the log file for PDIR-Now precipitation data \n
        productname (str): Name of the remote sensing product to be processed \n
        productpath (str): Path to the product folder where the product files are located \n
        vectorpath (str): Path to the vector folder with Shapefile with areas to be processed \n
        common_elements (list): common_elements (list): Elements in precipitation database \n
        product_files (list): List of product files in the product folder \n
        product_ids (list): List of product ids. Each product id is str with common tag by date \n
        all_scenes (list): List of all scenes (no matter the product id here) \n
        scenes_occurrences (list): List of scenes occurrences for each product id \n
        overpopulated_scenes (list): List of overpopulated scenes (more than 1 scene for modis) \n
        complete_scenes (list): List of complete scenes (1 scene for modis) \n
        incomplete_scenes (list): List of incomplete scenes (less than 1 scene for modis) \n
        scenes_to_process (list): List of scenes to process (complete scenes no processed) \n
    """

    def __init__(self, pp, product_path, vector_path, pp_log):
        """
        Examples:
            >>> from hidrocl import HidroCLVariable
            >>> from hidrocl import Pdirnow
            >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
            >>> product_path = '/home/user/data/PDIR-Now'
            >>> vector_path = '/home/user/data/vector.shp'
            >>> pp_log = '/home/user/data/logs/pp_log.txt'
            >>> pdirnow = Pdirnow(pp, product_path, vector_path, pp_log)
            >>> pdirnow
            "Class to extract PDIR-Now 0.04º"

        Args:
            pp (HidroCLVariable): HidroCLVariable object with PDIR-Now precipitation data \n
            product_path (str): Path to the product folder where the product files are located \n
            vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
            pp_log (str): Path to the log file for PDIR-Now precipitation data \n

        Raises:
            TypeError: If pp is not a HidroCLVariable object
        """
        if t.check_instance(pp):
            self.pp = pp
            self.pp_log = pp_log
            self.productname = "PDIR-Now 0.04º"
            self.productpath = product_path
            self.vectorpath = vector_path
            self.common_elements = self.pp.indatabase
            self.product_files = t.read_product_files(self.productpath, 'pdirnow')
            self.product_ids = t.get_product_ids(self.product_files, 'pdirnow')
            self.all_scenes = t.check_product_files(self.product_ids)
            self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
            (self.overpopulated_scenes,
             self.complete_scenes,
             self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, 'pdirnow')
            self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                            self.common_elements, what='pdirnow')
        else:
            raise TypeError('pp must be HidroCLVariable object')

    def __repr__(self):
        """
        Return a string representation of the object

        Returns:
             str: String representation of the object
        """
        return f'Class to extract {self.productname}'

    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

PDIR-Now precipitation records: {len(self.pp.indatabase)}.
PDIR-Now precipitation database path: {self.pp.database}
        '''

    def run_extraction(self, limit=None):
        """
        Run the extraction of the product.
        If limit is None, all scenes will be processed.
        If limit is a number, only the first limit scenes will be processed.

        Args:
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, 'pdirnow')

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        with TemporaryDirectory() as tempdirname:
            temp_dir = Path(tempdirname)

            if limit is not None:
                scenes_to_process = self.scenes_to_process[:limit]
            else:
                scenes_to_process = self.scenes_to_process

            for scene in scenes_to_process:
                if scene not in self.pp.indatabase:
                    e.zonal_stats(scene, scenes_path,
                                  temp_dir, "pdirnow",
                                  self.pp.catchment_names, self.pp_log,
                                  database=self.pp.database,
                                  pcdatabase=self.pp.pcdatabase,
                                  vector_path=self.vectorpath)

    def run_maintainer(self, log_file, limit=None):
        """
        Run file maintainer. It will remove any file with problems

        Args:
            log_file (str): log file path
            limit (int): length of the scenes_to_process

        Returns:
            str: Print
        """

        with t.HiddenPrints():
            self.pp.checkdatabase()

        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, 'pdirnow')

        scenes_path = t.get_scenes_path(self.product_files, self.productpath)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            m.file_maintainer(scene=scene,
                              scenes_path=scenes_path,
                              name='persiann',
                              log_file=log_file)

__init__(pp, product_path, vector_path, pp_log)

Examples:

>>> from hidrocl import HidroCLVariable
>>> from hidrocl import Pdirnow
>>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
>>> product_path = '/home/user/data/PDIR-Now'
>>> vector_path = '/home/user/data/vector.shp'
>>> pp_log = '/home/user/data/logs/pp_log.txt'
>>> pdirnow = Pdirnow(pp, product_path, vector_path, pp_log)
>>> pdirnow
"Class to extract PDIR-Now 0.04º"

Parameters:

Name Type Description Default
pp HidroCLVariable

HidroCLVariable object with PDIR-Now precipitation data

required
product_path str

Path to the product folder where the product files are located

required
vector_path str

Path to the vector folder with Shapefile with areas to be processed

required
pp_log str

Path to the log file for PDIR-Now precipitation data

required

Raises:

Type Description
TypeError

If pp is not a HidroCLVariable object

Source code in hidrocl/products/__init__.py
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
def __init__(self, pp, product_path, vector_path, pp_log):
    """
    Examples:
        >>> from hidrocl import HidroCLVariable
        >>> from hidrocl import Pdirnow
        >>> pp = HidroCLVariable('pp', 'pp.db', 'pp_pc.db')
        >>> product_path = '/home/user/data/PDIR-Now'
        >>> vector_path = '/home/user/data/vector.shp'
        >>> pp_log = '/home/user/data/logs/pp_log.txt'
        >>> pdirnow = Pdirnow(pp, product_path, vector_path, pp_log)
        >>> pdirnow
        "Class to extract PDIR-Now 0.04º"

    Args:
        pp (HidroCLVariable): HidroCLVariable object with PDIR-Now precipitation data \n
        product_path (str): Path to the product folder where the product files are located \n
        vector_path (str): Path to the vector folder with Shapefile with areas to be processed \n
        pp_log (str): Path to the log file for PDIR-Now precipitation data \n

    Raises:
        TypeError: If pp is not a HidroCLVariable object
    """
    if t.check_instance(pp):
        self.pp = pp
        self.pp_log = pp_log
        self.productname = "PDIR-Now 0.04º"
        self.productpath = product_path
        self.vectorpath = vector_path
        self.common_elements = self.pp.indatabase
        self.product_files = t.read_product_files(self.productpath, 'pdirnow')
        self.product_ids = t.get_product_ids(self.product_files, 'pdirnow')
        self.all_scenes = t.check_product_files(self.product_ids)
        self.scenes_occurrences = t.count_scenes_occurrences(self.all_scenes, self.product_ids)
        (self.overpopulated_scenes,
         self.complete_scenes,
         self.incomplete_scenes) = t.classify_occurrences(self.scenes_occurrences, 'pdirnow')
        self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes,
                                                        self.common_elements, what='pdirnow')
    else:
        raise TypeError('pp must be HidroCLVariable object')

__repr__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1889
1890
1891
1892
1893
1894
1895
1896
def __repr__(self):
    """
    Return a string representation of the object

    Returns:
         str: String representation of the object
    """
    return f'Class to extract {self.productname}'

__str__()

Return a string representation of the object

Returns:

Name Type Description
str

String representation of the object

Source code in hidrocl/products/__init__.py
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
    def __str__(self):
        """
        Return a string representation of the object

        Returns:
            str: String representation of the object
        """
        return f'''
Product: {self.productname}

PDIR-Now precipitation records: {len(self.pp.indatabase)}.
PDIR-Now precipitation database path: {self.pp.database}
        '''

run_extraction(limit=None)

Run the extraction of the product. If limit is None, all scenes will be processed. If limit is a number, only the first limit scenes will be processed.

Parameters:

Name Type Description Default
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
def run_extraction(self, limit=None):
    """
    Run the extraction of the product.
    If limit is None, all scenes will be processed.
    If limit is a number, only the first limit scenes will be processed.

    Args:
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, 'pdirnow')

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    with TemporaryDirectory() as tempdirname:
        temp_dir = Path(tempdirname)

        if limit is not None:
            scenes_to_process = self.scenes_to_process[:limit]
        else:
            scenes_to_process = self.scenes_to_process

        for scene in scenes_to_process:
            if scene not in self.pp.indatabase:
                e.zonal_stats(scene, scenes_path,
                              temp_dir, "pdirnow",
                              self.pp.catchment_names, self.pp_log,
                              database=self.pp.database,
                              pcdatabase=self.pp.pcdatabase,
                              vector_path=self.vectorpath)

run_maintainer(log_file, limit=None)

Run file maintainer. It will remove any file with problems

Parameters:

Name Type Description Default
log_file str

log file path

required
limit int

length of the scenes_to_process

None

Returns:

Name Type Description
str

Print

Source code in hidrocl/products/__init__.py
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
def run_maintainer(self, log_file, limit=None):
    """
    Run file maintainer. It will remove any file with problems

    Args:
        log_file (str): log file path
        limit (int): length of the scenes_to_process

    Returns:
        str: Print
    """

    with t.HiddenPrints():
        self.pp.checkdatabase()

    self.scenes_to_process = t.get_scenes_out_of_db(self.complete_scenes, self.pp.indatabase, 'pdirnow')

    scenes_path = t.get_scenes_path(self.product_files, self.productpath)

    if limit is not None:
        scenes_to_process = self.scenes_to_process[:limit]
    else:
        scenes_to_process = self.scenes_to_process

    for scene in scenes_to_process:
        m.file_maintainer(scene=scene,
                          scenes_path=scenes_path,
                          name='persiann',
                          log_file=log_file)