Skip to content

fix for ocean hosing (Sourcery refactored)#7

Open
sourcery-ai[bot] wants to merge 1 commit intolufrom
sourcery/lu
Open

fix for ocean hosing (Sourcery refactored)#7
sourcery-ai[bot] wants to merge 1 commit intolufrom
sourcery/lu

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Oct 6, 2021

Pull Request #6 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the lu branch, then run:

git fetch origin sourcery/lu
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from pgierz October 6, 2021 13:10
Comment on lines -9 to +53
if config["general"]["setup_name"] == "awiesm":
if config["fesom"].get("do_hosing"):
logger.info("Creating hosing files...")
hosing_type = config["fesom"].get("hosing_type")
if hosing_type == "homogeneous":
lat_0 = config["fesom"]["hosing_lat0"]
lat_1 = config["fesom"]["hosing_lat1"]
lon_0 = config["fesom"]["hosing_lon0"]
lon_1 = config["fesom"]["hosing_lon1"]
hosing_strength = config["fesom"]["hosing_strength"]
gfw_atmo_file = gfw_creator.create_homogeneous_hosing(
lat_0, lat_1, lon_0, lon_1, hosing_strength
)
gfw_atmo_file.to_netcdf(
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
)
logger.info(
f"Wrote {config['fesom']['thisrun_forcing_dir'] + '/gfw_atmo.nc'} for use in the simulation!"
)
config["oasis3mct"].setdefault("coupling_input_fields", {})
config["oasis3mct"]["coupling_input_fields"]["gfw_atmo"] = {
"freq": 86400,
"field_filepath": "gfw_atmo.nc",
}
config["fesom"].setdefault("forcing_files", {})
config["fesom"].setdefault("forcing_sources", {})
config["fesom"].setdefault("forcing_in_work", {})
if config["general"]["setup_name"] == "awiesm" and config["fesom"].get(
"do_hosing"
):
logger.info("Creating hosing files...")
hosing_type = config["fesom"].get("hosing_type")
if hosing_type == "homogeneous":
lat_0 = config["fesom"]["hosing_lat0"]
lat_1 = config["fesom"]["hosing_lat1"]
lon_0 = config["fesom"]["hosing_lon0"]
lon_1 = config["fesom"]["hosing_lon1"]
hosing_strength = config["fesom"]["hosing_strength"]
gfw_atmo_file = gfw_creator.create_homogeneous_hosing(
lat_0, lat_1, lon_0, lon_1, hosing_strength
)
gfw_atmo_file.to_netcdf(
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
)
logger.info(
f"Wrote {config['fesom']['thisrun_forcing_dir'] + '/gfw_atmo.nc'} for use in the simulation!"
)
config["oasis3mct"].setdefault("coupling_input_fields", {})
config["oasis3mct"]["coupling_input_fields"]["gfw_atmo"] = {
"freq": 86400,
"field_filepath": "gfw_atmo.nc",
}
config["fesom"].setdefault("forcing_files", {})
config["fesom"].setdefault("forcing_sources", {})
config["fesom"].setdefault("forcing_in_work", {})

config["fesom"]["forcing_files"]["gfw_atmo"] = "gfw_atmo"
config["fesom"]["forcing_sources"]["gfw_atmo"] = (
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
)
config["fesom"]["forcing_in_work"]["gfw_atmo"] = "gfw_atmo.nc"
return config
elif hosing_type == "from_file":
logger.error("Sorry, hosing from a file has no yet been implemented!")
sys.exit(1)
# TODO(PG): Later...
# hosing_file = config["fesom"]["hosing_file"]
else:
logger.error(
"Sorry, you must select between hosing_type: 'homogeneous' or hosing_type: 'from_file' in your fesom configuration!"
)
sys.exit(1)
config["fesom"]["forcing_files"]["gfw_atmo"] = "gfw_atmo"
config["fesom"]["forcing_sources"]["gfw_atmo"] = (
config["fesom"]["thisrun_forcing_dir"] + "/gfw_atmo.nc"
)
config["fesom"]["forcing_in_work"]["gfw_atmo"] = "gfw_atmo.nc"
return config
elif hosing_type == "from_file":
logger.error("Sorry, hosing from a file has no yet been implemented!")
sys.exit(1)
# TODO(PG): Later...
# hosing_file = config["fesom"]["hosing_file"]
else:
logger.error(
"Sorry, you must select between hosing_type: 'homogeneous' or hosing_type: 'from_file' in your fesom configuration!"
)
sys.exit(1)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function create_hosing_files refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai bot commented Oct 6, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.91%.

Quality metrics Before After Change
Complexity 8.00 ⭐ 6.00 ⭐ -2.00 👍
Method Length 110.00 🙂 110.00 🙂 0.00
Working memory 16.00 ⛔ 16.00 ⛔ 0.00
Quality 40.63% 😞 42.54% 😞 1.91% 👍
Other metrics Before After Change
Lines 52 53 1
Changed files Quality Before Quality After Quality Change
gfw_creator/esm_tools_plugin.py 40.63% 😞 42.54% 😞 1.91% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
gfw_creator/esm_tools_plugin.py create_hosing_files 6 ⭐ 213 ⛔ 16 ⛔ 42.54% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

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.

0 participants