-
Notifications
You must be signed in to change notification settings - Fork 112
Description
Version Checks (indicate both or one)
-
I have confirmed this bug exists on the lastest release of atlite.
-
I have confirmed this bug exists on the current
master
branch of atlite.
Issue Description
Hi all,
I am having issues to create atlitle cutouts with the Sarah module. The time resolution (dt) of the .nc files from Sarah is defined as "H", while atlite is looking for cutout.dt in ("30min", "30T", "h", "1h"). I have tried to modify the .nc files by opening each one with xarray and modify the "timefreq" attribute to "1h", so that atlite detects it. When I chech the attributes of the modified .nc files, I see that "timefreq" is set as "1h". However, when trying to do the atlite cutout, time resolution still shows as "H". I am working with instantaneous SIS and SID downloaded data from Sarah for the month of january 2013 and in Europe, and I downloaded and extracted all the files as explained in https://atlite.readthedocs.io/en/latest/examples/create_cutout_SARAH.html. I would appreciate some input on how to fix this bug. Thanks.
Reproducible Example
# I am trying something
import logging
import atlite
import xarray as xr
logging.basicConfig(level=logging.INFO)
import cdsapi
c = cdsapi.Client()
import os
import glob
import xarray as xr
# Original directory containing your SARAH NetCDF files
sarah_dir = r"C:/Users/marta/Desktop/Thesis/Climate-Change-Impacted-Solar-Energy-Generation/atlite examples/sarah2"
# New directory where fixed files will be saved
sarah_dir_fixed = r"C:/Users/marta/Desktop/Thesis/Climate-Change-Impacted-Solar-Energy-Generation/atlite examples/sarah2_fixed"
# Ensure the new directory exists
os.makedirs(sarah_dir_fixed, exist_ok=True)
# Pattern to find all .nc files in the original directory
file_pattern = os.path.join(sarah_dir, "*.nc")
# Loop over each NetCDF file in the directory
for file_path in glob.glob(file_pattern):
print(f"Processing: {file_path}")
# Open the dataset
ds = xr.open_dataset(file_path)
# Update or set the 'timefreq' attribute to "1h"
ds.attrs["timefreq"] = "1h"
# Optional resampling if needed
# ds = ds.resample(time="1H").nearest()
# Build a new filename in the 'sarah2_fixed' directory
# e.g. if file_path = ".../sarah2/file1.nc",
# we create ".../sarah2_fixed/file1_fixed.nc"
base_name = os.path.splitext(os.path.basename(file_path))[0]
new_file_path = os.path.join(sarah_dir_fixed, base_name + "_fixed.nc")
# Save the modified dataset
ds.to_netcdf(new_file_path)
# Close the dataset
ds.close()
print(f"Saved fixed file to: {new_file_path}")
print("All NetCDF files processed!")
cutout = atlite.Cutout(
path="europe-2013-01.nc",
module=["sarah", "era5"],
sarah_dir="C:/Users/marta/Desktop/Thesis/Climate-Change-Impacted-Solar-Energy-Generation/atlite examples/sarah2_fixed",
x=slice(-13.6913, 1.7712),
y=slice(49.9096, 60.8479),
time="2013-01",
)
print(f"Time resolution (dt): {cutout.dt}")
cutout.prepare()
Expected Behavior
Atlite should be able to prepare the cutout with time resolution of SARAH but it is not.
Installed Versions
Metadata
Metadata
Assignees
Labels
Type
Projects
Status