-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from climate_downscale.extract.ncei_climate_stations import ( | ||
extract_ncei_climate_stations, | ||
) | ||
from climate_downscale.extract.era5 import ( | ||
extract_era5, | ||
extract_era5_task, | ||
) | ||
from climate_downscale.extract.ncei_climate_stations import ( | ||
extract_ncei_climate_stations, | ||
) | ||
|
||
RUNNERS = { | ||
'ncei': extract_ncei_climate_stations, | ||
"ncei": extract_ncei_climate_stations, | ||
"era5": extract_era5, | ||
} | ||
|
||
TASK_RUNNERS = { | ||
'ncei': extract_ncei_climate_stations, | ||
"ncei": extract_ncei_climate_stations, | ||
"era5": extract_era5_task, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
from rra_tools.shell_tools import wget | ||
from rra_tools.cli_tools import ( | ||
with_output_directory | ||
) | ||
import shutil | ||
import tempfile | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
import click | ||
import pandas as pd | ||
from rra_tools.cli_tools import with_output_directory | ||
from rra_tools.shell_tools import wget | ||
|
||
from climate_downscale.data import ClimateDownscaleData, DEFAULT_ROOT | ||
|
||
from climate_downscale.data import DEFAULT_ROOT, ClimateDownscaleData | ||
|
||
EXTRACTION_YEARS = list(range(1990, 1992)) | ||
URL_TEMPLATE = 'https://www.ncei.noaa.gov/data/global-summary-of-the-day/archive/{year}.tar.gz' | ||
URL_TEMPLATE = ( | ||
"https://www.ncei.noaa.gov/data/global-summary-of-the-day/archive/{year}.tar.gz" | ||
) | ||
|
||
|
||
def extract_ncei_climate_stations_main(output_dir: str | Path): | ||
def extract_ncei_climate_stations_main(output_dir: str | Path) -> None: | ||
cd_data = ClimateDownscaleData(output_dir) | ||
|
||
data = [] | ||
dfs = [] | ||
for year in EXTRACTION_YEARS: | ||
with tempfile.NamedTemporaryFile(suffix='.tar.gz') as f: | ||
with tempfile.NamedTemporaryFile(suffix=".tar.gz") as f: | ||
url = URL_TEMPLATE.format(year=year) | ||
|
||
wget(url, f.name) | ||
|
||
with tempfile.TemporaryDirectory() as outdir: | ||
shutil.unpack_archive(f.name, outdir) | ||
data.append( | ||
pd.concat([pd.read_csv(f) for f in Path(outdir).glob('*.csv')]) | ||
dfs.append( | ||
pd.concat([pd.read_csv(f) for f in Path(outdir).glob("*.csv")]) | ||
) | ||
data = pd.concat(data) | ||
data = pd.concat(dfs) | ||
|
||
data.to_parquet(cd_data.ncei_climate_stations / 'climate_stations.parquet') | ||
data.to_parquet(cd_data.ncei_climate_stations / "climate_stations.parquet") | ||
|
||
|
||
@click.command() | ||
@click.command() # type: ignore[arg-type] | ||
@with_output_directory(DEFAULT_ROOT) | ||
def extract_ncei_climate_stations(output_dir: str): | ||
def extract_ncei_climate_stations(output_dir: str) -> None: | ||
extract_ncei_climate_stations_main(output_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
def test_climate_downscale() -> None: | ||
from climate_downscale import cli | ||
|
||
assert cli |