Skip to content

Commit

Permalink
add ability to skip cache
Browse files Browse the repository at this point in the history
  • Loading branch information
egagli committed Apr 1, 2024
1 parent b66bd9d commit 33749b0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions easysnowdata/automatic_weather_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,18 @@ def get_multiple_station_data(self, variables="WTEQ", start_date='1900-01-01', e
f"Full {variables} dataset has been added to the station object. Please use the .data attribute to access the dataset."
)

def get_entire_data_archive(self, temp_dir: str = "/tmp/") -> xr.Dataset:
def get_entire_data_archive(self, refresh: bool = True, temp_dir: str = "/tmp/") -> xr.Dataset:
"""
Downloads, decompresses and processes automatic weather station data into an xarray Dataset.
This function downloads a compressed file containing weather station data from a specific URL,
decompresses the file, and processes the data into an xarray Dataset. The data is organized by station,
with each station's data stored in a separate CSV file. The function also adds additional coordinates
to the Dataset from a provided GeoDataFrame.
to the Dataset from a provided GeoDataFrame. Set the refresh parameter to True to redownload cached data.
Parameters:
all_stations_gdf (GeoDataFrame): A GeoDataFrame containing additional data for each station.
refresh (bool, optional): If True, the compressed data file will be redownloaded. Defaults to True.
temp_dir (str, optional): The directory where the compressed data file will be downloaded and decompressed.
Defaults to '/tmp/'.
Expand All @@ -294,15 +295,15 @@ def get_entire_data_archive(self, temp_dir: str = "/tmp/") -> xr.Dataset:
compressed_file_path = pathlib.Path(temp_dir, "all_station_data.tar.lzma")
decompressed_dir_path = pathlib.Path(temp_dir, "data")

if not compressed_file_path.exists():
if not compressed_file_path.exists() or refresh:
print(
f"Downloading compressed data to a temporary directory ({compressed_file_path})..."
)
subprocess.run(
["wget", "-q", "-P", temp_dir, github_tar_file_path], check=True
)

if not decompressed_dir_path.exists():
if not decompressed_dir_path.exists() or refresh:
print(f"Decompressing data...")
subprocess.run(
["tar", "--lzma", "-xf", str(compressed_file_path), "-C", temp_dir],
Expand Down

0 comments on commit 33749b0

Please sign in to comment.