Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solarsally #181

Merged
merged 16 commits into from
Oct 9, 2024
Merged

Solarsally #181

merged 16 commits into from
Oct 9, 2024

Conversation

SallyElHajjar
Copy link
Collaborator

@SallyElHajjar SallyElHajjar commented Oct 4, 2024

I have added two options for the testing file, one for GCP and another for fake data. I have also tested both of them locally, it works with no error. Now the same code handles both fake and real data. @Katsutoshii

Copy link
Collaborator

@Katsutoshii Katsutoshii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just move the remote data dependency to a separate python file so it's not under unit test.

ds = xarray.open_dataset(io.BytesIO(ncfile_bytes))

# Initialize Google Cloud Storage client
storage_client = storage.Client()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the storage client code once debugging is complete.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# Set the time using numpy.datetime64 for the expected format
times[0] = numpy.datetime64("2010-02-02T18:00:00")
# Close the NetCDF file and retrieve its contents as bytes
memfile = ncfile.close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on my understanding we retrieve the contents of ncfile using memfile.tobytes(). I'm concerned about memfile = ncfile.close(), because the close() method doesn’t return any value, leading to a potential error.
just be careful and consider not closing the NetCDF file until after assigned the necessary data for xarray

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is with in-memory NetCDF files using netCDF4.Dataset, the behavior is a bit different than in typical file handling when the memory parameter is set to 1 (indicating in-memory storage). By specifying memory=1, we are instructing netCDF4 to create a file in memory instead of on disk, which changes the behavior of how the file is handled. now when we use "memfile = ncfile.close()" , instead of simply closing the file, the in-memory buffer (which contains the NetCDF file's contents) is returned. This buffer is similar to a file-like object, and we can then access the contents in bytes.

@SallyElHajjar SallyElHajjar merged commit 02edb3e into main Oct 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants