goesgcp 2.0.6__py3-none-any.whl → 2.0.8__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.
goesgcp/main.py CHANGED
@@ -2,6 +2,7 @@ import pathlib
2
2
  import shutil
3
3
  import time
4
4
  import xarray as xr
5
+ import subprocess
5
6
  import argparse
6
7
  import sys
7
8
  import tqdm
@@ -269,8 +270,65 @@ def crop_reproject(args):
269
270
  output_file = f"{output_directory}{file.split('/')[-1]}"
270
271
  ds.to_netcdf(output_file, mode='w')
271
272
 
273
+ # Close the file
272
274
  ds.close()
273
275
 
276
+ return output_file
277
+
278
+
279
+
280
+ def remap_file(args):
281
+ """ Remap the download file based on the input file. """
282
+
283
+ base_file, target_file, var_name, save_format, output = args
284
+
285
+ # Open the files
286
+ base_ds = xr.open_dataset(base_file, engine="netcdf4")
287
+
288
+ if save_format == 'by_date':
289
+ file_datetime = datetime.strptime(ds.time_coverage_start,
290
+ "%Y-%m-%dT%H:%M:%S.%fZ")
291
+ year = file_datetime.strftime("%Y")
292
+ month = file_datetime.strftime("%m")
293
+ day = file_datetime.strftime("%d")
294
+ output_directory = f"{output}{year}/{month}/{day}/"
295
+ elif save_format == 'julian':
296
+ file_datetime = datetime.strptime(ds.time_coverage_start,
297
+ "%Y-%m-%dT%H:%M:%S.%fZ")
298
+ year = file_datetime.strftime("%Y")
299
+ julian_day = file_datetime.timetuple().tm_yday
300
+ output_directory = f"{output}{year}/{julian_day}/"
301
+ else:
302
+ output_directory = output
303
+
304
+ # Create the output directory
305
+ pathlib.Path(output_directory).mkdir(parents=True, exist_ok=True)
306
+
307
+ output_file = f"{output_directory}{target_file.split('/')[-1]}"
308
+
309
+ # Add _ into output_file to prevent overwrite
310
+ output_file = output_file.replace(".nc", "_remap.nc")
311
+
312
+ # Run the cdo command
313
+ cdo_command = [
314
+ "cdo", "remapnn," + base_file, target_file, output_file
315
+ ]
316
+
317
+ try:
318
+ subprocess.run(cdo_command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
319
+ except subprocess.CalledProcessError as e:
320
+ print(f"Error remapping file {target_file}: {e}")
321
+ pass
322
+
323
+ # Close the files
324
+ base_ds.close()
325
+
326
+ # Delete the target file
327
+ pathlib.Path(target_file).unlink()
328
+
329
+ # Rename the output file
330
+ pathlib.Path(output_file).rename(target_file)
331
+
274
332
 
275
333
  def process_file(args):
276
334
  """
@@ -278,7 +336,7 @@ def process_file(args):
278
336
  """
279
337
 
280
338
  bucket_name, blob_name, local_path, output_path, var_name, lat_min, lat_max, lon_min, lon_max, resolution, \
281
- save_format, retries = args
339
+ save_format, retries, remap = args
282
340
 
283
341
  attempt = 0
284
342
  while attempt < retries:
@@ -300,7 +358,13 @@ def process_file(args):
300
358
  log_file.write(f"Failed to download {blob_name} after {retries} attempts. Error: {e}\n")
301
359
 
302
360
  # Crop the file
303
- crop_reproject((local_path, output_path, var_name, lat_min, lat_max, lon_min, lon_max, resolution, save_format))
361
+ output_file = crop_reproject((local_path, output_path, var_name,
362
+ lat_min, lat_max, lon_min, lon_max, resolution, save_format))
363
+
364
+ # Remap the file
365
+ if remap is not None:
366
+ # Remap the file
367
+ remap_file((remap, output_file, var_name, save_format, output_path))
304
368
 
305
369
  # Remove the local file
306
370
  pathlib.Path(local_path).unlink()
@@ -373,6 +437,9 @@ def main():
373
437
  parser.add_argument('--resolution', type=float, default=0.03208, help='Resolution of the output file')
374
438
  parser.add_argument('--output', type=str, default='output/', help='Path for saving output files')
375
439
 
440
+ # Remap
441
+ parser.add_argument('--remap', type=str, default=None, help='Give a input file to remap the output')
442
+
376
443
  # Other settings
377
444
  parser.add_argument('--parallel', type=lambda x: bool(strtobool(x)), default=True, help='Use parallel processing')
378
445
  parser.add_argument('--processes', type=int, default=4, help='Number of processes for parallel execution')
@@ -409,6 +476,7 @@ def main():
409
476
  bt_hour = args.bt_hour
410
477
  bt_min = args.bt_min
411
478
  save_format = args.save_format
479
+ remap = args.remap
412
480
 
413
481
 
414
482
  # Check mandatory arguments
@@ -466,7 +534,7 @@ def main():
466
534
  # Create a list of tasks
467
535
  tasks = [(bucket_name, file, f"tmp/{file.split('/')[-1]}", output_path, var_name,
468
536
  lat_min, lat_max, lon_min, lon_max, resolution,
469
- save_format, max_attempts) for file in files_list]
537
+ save_format, max_attempts, remap) for file in files_list]
470
538
 
471
539
  # Download files in parallel
472
540
  with Pool(processes=args.processes) as pool:
@@ -478,7 +546,7 @@ def main():
478
546
  local_path = f"tmp/{file.split('/')[-1]}"
479
547
  process_file((bucket_name, file, local_path, output_path, var_name,
480
548
  lat_min, lat_max, lon_min, lon_max, resolution,
481
- save_format, max_attempts))
549
+ save_format, max_attempts, remap))
482
550
  loading_bar.update(1)
483
551
  loading_bar.close()
484
552
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: goesgcp
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: A package to download and process GOES-16/17 data
5
5
  Home-page: https://github.com/helvecioneto/goesgcp
6
6
  Author: Helvecio B. L. Neto
@@ -12,11 +12,15 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Topic :: Scientific/Engineering
16
- Classifier: Topic :: Software Development
17
- Classifier: Topic :: Utilities
15
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
16
+ Classifier: Topic :: Scientific/Engineering :: GIS
18
17
  Description-Content-Type: text/markdown
19
18
  License-File: LICENSE
19
+ Requires-Dist: google-cloud-storage
20
+ Requires-Dist: pyproj
21
+ Requires-Dist: xarray
22
+ Requires-Dist: netcdf4
23
+ Requires-Dist: rioxarray
20
24
  Dynamic: author
21
25
  Dynamic: author-email
22
26
  Dynamic: classifier
@@ -24,12 +28,14 @@ Dynamic: description
24
28
  Dynamic: description-content-type
25
29
  Dynamic: home-page
26
30
  Dynamic: license
31
+ Dynamic: requires-dist
27
32
  Dynamic: summary
28
33
 
29
34
  # goesgcp
30
35
  <!-- badges: start -->
31
36
  [![pypi](https://badge.fury.io/py/goesgcp.svg)](https://pypi.python.org/pypi/goesgcp)
32
37
  [![Downloads](https://img.shields.io/pypi/dm/goesgcp.svg)](https://pypi.python.org/pypi/goesgcp)
38
+ [![Upload Python Package](https://github.com/helvecioneto/goesgcp/actions/workflows/python-publish.yml/badge.svg)](https://github.com/helvecioneto/goesgcp/actions/workflows/python-publish.yml)
33
39
  [![Contributors](https://img.shields.io/github/contributors/helvecioneto/goesgcp.svg)](https://github.com/helvecioneto/goesgcp/graphs/contributors)
34
40
  [![License](https://img.shields.io/pypi/l/goesgcp.svg)](https://github.com/helvecioneto/goesgcp/blob/main/LICENSE)
35
41
  <!-- badges: end -->
@@ -81,6 +87,7 @@ goesgcp [OPTIONS]
81
87
  | `--bt_hour` | Hour of the day to download data (default: [0, 1, ..., 23]). |
82
88
  | `--bt_minute` | Minute of the hour to download data (default: [0, 15, 30, 45]). |
83
89
  | `--save_format` | Format for saving output files (default: `by_date`). |
90
+ | `--remap` | Remap the data based on file (This function are in development). |
84
91
 
85
92
  #### Available GOES Products
86
93
  A comprehensive list of available GOES products can be found at the following link: [https://console.cloud.google.com/storage/browser/gcp-public-data-goes-16](https://console.cloud.google.com/storage/browser/gcp-public-data-goes-16)
@@ -0,0 +1,7 @@
1
+ goesgcp/__init__.py,sha256=MigXIT7A1M9YZuH2MyjKReSziFwzbZX2boVYsLosR6s,22
2
+ goesgcp/main.py,sha256=q_VS69wYxtC1gRbOnn3HetHroBSxykWlKAK6PJVD0nI,21388
3
+ goesgcp-2.0.8.dist-info/LICENSE,sha256=AHeZifD4UyBZI61Ug5lETXgX3Anp_XfAvFXQqrW9AnU,1078
4
+ goesgcp-2.0.8.dist-info/METADATA,sha256=Nu1pFFeX8ZM-ipfVhJouEWOdioiR8QkOXbWVulNHv6w,6457
5
+ goesgcp-2.0.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
+ goesgcp-2.0.8.dist-info/top_level.txt,sha256=C-C3vipI0AwEDW9nWFkJ6D0TkcKkIYlyyM15LMskUEc,8
7
+ goesgcp-2.0.8.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- goesgcp/__init__.py,sha256=MigXIT7A1M9YZuH2MyjKReSziFwzbZX2boVYsLosR6s,22
2
- goesgcp/main.py,sha256=o7JNz6QXmDToy5tCwPnQuEqmflSlQ8GZvo064o1srRw,19185
3
- goesgcp-2.0.6.dist-info/LICENSE,sha256=AHeZifD4UyBZI61Ug5lETXgX3Anp_XfAvFXQqrW9AnU,1078
4
- goesgcp-2.0.6.dist-info/METADATA,sha256=XPRkAxFiC-9yaE-wsZxtbRxzpPn72HskUOLRKkdOzBY,6010
5
- goesgcp-2.0.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
- goesgcp-2.0.6.dist-info/entry_points.txt,sha256=6afMW51WnUR9VZ_xvDoiB8JQb2OFiLuzRtV6dPL__OQ,46
7
- goesgcp-2.0.6.dist-info/top_level.txt,sha256=C-C3vipI0AwEDW9nWFkJ6D0TkcKkIYlyyM15LMskUEc,8
8
- goesgcp-2.0.6.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- goesgcp = goesgcp.main:main