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

WIP: fixed nc-bug, added dtype argument for monthly means, added quick fix… #14

Closed
wants to merge 7 commits into from

Conversation

sbnielsen
Copy link
Collaborator

… in case no ValidDate is in attribute for nc.

This branch is developed to make dlotter work for DANRA monthly means.

… in case no ValidDate is in attribute for nc
@sbnielsen sbnielsen marked this pull request as draft April 22, 2022 07:05
Comment on lines 98 to 102
parser_plot.add_argument('--dataset',
type=str,
help='Set to DANRAmm if DANRA monthly means are used.',
default='',
required=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either use default=None (empty strings are a bit dangerous) or set the variable as store_true so it can be used as a boolean flag instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed - should a similar change be added to --prefix and --postfix?

dlotter/plot.py Outdated Show resolved Hide resolved
@@ -183,7 +185,8 @@ def plot_t2m(self, args:argparse.Namespace, data:xr.Dataset) -> None:
colors='black',
levels=contour_levels,
linewidths=0.7,
transform=self.data_crs)
transform=self.data_crs,
transform_first=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

cool!

forecast = '1900-Jan-01 '+str(12+k)+':00:00'
else:
forecast = f.getncattr('ValidDate')

Copy link
Contributor

Choose a reason for hiding this comment

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

To prevent a clash when using many files, we could use a dummy starttime before the loop and use an iterator to update the forecasttime.

maybe something like:

Suggested change
dummy_time = dt.datetime(1900,1,1,0)
for k,f in enumerate(files_to_read):
f = nc.Dataset(files_to_read[k])
if not 'ValidDate' in f.ncattrs():
dummy_time+=dt.timedelta(minutes=k)
print('Warning: ValidDate not in attributes, setting date to {}'.format(dummy_time.strftime('%Y-%b-%d %H:%M:%S')))
forecast = dummy_time.strftime('%Y-%b-%d %H:%M:%S')
else:
forecast = f.getncattr('ValidDate')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Beautiful, but using k makes the time increase in a strange sequence, I think just using 1 minute for each file is "cleaner"?

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think we should give time as NaN if it is not found in the attributes. That will be much cleaner for the user.

@khintz khintz closed this Nov 24, 2023
@khintz khintz deleted the feature/danra branch November 30, 2023 07:27
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.

2 participants