Skip to content

Commit

Permalink
Updated libraries and tests so that everything is passing (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankinspace authored Jul 27, 2023
1 parent 90e9a59 commit cc40550
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 580 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Project migrated to https://github.com/podaac/net2cog

## [0.2.0-alpha.15] - 26 July 2023
### Added
- PCESA-2309 - Implemented the harmony-service-lib interface so that I can be run in the Harmony ngap account
### Changed
- PCESA-2309 - Updated Jenkins to include building and pushing to ECC_NEXUS
### Deprecated
### Removed
### Fixed
### Security
- PCESA-2309 - Updated Jenkins to include building and pushing to ECC_NEXUS

## [0.2.0-alpha.14] - 3 September 2020
### Changed
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
"""

import os
import pathlib
from os.path import join as pjoin, basename, dirname, exists, splitext
import subprocess
from subprocess import check_call

import logging
import tempfile
from typing import List

import xarray as xr
import rasterio
import rasterio.crs
Expand Down Expand Up @@ -61,7 +64,7 @@ def get_gtiff_name(output_file):
out_fname = pjoin(dir_path, rel_path)
if not exists(out_fname):
os.makedirs(out_fname)
return out_fname
return pjoin(out_fname, rel_path)


def _write_cogtiff(out_f_name, nc_xarray):
Expand Down Expand Up @@ -135,31 +138,22 @@ def rioxr_swapdims(netcdf_xarray):
dst_profile = cog_profiles.get("deflate")
cog_translate(src_dst, out_fname, dst_profile)

# cog validation method
# cogtif_val = [
# 'rio',
# 'cogeo',
# 'validate',
# out_fname
# ]
# run_command(cogtif_val, dirname(out_f_name))

cogs_generated.append(out_fname)
LOGGER.info("Finished conversion, writing variable: %s", out_fname)
LOGGER.info("NetCDF conversion complete. Returning COGs generated.")
return cogs_generated


def netcdf_converter(input_nc_file, output_cog_pathname, var_list=None):
def netcdf_converter(input_nc_file: pathlib.Path, output_cog_pathname: pathlib.Path, var_list: list = ()) -> List[str]:
"""
Primary function for beginning NetCDF conversion using rasterio,
rioxarray and xarray
Parameters
----------
input_nc_file : string
input_nc_file : pathlib.Path
Path to NetCDF file to process
output_cog_pathname : string
output_cog_pathname : pathlib.Path
COG Output path and NetCDF filename, filename converted to cog variable
filename (.tif)
ex: tests/data/tmpygj2vgxf/
Expand Down Expand Up @@ -189,7 +183,7 @@ def netcdf_converter(input_nc_file, output_cog_pathname, var_list=None):
# used to invert y axis
# xds_reversed = xds.reindex(lat=xds.lat[::-1])
LOGGER.info("Writing COG to %s", basename(gtiff_fname))
if var_list is not None and var_list != '':
if var_list:
xds = xds[var_list]
return _write_cogtiff(gtiff_fname, xds)
LOGGER.error("%s: NetCDF file does not contain spatial dimensions such as lat / lon "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
import pathlib

import harmony
import harmony.util
from harmony import BaseHarmonyAdapter

from podaac.netcdf_converter import netcdf_convert
from net2cog import netcdf_convert

DATA_DIRECTORY_ENV = "DATA_DIRECTORY"


class NetcdfConverterService(BaseHarmonyAdapter):
class NetcdfConverterService(harmony.BaseHarmonyAdapter):
"""
See https://git.earthdata.nasa.gov/projects/HARMONY/repos/harmony-service-lib-py/browse
See https://github.com/nasa/harmony-service-lib-py
for documentation and examples.
"""

Expand Down
File renamed without changes.
140 changes: 0 additions & 140 deletions podaac/netcdf_converter/netcdf_convert_worker.py

This file was deleted.

Loading

0 comments on commit cc40550

Please sign in to comment.