Skip to content

Make Python scripts smarter about lons [-180, 180) vs. [0, 360) #3001

Closed
@samsrabin

Description

@samsrabin

Brief summary of bug

The lon_range_0_to_360() function currently assumes that a longitude is given in the [-180, 180) format only if it's negative. However:

  1. If one longitude is given in that format, it's likely that they both are. There is no such assumption made here.
  2. It will not detect or warn the user if the user tries to give two positive longitudes in the [-180, 180) format.

Affected tools:

  • subset_data
  • modify_fsurdat
  • mesh_mask_modifier

Suggested resolution: Require that the user specify whether longitudes are in the [-180, 180) or [0, 360) format.

General bug information

CTSM version you are using: ctsm5.3.026

Does this bug cause significantly incorrect results in the model's science? Potentially, yes. A user of subset_data, for instance, might end up with a domain shifted horizontally 180 degrees from what they intended.

Important output or errors that show the problem

tools/site_and_regional/subset_data region --lat1 0 --lat2 40 --lon1 -20 --lon2 40 --create-domain

This throws the following error because of #2017, but note that only one of the two longitudes was converted:

            ERROR: lon1 is bigger than lon2.
            lon1 points to the westernmost longitude of the region. 340.0
            lon2 points to the easternmost longitude of the region. 40.0
            Please make sure lon1 is smaller than lon2.

            Please note that if longitude in -180-0, the code automatically
            convert it to 0-360.

Metadata

Metadata

Assignees

Labels

bugsomething is working incorrectlytest: pythonPass clm_pymods test suite plus Python sys/unit tests before merging

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions