If in controlled airspace it's determined by ATC, unless you are cleared at your discretion. If flying GA in uncontrolled airspace, it's based on published pattern altitude of the airport you are landing at, factoring in your airspeed, groundspeed, wind direction, and distance from the airport...