fix: enable proper running of backward dispersion models#82
Open
AlFontal wants to merge 4 commits intorich-iannone:mainfrom
Open
fix: enable proper running of backward dispersion models#82AlFontal wants to merge 4 commits intorich-iannone:mainfrom
AlFontal wants to merge 4 commits intorich-iannone:mainfrom
Conversation
The duration is computed as the difference between the start and end times. If the start time is after the end time, the duration is already negative, so we don't need to prepend a "-" to it or we have a double negative before the duration value and HYSPLIT crashes.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses #81, and also could be considered to address #66.
Basically, there were 2 really small errors that made the logic of running backwards dispersion models not work.
For starters, the
run_modelfunction has a hardcoded 'forward' parameter, so no matter the direction specified inadd_dispersion_params, thehysplit_dispersionfunction always received 'forward' as the parameter. This is fixedin commit caead2f.
Second, the
add_dispersion_paramsfunction has nodurationparameter. The value ofdurationthat is passed ontohysplit_dispersionis computed by the difference in hours between start_time and end_time:splitr/R/run_model.R
Line 51 in 4485112
In a backwards model, the
end_timeis before thestart_time, so this variable takes negative values.When writing the CONTROL file, however, there is an ifelse clause that prepends a '-' to the duration value. In the case of an already negative value, this writes a line with --duration, leading to a faulty CONTROL file that HYSPLIT doesn't accept and it just doesn't run. Removing the ifelse clause seems to work and is what I did in d4ca419.
It would be also nice to add some examples on how to run backward dispersion models, as there is none as of now.
I think that without this PR, a hacky way of running backward dispersion models is to simply use an
end_timethat is earlier than thestart_timeby as many hours as is desired, and then simply inputforwardin the direction parameter. This will write a negative duration value to the CONTROL file and HYSPLIT will read it and run it in backward mode anyway.I am rather unfamiliar on R package development as I am mainly a python developer, so I am pretty sure this PR might need several extra steps to make it workable.