anemoi-utils 0.3.1__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of anemoi-utils might be problematic. Click here for more details.

anemoi/utils/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.3.1'
16
- __version_tuple__ = version_tuple = (0, 3, 1)
15
+ __version__ = version = '0.3.2'
16
+ __version_tuple__ = version_tuple = (0, 3, 2)
anemoi/utils/cli.py CHANGED
@@ -41,7 +41,7 @@ def make_parser(description, commands):
41
41
 
42
42
  subparsers = parser.add_subparsers(help="commands:", dest="command")
43
43
  for name, command in commands.items():
44
- command_parser = subparsers.add_parser(name, help=command.__doc__)
44
+ command_parser = subparsers.add_parser(name, description=command.__doc__, help=command.__doc__)
45
45
  command.add_arguments(command_parser)
46
46
 
47
47
  return parser
anemoi/utils/s3.py ADDED
@@ -0,0 +1,57 @@
1
+ # (C) Copyright 2024 European Centre for Medium-Range Weather Forecasts.
2
+ # This software is licensed under the terms of the Apache Licence Version 2.0
3
+ # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
4
+ # In applying this licence, ECMWF does not waive the privileges and immunities
5
+ # granted to it by virtue of its status as an intergovernmental organisation
6
+ # nor does it submit to any jurisdiction.
7
+ import logging
8
+ import os
9
+ from contextlib import closing
10
+
11
+ import boto3
12
+ import tqdm
13
+
14
+ LOG = logging.getLogger(__name__)
15
+
16
+
17
+ def upload(source, target, overwrite=False, ignore_existing=False):
18
+ # https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html
19
+ assert target.startswith("s3://")
20
+
21
+ _, _, bucket, key = target.split("/", 3)
22
+
23
+ LOG.info(f"Uploading {source} to {target}")
24
+ s3_client = boto3.client("s3")
25
+
26
+ if not overwrite:
27
+ results = s3_client.list_objects(Bucket=bucket, Prefix=key)
28
+ if results.get("Contents"):
29
+ if ignore_existing:
30
+ LOG.info(f"{target} already exists, skipping")
31
+ return
32
+ else:
33
+ raise ValueError(f"{target} already exists, use --overwrite to replace")
34
+
35
+ size = os.path.getsize(source)
36
+ with closing(tqdm.tqdm(total=size, unit="B", unit_scale=True)) as t:
37
+ s3_client.upload_file(source, bucket, key, Callback=lambda x: t.update(x))
38
+
39
+ LOG.info(f"{target} is ready")
40
+
41
+
42
+ def download(source, target, overwrite=False):
43
+ assert source.startswith("s3://")
44
+
45
+ _, _, bucket, key = source.split("/", 3)
46
+
47
+ s3 = boto3.client("s3")
48
+ response = s3.head_object(Bucket=bucket, Key=key)
49
+ size = response["ContentLength"]
50
+
51
+ if not overwrite:
52
+ if os.path.exists(source) and os.path.getsize(source) == size:
53
+ LOG.info(f"{source} already exists, skipping")
54
+ return
55
+
56
+ with closing(tqdm.tqdm(total=size, unit="B", unit_scale=True)) as t:
57
+ s3.download_file(bucket, key, target, Callback=lambda x: t.update(x))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anemoi-utils
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A package to hold various functions to support training of ML models on ECMWF data.
5
5
  Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
6
6
  License: Apache License
@@ -1,23 +1,24 @@
1
1
  anemoi/utils/__init__.py,sha256=zZZpbKIoGWwdCOuo6YSruLR7C0GzvzI1Wzhyqaa0K7M,456
2
2
  anemoi/utils/__main__.py,sha256=cLA2PidDTOUHaDGzd0_E5iioKYNe-PSTv567Y2fuwQk,723
3
- anemoi/utils/_version.py,sha256=HzPz9rq3s1AiZXregKlqKaJJ2wGMtvH_a3V9la9CnpM,411
3
+ anemoi/utils/_version.py,sha256=9jP8Fo8egXoMs_T3DFqSuJYg4n9o9mnwYubl_hnut4k,411
4
4
  anemoi/utils/caching.py,sha256=HrC9aFHlcCTaM2Z5u0ivGIXz7eFu35UQQhUuwwuG2pk,1743
5
5
  anemoi/utils/checkpoints.py,sha256=1_3mg4B-ykTVfIvIUEv7IxGyREx_ZcilVbB3U-V6O6I,5165
6
- anemoi/utils/cli.py,sha256=39THXs5SVtJ3L4ugemgbRIlK4ivEGraSsu5ns9KUn68,3271
6
+ anemoi/utils/cli.py,sha256=d3TT9WSm6TDkbaJ9fL74wWG91Y27a9Uh17fPM4SomTs,3300
7
7
  anemoi/utils/config.py,sha256=XEesqODvkuE3ZA7dnEnZ-ooBRtU6ecPmkfP65FtialA,2147
8
8
  anemoi/utils/dates.py,sha256=Ot9OTY1uFvHxW1EU4DPv3oUqmzvkXTwKuwhlfVlY788,8426
9
9
  anemoi/utils/grib.py,sha256=gVfo4KYQv31iRyoqRDwk5tiqZDUgOIvhag_kO0qjYD0,3067
10
10
  anemoi/utils/humanize.py,sha256=LD6dGnqChxA5j3tMhSybsAGRQzi33d_qS9pUoUHubkc,10330
11
11
  anemoi/utils/provenance.py,sha256=v54L9jF1JgYcclOhg3iojRl1v3ajbiWz_oc289xTgO4,9574
12
+ anemoi/utils/s3.py,sha256=HG3YulSwBvutTOZe0vY9oDkXExtUCcr26U9WObzl2I4,2024
12
13
  anemoi/utils/text.py,sha256=pGWtDvRFoDxAnSuZJiA-GOGJOJLHsw2dAm0tfVvPKno,8599
13
14
  anemoi/utils/timer.py,sha256=JKOgFkpJxmVRn57DEBolmTGwr25P-ePTWASBd8CLeqM,972
14
15
  anemoi/utils/commands/__init__.py,sha256=qAybFZPBBQs0dyx7dZ3X5JsLpE90pwrqt1vSV7cqEIw,706
15
16
  anemoi/utils/commands/checkpoint.py,sha256=SEnAizU3WklqMXUjmIh4eNrgBVwmheKG9gEBS90zwYU,1741
16
17
  anemoi/utils/mars/__init__.py,sha256=RAeY8gJ7ZvsPlcIvrQ4fy9xVHs3SphTAPw_XJDtNIKo,1750
17
18
  anemoi/utils/mars/mars.yaml,sha256=R0dujp75lLA4wCWhPeOQnzJ45WZAYLT8gpx509cBFlc,66
18
- anemoi_utils-0.3.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
19
- anemoi_utils-0.3.1.dist-info/METADATA,sha256=Byi0PexhF8x5mUW-Pc0uChEfxMvtQctOHg9czUVfN0g,15513
20
- anemoi_utils-0.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
21
- anemoi_utils-0.3.1.dist-info/entry_points.txt,sha256=LENOkn88xzFQo-V59AKoA_F_cfYQTJYtrNTtf37YgHY,60
22
- anemoi_utils-0.3.1.dist-info/top_level.txt,sha256=DYn8VPs-fNwr7fNH9XIBqeXIwiYYd2E2k5-dUFFqUz0,7
23
- anemoi_utils-0.3.1.dist-info/RECORD,,
19
+ anemoi_utils-0.3.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
20
+ anemoi_utils-0.3.2.dist-info/METADATA,sha256=hZoPO-WGvJS7uOsRUxTd_RvyG27KvL6uXHEL638vnZg,15513
21
+ anemoi_utils-0.3.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
22
+ anemoi_utils-0.3.2.dist-info/entry_points.txt,sha256=LENOkn88xzFQo-V59AKoA_F_cfYQTJYtrNTtf37YgHY,60
23
+ anemoi_utils-0.3.2.dist-info/top_level.txt,sha256=DYn8VPs-fNwr7fNH9XIBqeXIwiYYd2E2k5-dUFFqUz0,7
24
+ anemoi_utils-0.3.2.dist-info/RECORD,,